his_api_controller.go 365KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  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. }
  83. func (c *PublicApiController) GetBaiLinExportData() {
  84. data := service.GetBaiLinOrderData()
  85. fmt.Println(len(data))
  86. var new_data []*models.NewCustomHisOrder
  87. for _, item := range data {
  88. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  89. new_data = append(new_data, item)
  90. }
  91. }
  92. fmt.Println(len(new_data))
  93. c.ServeSuccessJSON(map[string]interface{}{
  94. "list": new_data,
  95. })
  96. }
  97. func (c *HisApiController) GetHisUnChargePatientList() {
  98. record_date := c.GetString("record_date")
  99. timeLayout := "2006-01-02"
  100. loc, _ := time.LoadLocation("Local")
  101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  102. if err != nil {
  103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. recordDateTime := theTime.Unix()
  107. adminInfo := c.GetAdminUserInfo()
  108. var tempPatients []*service.NewTempPatients
  109. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  110. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  111. var patients []*service.NewTempPatients
  112. var patients_two []*service.NewTempPatients
  113. for _, item := range tempPatients {
  114. //过滤掉没挂号的和没开处方的
  115. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  116. patients = append(patients, item)
  117. }
  118. //过滤掉没挂号的
  119. if len(item.HisPatient) > 0 {
  120. patients_two = append(patients_two, item)
  121. }
  122. }
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "list": patients,
  125. "list_two": patients_two,
  126. })
  127. }
  128. func (c *HisApiController) GetPrivateExpensesOrder() {
  129. //id, _ := c.GetInt64("id")
  130. //record_time := c.GetString("record_time")
  131. order_id, _ := c.GetInt64("order_id")
  132. admin_user_id, _ := c.GetInt64("admin_user_id")
  133. //timeLayout := "2006-01-02"
  134. //loc, _ := time.LoadLocation("Local")
  135. //
  136. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  137. //if err != nil {
  138. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. // return
  140. //}
  141. //recordDateTime := theTime.Unix()
  142. adminUser := c.GetAdminUserInfo()
  143. order, _ := service.GetHisOrderByID(order_id)
  144. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  145. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  146. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  147. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  148. //var config []*models.HisXtDiagnoseConfig
  149. var name string
  150. if order.PType == 1 {
  151. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  152. for _, item := range diagnosis_ids {
  153. id, _ := strconv.ParseInt(item, 10, 64)
  154. diagnosisConfig, _ := service.FindDiagnoseById(id)
  155. if len(name) == 0 {
  156. name = diagnosisConfig.ClassName
  157. } else {
  158. name = name + "," + diagnosisConfig.ClassName
  159. }
  160. }
  161. } else {
  162. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  163. for _, item := range diagnosis_ids {
  164. id, _ := strconv.ParseInt(item, 10, 64)
  165. diagnosisConfig, _ := service.FindDiagnoseById(id)
  166. if len(name) == 0 {
  167. name = diagnosisConfig.ClassName
  168. } else {
  169. name = name + "," + diagnosisConfig.ClassName
  170. }
  171. }
  172. }
  173. var bedCostTotal float64 = 0 //床位总费
  174. //var bedCostSelfTotal float64 = 0 //床位自费
  175. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  176. var operationCostTotal float64 = 0 //手术费
  177. //var operationCostSelfTotal float64 = 0 //手术费
  178. var operationCostPartSelfTotal float64 = 0 //手术费
  179. var otherCostTotal float64 = 0 //其他费用
  180. //var otherCostSelfTotal float64 = 0 //其他费用
  181. var otherCostPartSelfTotal float64 = 0 //其他费用
  182. var materialCostTotal float64 = 0 //材料费
  183. //var materialCostSelfTotal float64 = 0 //材料费
  184. var materialCostPartSelfTotal float64 = 0 //材料费
  185. var westernMedicineCostTotal float64 = 0 //西药费
  186. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  187. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  188. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  189. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  190. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  191. var checkCostTotal float64 = 0 //检查费
  192. //var checkCostSelfTotal float64 = 0 //检查费
  193. var checkCostPartSelfTotal float64 = 0 //检查费
  194. var laboratoryCostTotal float64 = 0 //化验费
  195. //var laboratoryCostSelfTotal float64 = 0 //化验费
  196. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  197. var treatCostTotal float64 = 0 //治疗费用
  198. //var treatCostSelfTotal float64 = 0 //治疗费用
  199. var treatCostPartSelfTotal float64 = 0 //治疗费用
  200. var zhenChaCostTotal float64 = 0 //其他费用
  201. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  202. decimal.DivisionPrecision = 2
  203. for _, item := range orderInfos {
  204. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  205. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  206. item.MedChrgitmType = "09"
  207. }
  208. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  209. if item.HisPrescriptionProject.Type == 2 {
  210. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  211. fmt.Println("CostClassify")
  212. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  213. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  214. case 0:
  215. item.MedChrgitmType = "0"
  216. break
  217. case 1:
  218. item.MedChrgitmType = "14"
  219. break
  220. case 2:
  221. item.MedChrgitmType = "05"
  222. break
  223. case 3:
  224. item.MedChrgitmType = "03"
  225. break
  226. case 4:
  227. item.MedChrgitmType = "03"
  228. break
  229. case 5:
  230. item.MedChrgitmType = "08"
  231. break
  232. case 6:
  233. item.MedChrgitmType = "14"
  234. break
  235. case 7:
  236. item.MedChrgitmType = "14"
  237. break
  238. case 8:
  239. item.MedChrgitmType = "03"
  240. break
  241. case 9:
  242. item.MedChrgitmType = "14"
  243. break
  244. case 10:
  245. item.MedChrgitmType = "14"
  246. break
  247. case 11:
  248. item.MedChrgitmType = "06"
  249. break
  250. case 12:
  251. item.MedChrgitmType = "12"
  252. break
  253. case 13:
  254. item.MedChrgitmType = "01"
  255. break
  256. case 14:
  257. item.MedChrgitmType = "04"
  258. break
  259. case 15:
  260. item.MedChrgitmType = "14"
  261. break
  262. }
  263. } else {
  264. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  265. case 1:
  266. item.MedChrgitmType = "14"
  267. break
  268. case 2:
  269. item.MedChrgitmType = "05"
  270. break
  271. case 3:
  272. item.MedChrgitmType = "04"
  273. break
  274. case 4:
  275. item.MedChrgitmType = "14"
  276. break
  277. case 5:
  278. item.MedChrgitmType = "08"
  279. break
  280. case 6:
  281. item.MedChrgitmType = "14"
  282. break
  283. case 7:
  284. item.MedChrgitmType = "14"
  285. break
  286. case 8:
  287. item.MedChrgitmType = "03"
  288. break
  289. case 9:
  290. item.MedChrgitmType = "14"
  291. break
  292. }
  293. }
  294. } else if item.HisPrescriptionProject.Type == 3 {
  295. item.MedChrgitmType = "08"
  296. }
  297. }
  298. }
  299. order.PsnCashPay = order.MedfeeSumamt
  300. for _, item := range orderInfos {
  301. if item.MedChrgitmType == "01" { //床位费
  302. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. }
  306. if item.MedChrgitmType == "02" { //诊察费
  307. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  308. //zhenChaCostSelfTotal = zhenChaCostTotal
  309. }
  310. if item.MedChrgitmType == "03" { //检查费
  311. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  312. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  313. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "02" { //检查费
  316. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. }
  320. if item.MedChrgitmType == "04" { //化验费
  321. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  322. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  323. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  324. }
  325. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  326. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  327. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  328. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  329. }
  330. if item.MedChrgitmType == "06" { //手术费
  331. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  332. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  333. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  334. }
  335. if item.MedChrgitmType == "08" { //材料费
  336. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  337. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  338. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  339. }
  340. if item.MedChrgitmType == "09" { //西药费
  341. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  342. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  343. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  344. }
  345. if item.MedChrgitmType == "11" { //中成费
  346. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  347. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  348. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  349. }
  350. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  351. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  352. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  353. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  354. }
  355. }
  356. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  357. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  358. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  359. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  360. c.ServeSuccessJSON(map[string]interface{}{
  361. "patient": patient,
  362. "order_infos": orderInfos,
  363. "diagnosis": name,
  364. "bedCostTotal": bedCostTotal,
  365. "bedCostSelfTotal": bedCostTotal,
  366. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  367. "operationCostTotal": operationCostTotal,
  368. "operationCostSelfTotal": operationCostTotal,
  369. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  370. "otherCostTotal": otherCostTotal,
  371. "otherCostSelfTotal": otherCostTotal,
  372. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  373. "materialCostTotal": materialCostTotal,
  374. "materialCostSelfTotal": materialCostTotal,
  375. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  376. "westernMedicineCostTotal": westernMedicineCostTotal,
  377. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  378. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  379. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  380. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  381. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  382. "checkCostTotal": checkCostTotal,
  383. "checkCostSelfTotal": checkCostTotal,
  384. "zhenChaCostTotal": zhenChaCostTotal,
  385. "zhenChaCostSelfTotal": zhenChaCostTotal,
  386. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  387. "laboratoryCostTotal": laboratoryCostTotal,
  388. "laboratoryCostSelfTotal": laboratoryCostTotal,
  389. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  390. "treatCostTotal": treatCostTotal,
  391. "treatCostSelfTotal": treatCostTotal,
  392. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  393. "charge_admin": charge_admin,
  394. "printor_admin": printor_admin,
  395. "org_name": org.OrgName,
  396. "org_code": miConfig.Code,
  397. "name": patient.Name,
  398. "number": order.MdtrtId,
  399. "date": order.SettleAccountsDate,
  400. "info": order,
  401. "his_hospital": his_hospital,
  402. "his": his,
  403. })
  404. }
  405. func (c *HisApiController) RefudDetail() {
  406. order_id, _ := c.GetInt64("order_id")
  407. order, _ := service.GetHisOrderByID(order_id)
  408. adminUser := c.GetAdminUserInfo()
  409. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  410. c.ServeSuccessJSON(map[string]interface{}{
  411. "msg": "撤销成功",
  412. })
  413. }
  414. func (c *HisApiController) Sscard() {
  415. //r := CardInit()
  416. //if r == 0 {
  417. // GetBaseInfo()
  418. //}
  419. //c.ServeSuccessJSON(map[string]interface{}{
  420. // "list": "11",
  421. //})
  422. }
  423. func GetBaseInfo() error {
  424. //handle := syscall.MustLoadDLL("SSCard.dll")
  425. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  426. //
  427. //str := make([]byte, 256)
  428. //str1 := make([]byte, 256)
  429. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  430. //if ferr != nil {
  431. // fmt.Println("ReadCardBas 报错", ferr.Error())
  432. // return ferr
  433. //}
  434. //
  435. //fmt.Println(string(str))
  436. //
  437. //fmt.Println(r)
  438. return nil
  439. }
  440. func CardInit() int {
  441. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  442. //add := DllTestDef.MustFindProc("Init")
  443. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  444. //if err != nil {
  445. // fmt.Println("SSCard的运算结果为:", ret)
  446. //}
  447. //result := int(ret)
  448. return 0
  449. }
  450. func IntPtr(n int) uintptr {
  451. return uintptr(n)
  452. }
  453. func StrPtr(s string) uintptr {
  454. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  455. }
  456. func (c *HisApiController) GetHisPatientList() {
  457. //types, _ := c.GetInt64("type", 0)
  458. record_date := c.GetString("record_date")
  459. sch_type, _ := c.GetInt64("sch_type")
  460. timeLayout := "2006-01-02"
  461. loc, _ := time.LoadLocation("Local")
  462. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  463. if err != nil {
  464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  465. return
  466. }
  467. recordDateTime := theTime.Unix()
  468. adminInfo := c.GetAdminUserInfo()
  469. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  470. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  471. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  472. //获取当前用户的信息
  473. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  474. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  475. //获取所有科室信息
  476. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  477. c.ServeSuccessJSON(map[string]interface{}{
  478. "list": patients,
  479. "list_two": patients_two,
  480. "info": adminUserInfo,
  481. "doctors": doctors,
  482. "department": department,
  483. })
  484. }
  485. type CustomTemplate struct {
  486. ID int64 `gorm:"column:id" json:"id" form:"id"`
  487. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  488. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  489. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  490. Status int64 `gorm:"column:status" json:"status" form:"status"`
  491. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  492. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  493. Type int64 `gorm:"column:type" json:"type" form:"type"`
  494. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  495. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  496. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  497. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  498. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  499. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  500. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  501. }
  502. func (c *HisApiController) GetHisPatientInfo() {
  503. patient_id, _ := c.GetInt64("patient_id")
  504. his_patient_id, _ := c.GetInt64("his_patient_id")
  505. record_date := c.GetString("record_date")
  506. number := c.GetString("number")
  507. //start_time := c.GetString("start_time")
  508. //end_time := c.GetString("end_time")
  509. p_type, _ := c.GetInt64("p_type")
  510. timeLayout := "2006-01-02"
  511. loc, _ := time.LoadLocation("Local")
  512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  513. if err != nil {
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  515. return
  516. }
  517. recordDateTime := theTime.Unix()
  518. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  519. //if err != nil {
  520. //
  521. //}
  522. //startRecordDateTime := startTime.Unix()
  523. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  524. //if err != nil {
  525. //
  526. //}
  527. //endRecordDateTime := endTime.Unix()
  528. admin := c.GetAdminUserInfo()
  529. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  530. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  531. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  532. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  533. var prescriptions []*models.HisPrescription
  534. var last_prescriptions []*models.HisPrescription
  535. var sch_prescriptions []CustomTemplate
  536. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  537. if p_type == 1 { //住院
  538. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  539. for _, item := range prescriptions {
  540. for _, subItem := range item.HisDoctorAdviceInfo {
  541. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  542. if info.RetailPrice > 0 {
  543. subItem.Drug.MinPrice = info.RetailPrice
  544. }
  545. }
  546. }
  547. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  548. } else { //门诊
  549. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  550. for _, item := range prescriptions {
  551. for _, subItem := range item.HisDoctorAdviceInfo {
  552. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  553. if info.RetailPrice > 0 {
  554. subItem.Drug.MinPrice = info.RetailPrice
  555. }
  556. }
  557. }
  558. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  559. }
  560. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  561. if sch.ID > 0 {
  562. var week string
  563. t := time.Now()
  564. switch t.Weekday().String() {
  565. case "Monday":
  566. week = "周一"
  567. break
  568. case "Tuesday":
  569. week = "周二"
  570. break
  571. case "Wednesday":
  572. week = "周三"
  573. break
  574. case "Thursday":
  575. week = "周四"
  576. break
  577. case "Friday":
  578. week = "周五"
  579. break
  580. case "Saturday":
  581. week = "周六"
  582. break
  583. case "Sunday":
  584. week = "周日"
  585. break
  586. }
  587. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  588. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  589. //根据推送频率组装新的数组
  590. for _, item := range temp_sch_prescriptions {
  591. var cus CustomTemplate
  592. cus.ID = item.ID
  593. cus.UserOrgId = item.UserOrgId
  594. cus.PatientId = item.PatientId
  595. cus.MedType = item.MedType
  596. cus.RecordDate = item.RecordDate
  597. cus.Type = item.Type
  598. cus.PType = item.PType
  599. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  600. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  601. if subItem.FrequencyType == 1 { //每次必推
  602. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  603. }
  604. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  605. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  606. }
  607. if subItem.FrequencyType == 2 { //按照天数频率
  608. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  609. now := p.Unix()
  610. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  611. dayStr2 := "-" + dayStr
  612. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  613. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  614. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  615. if len(advices) == 0 {
  616. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  617. }
  618. }
  619. }
  620. }
  621. for _, subItem := range item.HisPrescriptionProjectTemplate {
  622. if subItem.Type == 2 {
  623. if subItem.XtHisProject.MedicalStatus != 1 {
  624. if subItem.FrequencyType == 1 {
  625. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  626. }
  627. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  628. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  629. }
  630. if subItem.FrequencyType == 2 {
  631. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  632. now := p.Unix()
  633. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  634. dayStr2 := "-" + dayStr
  635. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  636. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  637. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  638. if len(projects) == 0 {
  639. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  640. }
  641. }
  642. }
  643. } else if subItem.Type == 3 {
  644. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  645. if subItem.FrequencyType == 1 {
  646. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  647. }
  648. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  649. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  650. }
  651. if subItem.FrequencyType == 2 {
  652. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  653. now := p.Unix()
  654. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  655. dayStr2 := "-" + dayStr
  656. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  657. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  658. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  659. if len(projects) == 0 {
  660. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  661. }
  662. }
  663. }
  664. }
  665. }
  666. sch_prescriptions = append(sch_prescriptions, cus)
  667. }
  668. for _, item := range sch_prescriptions {
  669. if len(item.HisPrescriptionProjectTemplate) == 0 {
  670. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  671. }
  672. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  673. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  674. }
  675. }
  676. }
  677. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  678. if config.ID > 0 && config.IsOpen == 1 {
  679. for _, item := range sch_prescriptions {
  680. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  681. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  682. if info.RetailPrice > 0 {
  683. subItem.Drug.MinPrice = info.RetailPrice
  684. }
  685. }
  686. }
  687. }
  688. if config.ID > 0 && config.IsOpen == 1 {
  689. for _, item := range sch_prescriptions {
  690. for _, subItem := range item.HisPrescriptionProjectTemplate {
  691. if subItem.Type == 3 {
  692. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  693. if info.Price > 0 {
  694. subItem.GoodInfo.PackingPrice = info.Price
  695. }
  696. }
  697. }
  698. }
  699. }
  700. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  701. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  702. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  703. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  704. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  705. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  706. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  707. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  708. //获取所有科室信息
  709. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  710. c.ServeSuccessJSON(map[string]interface{}{
  711. "his_info": his_patient_info,
  712. "xt_info": xt_patient_info,
  713. "prescription": prescriptions,
  714. "case_history": case_history,
  715. "info": patientPrescriptionInfo,
  716. //"month_prescriptions": monthPrescriptions,
  717. "order": order,
  718. "doctors": doctors,
  719. "department": department,
  720. "sch_prescriptions": sch_prescriptions,
  721. "last_prescriptions": last_prescriptions,
  722. "schedule": sch,
  723. "count": count,
  724. "drugStockConfig": drugStockConfig,
  725. "last_info": lastPatientPrescriptionInfo,
  726. })
  727. return
  728. }
  729. func (c *HisApiController) GetHisPrescriptionConfig() {
  730. adminInfo := c.GetAdminUserInfo()
  731. //获取医嘱模版
  732. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  733. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  734. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  735. //获取所有基础药
  736. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  737. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  738. if config.ID > 0 && config.IsOpen == 1 {
  739. for _, item := range drugs {
  740. var index = 0
  741. for _, subItem := range item.OtherDrugWarehouseInfo {
  742. if index == 0 {
  743. index = index + 1
  744. if subItem.RetailPrice > 0 {
  745. item.MinPrice = subItem.RetailPrice
  746. }
  747. }
  748. }
  749. }
  750. }
  751. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  752. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  753. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  754. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  755. //获取所有科室信息
  756. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  757. //获取诊断信息
  758. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  759. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  760. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  761. c.ServeSuccessJSON(map[string]interface{}{
  762. "drugs": drugs,
  763. "advices_template": advices,
  764. "drugways": drugways,
  765. "efs": efs,
  766. "doctors": doctors,
  767. "department": department,
  768. "sick": sick,
  769. "additions": additions,
  770. "diagnose": diagnose,
  771. "manufacturers": manufacturers,
  772. })
  773. }
  774. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  775. //获取所有基础药
  776. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  777. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  778. if config.ID > 0 && config.IsOpen == 1 {
  779. for _, item := range drugs {
  780. var index = 0
  781. for _, subItem := range item.OtherDrugWarehouseInfo {
  782. if index == 0 {
  783. index = index + 1
  784. if subItem.RetailPrice > 0 {
  785. item.MinPrice = subItem.RetailPrice
  786. }
  787. }
  788. }
  789. }
  790. }
  791. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  792. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  793. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  794. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  795. //获取所有科室信息
  796. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  797. //获取诊断信息
  798. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  799. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  800. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  801. c.ServeSuccessJSON(map[string]interface{}{
  802. "drugs": drugs,
  803. "advices_template": advices,
  804. "drugways": drugways,
  805. "efs": efs,
  806. "doctors": doctors,
  807. "department": department,
  808. "sick": sick,
  809. "additions": additions,
  810. "diagnose": diagnose,
  811. "manufacturers": manufacturers,
  812. })
  813. }
  814. }
  815. func (c *HisApiController) CreateHisPrescription() {
  816. record_date := c.GetString("record_date")
  817. patient_id, _ := c.GetInt64("patient_id")
  818. reg_type, _ := c.GetInt64("reg_type")
  819. diagnose := c.GetString("diagnose")
  820. sick_type, _ := c.GetInt64("sick_type")
  821. sick_history := c.GetString("sick_history")
  822. doctor_id, _ := c.GetInt64("doctor", 0)
  823. department, _ := c.GetInt64("department", 0)
  824. his_patient_id, _ := c.GetInt64("his_patient_id")
  825. p_type, _ := c.GetInt64("p_type")
  826. dataBody := make(map[string]interface{}, 0)
  827. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  828. if err != nil {
  829. utils.ErrorLog(err.Error())
  830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  831. return
  832. }
  833. timeLayout := "2006-01-02"
  834. loc, _ := time.LoadLocation("Local")
  835. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  836. if err != nil {
  837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  838. return
  839. }
  840. adminInfo := c.GetAdminUserInfo()
  841. recordDateTime := theTime.Unix()
  842. //查询默认出库仓库库存
  843. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  844. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  845. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  846. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  847. if len(lists) == 1 {
  848. his_patient_id = lists[0].ID
  849. }
  850. }
  851. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  852. //保存处方出库
  853. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  854. //自动出库
  855. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  856. //耗材保存处方出库
  857. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  858. //已发药和已收费限制逻辑
  859. isMidicine := false
  860. isCharge := false
  861. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  862. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  863. if len(prescriptions) > 0 {
  864. for _, item := range prescriptions {
  865. items := item.(map[string]interface{})
  866. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  867. utils.ErrorLog("id")
  868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  869. return
  870. }
  871. id := int64(items["id"].(float64))
  872. if id > 0 {
  873. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  874. if err != nil {
  875. if new_prescription.OrderStatus == 4 {
  876. isCharge = true
  877. }
  878. }
  879. }
  880. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  881. advices := items["advices"].([]interface{})
  882. if len(advices) > 0 {
  883. for _, advice := range advices {
  884. var adviceId int64
  885. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  886. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  887. }
  888. if adviceId > 0 {
  889. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  890. if err == nil {
  891. if his_advice_info.IsMedicine == 1 {
  892. isMidicine = true
  893. }
  894. }
  895. }
  896. }
  897. }
  898. }
  899. }
  900. }
  901. }
  902. if isMidicine == true {
  903. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  904. return
  905. }
  906. if isCharge == true {
  907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  908. return
  909. }
  910. //已发药和已收费限制逻辑
  911. if drugStockConfig.IsOpen == 1 {
  912. //校验库存总量
  913. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  914. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  915. if len(prescriptions) > 0 {
  916. for _, item := range prescriptions {
  917. items := item.(map[string]interface{})
  918. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  919. advices := items["advices"].([]interface{})
  920. if len(advices) > 0 {
  921. for _, advice := range advices {
  922. var drug_id int64
  923. var prescribing_number float64
  924. var prescribingNumberUnit string
  925. var adviceId int64
  926. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  927. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  928. }
  929. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  930. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  931. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  932. }
  933. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  934. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  935. }
  936. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  937. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  938. }
  939. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  940. if drug.ID == 0 {
  941. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  942. return
  943. }
  944. //查询药品的所有库存
  945. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  946. var total_count int64
  947. for _, it := range list {
  948. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  949. }
  950. totals := strconv.FormatInt(total_count, 10)
  951. //查询该药品是否存在开药记录
  952. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  953. //查询最新批次库存
  954. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  955. var batch_number_count int64
  956. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  957. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  958. //新增处方
  959. if advicelist.ID == 0 {
  960. all_count, _ := strconv.ParseFloat(totals, 64)
  961. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  962. if prescribingNumberUnit == drug.MinUnit {
  963. if drug.IsUse != 1 {
  964. if prescribing_number > all_count {
  965. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  966. return
  967. }
  968. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  969. if prescribing_number > batch_number_all_count {
  970. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  971. return
  972. }
  973. }
  974. }
  975. }
  976. if prescribingNumberUnit == drug.MaxUnit {
  977. num := prescribing_number * float64(drug.MinNumber)
  978. if drug.IsUse != 1 {
  979. if num > all_count {
  980. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  981. return
  982. }
  983. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  984. if num > batch_number_all_count {
  985. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  986. return
  987. }
  988. }
  989. }
  990. }
  991. }
  992. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  993. if drugOutConfig.IsOpen != 1 {
  994. //修改处方
  995. for _, advice := range advices {
  996. var drug_id int64
  997. var prescribing_number float64
  998. var prescribingNumberUnit string
  999. var prescribingNumber string
  1000. var adviceId int64
  1001. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1002. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1003. }
  1004. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1005. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1006. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1007. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1008. }
  1009. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1010. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1011. }
  1012. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1013. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1014. }
  1015. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1016. if drug.ID == 0 {
  1017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1018. return
  1019. }
  1020. //查询药品的所有库存
  1021. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1022. var total_count int64
  1023. for _, it := range list {
  1024. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1025. }
  1026. totals := strconv.FormatInt(total_count, 10)
  1027. //查询该药品是否存在开药记录
  1028. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1029. //新增处方
  1030. if advicelist.ID == 0 {
  1031. //查询最新批次库存
  1032. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1033. var batch_number_count int64
  1034. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1035. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1036. all_count, _ := strconv.ParseFloat(totals, 64)
  1037. if prescribingNumberUnit == drug.MinUnit {
  1038. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1039. if drug.IsUse != 1 {
  1040. if prescribing_number > all_count {
  1041. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1042. return
  1043. }
  1044. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1045. if prescribing_number > batch_number_all_count {
  1046. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1047. return
  1048. }
  1049. }
  1050. }
  1051. } else {
  1052. if prescribingNumberUnit == drug.MaxUnit {
  1053. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1054. num := prescribing_number * float64(drug.MinNumber)
  1055. if drug.IsUse != 1 {
  1056. if num > all_count {
  1057. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1058. return
  1059. }
  1060. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1061. if prescribing_number > batch_number_all_count {
  1062. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1063. return
  1064. }
  1065. }
  1066. }
  1067. }
  1068. }
  1069. }
  1070. //修改处方
  1071. if advicelist.ID > 0 {
  1072. //查询最新批次库存
  1073. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1074. var batch_number_count int64
  1075. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1076. var device_number int64
  1077. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1078. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1079. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1080. device_number = prescribingNumberInt * drug.MinNumber
  1081. }
  1082. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1083. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1084. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1085. device_number = prescribingNumberInt
  1086. }
  1087. var number_count int64
  1088. if prescribingNumberUnit == drug.MaxUnit {
  1089. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1090. number_count = prescribingNumberInt * drug.MinNumber
  1091. }
  1092. if prescribingNumberUnit == drug.MinUnit {
  1093. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1094. number_count = prescribingNumberInt
  1095. }
  1096. //如果修改的数量大于之前修改的数量
  1097. if (number_count - device_number) > 0 {
  1098. //如果修改的差数量 大于库存数量
  1099. if drug.IsUse != 1 {
  1100. if (number_count - device_number) > total_count {
  1101. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1102. return
  1103. }
  1104. if (number_count - device_number) > batch_number_count {
  1105. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1106. return
  1107. }
  1108. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 9671 {
  1109. // 查询该药品最后一次出库记录
  1110. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1111. var out_count int64
  1112. var in_count int64
  1113. var stock_max_number int64
  1114. var stock_min_number int64
  1115. for _, it := range outInfo {
  1116. if it.CountUnit == drug.MaxUnit {
  1117. it.Count = it.Count * drug.MinNumber
  1118. }
  1119. out_count += it.Count
  1120. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1121. stock_max_number = warehouseInfoList.StockMaxNumber
  1122. stock_min_number = warehouseInfoList.StockMinNumber
  1123. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1124. }
  1125. if out_count > 0 {
  1126. if (number_count - device_number) > in_count {
  1127. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1128. return
  1129. }
  1130. }
  1131. // 未出库
  1132. if out_count == 0 {
  1133. var sum_in_count int64
  1134. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1135. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1136. fmt.Println("sum_in_count", sum_in_count)
  1137. //如果修改的数量大于有库存的第一个批次
  1138. if number_count > sum_in_count {
  1139. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1140. return
  1141. }
  1142. }
  1143. }
  1144. }
  1145. }
  1146. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1147. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1148. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1149. if pharmacyConfig.IsOpen != 1 {
  1150. if device_number != number_count {
  1151. // 查询该药品最后一次出库记录
  1152. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1153. //回退库存
  1154. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1155. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1156. }
  1157. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1158. var stock_max_number int64
  1159. var stock_min_number int64
  1160. if number_count >= drug.MinNumber {
  1161. stock_max_number = device_number / drug.MinNumber
  1162. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1163. stock_min_number = device_number % drug.MinNumber
  1164. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1165. } else {
  1166. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1167. }
  1168. }
  1169. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1170. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1171. }
  1172. //删除记录
  1173. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1174. //查询默认仓库剩余多少库存
  1175. var sum_count int64
  1176. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1177. for _, its := range stockInfo {
  1178. if its.MaxUnit == drug.MaxUnit {
  1179. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1180. }
  1181. sum_count += its.StockMaxNumber + its.StockMinNumber
  1182. }
  1183. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1184. }
  1185. }
  1186. }
  1187. }
  1188. }
  1189. //保存处方开药
  1190. if drugOutConfig.IsOpen == 1 {
  1191. //修改处方
  1192. for _, advice := range advices {
  1193. var drug_id int64
  1194. var prescribing_number float64
  1195. var prescribingNumberUnit string
  1196. var prescribingNumber string
  1197. var adviceId int64
  1198. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1199. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1200. }
  1201. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1202. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1203. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1204. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1205. }
  1206. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1207. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1208. }
  1209. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1210. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1211. }
  1212. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1213. if drug.ID == 0 {
  1214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1215. return
  1216. }
  1217. //查询药品的所有库存
  1218. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1219. var total_count int64
  1220. for _, it := range list {
  1221. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1222. }
  1223. totals := strconv.FormatInt(total_count, 10)
  1224. //查询该药品是否存在开药记录
  1225. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1226. //新增处方
  1227. if advicelist.ID == 0 {
  1228. //查询最新批次库存
  1229. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1230. var batch_number_count int64
  1231. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1232. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1233. all_count, _ := strconv.ParseFloat(totals, 64)
  1234. if prescribingNumberUnit == drug.MinUnit {
  1235. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1236. if drug.IsUse != 1 {
  1237. if prescribing_number > all_count {
  1238. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1239. return
  1240. }
  1241. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1242. if prescribing_number > batch_number_all_count {
  1243. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1244. return
  1245. }
  1246. }
  1247. }
  1248. } else {
  1249. if prescribingNumberUnit == drug.MaxUnit {
  1250. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1251. num := prescribing_number * float64(drug.MinNumber)
  1252. if drug.IsUse != 1 {
  1253. if num > all_count {
  1254. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1255. return
  1256. }
  1257. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1258. if prescribing_number > batch_number_all_count {
  1259. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1260. return
  1261. }
  1262. }
  1263. }
  1264. }
  1265. }
  1266. }
  1267. //修改处方
  1268. if advicelist.ID > 0 {
  1269. //查询最新批次库存
  1270. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1271. var batch_number_count int64
  1272. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1273. var device_number int64
  1274. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1275. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1276. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1277. device_number = prescribingNumberInt * drug.MinNumber
  1278. }
  1279. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1280. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1281. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1282. device_number = prescribingNumberInt
  1283. }
  1284. var number_count int64
  1285. if prescribingNumberUnit == drug.MaxUnit {
  1286. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1287. number_count = prescribingNumberInt * drug.MinNumber
  1288. }
  1289. if prescribingNumberUnit == drug.MinUnit {
  1290. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1291. number_count = prescribingNumberInt
  1292. }
  1293. //如果修改的数量大于之前修改的数量
  1294. if (number_count - device_number) > 0 {
  1295. //如果修改的差数量 大于库存数量
  1296. if drug.IsUse != 1 {
  1297. if (number_count - device_number) > total_count {
  1298. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1299. return
  1300. }
  1301. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1302. if (number_count - device_number) > batch_number_count {
  1303. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1304. return
  1305. }
  1306. }
  1307. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1308. //查询历史出库数据总批次
  1309. // 查询该药品最后一次出库记录
  1310. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1311. var out_count int64
  1312. var in_count int64
  1313. var stock_max_number int64
  1314. var stock_min_number int64
  1315. for _, it := range outInfo {
  1316. if it.CountUnit == drug.MaxUnit {
  1317. it.Count = it.Count * drug.MinNumber
  1318. }
  1319. out_count += it.Count
  1320. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1321. stock_max_number = warehouseInfoList.StockMaxNumber
  1322. stock_min_number = warehouseInfoList.StockMinNumber
  1323. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1324. }
  1325. if out_count > 0 {
  1326. if (number_count - device_number) > in_count {
  1327. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1328. return
  1329. }
  1330. }
  1331. // 未出库
  1332. if out_count == 0 {
  1333. var sum_in_count int64
  1334. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1335. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1336. //如果修改的数量大于有库存的第一个批次
  1337. if number_count > sum_in_count {
  1338. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1339. return
  1340. }
  1341. }
  1342. }
  1343. }
  1344. }
  1345. }
  1346. }
  1347. }
  1348. }
  1349. }
  1350. }
  1351. }
  1352. }
  1353. }
  1354. }
  1355. //不使用耗材保存处方出库
  1356. if goodOutConfig.IsOpen != 1 {
  1357. if stockConfig.IsOpen == 1 {
  1358. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1359. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1360. if len(prescriptions) > 0 {
  1361. for _, item := range prescriptions {
  1362. items := item.(map[string]interface{})
  1363. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1364. projects := items["project"].([]interface{})
  1365. if len(projects) > 0 {
  1366. for _, project := range projects {
  1367. var project_id int64
  1368. var project_type int64
  1369. var totals float64
  1370. var project_name string
  1371. var parsetotal int64
  1372. var id int64
  1373. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  1374. id = int64(project.(map[string]interface{})["id"].(float64))
  1375. }
  1376. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1377. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1378. }
  1379. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1380. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1381. }
  1382. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1383. total, _ := project.(map[string]interface{})["total"].(string)
  1384. totals, _ = strconv.ParseFloat(total, 64)
  1385. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  1386. }
  1387. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1388. project_name = project.(map[string]interface{})["project_name"].(string)
  1389. }
  1390. if project_type == 3 {
  1391. //查找该耗材的出库记录
  1392. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1393. if len(goodWarehouseInfo) == 0 {
  1394. //查询耗材库存
  1395. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  1396. var stock_count int64
  1397. for _, it := range list {
  1398. stock_count += it.StockCount
  1399. }
  1400. stock_counts := strconv.FormatInt(stock_count, 10)
  1401. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1402. if totals > stock_total_count {
  1403. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1404. return
  1405. }
  1406. //查找今日该患者已经出库的所有耗材
  1407. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1408. for _, item := range goodList {
  1409. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1410. var flush_count int64
  1411. for _, it := range goodListSix {
  1412. flush_count += it.StockCount
  1413. }
  1414. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1415. creater := adminInfo.AdminUser.Id
  1416. if errs != nil {
  1417. goodErrcode := models.XtGoodErrcode{
  1418. UserOrgId: item.OrgId,
  1419. Errcode: "手动出库更新剩余出库失败",
  1420. GoodId: item.GoodId,
  1421. Status: 1,
  1422. Ctime: time.Now().Unix(),
  1423. Mtime: 0,
  1424. Count: 0,
  1425. StockCount: 0,
  1426. Creater: creater,
  1427. BatchNumberId: 0,
  1428. WarehouseOutId: 0,
  1429. }
  1430. service.CreateGoodErrcode(goodErrcode)
  1431. }
  1432. }
  1433. //删除记录
  1434. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1435. }
  1436. if len(goodWarehouseInfo) > 0 {
  1437. //查询该患者耗材的历史数据
  1438. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1439. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1440. //数量发生改变
  1441. if parsetotal != count {
  1442. //查找今日该患者已经出库的所有耗材
  1443. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1444. for _, item := range goodList {
  1445. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1446. var flush_count int64
  1447. for _, it := range goodListSix {
  1448. flush_count += it.StockCount
  1449. }
  1450. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1451. //减少出库数量
  1452. creater := adminInfo.AdminUser.Id
  1453. if errs != nil {
  1454. goodErrcode := models.XtGoodErrcode{
  1455. UserOrgId: item.OrgId,
  1456. Errcode: "手动出库更新剩余出库失败",
  1457. GoodId: item.GoodId,
  1458. Status: 1,
  1459. Ctime: time.Now().Unix(),
  1460. Mtime: 0,
  1461. Count: 0,
  1462. StockCount: 0,
  1463. Creater: creater,
  1464. BatchNumberId: 0,
  1465. WarehouseOutId: 0,
  1466. }
  1467. service.CreateGoodErrcode(goodErrcode)
  1468. }
  1469. //查询默认仓库
  1470. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  1471. var total_count int64
  1472. for _, it := range stockList {
  1473. total_count += it.StockCount
  1474. }
  1475. //基础库插入数据
  1476. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  1477. }
  1478. //删除记录
  1479. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1480. }
  1481. }
  1482. }
  1483. }
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. }
  1490. }
  1491. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1492. var hpInfo models.HisPrescriptionInfo
  1493. if info.ID == 0 {
  1494. var randNum int
  1495. randNum = rand.Intn(10000) + 1000
  1496. timestamp := time.Now().Unix()
  1497. tempTime := time.Unix(timestamp, 0)
  1498. timeFormat := tempTime.Format("20060102150405")
  1499. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1500. hpInfo = models.HisPrescriptionInfo{
  1501. HisPatientId: his_patient_id,
  1502. UserOrgId: adminInfo.CurrentOrgId,
  1503. RecordDate: theTime.Unix(),
  1504. PatientId: patient_id,
  1505. Status: 1,
  1506. Ctime: time.Now().Unix(),
  1507. Mtime: time.Now().Unix(),
  1508. Creator: adminInfo.AdminUser.Id,
  1509. Modifier: adminInfo.AdminUser.Id,
  1510. Diagnosis: diagnose,
  1511. SickHistory: sick_history,
  1512. Departments: department,
  1513. RegisterType: reg_type,
  1514. PrescriptionNumber: p_number,
  1515. PrescriptionStatus: 1,
  1516. Doctor: role.UserName,
  1517. DoctorId: doctor_id,
  1518. SickType: sick_type,
  1519. PType: p_type,
  1520. }
  1521. service.SavePatientPrescriptionInfo(hpInfo)
  1522. redis := service.RedisClient()
  1523. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1524. redis.Set(key, "", time.Second)
  1525. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1526. redis.Set(keyOne, "", time.Second)
  1527. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1528. redis.Set(keySeven, "", time.Second)
  1529. defer redis.Close()
  1530. } else {
  1531. hpInfo = models.HisPrescriptionInfo{
  1532. ID: info.ID,
  1533. UserOrgId: adminInfo.CurrentOrgId,
  1534. RecordDate: info.RecordDate,
  1535. PatientId: info.PatientId,
  1536. Status: 1,
  1537. Ctime: info.Ctime,
  1538. Mtime: time.Now().Unix(),
  1539. Creator: info.Creator,
  1540. Modifier: adminInfo.AdminUser.Id,
  1541. Diagnosis: diagnose,
  1542. SickHistory: sick_history,
  1543. Departments: department,
  1544. RegisterType: reg_type,
  1545. PrescriptionNumber: info.PrescriptionNumber,
  1546. Doctor: role.UserName,
  1547. PrescriptionStatus: info.PrescriptionStatus,
  1548. DoctorId: doctor_id,
  1549. SickType: sick_type,
  1550. PType: info.PType,
  1551. HisPatientId: info.HisPatientId,
  1552. }
  1553. service.SavePatientPrescriptionInfo(hpInfo)
  1554. redis := service.RedisClient()
  1555. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1556. redis.Set(key, "", time.Second)
  1557. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1558. redis.Set(keyOne, "", time.Second)
  1559. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1560. redis.Set(keySeven, "", time.Second)
  1561. defer redis.Close()
  1562. }
  1563. //定义切片
  1564. var adviceList []models.HisDoctorAdviceInfo
  1565. var projectList []models.HisPrescriptionProject
  1566. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1567. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1568. var tempPrescription *models.HisPrescription
  1569. if len(prescriptions) > 0 {
  1570. for _, item := range prescriptions {
  1571. items := item.(map[string]interface{})
  1572. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1573. utils.ErrorLog("id")
  1574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1575. return
  1576. }
  1577. id := int64(items["id"].(float64))
  1578. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1579. tempPrescription = &new_prescription
  1580. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1581. utils.ErrorLog("type")
  1582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1583. return
  1584. }
  1585. types := int64(items["type"].(float64))
  1586. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1587. utils.ErrorLog("med_type")
  1588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1589. return
  1590. }
  1591. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1592. if med_type == "0" {
  1593. med_type = "14"
  1594. }
  1595. //if order_status == 0 {
  1596. // order_status = 1
  1597. //}
  1598. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  1599. utils.ErrorLog("pre_time")
  1600. }
  1601. preTime, _ := items["pre_time"].(string)
  1602. timeLayout := "2006-01-02"
  1603. loc, _ := time.LoadLocation("Local")
  1604. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  1605. if err != nil {
  1606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1607. return
  1608. }
  1609. pTime := theTime2.Unix()
  1610. ctime := time.Now().Unix()
  1611. if tempPrescription.ID == 0 {
  1612. prescription := &models.HisPrescription{
  1613. ID: 0,
  1614. PatientId: patient_id,
  1615. UserOrgId: adminInfo.CurrentOrgId,
  1616. RecordDate: recordDateTime,
  1617. Ctime: ctime,
  1618. Mtime: ctime,
  1619. Type: types,
  1620. Modifier: adminInfo.AdminUser.Id,
  1621. Creator: adminInfo.AdminUser.Id,
  1622. Status: 1,
  1623. Doctor: role.UserName,
  1624. HisPatientId: his_patient_id,
  1625. OrderStatus: 1,
  1626. BatchNumber: "",
  1627. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1628. PreTime: pTime,
  1629. PType: p_type,
  1630. MedType: med_type,
  1631. }
  1632. tempPrescription = prescription
  1633. service.SaveHisPrescription(tempPrescription)
  1634. redis := service.RedisClient()
  1635. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1636. redis.Set(key, "", time.Second)
  1637. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1638. redis.Set(keyOne, "", time.Second)
  1639. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1640. redis.Set(keySeven, "", time.Second)
  1641. defer redis.Close()
  1642. } else {
  1643. tempPrescription.ID = id
  1644. tempPrescription.Type = types
  1645. tempPrescription.Modifier = adminInfo.AdminUser.Id
  1646. tempPrescription.Mtime = time.Now().Unix()
  1647. tempPrescription.Doctor = role.UserName
  1648. //tempPrescription.OrderStatus = order_status
  1649. tempPrescription.PreTime = pTime
  1650. tempPrescription.MedType = med_type
  1651. service.SaveHisPrescription(tempPrescription)
  1652. redis := service.RedisClient()
  1653. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1654. redis.Set(key, "", time.Second)
  1655. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1656. redis.Set(keyOne, "", time.Second)
  1657. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1658. redis.Set(keySeven, "", time.Second)
  1659. defer redis.Close()
  1660. }
  1661. //service.SaveHisPrescription(prescription)
  1662. //更改患者挂号状态
  1663. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1664. fmt.Println("更改失败", err2)
  1665. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1666. advices := items["advices"].([]interface{})
  1667. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1668. groupNo := int64(0)
  1669. ctime := time.Now().Unix()
  1670. mtime := ctime
  1671. if len(advices) > 0 {
  1672. for _, advice := range advices {
  1673. var s models.HisDoctorAdviceInfo
  1674. s.PrescriptionId = tempPrescription.ID
  1675. s.AdviceType = 2
  1676. s.AdviceDoctor = doctor_id
  1677. s.StopState = 2
  1678. s.ExecutionState = 2
  1679. s.AdviceDate = recordDateTime
  1680. s.Status = 1
  1681. s.UserOrgId = adminInfo.CurrentOrgId
  1682. s.RecordDate = recordDateTime
  1683. s.StartTime = tempPrescription.PreTime
  1684. s.Groupno = groupNo
  1685. s.CreatedTime = ctime
  1686. s.UpdatedTime = mtime
  1687. s.PatientId = patient_id
  1688. s.HisPatientId = his_patient_id
  1689. s.StartTime = pTime
  1690. s.IsSettle = 2
  1691. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  1692. if errcode > 0 {
  1693. c.ServeFailJSONWithSGJErrorCode(errcode)
  1694. return
  1695. }
  1696. s.StartTime = pTime
  1697. var total_count int64 //处方总库存
  1698. //查询改药品信息
  1699. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  1700. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  1701. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  1702. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1703. total_count += prescribingNumberSeven * medical.MinNumber
  1704. }
  1705. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1706. total_count += prescribingNumberSeven
  1707. }
  1708. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  1709. total_count += prescribingNumberSeven
  1710. }
  1711. service.CreateHisDoctorAdvice(&s)
  1712. //存储切片中
  1713. adviceList = append(adviceList, s)
  1714. redis := service.RedisClient()
  1715. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1716. redis.Set(key, "", time.Second)
  1717. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1718. redis.Set(keyOne, "", time.Second)
  1719. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1720. redis.Set(keySeven, "", time.Second)
  1721. var randNum int
  1722. randNum = rand.Intn(10000) + 1000
  1723. timestamp := time.Now().Unix()
  1724. tempTime := time.Unix(timestamp, 0)
  1725. timeFormat := tempTime.Format("20060102150405")
  1726. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  1727. service.CreateHisDoctorAdvice(&s)
  1728. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1729. redis.Set(keySix, "", time.Second)
  1730. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1731. redis.Set(keyFive, "", time.Second)
  1732. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1733. redis.Set(keyEight, "", time.Second)
  1734. defer redis.Close()
  1735. }
  1736. }
  1737. }
  1738. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1739. projects := items["project"].([]interface{})
  1740. if len(projects) > 0 {
  1741. for _, project := range projects {
  1742. var p models.HisPrescriptionProject
  1743. p.PrescriptionId = tempPrescription.ID
  1744. p.Ctime = time.Now().Unix()
  1745. p.Mtime = time.Now().Unix()
  1746. p.PatientId = patient_id
  1747. p.RecordDate = recordDateTime
  1748. p.Doctor = doctor_id
  1749. p.UserOrgId = adminInfo.CurrentOrgId
  1750. p.HisPatientId = his_patient_id
  1751. p.Status = 1
  1752. p.StartTime = pTime
  1753. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  1754. if errcode > 0 {
  1755. c.ServeFailJSONWithSGJErrorCode(errcode)
  1756. return
  1757. }
  1758. if p.ID == 0 {
  1759. p.IsOut = 2
  1760. }
  1761. if p.ID > 0 {
  1762. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  1763. p.IsOut = projectDetail.IsOut
  1764. }
  1765. service.CreateHisProjectTwo(&p)
  1766. projectList = append(projectList, p)
  1767. var randNum int
  1768. randNum = rand.Intn(10000) + 1000
  1769. timestamp := time.Now().Unix()
  1770. tempTime := time.Unix(timestamp, 0)
  1771. timeFormat := tempTime.Format("20060102150405")
  1772. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  1773. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  1774. //新增或者编辑项目,修改对应的标签数据
  1775. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  1776. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  1777. var label models.HisLabelPrintInfo
  1778. project, _ := service.GetProjectDetail(p.ProjectId)
  1779. if project.CostClassify == 3 { //类别为检验检查
  1780. if p.TeamId > 0 { //检验检查组套
  1781. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  1782. if tempLabel.ID == 0 {
  1783. team, _ := service.GetProjectTeamDetail(p.TeamId)
  1784. label.Number = tempPrescription.PrescriptionNumber
  1785. label.ProjectId = project.ID
  1786. label.Status = 1
  1787. label.IsPrint = 2
  1788. label.DoctorId = info.DoctorId
  1789. label.UserOrgId = p.UserOrgId
  1790. label.PatientId = patient_id
  1791. label.RecordDate = recordDateTime
  1792. label.Ctime = time.Now().Unix()
  1793. label.Mtime = time.Now().Unix()
  1794. label.ItemId = p.TeamId
  1795. label.FeedetlSn = p.FeedetlSn
  1796. label.PProjectId = p.ID
  1797. label.ProjectName = team.ProjectTeam
  1798. label.PatientName = patient.Name
  1799. service.CreateHisLabelRecord(&label)
  1800. }
  1801. } else { //单条检验检查项目
  1802. label.Number = tempPrescription.PrescriptionNumber
  1803. label.ProjectId = project.ID
  1804. label.Status = 1
  1805. label.DoctorId = info.DoctorId
  1806. label.UserOrgId = p.UserOrgId
  1807. label.PatientId = patient_id
  1808. label.RecordDate = recordDateTime
  1809. label.IsPrint = 2
  1810. label.Ctime = time.Now().Unix()
  1811. label.Mtime = time.Now().Unix()
  1812. label.FeedetlSn = p.FeedetlSn
  1813. label.PProjectId = p.ID
  1814. label.ItemId = p.TeamId
  1815. label.ProjectName = project.ProjectName
  1816. label.PatientName = patient.Name
  1817. service.CreateHisLabelRecord(&label)
  1818. }
  1819. }
  1820. }
  1821. }
  1822. service.SaveHisProjectTwo(&p)
  1823. }
  1824. }
  1825. }
  1826. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1827. // addition := items["addition"].([]interface{})
  1828. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1829. // ctime := time.Now().Unix()
  1830. // mtime := ctime
  1831. // if len(addition) > 0 {
  1832. // for _, item := range addition {
  1833. // var s models.HisAdditionalCharge
  1834. // s.PrescriptionId = tempPrescription.ID
  1835. // s.Status = 1
  1836. // s.UserOrgId = adminInfo.CurrentOrgId
  1837. // s.RecordDate = recordDateTime
  1838. // s.CreatedTime = ctime
  1839. // s.UpdatedTime = mtime
  1840. // s.PatientId = patient_id
  1841. // s.HisPatientId = his_patient_id
  1842. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1843. // if errcode > 0 {
  1844. // c.ServeFailJSONWithSGJErrorCode(errcode)
  1845. // return
  1846. // }
  1847. // service.CreateAdditionalCharge(&s)
  1848. // var randNum int
  1849. // randNum = rand.Intn(10000) + 1000
  1850. // timestamp := time.Now().Unix()
  1851. // tempTime := time.Unix(timestamp, 0)
  1852. // timeFormat := tempTime.Format("20060102150405")
  1853. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  1854. // service.CreateAdditionalCharge(&s)
  1855. //
  1856. // }
  1857. // }
  1858. //}
  1859. }
  1860. }
  1861. //查询今日该患者开的药品处方
  1862. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1863. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1864. //药品出库
  1865. if drugOutConfig.IsOpen == 1 {
  1866. for _, item := range hisdoctorlist {
  1867. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  1868. // 查询该药品最后一次出库记录
  1869. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  1870. if len(druginfo) > 0 {
  1871. //回退库存
  1872. for _, it := range druginfo {
  1873. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1874. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1875. }
  1876. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1877. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1878. }
  1879. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  1880. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1881. }
  1882. }
  1883. }
  1884. //删除记录
  1885. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  1886. //查询最后一次数据
  1887. if drugOutConfig.IsOpen == 1 {
  1888. //出库
  1889. if drug.IsUse == 2 {
  1890. creater := adminInfo.AdminUser.Id
  1891. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  1892. }
  1893. //更新字典里面的库存
  1894. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1895. var sum_count int64
  1896. for _, its := range stockInfo {
  1897. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1898. if its.MaxUnit == baseDrug.MaxUnit {
  1899. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1900. }
  1901. sum_count += its.StockMaxNumber + its.StockMinNumber
  1902. }
  1903. //更新基础库存
  1904. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1905. //剩余库存
  1906. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  1907. }
  1908. }
  1909. }
  1910. //耗材保存处方出库
  1911. if goodOutConfig.IsOpen == 1 {
  1912. //查询今日耗材出库数量
  1913. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1914. for _, item := range hisgoodlist {
  1915. //查询耗材最后一次出库记录
  1916. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  1917. if len(wareOut) > 0 {
  1918. for _, it := range wareOut {
  1919. //回退库存
  1920. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  1921. //删除出库记录
  1922. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  1923. }
  1924. }
  1925. timeStr := time.Now().Format("2006-01-02")
  1926. timeArr := strings.Split(timeStr, "-")
  1927. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  1928. total = total + 1
  1929. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1930. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1931. number = number + total
  1932. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1933. operation_time := time.Now().Unix()
  1934. creater := c.GetAdminUserInfo().AdminUser.Id
  1935. //查询默认出库仓库库存
  1936. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1937. recordDateStr := time.Now().Format("2006-01-02")
  1938. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  1939. nowtime := recordDate.Unix()
  1940. warehouseOut := models.WarehouseOut{
  1941. WarehouseOutOrderNumber: warehousing_out_order,
  1942. OperationTime: operation_time,
  1943. OrgId: adminInfo.CurrentOrgId,
  1944. Creater: creater,
  1945. Ctime: time.Now().Unix(),
  1946. Status: 1,
  1947. WarehouseOutTime: nowtime,
  1948. Type: 1,
  1949. StorehouseId: storeConfig.StorehouseOutInfo,
  1950. IsCheck: 1,
  1951. IsSys: 1,
  1952. }
  1953. //查询是否生成出库单
  1954. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  1955. if out.ID == 0 {
  1956. service.AddSigleWarehouseOut(&warehouseOut)
  1957. }
  1958. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  1959. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  1960. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  1961. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  1962. dialyPrepareOne := models.DialysisBeforePrepare{
  1963. GoodTypeId: goodObj.GoodTypeId,
  1964. GoodId: item.ProjectId,
  1965. PatientId: item.PatientId,
  1966. RecordDate: item.RecordDate,
  1967. UserOrgId: adminInfo.CurrentOrgId,
  1968. Count: parseIntCount,
  1969. Ctime: time.Now().Unix(),
  1970. Creater: creater,
  1971. Status: 1,
  1972. StorehouseId: houseConfig.StorehouseOutInfo,
  1973. ProjectId: item.ID,
  1974. }
  1975. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater)
  1976. //查询剩余库存
  1977. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId)
  1978. var sum_count int64
  1979. for _, item := range goodList {
  1980. sum_count += item.StockCount
  1981. }
  1982. //更新剩余库存
  1983. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  1984. //耗材
  1985. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  1986. }
  1987. }
  1988. }
  1989. //redisClient := service.RedisClient()
  1990. //defer redisClient.Close()
  1991. //
  1992. //list := models.HisList{
  1993. // Patient_id: patient_id,
  1994. // Advice_id:0,
  1995. // Record_date: 0,
  1996. // Advice: adviceList,
  1997. // Project: nil,
  1998. //}
  1999. //hisLis = append(hisLis, list)
  2000. //
  2001. //advice_json, _ := json.Marshal(&hisLis)
  2002. //redisClient.RPush("111", advice_json).Result()
  2003. //result, _ := redisClient.RPop("111").Result()
  2004. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2005. //
  2006. //var dat []map[string]interface{}
  2007. //json.Unmarshal([]byte(result), &dat)
  2008. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  2009. //
  2010. //for k,v:=range dat{
  2011. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  2012. //}
  2013. //project_json, _ := json.Marshal(&projectList)
  2014. //redisClient.LPush("222", project_json).Result()
  2015. if err == nil {
  2016. c.ServeSuccessJSON(map[string]interface{}{
  2017. "msg": "保存成功",
  2018. })
  2019. return
  2020. } else {
  2021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2022. return
  2023. }
  2024. }
  2025. func (c *HisApiController) EditHisPrescription() {
  2026. record_date := c.GetString("record_date")
  2027. patient_id, _ := c.GetInt64("patient_id")
  2028. reg_type, _ := c.GetInt64("reg_type")
  2029. //diagnose, _ := c.GetInt64("diagnose", 0)
  2030. diagnose := c.GetString("diagnose")
  2031. sick_type, _ := c.GetInt64("sick_type")
  2032. sick_history := c.GetString("sick_history")
  2033. doctor_id, _ := c.GetInt64("doctor", 0)
  2034. department, _ := c.GetInt64("department", 0)
  2035. his_patient_id, _ := c.GetInt64("his_patient_id")
  2036. p_type, _ := c.GetInt64("p_type")
  2037. dataBody := make(map[string]interface{}, 0)
  2038. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2039. if err != nil {
  2040. utils.ErrorLog(err.Error())
  2041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2042. return
  2043. }
  2044. timeLayout := "2006-01-02"
  2045. loc, _ := time.LoadLocation("Local")
  2046. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2047. if err != nil {
  2048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2049. return
  2050. }
  2051. adminInfo := c.GetAdminUserInfo()
  2052. recordDateTime := theTime.Unix()
  2053. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  2054. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2055. var hpInfo models.HisPrescriptionInfo
  2056. if info.ID == 0 {
  2057. var randNum int
  2058. randNum = rand.Intn(10000) + 1000
  2059. timestamp := time.Now().Unix()
  2060. tempTime := time.Unix(timestamp, 0)
  2061. timeFormat := tempTime.Format("20060102150405")
  2062. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2063. hpInfo = models.HisPrescriptionInfo{
  2064. UserOrgId: adminInfo.CurrentOrgId,
  2065. RecordDate: theTime.Unix(),
  2066. PatientId: patient_id,
  2067. Status: 1,
  2068. Ctime: time.Now().Unix(),
  2069. Mtime: time.Now().Unix(),
  2070. Creator: adminInfo.AdminUser.Id,
  2071. Modifier: adminInfo.AdminUser.Id,
  2072. Diagnosis: diagnose,
  2073. SickHistory: sick_history,
  2074. Departments: department,
  2075. RegisterType: reg_type,
  2076. PrescriptionNumber: p_number,
  2077. PrescriptionStatus: 1,
  2078. Doctor: role.UserName,
  2079. DoctorId: doctor_id,
  2080. SickType: sick_type,
  2081. PType: p_type,
  2082. }
  2083. service.SavePatientPrescriptionInfo(hpInfo)
  2084. } else {
  2085. hpInfo = models.HisPrescriptionInfo{
  2086. ID: info.ID,
  2087. UserOrgId: adminInfo.CurrentOrgId,
  2088. RecordDate: info.RecordDate,
  2089. PatientId: info.PatientId,
  2090. Status: 1,
  2091. Ctime: info.Ctime,
  2092. Mtime: time.Now().Unix(),
  2093. Creator: info.Creator,
  2094. Modifier: adminInfo.AdminUser.Id,
  2095. Diagnosis: diagnose,
  2096. SickHistory: sick_history,
  2097. Departments: department,
  2098. RegisterType: reg_type,
  2099. PrescriptionNumber: info.PrescriptionNumber,
  2100. Doctor: role.UserName,
  2101. PrescriptionStatus: info.PrescriptionStatus,
  2102. DoctorId: doctor_id,
  2103. SickType: sick_type,
  2104. PType: info.PType,
  2105. }
  2106. service.SavePatientPrescriptionInfo(hpInfo)
  2107. }
  2108. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2109. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2110. if len(prescriptions) > 0 {
  2111. for _, item := range prescriptions {
  2112. items := item.(map[string]interface{})
  2113. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2114. utils.ErrorLog("id")
  2115. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2116. return
  2117. }
  2118. id := int64(items["id"].(float64))
  2119. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2120. utils.ErrorLog("type")
  2121. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2122. return
  2123. }
  2124. types := int64(items["type"].(float64))
  2125. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2126. utils.ErrorLog("med_type")
  2127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2128. return
  2129. }
  2130. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2131. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  2132. ctime := time.Now().Unix()
  2133. prescription := &models.HisPrescription{
  2134. ID: id,
  2135. PatientId: patient_id,
  2136. UserOrgId: adminInfo.CurrentOrgId,
  2137. RecordDate: recordDateTime,
  2138. Ctime: ctime,
  2139. Mtime: ctime,
  2140. Type: types,
  2141. Modifier: adminInfo.AdminUser.Id,
  2142. Creator: adminInfo.AdminUser.Id,
  2143. Status: 1,
  2144. Doctor: role.UserName,
  2145. HisPatientId: his_patient_id,
  2146. OrderStatus: 1,
  2147. BatchNumber: "",
  2148. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2149. PType: hpInfo.PType,
  2150. MedType: med_type,
  2151. }
  2152. if historyPrescription.ID > 0 {
  2153. prescription.PreTime = historyPrescription.PreTime
  2154. }
  2155. service.SaveHisPrescription(prescription)
  2156. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2157. advices := items["advices"].([]interface{})
  2158. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2159. groupNo := int64(0)
  2160. ctime := time.Now().Unix()
  2161. mtime := ctime
  2162. if len(advices) > 0 {
  2163. for _, advice := range advices {
  2164. var s models.HisDoctorAdviceInfo
  2165. s.PrescriptionId = prescription.ID
  2166. s.AdviceType = 2
  2167. s.AdviceDoctor = adminInfo.AdminUser.Id
  2168. s.StopState = 2
  2169. s.ExecutionState = 2
  2170. s.AdviceDate = recordDateTime
  2171. s.Status = 1
  2172. s.UserOrgId = adminInfo.CurrentOrgId
  2173. s.RecordDate = recordDateTime
  2174. s.StartTime = prescription.PreTime
  2175. s.Groupno = groupNo
  2176. s.CreatedTime = ctime
  2177. s.UpdatedTime = mtime
  2178. s.PatientId = patient_id
  2179. s.HisPatientId = his_patient_id
  2180. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  2181. if errcode > 0 {
  2182. c.ServeFailJSONWithSGJErrorCode(errcode)
  2183. return
  2184. }
  2185. service.CreateHisDoctorAdvice(&s)
  2186. redis := service.RedisClient()
  2187. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2188. redis.Set(key, "", time.Second)
  2189. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2190. fmt.Println("keyOne", keyOne)
  2191. redis.Set(keyOne, "", time.Second)
  2192. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2193. redis.Set(keySeven, "", time.Second)
  2194. redis.Close()
  2195. }
  2196. }
  2197. }
  2198. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2199. projects := items["project"].([]interface{})
  2200. if len(projects) > 0 {
  2201. for _, project := range projects {
  2202. var p models.HisPrescriptionProject
  2203. p.PrescriptionId = prescription.ID
  2204. p.Ctime = time.Now().Unix()
  2205. p.Mtime = time.Now().Unix()
  2206. p.PatientId = patient_id
  2207. p.RecordDate = recordDateTime
  2208. p.UserOrgId = adminInfo.CurrentOrgId
  2209. p.HisPatientId = his_patient_id
  2210. p.Status = 1
  2211. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  2212. if errcode > 0 {
  2213. c.ServeFailJSONWithSGJErrorCode(errcode)
  2214. return
  2215. }
  2216. service.CreateHisProjectTwo(&p)
  2217. }
  2218. }
  2219. }
  2220. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2221. addition := items["addition"].([]interface{})
  2222. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2223. ctime := time.Now().Unix()
  2224. mtime := ctime
  2225. if len(addition) > 0 {
  2226. for _, item := range addition {
  2227. var s models.HisAdditionalCharge
  2228. s.PrescriptionId = prescription.ID
  2229. s.Status = 1
  2230. s.UserOrgId = adminInfo.CurrentOrgId
  2231. s.RecordDate = recordDateTime
  2232. s.CreatedTime = ctime
  2233. s.UpdatedTime = mtime
  2234. s.PatientId = patient_id
  2235. s.HisPatientId = his_patient_id
  2236. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2237. if errcode > 0 {
  2238. c.ServeFailJSONWithSGJErrorCode(errcode)
  2239. return
  2240. }
  2241. service.CreateAdditionalCharge(&s)
  2242. }
  2243. }
  2244. }
  2245. }
  2246. }
  2247. }
  2248. if err == nil {
  2249. c.ServeSuccessJSON(map[string]interface{}{
  2250. "msg": "保存成功",
  2251. })
  2252. return
  2253. } else {
  2254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2255. return
  2256. }
  2257. }
  2258. func (c *HisApiController) DeletePrescription() {
  2259. prescription_id, _ := c.GetInt64("id")
  2260. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  2261. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  2262. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2263. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2264. //耗材保存处方出库
  2265. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2266. //已收费和已发药限制逻辑
  2267. isCharge := false
  2268. isMedicine := false
  2269. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2270. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2271. for _, item := range new_prescriptions {
  2272. if item.IsMedicine == 1 {
  2273. isMedicine = true
  2274. }
  2275. }
  2276. for _, item := range new_prescriptions {
  2277. if item.OrderStatus == 4 {
  2278. isCharge = true
  2279. }
  2280. }
  2281. if p_err != nil {
  2282. if new_prescription.ID > 0 {
  2283. if new_prescription.OrderStatus == 2 {
  2284. isCharge = true
  2285. }
  2286. }
  2287. }
  2288. for _, item := range advices {
  2289. if item.IsMedicine == 1 {
  2290. isMedicine = true
  2291. }
  2292. }
  2293. if isCharge {
  2294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2295. return
  2296. }
  2297. if isMedicine {
  2298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2299. return
  2300. }
  2301. //已收费和已发药限制逻辑
  2302. if len(projects) > 0 {
  2303. for _, item := range projects {
  2304. service.DeletePrintInfo(item.ID) //删除打印信息
  2305. if goodOutConfig.IsOpen != 1 {
  2306. if stockConfig.IsOpen == 1 {
  2307. if item.Type == 3 && item.IsOut == 1 {
  2308. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  2309. f_count, _ := strconv.ParseFloat(item.Count, 64)
  2310. good.Total = good.Total + f_count
  2311. service.UpdateGoodInfo(&good)
  2312. operation_time := time.Now().Unix()
  2313. creater := c.GetAdminUserInfo().AdminUser.Id
  2314. //创建退库单
  2315. timeStr := time.Now().Format("2006-01-02")
  2316. timeArr := strings.Split(timeStr, "-")
  2317. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  2318. total = total + 1
  2319. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2320. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2321. cancelStock := models.CancelStock{
  2322. OrderNumber: orderNumber,
  2323. OperaTime: operation_time,
  2324. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2325. Creater: creater,
  2326. Ctime: time.Now().Unix(),
  2327. Status: 1,
  2328. ReturnTime: item.RecordDate,
  2329. Type: 1,
  2330. StorehouseId: houseConfig.StorehouseOutInfo,
  2331. IsCheck: 1,
  2332. }
  2333. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  2334. if msgerrkonde == gorm.ErrRecordNotFound {
  2335. service.AddSigleCancelStock(&cancelStock)
  2336. }
  2337. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  2338. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2339. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2340. //查询该耗材是否出库
  2341. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  2342. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2343. deaerler, _ := service.GetDealerById(info.Dealer)
  2344. var total_count int64
  2345. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2346. total_count += count
  2347. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2348. var flush_count int64
  2349. for _, it := range goodList {
  2350. flush_count += it.StockCount
  2351. }
  2352. if info.ID > 0 {
  2353. if info.Count >= total_count {
  2354. //回退库存
  2355. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2356. cancelStockInfo := models.CancelStockInfo{
  2357. GoodId: item.ProjectId,
  2358. CancelStockId: cancel.ID,
  2359. GoodTypeId: good.GoodTypeId,
  2360. Count: prescribingNumber,
  2361. Price: info.Price,
  2362. Total: 0,
  2363. ProductDate: info.ProductDate,
  2364. ExpiryDate: info.ExpiryDate,
  2365. Ctime: time.Now().Unix(),
  2366. Status: 1,
  2367. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2368. OrderNumber: cancel.OrderNumber,
  2369. Type: 0,
  2370. Dealer: deaerler.DealerName,
  2371. Manufacturer: manufacturer.ManufacturerName,
  2372. Number: info.Number,
  2373. RegisterAccount: "",
  2374. Remark: "",
  2375. WarehouseInfoId: info.WarehouseInfotId,
  2376. PatientId: info.PatientId,
  2377. RecordDate: info.SysRecordTime,
  2378. StorehouseId: houseConfig.StorehouseOutInfo,
  2379. IsCheck: 1,
  2380. }
  2381. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2382. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2383. flow := models.VmStockFlow{
  2384. WarehousingId: info.WarehouseInfotId,
  2385. GoodId: item.ProjectId,
  2386. Number: info.Number,
  2387. LicenseNumber: info.LicenseNumber,
  2388. Count: prescribingNumber,
  2389. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2390. PatientId: item.PatientId,
  2391. SystemTime: info.SysRecordTime,
  2392. ConsumableType: 7,
  2393. IsSys: 0,
  2394. WarehousingOrder: "",
  2395. WarehouseOutId: info.WarehouseOutId,
  2396. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2397. IsEdit: 0,
  2398. CancelStockId: cancel.ID,
  2399. CancelOrderNumber: cancel.OrderNumber,
  2400. Manufacturer: manufacturer.ID,
  2401. Dealer: 0,
  2402. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2403. UpdateCreator: 0,
  2404. Status: 1,
  2405. Ctime: time.Now().Unix(),
  2406. Mtime: 0,
  2407. Price: info.Price,
  2408. WarehousingDetailId: info.WarehouseInfotId,
  2409. WarehouseOutDetailId: info.ID,
  2410. CancelOutDetailId: cancelInfo.ID,
  2411. ProductDate: info.ProductDate,
  2412. ExpireDate: info.ExpiryDate,
  2413. StorehouseId: houseConfig.StorehouseOutInfo,
  2414. OverCount: flush_count,
  2415. }
  2416. service.CreateStockFlowOne(flow)
  2417. //退库数量增加
  2418. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  2419. //出库数量减少
  2420. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  2421. }
  2422. if info.Count < total_count {
  2423. //回退库存
  2424. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2425. cancelStockInfo := models.CancelStockInfo{
  2426. GoodId: item.ProjectId,
  2427. CancelStockId: cancel.ID,
  2428. GoodTypeId: good.GoodTypeId,
  2429. Count: info.Count,
  2430. Price: info.Price,
  2431. Total: 0,
  2432. ProductDate: info.ProductDate,
  2433. ExpiryDate: info.ExpiryDate,
  2434. Ctime: time.Now().Unix(),
  2435. Status: 1,
  2436. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2437. OrderNumber: cancel.OrderNumber,
  2438. Type: 0,
  2439. Dealer: deaerler.DealerName,
  2440. Manufacturer: manufacturer.ManufacturerName,
  2441. Number: info.Number,
  2442. RegisterAccount: "",
  2443. Remark: "",
  2444. WarehouseInfoId: info.WarehouseInfotId,
  2445. PatientId: info.PatientId,
  2446. RecordDate: info.SysRecordTime,
  2447. StorehouseId: houseConfig.StorehouseOutInfo,
  2448. IsCheck: 1,
  2449. }
  2450. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2451. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2452. flow := models.VmStockFlow{
  2453. WarehousingId: info.WarehouseInfotId,
  2454. GoodId: item.ProjectId,
  2455. Number: info.Number,
  2456. LicenseNumber: info.LicenseNumber,
  2457. Count: info.Count,
  2458. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2459. PatientId: item.PatientId,
  2460. SystemTime: info.SysRecordTime,
  2461. ConsumableType: 7,
  2462. IsSys: 0,
  2463. WarehousingOrder: "",
  2464. WarehouseOutId: info.WarehouseOutId,
  2465. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2466. IsEdit: 0,
  2467. CancelStockId: cancel.ID,
  2468. CancelOrderNumber: cancel.OrderNumber,
  2469. Manufacturer: manufacturer.ID,
  2470. Dealer: 0,
  2471. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2472. UpdateCreator: 0,
  2473. Status: 1,
  2474. Ctime: time.Now().Unix(),
  2475. Mtime: 0,
  2476. Price: info.Price,
  2477. WarehousingDetailId: info.WarehouseInfotId,
  2478. WarehouseOutDetailId: info.ID,
  2479. CancelOutDetailId: cancelInfo.ID,
  2480. ProductDate: info.ProductDate,
  2481. ExpireDate: info.ExpiryDate,
  2482. StorehouseId: houseConfig.StorehouseOutInfo,
  2483. OverCount: flush_count,
  2484. }
  2485. service.CreateStockFlowOne(flow)
  2486. //退库数量增加
  2487. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  2488. //出库数量减少
  2489. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  2490. }
  2491. //查询已出库数量
  2492. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2493. if prescribingNumber < dialysisInfo.Count {
  2494. //改变数量
  2495. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  2496. }
  2497. if prescribingNumber >= dialysisInfo.Count {
  2498. //删除出库表
  2499. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2500. }
  2501. //更新库存
  2502. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  2503. //更新基础库库存
  2504. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  2505. //查询今日该耗材退库数量
  2506. //cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  2507. //var cancel_Count int64
  2508. //for _, items := range cancelInfoOne {
  2509. // cancel_Count += items.Count
  2510. //}
  2511. //
  2512. //cha_count = total_count - cancel_Count
  2513. //
  2514. //if total_count > cancel_Count {
  2515. //
  2516. // out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  2517. // if err == gorm.ErrRecordNotFound {
  2518. // //没有记录,则创建出库单
  2519. // timeStr := time.Now().Format("2006-01-02")
  2520. // timeArr := strings.Split(timeStr, "-")
  2521. // total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  2522. // total = total + 1
  2523. // warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2524. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2525. // number = number + total
  2526. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2527. // warehouseOut := models.WarehouseOut{
  2528. // WarehouseOutOrderNumber: warehousing_out_order,
  2529. // OperationTime: time.Now().Unix(),
  2530. // OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2531. // Creater: creater,
  2532. // Ctime: time.Now().Unix(),
  2533. // Status: 1,
  2534. // WarehouseOutTime: info.SysRecordTime,
  2535. // Dealer: 0,
  2536. // Manufacturer: 0,
  2537. // Type: 1,
  2538. // IsSys: 1,
  2539. // StorehouseId: houseConfig.StorehouseOutInfo,
  2540. // IsCheck: 1,
  2541. // }
  2542. // err := service.AddSigleWarehouseOut(&warehouseOut)
  2543. // if err != nil {
  2544. // utils.TraceLog("创建出库单失败 err = %v", err)
  2545. // return
  2546. // }
  2547. // prepare := &models.DialysisBeforePrepare{
  2548. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2549. // PatientId: info.PatientId,
  2550. // RecordDate: info.SysRecordTime,
  2551. // GoodId: item.ProjectId,
  2552. // GoodTypeId: info.GoodTypeId,
  2553. // Count: cha_count,
  2554. // StorehouseId: houseConfig.StorehouseOutInfo,
  2555. // }
  2556. // //出库
  2557. // service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2558. // } else if err == nil {
  2559. //
  2560. // prepare := &models.DialysisBeforePrepare{
  2561. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2562. // PatientId: info.PatientId,
  2563. // RecordDate: info.SysRecordTime,
  2564. // GoodId: item.ProjectId,
  2565. // GoodTypeId: info.GoodTypeId,
  2566. // Count: cha_count,
  2567. // StorehouseId: houseConfig.StorehouseOutInfo,
  2568. // }
  2569. // //出库
  2570. // service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2571. // }
  2572. //
  2573. //}
  2574. }
  2575. }
  2576. }
  2577. }
  2578. fmt.Println("goodOutConfig.IsOpen23232332233232232323232323", goodOutConfig.IsOpen)
  2579. //保存耗材出库
  2580. if goodOutConfig.IsOpen == 1 {
  2581. if item.Type == 3 {
  2582. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  2583. f_count, _ := strconv.ParseFloat(item.Count, 64)
  2584. good.Total = good.Total + f_count
  2585. service.UpdateGoodInfo(&good)
  2586. operation_time := time.Now().Unix()
  2587. creater := c.GetAdminUserInfo().AdminUser.Id
  2588. //创建退库单
  2589. timeStr := time.Now().Format("2006-01-02")
  2590. timeArr := strings.Split(timeStr, "-")
  2591. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  2592. total = total + 1
  2593. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2594. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2595. cancelStock := models.CancelStock{
  2596. OrderNumber: orderNumber,
  2597. OperaTime: operation_time,
  2598. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2599. Creater: creater,
  2600. Ctime: time.Now().Unix(),
  2601. Status: 1,
  2602. ReturnTime: item.RecordDate,
  2603. Type: 1,
  2604. StorehouseId: houseConfig.StorehouseOutInfo,
  2605. IsCheck: 1,
  2606. }
  2607. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  2608. if msgerrkonde == gorm.ErrRecordNotFound {
  2609. service.AddSigleCancelStock(&cancelStock)
  2610. }
  2611. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  2612. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2613. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2614. //查询该耗材是否出库
  2615. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  2616. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2617. deaerler, _ := service.GetDealerById(info.Dealer)
  2618. var total_count int64
  2619. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2620. total_count += count
  2621. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2622. var flush_count int64
  2623. for _, it := range goodList {
  2624. flush_count += it.StockCount
  2625. }
  2626. fmt.Println("nfo.Count342232332323223232323", info.Count)
  2627. fmt.Println("total_count0999923923932923", total_count)
  2628. if info.ID > 0 {
  2629. if info.Count >= total_count {
  2630. //回退库存
  2631. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2632. cancelStockInfo := models.CancelStockInfo{
  2633. GoodId: item.ProjectId,
  2634. CancelStockId: cancel.ID,
  2635. GoodTypeId: good.GoodTypeId,
  2636. Count: prescribingNumber,
  2637. Price: info.Price,
  2638. Total: 0,
  2639. ProductDate: info.ProductDate,
  2640. ExpiryDate: info.ExpiryDate,
  2641. Ctime: time.Now().Unix(),
  2642. Status: 1,
  2643. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2644. OrderNumber: cancel.OrderNumber,
  2645. Type: 0,
  2646. Dealer: deaerler.DealerName,
  2647. Manufacturer: manufacturer.ManufacturerName,
  2648. Number: info.Number,
  2649. RegisterAccount: "",
  2650. Remark: "",
  2651. WarehouseInfoId: info.WarehouseInfotId,
  2652. PatientId: info.PatientId,
  2653. RecordDate: info.SysRecordTime,
  2654. StorehouseId: houseConfig.StorehouseOutInfo,
  2655. IsCheck: 1,
  2656. }
  2657. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2658. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2659. flow := models.VmStockFlow{
  2660. WarehousingId: info.WarehouseInfotId,
  2661. GoodId: item.ProjectId,
  2662. Number: info.Number,
  2663. LicenseNumber: info.LicenseNumber,
  2664. Count: prescribingNumber,
  2665. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2666. PatientId: item.PatientId,
  2667. SystemTime: info.SysRecordTime,
  2668. ConsumableType: 7,
  2669. IsSys: 0,
  2670. WarehousingOrder: "",
  2671. WarehouseOutId: info.WarehouseOutId,
  2672. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2673. IsEdit: 0,
  2674. CancelStockId: cancel.ID,
  2675. CancelOrderNumber: cancel.OrderNumber,
  2676. Manufacturer: manufacturer.ID,
  2677. Dealer: 0,
  2678. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2679. UpdateCreator: 0,
  2680. Status: 1,
  2681. Ctime: time.Now().Unix(),
  2682. Mtime: 0,
  2683. Price: info.Price,
  2684. WarehousingDetailId: info.WarehouseInfotId,
  2685. WarehouseOutDetailId: info.ID,
  2686. CancelOutDetailId: cancelInfo.ID,
  2687. ProductDate: info.ProductDate,
  2688. ExpireDate: info.ExpiryDate,
  2689. StorehouseId: houseConfig.StorehouseOutInfo,
  2690. OverCount: flush_count,
  2691. }
  2692. service.CreateStockFlowOne(flow)
  2693. //退库数量增加
  2694. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  2695. //出库数量减少
  2696. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  2697. }
  2698. if info.Count < total_count {
  2699. //回退库存
  2700. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2701. cancelStockInfo := models.CancelStockInfo{
  2702. GoodId: item.ProjectId,
  2703. CancelStockId: cancel.ID,
  2704. GoodTypeId: good.GoodTypeId,
  2705. Count: info.Count,
  2706. Price: info.Price,
  2707. Total: 0,
  2708. ProductDate: info.ProductDate,
  2709. ExpiryDate: info.ExpiryDate,
  2710. Ctime: time.Now().Unix(),
  2711. Status: 1,
  2712. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2713. OrderNumber: cancel.OrderNumber,
  2714. Type: 0,
  2715. Dealer: deaerler.DealerName,
  2716. Manufacturer: manufacturer.ManufacturerName,
  2717. Number: info.Number,
  2718. RegisterAccount: "",
  2719. Remark: "",
  2720. WarehouseInfoId: info.WarehouseInfotId,
  2721. PatientId: info.PatientId,
  2722. RecordDate: info.SysRecordTime,
  2723. StorehouseId: houseConfig.StorehouseOutInfo,
  2724. IsCheck: 1,
  2725. }
  2726. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2727. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2728. flow := models.VmStockFlow{
  2729. WarehousingId: info.WarehouseInfotId,
  2730. GoodId: item.ProjectId,
  2731. Number: info.Number,
  2732. LicenseNumber: info.LicenseNumber,
  2733. Count: info.Count,
  2734. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2735. PatientId: item.PatientId,
  2736. SystemTime: info.SysRecordTime,
  2737. ConsumableType: 7,
  2738. IsSys: 0,
  2739. WarehousingOrder: "",
  2740. WarehouseOutId: info.WarehouseOutId,
  2741. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2742. IsEdit: 0,
  2743. CancelStockId: cancel.ID,
  2744. CancelOrderNumber: cancel.OrderNumber,
  2745. Manufacturer: manufacturer.ID,
  2746. Dealer: 0,
  2747. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2748. UpdateCreator: 0,
  2749. Status: 1,
  2750. Ctime: time.Now().Unix(),
  2751. Mtime: 0,
  2752. Price: info.Price,
  2753. WarehousingDetailId: info.WarehouseInfotId,
  2754. WarehouseOutDetailId: info.ID,
  2755. CancelOutDetailId: cancelInfo.ID,
  2756. ProductDate: info.ProductDate,
  2757. ExpireDate: info.ExpiryDate,
  2758. StorehouseId: houseConfig.StorehouseOutInfo,
  2759. OverCount: flush_count,
  2760. }
  2761. service.CreateStockFlowOne(flow)
  2762. //退库数量增加
  2763. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  2764. //出库数量减少
  2765. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  2766. }
  2767. //查询已出库数量
  2768. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2769. if prescribingNumber < dialysisInfo.Count {
  2770. //改变数量
  2771. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  2772. }
  2773. if prescribingNumber >= dialysisInfo.Count {
  2774. //删除出库表
  2775. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2776. }
  2777. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2778. var flush_count_one int64
  2779. for _, it := range goodList {
  2780. flush_count_one += it.StockCount
  2781. }
  2782. //更新库存
  2783. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  2784. fmt.Println("msgerrkonde23332323", msgerrkonde)
  2785. //更新基础库库存
  2786. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  2787. }
  2788. }
  2789. }
  2790. }
  2791. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2792. fmt.Println(err)
  2793. }
  2794. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2795. fmt.Println(err)
  2796. if len(advices) > 0 {
  2797. for _, item := range advices {
  2798. redis := service.RedisClient()
  2799. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2800. redis.Set(keyFive, "", time.Second)
  2801. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2802. redis.Set(keyOne, "", time.Second)
  2803. redis.Close()
  2804. }
  2805. }
  2806. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  2807. if len(advices) > 0 {
  2808. for _, item := range advices {
  2809. creater := c.GetAdminUserInfo().AdminUser.Id
  2810. service.DrugAutoAddCancelInfo(item, creater)
  2811. }
  2812. }
  2813. } else {
  2814. if drugStockConfig.IsOpen == 1 {
  2815. if len(advices) > 0 {
  2816. for _, item := range advices {
  2817. creater := c.GetAdminUserInfo().AdminUser.Id
  2818. service.DrugAutoAddCancelInfo(item, creater)
  2819. }
  2820. }
  2821. }
  2822. }
  2823. c.ServeSuccessJSON(map[string]interface{}{
  2824. "msg": "删除成功",
  2825. })
  2826. return
  2827. }
  2828. func (c *HisApiController) DeleteDoctorAdvice() {
  2829. id, _ := c.GetInt64("id")
  2830. advice, _ := service.GetHisDoctorAdvicesById(id)
  2831. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2832. //已收费和已发药的限制逻辑
  2833. isCharge := false
  2834. isMedicine := false
  2835. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  2836. //获取今天该患者所有处方,判断是否发药或者收费
  2837. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2838. for _, item := range new_prescriptions {
  2839. if item.IsMedicine == 1 {
  2840. isMedicine = true
  2841. }
  2842. }
  2843. for _, item := range new_prescriptions {
  2844. if item.OrderStatus == 4 {
  2845. isCharge = true
  2846. }
  2847. }
  2848. if isMedicine {
  2849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2850. return
  2851. }
  2852. if isCharge {
  2853. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2854. return
  2855. }
  2856. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  2857. for _, item := range advices {
  2858. if item.IsMedicine == 1 {
  2859. isMedicine = true
  2860. }
  2861. }
  2862. if isMedicine {
  2863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  2864. return
  2865. }
  2866. if new_prescription.ID > 0 {
  2867. if new_prescription.OrderStatus == 2 {
  2868. isCharge = true
  2869. }
  2870. }
  2871. if isCharge {
  2872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  2873. return
  2874. }
  2875. //已收费和已发药的限制逻辑
  2876. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  2877. redis := service.RedisClient()
  2878. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2879. redis.Set(keyFive, "", time.Second)
  2880. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2881. redis.Set(keyOne, "", time.Second)
  2882. defer redis.Close()
  2883. if err == nil {
  2884. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  2885. //查询是否在处方中出库
  2886. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  2887. if openConfig.IsOpen != 1 {
  2888. //判断该医嘱是否执行了
  2889. if advice.ExecutionState == 1 {
  2890. creater := c.GetAdminUserInfo().AdminUser.Id
  2891. service.DrugAutoAddCancelInfo(&advice, creater)
  2892. }
  2893. }
  2894. //开启保存处方扣减功能
  2895. if openConfig.IsOpen == 1 {
  2896. creater := c.GetAdminUserInfo().AdminUser.Id
  2897. service.DrugAutoAddCancelInfo(&advice, creater)
  2898. }
  2899. } else {
  2900. if drugStockConfig.IsOpen == 1 {
  2901. //查询是否在处方中出库
  2902. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  2903. if openConfig.IsOpen != 1 {
  2904. //判断该医嘱是否执行了
  2905. if advice.ExecutionState == 1 {
  2906. creater := c.GetAdminUserInfo().AdminUser.Id
  2907. service.DrugAutoAddCancelInfo(&advice, creater)
  2908. }
  2909. }
  2910. //开启保存处方扣减功能
  2911. if openConfig.IsOpen == 1 {
  2912. creater := c.GetAdminUserInfo().AdminUser.Id
  2913. service.DrugAutoAddCancelInfo(&advice, creater)
  2914. }
  2915. }
  2916. }
  2917. c.ServeSuccessJSON(map[string]interface{}{
  2918. "msg": "删除成功",
  2919. })
  2920. return
  2921. } else {
  2922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2923. return
  2924. }
  2925. }
  2926. func (c *HisApiController) DeleteProject() {
  2927. id, _ := c.GetInt64("id")
  2928. adminInfo := c.GetAdminUserInfo()
  2929. project, _ := service.GetHisProjectByID(id)
  2930. // var consumable models.DialysisBeforePrepare
  2931. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2932. //耗材保存处方出库
  2933. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2934. isCharge := false
  2935. isMedicine := false
  2936. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  2937. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2938. for _, item := range new_prescriptions {
  2939. if item.IsMedicine == 1 {
  2940. isMedicine = true
  2941. }
  2942. }
  2943. for _, item := range new_prescriptions {
  2944. if item.OrderStatus == 4 {
  2945. isCharge = true
  2946. }
  2947. }
  2948. if isMedicine {
  2949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2950. return
  2951. }
  2952. if isCharge {
  2953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2954. return
  2955. }
  2956. if new_prescription.ID > 0 {
  2957. if new_prescription.OrderStatus == 2 {
  2958. isCharge = true
  2959. }
  2960. }
  2961. if isCharge {
  2962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  2963. return
  2964. }
  2965. service.DeletePrintInfo(id)
  2966. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  2967. label.Status = 0
  2968. service.CreateHisLabelRecord(&label)
  2969. if goodOutConfig.IsOpen != 1 {
  2970. if stockConfig.IsOpen == 1 {
  2971. if project.Type == 2 {
  2972. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2973. fmt.Println(err)
  2974. }
  2975. if project.Type == 3 && project.IsOut == 1 {
  2976. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2977. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2978. f_count, _ := strconv.ParseFloat(project.Count, 64)
  2979. operation_time := time.Now().Unix()
  2980. creater := adminInfo.AdminUser.Id
  2981. //创建退库单
  2982. timeStr := time.Now().Format("2006-01-02")
  2983. timeArr := strings.Split(timeStr, "-")
  2984. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  2985. total = total + 1
  2986. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2987. cancelStock := models.CancelStock{
  2988. OrderNumber: orderNumber,
  2989. OperaTime: operation_time,
  2990. OrgId: adminInfo.CurrentOrgId,
  2991. Creater: creater,
  2992. Ctime: time.Now().Unix(),
  2993. Status: 1,
  2994. ReturnTime: project.RecordDate,
  2995. Type: 1,
  2996. StorehouseId: houseConfig.StorehouseOutInfo,
  2997. IsCheck: 1,
  2998. }
  2999. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3000. if msgerrkonde == gorm.ErrRecordNotFound {
  3001. service.AddSigleCancelStock(&cancelStock)
  3002. }
  3003. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3004. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3005. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3006. //获取出库数据
  3007. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3008. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3009. deaerler, _ := service.GetDealerById(info.Dealer)
  3010. if info.ID > 0 {
  3011. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3012. if info.Count >= prescribingNumber {
  3013. cancelStockInfo := models.CancelStockInfo{
  3014. GoodId: project.ProjectId,
  3015. CancelStockId: cancel.ID,
  3016. GoodTypeId: good.GoodTypeId,
  3017. Count: prescribingNumber,
  3018. Price: info.Price,
  3019. Total: 0,
  3020. ProductDate: info.ProductDate,
  3021. ExpiryDate: info.ExpiryDate,
  3022. Ctime: time.Now().Unix(),
  3023. Status: 1,
  3024. OrgId: adminInfo.CurrentOrgId,
  3025. OrderNumber: cancel.OrderNumber,
  3026. Type: 0,
  3027. Dealer: deaerler.DealerName,
  3028. Manufacturer: manufacturer.ManufacturerName,
  3029. Number: info.Number,
  3030. RegisterAccount: "",
  3031. Remark: "",
  3032. WarehouseInfoId: info.WarehouseInfotId,
  3033. PatientId: info.PatientId,
  3034. RecordDate: info.SysRecordTime,
  3035. StorehouseId: houseConfig.StorehouseOutInfo,
  3036. IsCheck: 1,
  3037. }
  3038. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3039. //回退库存
  3040. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3041. //退库数量增加
  3042. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3043. //出库数量减少
  3044. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3045. }
  3046. if info.Count < prescribingNumber {
  3047. cancelStockInfo := models.CancelStockInfo{
  3048. GoodId: project.ProjectId,
  3049. CancelStockId: cancel.ID,
  3050. GoodTypeId: good.GoodTypeId,
  3051. Count: info.Count,
  3052. Price: info.Price,
  3053. Total: 0,
  3054. ProductDate: info.ProductDate,
  3055. ExpiryDate: info.ExpiryDate,
  3056. Ctime: time.Now().Unix(),
  3057. Status: 1,
  3058. OrgId: adminInfo.CurrentOrgId,
  3059. OrderNumber: cancel.OrderNumber,
  3060. Type: 0,
  3061. Dealer: deaerler.DealerName,
  3062. Manufacturer: manufacturer.ManufacturerName,
  3063. Number: info.Number,
  3064. RegisterAccount: "",
  3065. Remark: "",
  3066. WarehouseInfoId: info.WarehouseInfotId,
  3067. PatientId: info.PatientId,
  3068. RecordDate: info.SysRecordTime,
  3069. StorehouseId: houseConfig.StorehouseOutInfo,
  3070. IsCheck: 1,
  3071. }
  3072. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3073. //回退库存
  3074. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3075. //退库数量增加
  3076. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3077. //出库数量减少
  3078. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3079. }
  3080. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3081. var over_count int64
  3082. for _, it := range goodList {
  3083. over_count += it.StockCount
  3084. }
  3085. if info.Count >= prescribingNumber {
  3086. flow := models.VmStockFlow{
  3087. WarehousingId: info.WarehouseInfotId,
  3088. GoodId: project.ProjectId,
  3089. Number: info.Number,
  3090. LicenseNumber: info.LicenseNumber,
  3091. Count: prescribingNumber,
  3092. UserOrgId: adminInfo.CurrentOrgId,
  3093. PatientId: project.PatientId,
  3094. SystemTime: info.SysRecordTime,
  3095. ConsumableType: 7,
  3096. IsSys: 0,
  3097. WarehousingOrder: "",
  3098. WarehouseOutId: info.WarehouseOutId,
  3099. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3100. IsEdit: 0,
  3101. CancelStockId: cancel.ID,
  3102. CancelOrderNumber: cancel.OrderNumber,
  3103. Manufacturer: manufacturer.ID,
  3104. Dealer: 0,
  3105. Creator: adminInfo.AdminUser.Id,
  3106. UpdateCreator: 0,
  3107. Status: 1,
  3108. Ctime: time.Now().Unix(),
  3109. Mtime: 0,
  3110. Price: info.Price,
  3111. WarehousingDetailId: info.WarehouseInfotId,
  3112. WarehouseOutDetailId: info.ID,
  3113. CancelOutDetailId: cancelInfo.ID,
  3114. ProductDate: info.ProductDate,
  3115. ExpireDate: info.ExpiryDate,
  3116. StorehouseId: houseConfig.StorehouseOutInfo,
  3117. OverCount: over_count,
  3118. }
  3119. service.CreateStockFlowOne(flow)
  3120. }
  3121. if info.Count < prescribingNumber {
  3122. flow := models.VmStockFlow{
  3123. WarehousingId: info.WarehouseInfotId,
  3124. GoodId: project.ProjectId,
  3125. Number: info.Number,
  3126. LicenseNumber: info.LicenseNumber,
  3127. Count: info.Count,
  3128. UserOrgId: adminInfo.CurrentOrgId,
  3129. PatientId: project.PatientId,
  3130. SystemTime: info.SysRecordTime,
  3131. ConsumableType: 7,
  3132. IsSys: 0,
  3133. WarehousingOrder: "",
  3134. WarehouseOutId: info.WarehouseOutId,
  3135. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3136. IsEdit: 0,
  3137. CancelStockId: cancel.ID,
  3138. CancelOrderNumber: cancel.OrderNumber,
  3139. Manufacturer: manufacturer.ID,
  3140. Dealer: 0,
  3141. Creator: adminInfo.AdminUser.Id,
  3142. UpdateCreator: 0,
  3143. Status: 1,
  3144. Ctime: time.Now().Unix(),
  3145. Mtime: 0,
  3146. Price: info.Price,
  3147. WarehousingDetailId: info.WarehouseInfotId,
  3148. WarehouseOutDetailId: info.ID,
  3149. CancelOutDetailId: cancelInfo.ID,
  3150. ProductDate: info.ProductDate,
  3151. ExpireDate: info.ExpiryDate,
  3152. StorehouseId: houseConfig.StorehouseOutInfo,
  3153. OverCount: over_count,
  3154. }
  3155. service.CreateStockFlowOne(flow)
  3156. }
  3157. //查询已出库数量
  3158. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3159. if prescribingNumber < dialysisInfo.Count {
  3160. //改变数量
  3161. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3162. }
  3163. if prescribingNumber >= dialysisInfo.Count {
  3164. //删除出库表
  3165. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3166. }
  3167. //更新剩余库存
  3168. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3169. //查询今日该患者开了多少耗材
  3170. //projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  3171. //
  3172. //var total_count int64
  3173. //var cha_count int64
  3174. //for _, item := range projectList {
  3175. // count, _ := strconv.ParseInt(item.Count, 10, 64)
  3176. // total_count += count
  3177. //}
  3178. //
  3179. ////查询今日该耗材退库数量
  3180. //cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  3181. //var cancel_count int64
  3182. //for _, items := range cancelInfoOne {
  3183. // cancel_count += items.Count
  3184. //}
  3185. //
  3186. //cha_count = total_count - cancel_count
  3187. //
  3188. //if total_count > cancel_count {
  3189. //
  3190. // out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  3191. // if err == gorm.ErrRecordNotFound {
  3192. // //没有记录,则创建出库单
  3193. // timeStr := time.Now().Format("2006-01-02")
  3194. // timeArr := strings.Split(timeStr, "-")
  3195. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3196. // total = total + 1
  3197. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3198. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3199. // number = number + total
  3200. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3201. // warehouseOut := models.WarehouseOut{
  3202. // WarehouseOutOrderNumber: warehousing_out_order,
  3203. // OperationTime: time.Now().Unix(),
  3204. // OrgId: adminInfo.CurrentOrgId,
  3205. // Creater: creater,
  3206. // Ctime: time.Now().Unix(),
  3207. // Status: 1,
  3208. // WarehouseOutTime: info.SysRecordTime,
  3209. // Dealer: 0,
  3210. // Manufacturer: 0,
  3211. // Type: 1,
  3212. // IsSys: 1,
  3213. // StorehouseId: houseConfig.StorehouseOutInfo,
  3214. // }
  3215. // err := service.AddSigleWarehouseOut(&warehouseOut)
  3216. // if err != nil {
  3217. // utils.TraceLog("创建出库单失败 err = %v", err)
  3218. // return
  3219. // }
  3220. // prepare := &models.DialysisBeforePrepare{
  3221. // UserOrgId: adminInfo.CurrentOrgId,
  3222. // PatientId: info.PatientId,
  3223. // RecordDate: info.SysRecordTime,
  3224. // GoodId: project.ProjectId,
  3225. // GoodTypeId: info.GoodTypeId,
  3226. // Count: cha_count,
  3227. // StorehouseId: houseConfig.StorehouseOutInfo,
  3228. // }
  3229. // //出库
  3230. // service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  3231. // } else if err == nil {
  3232. // prepare := &models.DialysisBeforePrepare{
  3233. // UserOrgId: adminInfo.CurrentOrgId,
  3234. // PatientId: info.PatientId,
  3235. // RecordDate: info.SysRecordTime,
  3236. // GoodId: project.ProjectId,
  3237. // GoodTypeId: info.GoodTypeId,
  3238. // Count: cha_count,
  3239. // StorehouseId: houseConfig.StorehouseOutInfo,
  3240. // }
  3241. // //出库
  3242. // service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  3243. // }
  3244. //
  3245. //}
  3246. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3247. var total_count_one int64
  3248. for _, it := range stockList {
  3249. total_count_one += it.StockCount
  3250. }
  3251. //基础库插入数据
  3252. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3253. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3254. var flush_count int64
  3255. for _, it := range goodListOne {
  3256. flush_count += it.StockCount
  3257. }
  3258. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3259. if errs != nil {
  3260. goodErrcode := models.XtGoodErrcode{
  3261. UserOrgId: project.UserOrgId,
  3262. Errcode: "手动出库更新剩余出库失败",
  3263. GoodId: project.ProjectId,
  3264. Status: 1,
  3265. Ctime: time.Now().Unix(),
  3266. Mtime: 0,
  3267. Count: 0,
  3268. StockCount: 0,
  3269. Creater: creater,
  3270. BatchNumberId: 0,
  3271. WarehouseOutId: 0,
  3272. }
  3273. service.CreateGoodErrcode(goodErrcode)
  3274. }
  3275. }
  3276. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3277. fmt.Println(err)
  3278. } else {
  3279. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3280. fmt.Println(err)
  3281. }
  3282. }
  3283. }
  3284. if goodOutConfig.IsOpen == 1 {
  3285. if project.Type == 3 {
  3286. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3287. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3288. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3289. operation_time := time.Now().Unix()
  3290. creater := adminInfo.AdminUser.Id
  3291. //创建退库单
  3292. timeStr := time.Now().Format("2006-01-02")
  3293. timeArr := strings.Split(timeStr, "-")
  3294. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3295. total = total + 1
  3296. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3297. cancelStock := models.CancelStock{
  3298. OrderNumber: orderNumber,
  3299. OperaTime: operation_time,
  3300. OrgId: adminInfo.CurrentOrgId,
  3301. Creater: creater,
  3302. Ctime: time.Now().Unix(),
  3303. Status: 1,
  3304. ReturnTime: project.RecordDate,
  3305. Type: 1,
  3306. StorehouseId: houseConfig.StorehouseOutInfo,
  3307. IsCheck: 1,
  3308. }
  3309. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3310. if msgerrkonde == gorm.ErrRecordNotFound {
  3311. service.AddSigleCancelStock(&cancelStock)
  3312. }
  3313. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3314. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3315. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3316. //获取出库数据
  3317. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3318. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3319. deaerler, _ := service.GetDealerById(info.Dealer)
  3320. if info.ID > 0 {
  3321. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3322. if info.Count >= prescribingNumber {
  3323. cancelStockInfo := models.CancelStockInfo{
  3324. GoodId: project.ProjectId,
  3325. CancelStockId: cancel.ID,
  3326. GoodTypeId: good.GoodTypeId,
  3327. Count: prescribingNumber,
  3328. Price: info.Price,
  3329. Total: 0,
  3330. ProductDate: info.ProductDate,
  3331. ExpiryDate: info.ExpiryDate,
  3332. Ctime: time.Now().Unix(),
  3333. Status: 1,
  3334. OrgId: adminInfo.CurrentOrgId,
  3335. OrderNumber: cancel.OrderNumber,
  3336. Type: 0,
  3337. Dealer: deaerler.DealerName,
  3338. Manufacturer: manufacturer.ManufacturerName,
  3339. Number: info.Number,
  3340. RegisterAccount: "",
  3341. Remark: "",
  3342. WarehouseInfoId: info.WarehouseInfotId,
  3343. PatientId: info.PatientId,
  3344. RecordDate: info.SysRecordTime,
  3345. StorehouseId: houseConfig.StorehouseOutInfo,
  3346. IsCheck: 1,
  3347. }
  3348. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3349. //回退库存
  3350. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3351. //退库数量增加
  3352. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3353. //出库数量减少
  3354. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3355. }
  3356. if info.Count < prescribingNumber {
  3357. cancelStockInfo := models.CancelStockInfo{
  3358. GoodId: project.ProjectId,
  3359. CancelStockId: cancel.ID,
  3360. GoodTypeId: good.GoodTypeId,
  3361. Count: info.Count,
  3362. Price: info.Price,
  3363. Total: 0,
  3364. ProductDate: info.ProductDate,
  3365. ExpiryDate: info.ExpiryDate,
  3366. Ctime: time.Now().Unix(),
  3367. Status: 1,
  3368. OrgId: adminInfo.CurrentOrgId,
  3369. OrderNumber: cancel.OrderNumber,
  3370. Type: 0,
  3371. Dealer: deaerler.DealerName,
  3372. Manufacturer: manufacturer.ManufacturerName,
  3373. Number: info.Number,
  3374. RegisterAccount: "",
  3375. Remark: "",
  3376. WarehouseInfoId: info.WarehouseInfotId,
  3377. PatientId: info.PatientId,
  3378. RecordDate: info.SysRecordTime,
  3379. StorehouseId: houseConfig.StorehouseOutInfo,
  3380. IsCheck: 1,
  3381. }
  3382. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3383. //回退库存
  3384. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3385. //退库数量增加
  3386. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3387. //出库数量减少
  3388. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3389. }
  3390. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3391. var over_count int64
  3392. for _, it := range goodList {
  3393. over_count += it.StockCount
  3394. }
  3395. if info.Count >= prescribingNumber {
  3396. flow := models.VmStockFlow{
  3397. WarehousingId: info.WarehouseInfotId,
  3398. GoodId: project.ProjectId,
  3399. Number: info.Number,
  3400. LicenseNumber: info.LicenseNumber,
  3401. Count: prescribingNumber,
  3402. UserOrgId: adminInfo.CurrentOrgId,
  3403. PatientId: project.PatientId,
  3404. SystemTime: info.SysRecordTime,
  3405. ConsumableType: 7,
  3406. IsSys: 0,
  3407. WarehousingOrder: "",
  3408. WarehouseOutId: info.WarehouseOutId,
  3409. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3410. IsEdit: 0,
  3411. CancelStockId: cancel.ID,
  3412. CancelOrderNumber: cancel.OrderNumber,
  3413. Manufacturer: manufacturer.ID,
  3414. Dealer: 0,
  3415. Creator: adminInfo.AdminUser.Id,
  3416. UpdateCreator: 0,
  3417. Status: 1,
  3418. Ctime: time.Now().Unix(),
  3419. Mtime: 0,
  3420. Price: info.Price,
  3421. WarehousingDetailId: info.WarehouseInfotId,
  3422. WarehouseOutDetailId: info.ID,
  3423. CancelOutDetailId: cancelInfo.ID,
  3424. ProductDate: info.ProductDate,
  3425. ExpireDate: info.ExpiryDate,
  3426. StorehouseId: houseConfig.StorehouseOutInfo,
  3427. OverCount: over_count,
  3428. }
  3429. service.CreateStockFlowOne(flow)
  3430. }
  3431. if info.Count < prescribingNumber {
  3432. flow := models.VmStockFlow{
  3433. WarehousingId: info.WarehouseInfotId,
  3434. GoodId: project.ProjectId,
  3435. Number: info.Number,
  3436. LicenseNumber: info.LicenseNumber,
  3437. Count: info.Count,
  3438. UserOrgId: adminInfo.CurrentOrgId,
  3439. PatientId: project.PatientId,
  3440. SystemTime: info.SysRecordTime,
  3441. ConsumableType: 7,
  3442. IsSys: 0,
  3443. WarehousingOrder: "",
  3444. WarehouseOutId: info.WarehouseOutId,
  3445. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3446. IsEdit: 0,
  3447. CancelStockId: cancel.ID,
  3448. CancelOrderNumber: cancel.OrderNumber,
  3449. Manufacturer: manufacturer.ID,
  3450. Dealer: 0,
  3451. Creator: adminInfo.AdminUser.Id,
  3452. UpdateCreator: 0,
  3453. Status: 1,
  3454. Ctime: time.Now().Unix(),
  3455. Mtime: 0,
  3456. Price: info.Price,
  3457. WarehousingDetailId: info.WarehouseInfotId,
  3458. WarehouseOutDetailId: info.ID,
  3459. CancelOutDetailId: cancelInfo.ID,
  3460. ProductDate: info.ProductDate,
  3461. ExpireDate: info.ExpiryDate,
  3462. StorehouseId: houseConfig.StorehouseOutInfo,
  3463. OverCount: over_count,
  3464. }
  3465. service.CreateStockFlowOne(flow)
  3466. }
  3467. //查询已出库数量
  3468. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3469. if prescribingNumber < dialysisInfo.Count {
  3470. //改变数量
  3471. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3472. }
  3473. if prescribingNumber >= dialysisInfo.Count {
  3474. //删除出库表
  3475. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3476. }
  3477. //更新剩余库存
  3478. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3479. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3480. var total_count_one int64
  3481. for _, it := range stockList {
  3482. total_count_one += it.StockCount
  3483. }
  3484. //基础库插入数据
  3485. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3486. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3487. var flush_count int64
  3488. for _, it := range goodListOne {
  3489. flush_count += it.StockCount
  3490. }
  3491. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3492. if errs != nil {
  3493. goodErrcode := models.XtGoodErrcode{
  3494. UserOrgId: project.UserOrgId,
  3495. Errcode: "手动出库更新剩余出库失败",
  3496. GoodId: project.ProjectId,
  3497. Status: 1,
  3498. Ctime: time.Now().Unix(),
  3499. Mtime: 0,
  3500. Count: 0,
  3501. StockCount: 0,
  3502. Creater: creater,
  3503. BatchNumberId: 0,
  3504. WarehouseOutId: 0,
  3505. }
  3506. service.CreateGoodErrcode(goodErrcode)
  3507. }
  3508. }
  3509. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3510. fmt.Println(err)
  3511. } else {
  3512. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3513. fmt.Println(err)
  3514. }
  3515. }
  3516. c.ServeSuccessJSON(map[string]interface{}{
  3517. "msg": "删除成功",
  3518. })
  3519. return
  3520. }
  3521. func (c *HisApiController) CreateHisAdditionalCharge() {
  3522. his_patient_id, _ := c.GetInt64("his_patient_id")
  3523. patient_id, _ := c.GetInt64("patient_id")
  3524. record_date := c.GetString("record_date")
  3525. timeLayout := "2006-01-02"
  3526. loc, _ := time.LoadLocation("Local")
  3527. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3528. if err != nil {
  3529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3530. return
  3531. }
  3532. adminInfo := c.GetAdminUserInfo()
  3533. recordDateTime := theTime.Unix()
  3534. dataBody := make(map[string]interface{}, 0)
  3535. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3536. if err != nil {
  3537. utils.ErrorLog(err.Error())
  3538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3539. return
  3540. }
  3541. var additions []*models.HisAdditionalCharge
  3542. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  3543. additions, _ := dataBody["addition"].([]interface{})
  3544. if len(additions) > 0 {
  3545. for _, item := range additions {
  3546. items := item.(map[string]interface{})
  3547. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  3548. utils.ErrorLog("item_id")
  3549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3550. return
  3551. }
  3552. item_id := int64(items["item_id"].(float64))
  3553. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  3554. utils.ErrorLog("item_name")
  3555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3556. return
  3557. }
  3558. item_name := items["item_name"].(string)
  3559. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  3560. utils.ErrorLog("price")
  3561. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3562. return
  3563. }
  3564. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  3565. ctime := time.Now().Unix()
  3566. additional := &models.HisAdditionalCharge{
  3567. PatientId: patient_id,
  3568. HisPatientId: his_patient_id,
  3569. UserOrgId: adminInfo.CurrentOrgId,
  3570. RecordDate: recordDateTime,
  3571. CreatedTime: ctime,
  3572. UpdatedTime: ctime,
  3573. Modifier: adminInfo.AdminUser.Id,
  3574. Creator: adminInfo.AdminUser.Id,
  3575. Price: price,
  3576. ItemName: item_name,
  3577. ItemId: item_id,
  3578. Status: 1,
  3579. }
  3580. additions = append(additions, additional)
  3581. }
  3582. }
  3583. }
  3584. for _, item := range additions {
  3585. service.CreateAddtionalCharge(item)
  3586. }
  3587. c.ServeSuccessJSON(map[string]interface{}{
  3588. "msg": "创建成功",
  3589. })
  3590. }
  3591. func (c *HisApiController) CreateHisPatientCaseHistory() {
  3592. blood_fat := c.GetString("blood_fat")
  3593. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  3594. blood_sugar := c.GetString("blood_sugar")
  3595. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  3596. chief_conplaint := c.GetString("chief_conplaint")
  3597. dbp := c.GetString("dbp")
  3598. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  3599. delivery_way, _ := c.GetInt64("delivery_way")
  3600. diagnostic := c.GetString("diagnostic")
  3601. family_history := c.GetString("family_history")
  3602. height := c.GetString("height")
  3603. history_of_present_illness := c.GetString("history_of_present_illness")
  3604. is_infect, _ := c.GetInt64("is_infect")
  3605. past_history := c.GetString("past_history")
  3606. patient_id, _ := c.GetInt64("patient_id")
  3607. his_patient_id, _ := c.GetInt64("his_patient_id")
  3608. personal_history := c.GetString("personal_history")
  3609. pulse := c.GetString("pulse")
  3610. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  3611. sbp := c.GetString("sbp")
  3612. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  3613. heightfloat, _ := strconv.ParseFloat(height, 64)
  3614. sicktype := c.GetString("sick_type")
  3615. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  3616. symptom := c.GetString("symptom")
  3617. sick_date := c.GetString("sick_date")
  3618. temperatures := c.GetString("temperature")
  3619. temperature, _ := strconv.ParseFloat(temperatures, 64)
  3620. record_date := c.GetString("record_date")
  3621. breathing := c.GetString("breathing")
  3622. doctor_advice := c.GetString("doctor_advice")
  3623. remark := c.GetString("remark")
  3624. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  3625. sick, _ := c.GetInt64("sick")
  3626. diagnose, _ := c.GetInt64("diagnose")
  3627. //id, _ := c.GetInt64("id")
  3628. timeLayout := "2006-01-02"
  3629. loc, _ := time.LoadLocation("Local")
  3630. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3631. allergic_history := c.GetString("allergic_history")
  3632. if err != nil {
  3633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3634. return
  3635. }
  3636. recordDateTime := theTime.Unix()
  3637. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  3638. if err != nil {
  3639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3640. return
  3641. }
  3642. sickTimes := sickTime.Unix()
  3643. ctime := time.Now().Unix()
  3644. primary_disease := c.GetString("primary_disease")
  3645. confirm_failure_date := c.GetString("confirm_failure_date")
  3646. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  3647. drug_allergy_history := c.GetString("drug_allergy_history")
  3648. physical_examination := c.GetString("physical_examination")
  3649. special_inspection := c.GetString("special_inspection")
  3650. lab_apparatus := c.GetString("lab_apparatus")
  3651. caseHistory := models.HisPatientCaseHistory{
  3652. HisPatientId: his_patient_id,
  3653. PatientId: patient_id,
  3654. Temperature: temperature,
  3655. BloodSugar: bloodsugarfloat,
  3656. Pulse: pulsefloat,
  3657. Sbp: sbpfloat,
  3658. Dbp: dbpfloat,
  3659. Height: heightfloat,
  3660. BloodFat: bloodfatfloat,
  3661. SickType: sick_type,
  3662. Symptom: symptom,
  3663. SickDate: sickTimes,
  3664. IsInfect: is_infect,
  3665. HistoryOfPresentIllness: history_of_present_illness,
  3666. PastHistory: past_history,
  3667. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  3668. ChiefConplaint: chief_conplaint,
  3669. PersonalHistory: personal_history,
  3670. FamilyHistory: family_history,
  3671. Diagnostic: diagnostic,
  3672. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3673. Status: 1,
  3674. Ctime: ctime,
  3675. Mtime: ctime,
  3676. RecordDate: recordDateTime,
  3677. DeliveryWay: delivery_way,
  3678. Breathing: breathingfloat,
  3679. DoctorAdvice: doctor_advice,
  3680. Remark: remark,
  3681. Sick: sick,
  3682. Diagnose: diagnose,
  3683. AllergicHistory: allergic_history,
  3684. PrimaryDisease: primary_disease,
  3685. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  3686. DrugAllergyHistory: drug_allergy_history,
  3687. PhysicalExamination: physical_examination,
  3688. SpecialInspection: special_inspection,
  3689. LabApparatus: lab_apparatus,
  3690. }
  3691. //查询该患者是否有病历
  3692. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  3693. if errcodes == gorm.ErrRecordNotFound {
  3694. err = service.SaveHisPatientCaseHistory(&caseHistory)
  3695. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  3696. if err != nil {
  3697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3698. return
  3699. }
  3700. c.ServeSuccessJSON(map[string]interface{}{
  3701. "caseHistory": caseHistory,
  3702. "historyInfo": historyInfo,
  3703. })
  3704. return
  3705. } else if errcodes == nil {
  3706. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  3707. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  3708. if err != nil {
  3709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3710. return
  3711. }
  3712. c.ServeSuccessJSON(map[string]interface{}{
  3713. "caseHistory": caseHistory,
  3714. "historyInfo": historyInfo,
  3715. })
  3716. }
  3717. //查询该患者是否有病历
  3718. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  3719. //if errcode == gorm.ErrRecordNotFound {
  3720. // err = service.SaveHisPatientCaseHistory(caseHistory)
  3721. // if err != nil {
  3722. // c.ServeSuccessJSON(map[string]interface{}{
  3723. // "msg": "保存成功",
  3724. // })
  3725. // }
  3726. //} else if errcode == nil {
  3727. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3728. // return
  3729. //}
  3730. }
  3731. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  3732. patient_id, _ := c.GetInt64("patient_id", 0)
  3733. adminUser := c.GetAdminUserInfo()
  3734. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  3735. c.ServeSuccessJSON(map[string]interface{}{
  3736. "list": caseHistorys,
  3737. })
  3738. }
  3739. func (c *HisApiController) GetHisPatientCaseHistory() {
  3740. record_date, _ := c.GetInt64("record_date", 0)
  3741. patient_id, _ := c.GetInt64("patient_id", 0)
  3742. admin := c.GetAdminUserInfo()
  3743. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  3744. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  3745. c.ServeSuccessJSON(map[string]interface{}{
  3746. "info": info,
  3747. "case_history": case_history,
  3748. })
  3749. }
  3750. func (c *HisApiController) CreateCaseHistoryTemplate() {
  3751. template_name := c.GetString("template_name")
  3752. template_remark := c.GetString("template_remark")
  3753. doctor := c.GetAdminUserInfo().AdminUser.Id
  3754. diagnostic := c.GetString("diagnostic")
  3755. chief_conplaint := c.GetString("chief_conplain")
  3756. history_of_present_illness := c.GetString("history_of_present_illness")
  3757. past_history := c.GetString("past_history")
  3758. personal_history := c.GetString("personal_history")
  3759. family_history := c.GetString("family_history")
  3760. user_name := c.GetString("user_name")
  3761. doctor_advice := c.GetString("doctor_advice")
  3762. remark := c.GetString("remark")
  3763. //record_date := c.GetString("record_date")
  3764. //fmt.Println("record_date--------",record_date)
  3765. //timeLayout := "2006-01-02"
  3766. //loc, _ := time.LoadLocation("Local")
  3767. //
  3768. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3769. //if err != nil {
  3770. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3771. // return
  3772. //}
  3773. //recordDateTime := theTime.Unix()
  3774. ctime := time.Now().Unix()
  3775. template := models.HisCaseHistoryTemplate{
  3776. HistoryOfPresentIllness: history_of_present_illness,
  3777. PastHistory: past_history,
  3778. ChiefConplaint: chief_conplaint,
  3779. PersonalHistory: personal_history,
  3780. FamilyHistory: family_history,
  3781. Diagnostic: diagnostic,
  3782. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3783. Status: 1,
  3784. Ctime: ctime,
  3785. Mtime: ctime,
  3786. RecordDate: time.Now().Unix(),
  3787. TemplateName: template_name,
  3788. TemplateRemark: template_remark,
  3789. Creator: doctor,
  3790. Modifier: doctor,
  3791. UserName: user_name,
  3792. DoctorAdvice: doctor_advice,
  3793. Remark: remark,
  3794. }
  3795. err := service.SaveHisPatientCaseHistoryTemplate(template)
  3796. if err == nil {
  3797. c.ServeSuccessJSON(map[string]interface{}{
  3798. "msg": "保存成功",
  3799. })
  3800. } else {
  3801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3802. return
  3803. }
  3804. }
  3805. func (c *HisApiController) GetCaseHistoryTemplate() {
  3806. timeLayout := "2006-01-02"
  3807. loc, _ := time.LoadLocation("Local")
  3808. keyword := c.GetString("keyword")
  3809. start_time := c.GetString("start_time")
  3810. end_time := c.GetString("end_time")
  3811. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3812. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3813. admin := c.GetAdminUserInfo()
  3814. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  3815. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  3816. c.ServeSuccessJSON(map[string]interface{}{
  3817. "template": template,
  3818. //"history": history,
  3819. })
  3820. }
  3821. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  3822. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3823. utils.ErrorLog("drug_name")
  3824. return enums.ErrorCodeParamWrong
  3825. }
  3826. adviceName, _ := json["drug_name"].(string)
  3827. if len(adviceName) == 0 {
  3828. utils.ErrorLog("len(advice_name) == 0")
  3829. return enums.ErrorCodeParamWrong
  3830. }
  3831. advice.AdviceName = adviceName
  3832. adviceDesc, _ := json["advice_desc"].(string)
  3833. advice.AdviceDesc = adviceDesc
  3834. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3835. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3836. advice.DrugSpec = drugSpec
  3837. }
  3838. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3839. remark, _ := json["remark"].(string)
  3840. advice.Remark = remark
  3841. }
  3842. if json["id"] == nil {
  3843. advice.DrugId = 0
  3844. } else {
  3845. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3846. drug_id := int64(json["id"].(float64))
  3847. advice.DrugId = drug_id
  3848. }
  3849. }
  3850. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3851. advice_id := int64(json["advice_id"].(float64))
  3852. advice.ID = advice_id
  3853. if advice.ID > 0 {
  3854. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3855. if err == nil {
  3856. if hisAdvice.ID > 0 {
  3857. advice.ExecutionTime = hisAdvice.ExecutionTime
  3858. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3859. advice.ExecutionState = hisAdvice.ExecutionState
  3860. advice.CheckTime = hisAdvice.CheckTime
  3861. advice.Checker = hisAdvice.Checker
  3862. advice.CheckState = hisAdvice.CheckState
  3863. advice.StartTime = hisAdvice.StartTime
  3864. advice.FeedetlSn = hisAdvice.FeedetlSn
  3865. }
  3866. }
  3867. }
  3868. }
  3869. //
  3870. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3871. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3872. // advice.ExecutionTime = execution_time
  3873. //}
  3874. //
  3875. //
  3876. //
  3877. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3878. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3879. // advice.ExecutionStaff = execution_staff
  3880. //}
  3881. //
  3882. //
  3883. //
  3884. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3885. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3886. // advice.ExecutionState = execution_state
  3887. //}
  3888. //
  3889. //
  3890. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3891. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3892. // advice.CheckTime = check_time
  3893. //}
  3894. //
  3895. //
  3896. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3897. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3898. // advice.CheckState = check_state
  3899. //}
  3900. //
  3901. //
  3902. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3903. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3904. // advice.Checker = checker
  3905. //}
  3906. //
  3907. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3908. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3909. // advice.StartTime = start_time
  3910. //}
  3911. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3912. drugSpecUnit, _ := json["min_unit"].(string)
  3913. advice.DrugSpecUnit = drugSpecUnit
  3914. }
  3915. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3916. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3917. advice.SingleDose = singleDose
  3918. }
  3919. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3920. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3921. advice.SingleDoseUnit = singleDoseUnit
  3922. }
  3923. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3924. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3925. advice.PrescribingNumber = prescribingNumber
  3926. }
  3927. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3928. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3929. advice.PrescribingNumberUnit = prescribingNumberUnit
  3930. }
  3931. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3932. deliveryWay, _ := json["delivery_way"].(string)
  3933. advice.DeliveryWay = deliveryWay
  3934. }
  3935. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3936. executionFrequency, _ := json["execution_frequency"].(string)
  3937. advice.ExecutionFrequency = executionFrequency
  3938. }
  3939. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3940. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3941. advice.Price = price
  3942. }
  3943. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3944. med_list_codg, _ := json["medical_insurance_number"].(string)
  3945. advice.MedListCodg = med_list_codg
  3946. }
  3947. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3948. day := int64(json["day"].(float64))
  3949. advice.Day = day
  3950. }
  3951. return 0
  3952. }
  3953. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3954. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3955. id := int64(json["id"].(float64))
  3956. project.ID = id
  3957. historyProject, _ := service.GetHisProjectByID(id)
  3958. project.FeedetlSn = historyProject.FeedetlSn
  3959. }
  3960. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3961. project_id := int64(json["project_id"].(float64))
  3962. project.ProjectId = project_id
  3963. }
  3964. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3965. // price := int64(json["price"].(float64))
  3966. // formatInt_price := strconv.FormatInt(price, 10)
  3967. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3968. // project.Price = float_price
  3969. // }
  3970. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3971. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3972. project.Price = price
  3973. }
  3974. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3975. total, _ := json["total"].(string)
  3976. project.Count = total
  3977. }
  3978. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3979. medical_code, _ := json["medical_code"].(string)
  3980. project.MedListCodg = medical_code
  3981. }
  3982. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3983. single_dose, _ := json["single_dose"].(string)
  3984. project.SingleDose = single_dose
  3985. }
  3986. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3987. delivery_way, _ := json["delivery_way"].(string)
  3988. project.DeliveryWay = delivery_way
  3989. }
  3990. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3991. execution_frequency, _ := json["execution_frequency"].(string)
  3992. project.ExecutionFrequency = execution_frequency
  3993. }
  3994. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3995. remark, _ := json["remark"].(string)
  3996. project.Remark = remark
  3997. }
  3998. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3999. day, _ := json["number_days"].(string)
  4000. project.Day = day
  4001. }
  4002. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4003. unit, _ := json["unit"].(string)
  4004. project.Unit = unit
  4005. }
  4006. return 0
  4007. }
  4008. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4009. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4010. id := int64(json["id"].(float64))
  4011. historyAddtions, _ := service.GetHisAdditionByID(id)
  4012. additionalCharge.ID = id
  4013. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4014. }
  4015. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4016. item_id := int64(json["item_id"].(float64))
  4017. additionalCharge.ItemId = item_id
  4018. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4019. if config.ID > 0 {
  4020. if len(config.Code) > 0 {
  4021. additionalCharge.MedListCodg = config.Code
  4022. }
  4023. }
  4024. }
  4025. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4026. // price := int64(json["price"].(float64))
  4027. // formatInt_price := strconv.FormatInt(price, 10)
  4028. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4029. // additionalCharge.Price = float_price
  4030. // }
  4031. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4032. // price := int64(json["price"].(float64))
  4033. // formatInt_price := strconv.FormatInt(price, 10)
  4034. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4035. // additionalCharge.Price = float_price
  4036. //}
  4037. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4038. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4039. additionalCharge.Price = price
  4040. }
  4041. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4042. count, _ := json["count"].(string)
  4043. counts, _ := strconv.ParseInt(count, 10, 64)
  4044. additionalCharge.Count = counts
  4045. }
  4046. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4047. item_name, _ := json["item_name"].(string)
  4048. additionalCharge.ItemName = item_name
  4049. }
  4050. return 0
  4051. }
  4052. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4053. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4054. utils.ErrorLog("drug_name")
  4055. return enums.ErrorCodeParamWrong
  4056. }
  4057. adviceName, _ := json["drug_name"].(string)
  4058. if len(adviceName) == 0 {
  4059. utils.ErrorLog("len(advice_name) == 0")
  4060. return enums.ErrorCodeParamWrong
  4061. }
  4062. advice.AdviceName = adviceName
  4063. adviceDesc, _ := json["advice_desc"].(string)
  4064. advice.AdviceDesc = adviceDesc
  4065. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4066. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4067. advice.DrugSpec = drugSpec
  4068. }
  4069. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4070. remark, _ := json["remark"].(string)
  4071. advice.Remark = remark
  4072. }
  4073. if json["id"] == nil {
  4074. advice.DrugId = 0
  4075. } else {
  4076. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4077. drug_id := int64(json["id"].(float64))
  4078. advice.DrugId = drug_id
  4079. }
  4080. }
  4081. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4082. groupno := int64(json["groupno"].(float64))
  4083. advice.Groupno = groupno
  4084. }
  4085. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4086. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4087. advice.HospApprFlag = hosp_appr_flag
  4088. }
  4089. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4090. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4091. advice.PrescribingNumber = prescribingNumber
  4092. }
  4093. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4094. // frequency_type := int64(json["frequency_type"].(float64))
  4095. // advice.FrequencyType = frequency_type
  4096. //}
  4097. //
  4098. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4099. // day_count := int64(json["day_count"].(float64))
  4100. // advice.DayCount = day_count
  4101. //}
  4102. //
  4103. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4104. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4105. // week_day, _ := json["week_day"].(string)
  4106. // advice.WeekDay = week_day
  4107. //}
  4108. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4109. drugSpecUnit, _ := json["min_unit"].(string)
  4110. advice.DrugSpecUnit = drugSpecUnit
  4111. }
  4112. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4113. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4114. advice.SingleDose = singleDose
  4115. }
  4116. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4117. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4118. advice.SingleDoseUnit = singleDoseUnit
  4119. }
  4120. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4121. deliveryWay, _ := json["delivery_way"].(string)
  4122. advice.DeliveryWay = deliveryWay
  4123. }
  4124. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4125. executionFrequency, _ := json["execution_frequency"].(string)
  4126. advice.ExecutionFrequency = executionFrequency
  4127. }
  4128. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4129. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4130. advice.Price = price
  4131. }
  4132. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4133. med_list_codg, _ := json["medical_insurance_number"].(string)
  4134. advice.MedListCodg = med_list_codg
  4135. }
  4136. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4137. day := int64(json["day"].(float64))
  4138. advice.Day = day
  4139. }
  4140. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4141. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4142. advice.PrescribingNumberUnit = prescribingNumberUnit
  4143. }
  4144. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4145. advice_id := int64(json["advice_id"].(float64))
  4146. advice.ID = advice_id
  4147. if advice.ID > 0 {
  4148. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4149. if err == nil {
  4150. if hisAdvice.ID > 0 {
  4151. advice.ExecutionTime = hisAdvice.ExecutionTime
  4152. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4153. advice.ExecutionState = hisAdvice.ExecutionState
  4154. advice.CheckTime = hisAdvice.CheckTime
  4155. advice.Checker = hisAdvice.Checker
  4156. advice.CheckState = hisAdvice.CheckState
  4157. advice.StartTime = hisAdvice.StartTime
  4158. advice.HospApprFlag = hisAdvice.HospApprFlag
  4159. advice.IsMedicine = hisAdvice.IsMedicine
  4160. if hisAdvice.UserOrgId == 10028 {
  4161. 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 {
  4162. advice.ExecutionTime = 0
  4163. advice.ExecutionStaff = 0
  4164. advice.ExecutionState = 2
  4165. advice.CheckTime = 0
  4166. advice.Checker = 0
  4167. advice.CheckState = 2
  4168. }
  4169. } else {
  4170. 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 {
  4171. advice.ExecutionTime = 0
  4172. advice.ExecutionStaff = 0
  4173. advice.ExecutionState = 2
  4174. advice.CheckTime = 0
  4175. advice.Checker = 0
  4176. advice.CheckState = 2
  4177. }
  4178. }
  4179. //advice.Groupno = hisAdvice.Groupno
  4180. }
  4181. }
  4182. }
  4183. }
  4184. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  4185. //
  4186. //if drugStockConfig.IsOpen == 1 {
  4187. //
  4188. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  4189. // if advice.ID == 0 { //医嘱不存在
  4190. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  4191. // drug.Total = drug.Total - advice.PrescribingNumber
  4192. // service.UpdateBaseDrugLib(&drug)
  4193. //
  4194. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  4195. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  4196. // drug.Total = drug.Total - num
  4197. // service.UpdateBaseDrugLib(&drug)
  4198. // }
  4199. //
  4200. // } else if advice.ID > 0 { //医嘱存在
  4201. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  4202. // var num float64
  4203. //
  4204. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  4205. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  4206. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  4207. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  4208. // drug.Total = drug.Total + num
  4209. // service.UpdateBaseDrugLib(&drug)
  4210. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  4211. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  4212. // drug.Total = drug.Total - num
  4213. // service.UpdateBaseDrugLib(&drug)
  4214. // }
  4215. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  4216. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4217. // if num2 > advice.PrescribingNumber {
  4218. // num = num2 - advice.PrescribingNumber
  4219. // drug.Total = drug.Total + num
  4220. // service.UpdateBaseDrugLib(&drug)
  4221. // } else if num2 < advice.PrescribingNumber {
  4222. // num = advice.PrescribingNumber - num2
  4223. // drug.Total = drug.Total - num
  4224. // service.UpdateBaseDrugLib(&drug)
  4225. // }
  4226. //
  4227. // }
  4228. //
  4229. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  4230. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  4231. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4232. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4233. // if num1 > num2 {
  4234. // num = num1 - num2
  4235. // drug.Total = drug.Total + num
  4236. // service.UpdateBaseDrugLib(&drug)
  4237. // } else if num1 < num2 {
  4238. // num = num2 - num1
  4239. // drug.Total = drug.Total - num
  4240. // service.UpdateBaseDrugLib(&drug)
  4241. // }
  4242. //
  4243. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  4244. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4245. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  4246. // if hisAdvice.PrescribingNumber > num2 {
  4247. // num = hisAdvice.PrescribingNumber - num2
  4248. // drug.Total = drug.Total + num
  4249. // service.UpdateBaseDrugLib(&drug)
  4250. // } else if num2 < advice.PrescribingNumber {
  4251. // num = num2 - hisAdvice.PrescribingNumber
  4252. // drug.Total = drug.Total - num
  4253. // service.UpdateBaseDrugLib(&drug)
  4254. // }
  4255. //
  4256. // }
  4257. // }
  4258. // }
  4259. //}
  4260. //
  4261. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4262. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4263. // advice.ExecutionTime = execution_time
  4264. //}
  4265. //
  4266. //
  4267. //
  4268. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4269. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4270. // advice.ExecutionStaff = execution_staff
  4271. //}
  4272. //
  4273. //
  4274. //
  4275. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4276. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4277. // advice.ExecutionState = execution_state
  4278. //}
  4279. //
  4280. //
  4281. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4282. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4283. // advice.CheckTime = check_time
  4284. //}
  4285. //
  4286. //
  4287. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4288. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4289. // advice.CheckState = check_state
  4290. //}
  4291. //
  4292. //
  4293. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4294. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4295. // advice.Checker = checker
  4296. //}
  4297. //
  4298. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4299. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4300. // advice.StartTime = start_time
  4301. //}
  4302. return 0
  4303. }
  4304. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4305. project.ExecutionStaff = 0
  4306. project.ExecutionState = 2
  4307. project.ExecutionTime = 0
  4308. project.Checker = 0
  4309. project.CheckState = 2
  4310. project.CheckTime = 0
  4311. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4312. id := int64(json["id"].(float64))
  4313. project.ID = id
  4314. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  4315. project.ExecutionStaff = temp_project.ExecutionStaff
  4316. project.ExecutionState = temp_project.ExecutionState
  4317. project.ExecutionTime = temp_project.ExecutionTime
  4318. project.Checker = temp_project.Checker
  4319. project.CheckState = temp_project.CheckState
  4320. project.CheckTime = temp_project.CheckTime
  4321. project.TeamId = temp_project.TeamId
  4322. }
  4323. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4324. types := int64(json["type"].(float64))
  4325. project.Type = types
  4326. }
  4327. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4328. project_id := int64(json["project_id"].(float64))
  4329. project.ProjectId = project_id
  4330. }
  4331. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  4332. team_id := int64(json["team_id"].(float64))
  4333. project.TeamId = team_id
  4334. }
  4335. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4336. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4337. project.Price = price
  4338. }
  4339. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4340. total, _ := json["total"].(string)
  4341. //totals, _ := strconv.ParseInt(total, 10, 64)
  4342. project.Count = total
  4343. }
  4344. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4345. medical_code, _ := json["medical_code"].(string)
  4346. project.MedListCodg = medical_code
  4347. }
  4348. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4349. single_dose, _ := json["single_dose"].(string)
  4350. project.SingleDose = single_dose
  4351. }
  4352. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4353. delivery_way, _ := json["delivery_way"].(string)
  4354. project.DeliveryWay = delivery_way
  4355. }
  4356. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4357. execution_frequency, _ := json["execution_frequency"].(string)
  4358. project.ExecutionFrequency = execution_frequency
  4359. }
  4360. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4361. remark, _ := json["remark"].(string)
  4362. project.Remark = remark
  4363. }
  4364. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4365. day, _ := json["number_days"].(string)
  4366. project.Day = day
  4367. }
  4368. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4369. unit, _ := json["unit"].(string)
  4370. project.Unit = unit
  4371. }
  4372. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4373. // frequency_type := int64(json["frequency_type"].(float64))
  4374. // project.FrequencyType = frequency_type
  4375. //}
  4376. //
  4377. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4378. // day_count := int64(json["day_count"].(float64))
  4379. // project.DayCount = day_count
  4380. //}
  4381. //
  4382. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4383. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4384. // week_day, _ := json["week_day"].(string)
  4385. // project.WeekDay = week_day
  4386. //}
  4387. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  4388. //
  4389. //if project.ID == 0 {
  4390. // if stockConfig.IsOpen == 1 {
  4391. // if project.Type == 3 {
  4392. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4393. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  4394. // good.Total = good.Total - f_count
  4395. // service.UpdateGoodInfo(&good)
  4396. // }
  4397. // }
  4398. //
  4399. //} else {
  4400. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  4401. //
  4402. // if stockConfig.IsOpen == 1 {
  4403. // if project.Type == 3 {
  4404. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4405. // if project.Count < temp_project.Count {
  4406. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  4407. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  4408. //
  4409. // other_count := f_count_two - f_count_one
  4410. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  4411. // good.Total = good.Total + other_count_two
  4412. // service.UpdateGoodInfo(&good)
  4413. // } else if project.Count > temp_project.Count {
  4414. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  4415. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  4416. //
  4417. // other_count := f_count_one - f_count_two
  4418. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  4419. // good.Total = good.Total - other_count_two
  4420. // service.UpdateGoodInfo(&good)
  4421. // }
  4422. //
  4423. // }
  4424. // }
  4425. //
  4426. //}
  4427. return 0
  4428. }
  4429. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4430. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4431. id := int64(json["id"].(float64))
  4432. additionalCharge.ID = id
  4433. }
  4434. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4435. item_id := int64(json["item_id"].(float64))
  4436. additionalCharge.ItemId = item_id
  4437. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4438. if config.ID > 0 {
  4439. if len(config.Code) > 0 {
  4440. additionalCharge.MedListCodg = config.Code
  4441. }
  4442. }
  4443. }
  4444. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4445. // price := int64(json["price"].(float64))
  4446. // formatInt_price := strconv.FormatInt(price, 10)
  4447. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4448. // additionalCharge.Price = float_price
  4449. // }
  4450. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4451. // price := int64(json["price"].(float64))
  4452. // formatInt_price := strconv.FormatInt(price, 10)
  4453. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4454. // additionalCharge.Price = float_price
  4455. //}
  4456. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4457. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4458. additionalCharge.Price = price
  4459. }
  4460. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4461. count, _ := json["count"].(string)
  4462. counts, _ := strconv.ParseInt(count, 10, 64)
  4463. additionalCharge.Count = counts
  4464. }
  4465. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4466. item_name, _ := json["item_name"].(string)
  4467. additionalCharge.ItemName = item_name
  4468. }
  4469. return 0
  4470. }
  4471. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  4472. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4473. utils.ErrorLog("drug_name")
  4474. return enums.ErrorCodeParamWrong
  4475. }
  4476. adviceName, _ := json["drug_name"].(string)
  4477. if len(adviceName) == 0 {
  4478. utils.ErrorLog("len(advice_name) == 0")
  4479. return enums.ErrorCodeParamWrong
  4480. }
  4481. advice.AdviceName = adviceName
  4482. adviceDesc, _ := json["advice_desc"].(string)
  4483. advice.AdviceDesc = adviceDesc
  4484. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4485. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4486. advice.DrugSpec = drugSpec
  4487. }
  4488. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4489. remark, _ := json["remark"].(string)
  4490. advice.Remark = remark
  4491. }
  4492. if json["id"] == nil {
  4493. advice.DrugId = 0
  4494. } else {
  4495. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4496. drug_id := int64(json["id"].(float64))
  4497. advice.DrugId = drug_id
  4498. }
  4499. }
  4500. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4501. drugSpecUnit, _ := json["min_unit"].(string)
  4502. advice.DrugSpecUnit = drugSpecUnit
  4503. }
  4504. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4505. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4506. advice.SingleDose = singleDose
  4507. }
  4508. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4509. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4510. advice.SingleDoseUnit = singleDoseUnit
  4511. }
  4512. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4513. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4514. advice.PrescribingNumber = prescribingNumber
  4515. }
  4516. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4517. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4518. advice.PrescribingNumberUnit = prescribingNumberUnit
  4519. }
  4520. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4521. deliveryWay, _ := json["delivery_way"].(string)
  4522. advice.DeliveryWay = deliveryWay
  4523. }
  4524. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4525. executionFrequency, _ := json["execution_frequency"].(string)
  4526. advice.ExecutionFrequency = executionFrequency
  4527. }
  4528. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4529. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4530. advice.Price = price
  4531. }
  4532. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4533. med_list_codg, _ := json["medical_insurance_number"].(string)
  4534. advice.MedListCodg = med_list_codg
  4535. }
  4536. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4537. day := int64(json["day"].(float64))
  4538. advice.Day = day
  4539. }
  4540. return 0
  4541. }
  4542. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  4543. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4544. types := int64(json["type"].(float64))
  4545. project.Type = types
  4546. }
  4547. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4548. project_id := int64(json["project_id"].(float64))
  4549. project.ProjectId = project_id
  4550. }
  4551. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4552. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4553. project.Price = price
  4554. }
  4555. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4556. total, _ := json["total"].(string)
  4557. //totals, _ := strconv.ParseInt(total, 10, 64)
  4558. project.Count = total
  4559. }
  4560. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4561. medical_code, _ := json["medical_code"].(string)
  4562. project.MedListCodg = medical_code
  4563. }
  4564. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4565. single_dose, _ := json["single_dose"].(string)
  4566. project.SingleDose = single_dose
  4567. }
  4568. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4569. delivery_way, _ := json["delivery_way"].(string)
  4570. project.DeliveryWay = delivery_way
  4571. }
  4572. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4573. execution_frequency, _ := json["execution_frequency"].(string)
  4574. project.ExecutionFrequency = execution_frequency
  4575. }
  4576. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4577. remark, _ := json["remark"].(string)
  4578. project.Remark = remark
  4579. }
  4580. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4581. day, _ := json["number_days"].(string)
  4582. project.Day = day
  4583. }
  4584. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4585. unit, _ := json["unit"].(string)
  4586. project.Unit = unit
  4587. }
  4588. return 0
  4589. }
  4590. func (c *HisApiController) GetHisOrderList() {
  4591. page, _ := c.GetInt64("page", -1)
  4592. limit, _ := c.GetInt64("limit", -1)
  4593. start_time := c.GetString("start_time")
  4594. end_time := c.GetString("end_time")
  4595. types, _ := c.GetInt64("type", 0)
  4596. keywords := c.GetString("keywords")
  4597. p_type, _ := c.GetInt64("p_type", 0)
  4598. sort_type, _ := c.GetInt64("sort_type", 0)
  4599. charge_type, _ := c.GetInt64("charge_type", 0)
  4600. timeLayout := "2006-01-02"
  4601. loc, _ := time.LoadLocation("Local")
  4602. var startTime int64
  4603. if len(start_time) > 0 {
  4604. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4605. if err != nil {
  4606. //fmt.Println(err)
  4607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4608. return
  4609. }
  4610. startTime = theTime.Unix()
  4611. }
  4612. var endTime int64
  4613. if len(end_time) > 0 {
  4614. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4615. if err != nil {
  4616. utils.ErrorLog(err.Error())
  4617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4618. return
  4619. }
  4620. endTime = theTime.Unix()
  4621. }
  4622. adminUser := c.GetAdminUserInfo()
  4623. org_id := adminUser.CurrentOrgId
  4624. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type)
  4625. for _, item := range order {
  4626. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  4627. item.DoctorName = info.Doctor
  4628. item.DepartmentName = info.XtHisDepartment.Name
  4629. }
  4630. if err == nil {
  4631. c.ServeSuccessJSON(map[string]interface{}{
  4632. "order": order,
  4633. "total": total,
  4634. })
  4635. } else {
  4636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4637. return
  4638. }
  4639. }
  4640. func (c *HisApiController) GetHisOrder() {
  4641. patient_id, _ := c.GetInt64("patient_id", 0)
  4642. number := c.GetString("number")
  4643. adminInfo := c.GetAdminUserInfo()
  4644. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  4645. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  4646. if err == nil {
  4647. c.ServeSuccessJSON(map[string]interface{}{
  4648. "order": order,
  4649. "prescription": prescriptions,
  4650. })
  4651. } else {
  4652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4653. return
  4654. }
  4655. }
  4656. func (c *HisApiController) GetHisPrescriptionList() {
  4657. record_date := c.GetString("record_date")
  4658. keywords := c.GetString("keywords")
  4659. page, _ := c.GetInt64("page")
  4660. limit, _ := c.GetInt64("limit")
  4661. timeLayout := "2006-01-02"
  4662. loc, _ := time.LoadLocation("Local")
  4663. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4664. if err != nil {
  4665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4666. return
  4667. }
  4668. recordDateTime := theTime.Unix()
  4669. adminInfo := c.GetAdminUserInfo()
  4670. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  4671. //adminInfo := c.GetAdminUserInfo()
  4672. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  4673. //fmt.Println(prescriptionOrder)
  4674. if err == nil {
  4675. c.ServeSuccessJSON(map[string]interface{}{
  4676. "order": prescriptionOrder,
  4677. "total": total,
  4678. })
  4679. } else {
  4680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4681. return
  4682. }
  4683. }
  4684. func (c *HisApiController) GetHisPrescriptionInfo() {
  4685. id, _ := c.GetInt64("id")
  4686. adminInfo := c.GetAdminUserInfo()
  4687. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  4688. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  4689. if err == nil {
  4690. c.ServeSuccessJSON(map[string]interface{}{
  4691. "order": prescriptionOrder,
  4692. "prescription": prescription,
  4693. })
  4694. } else {
  4695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4696. return
  4697. }
  4698. }
  4699. func (c *HisApiController) GetMedicalInsuranceConfig() {
  4700. adminUser := c.GetAdminUserInfo()
  4701. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4702. c.ServeSuccessJSON(map[string]interface{}{
  4703. "config": config,
  4704. })
  4705. }
  4706. type ResultTwo struct {
  4707. ErrMsg interface{} `json:"err_msg"`
  4708. InfRefmsgid string `json:"inf_refmsgid"`
  4709. Infcode int64 `json:"infcode"`
  4710. Output struct {
  4711. Baseinfo struct {
  4712. Age float64 `json:"age"`
  4713. Brdy string `json:"brdy"`
  4714. Certno string `json:"certno"`
  4715. Gend string `json:"gend"`
  4716. Naty string `json:"naty"`
  4717. PsnCertType string `json:"psn_cert_type"`
  4718. PsnName string `json:"psn_name"`
  4719. PsnNo string `json:"psn_no"`
  4720. } `json:"baseinfo"`
  4721. Idetinfo []interface{} `json:"idetinfo"`
  4722. Iinfo []struct {
  4723. Balc float64 `json:"balc"`
  4724. CvlservFlag string `json:"cvlserv_flag"`
  4725. EmpName string `json:"emp_name"`
  4726. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  4727. Insutype string `json:"insutype"`
  4728. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  4729. PausInsuDate interface{} `json:"paus_insu_date"`
  4730. PsnInsuDate string `json:"psn_insu_date"`
  4731. PsnInsuStas string `json:"psn_insu_stas"`
  4732. PsnType string `json:"psn_type"`
  4733. } `json:"insuinfo"`
  4734. } `json:"output"`
  4735. RefmsgTime string `json:"refmsg_time"`
  4736. RespondTime string `json:"respond_time"`
  4737. Signtype interface{} `json:"signtype"`
  4738. WarnInfo interface{} `json:"warn_info"`
  4739. }
  4740. type ResultThree struct {
  4741. Cainfo interface{} `json:"cainfo"`
  4742. ErrMsg interface{} `json:"err_msg"`
  4743. InfRefmsgid string `json:"inf_refmsgid"`
  4744. Infcode int64 `json:"infcode"`
  4745. Output struct {
  4746. Data struct {
  4747. IptOtpNo string `json:"ipt_otp_no"`
  4748. MdtrtID string `json:"mdtrt_id"`
  4749. PsnNo string `json:"psn_no"`
  4750. } `json:"data"`
  4751. } `json:"output"`
  4752. RefmsgTime string `json:"refmsg_time"`
  4753. RespondTime string `json:"respond_time"`
  4754. Signtype interface{} `json:"signtype"`
  4755. WarnMsg interface{} `json:"warn_msg"`
  4756. }
  4757. type ResultFour struct {
  4758. Cainfo string `json:"cainfo"`
  4759. ErrMsg string `json:"err_msg"`
  4760. InfRefmsgid string `json:"inf_refmsgid"`
  4761. Infcode int64 `json:"infcode"`
  4762. Output struct {
  4763. Result []struct {
  4764. BasMednFlag string `json:"bas_medn_flag"`
  4765. ChldMedcFlag string `json:"chld_medc_flag"`
  4766. ChrgitmLv string `json:"chrgitm_lv"`
  4767. Cnt float64 `json:"cnt"`
  4768. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  4769. DrtReimFlag string `json:"drt_reim_flag"`
  4770. FeedetlSn string `json:"feedetl_sn"`
  4771. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4772. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  4773. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4774. ListSpItemFlag string `json:"list_sp_item_flag"`
  4775. LmtUsedFlag string `json:"lmt_used_flag"`
  4776. MedChrgitmType string `json:"med_chrgitm_type"`
  4777. Memo string `json:"memo"`
  4778. OverlmtAmt float64 `json:"overlmt_amt"`
  4779. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4780. Pric float64 `json:"pric"`
  4781. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  4782. SelfpayProp float64 `json:"selfpay_prop"`
  4783. } `json:"result"`
  4784. } `json:"output"`
  4785. RefmsgTime string `json:"refmsg_time"`
  4786. RespondTime string `json:"respond_time"`
  4787. Signtype string `json:"signtype"`
  4788. WarnMsg string `json:"warn_msg"`
  4789. }
  4790. type ResultFive struct {
  4791. Insutype string `json:"insutype"`
  4792. }
  4793. type ResultSix struct {
  4794. Cainfo interface{} `json:"cainfo"`
  4795. ErrMsg interface{} `json:"err_msg"`
  4796. InfRefmsgid string `json:"inf_refmsgid"`
  4797. Infcode int64 `json:"infcode"`
  4798. Output struct {
  4799. } `json:"output"`
  4800. RefmsgTime string `json:"refmsg_time"`
  4801. RespondTime string `json:"respond_time"`
  4802. Signtype interface{} `json:"signtype"`
  4803. WarnMsg interface{} `json:"warn_msg"`
  4804. }
  4805. type ResultSeven struct {
  4806. Cainfo string `json:"cainfo"`
  4807. ErrMsg string `json:"err_msg"`
  4808. InfRefmsgid string `json:"inf_refmsgid"`
  4809. Infcode int64 `json:"infcode"`
  4810. Output struct {
  4811. Setldetail []interface{} `json:"setldetail"`
  4812. Setlinfo struct {
  4813. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  4814. AcctPay float64 `json:"acct_pay"`
  4815. ActPayDedc float64 `json:"act_pay_dedc"`
  4816. Age float64 `json:"age"`
  4817. Balc float64 `json:"balc"`
  4818. Brdy string `json:"brdy"`
  4819. Certno string `json:"certno"`
  4820. ClrOptins string `json:"clr_optins"`
  4821. ClrType string `json:"clr_type"`
  4822. ClrWay string `json:"clr_way"`
  4823. CvlservFlag string `json:"cvlserv_flag"`
  4824. CvlservPay float64 `json:"cvlserv_pay"`
  4825. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4826. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  4827. Gend string `json:"gend"`
  4828. HifesPay float64 `json:"hifes_pay"`
  4829. HifmiPay float64 `json:"hifmi_pay"`
  4830. HifobPay float64 `json:"hifob_pay"`
  4831. HifpPay float64 `json:"hifp_pay"`
  4832. HospPartAmt float64 `json:"hosp_part_amt"`
  4833. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4834. Insutype string `json:"insutype"`
  4835. MafPay float64 `json:"maf_pay"`
  4836. MdtrtCertType string `json:"mdtrt_cert_type"`
  4837. MdtrtID string `json:"mdtrt_id"`
  4838. MedType string `json:"med_type"`
  4839. MedfeeSumamt float64 `json:"medfee_sumamt"`
  4840. MedinsSetlID string `json:"medins_setl_id"`
  4841. Naty string `json:"naty"`
  4842. OthPay float64 `json:"oth_pay"`
  4843. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  4844. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  4845. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4846. PsnCashPay float64 `json:"psn_cash_pay"`
  4847. PsnCertType string `json:"psn_cert_type"`
  4848. PsnName string `json:"psn_name"`
  4849. PsnNo string `json:"psn_no"`
  4850. PsnPartAmt float64 `json:"psn_part_amt"`
  4851. PsnType string `json:"psn_type"`
  4852. SetlID string `json:"setl_id"`
  4853. SetlTime string `json:"setl_time"`
  4854. } `json:"setlinfo"`
  4855. } `json:"output"`
  4856. RefmsgTime string `json:"refmsg_time"`
  4857. RespondTime string `json:"respond_time"`
  4858. Signtype interface{} `json:"signtype"`
  4859. WarnMsg interface{} `json:"warn_msg"`
  4860. }
  4861. type ResultEight struct {
  4862. Cainfo string `json:"cainfo"`
  4863. ErrMsg string `json:"err_msg"`
  4864. InfRefmsgid string `json:"inf_refmsgid"`
  4865. Infcode int64 `json:"infcode"`
  4866. Output struct {
  4867. Stmtinfo struct {
  4868. SetlOptins string `json:"setl_optins"`
  4869. StmtRslt string `json:"stmt_rslt"`
  4870. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  4871. } `json:"stmtinfo"`
  4872. } `json:"output"`
  4873. RefmsgTime string `json:"refmsg_time"`
  4874. RespondTime string `json:"respond_time"`
  4875. Signtype interface{} `json:"signtype"`
  4876. WarnMsg interface{} `json:"warn_msg"`
  4877. }
  4878. type ResultNine struct {
  4879. Cainfo string `json:"cainfo"`
  4880. ErrMsg string `json:"err_msg"`
  4881. InfRefmsgid string `json:"inf_refmsgid"`
  4882. Infcode int64 `json:"infcode"`
  4883. Output struct {
  4884. FileQuryNo string `json:"file_qury_no"`
  4885. } `json:"output"`
  4886. RefmsgTime string `json:"refmsg_time"`
  4887. RespondTime string `json:"respond_time"`
  4888. Signtype interface{} `json:"signtype"`
  4889. WarnMsg interface{} `json:"warn_msg"`
  4890. }
  4891. type ResultTen struct {
  4892. Cainfo string `json:"cainfo"`
  4893. ErrMsg string `json:"err_msg"`
  4894. InfRefmsgid string `json:"inf_refmsgid"`
  4895. Infcode int64 `json:"infcode"`
  4896. Output struct {
  4897. DldEndtime string `json:"dld_endtime"`
  4898. FileQuryNo string `json:"file_qury_no"`
  4899. Filename string `json:"filename"`
  4900. } `json:"output"`
  4901. RefmsgTime string `json:"refmsg_time"`
  4902. RespondTime string `json:"respond_time"`
  4903. Signtype interface{} `json:"signtype"`
  4904. WarnMsg interface{} `json:"warn_msg"`
  4905. }
  4906. type ResultEleven struct {
  4907. Cainfo string `json:"cainfo"`
  4908. ErrMsg string `json:"err_msg"`
  4909. InfRefmsgid string `json:"inf_refmsgid"`
  4910. Infcode int64 `json:"infcode"`
  4911. Output struct {
  4912. Setlinfo struct {
  4913. FixmedinsName string `json:"fixmedins_name"`
  4914. FixmedinsCode string `json:"fixmedins_code"`
  4915. PsnNo string `json:"psn_no"`
  4916. PsnName string `json:"psn_name"`
  4917. HifobPay float64 `json:"hifob_pay"`
  4918. Gend string `json:"gend"`
  4919. Brdy string `json:"brdy"`
  4920. PsnCertType string `json:"psn_cert_type"`
  4921. PsnType string `json:"psn_type"`
  4922. EmpName string `json:"emp_name"`
  4923. Certno string `json:"certno"`
  4924. Insutype string `json:"insutype"`
  4925. MedfeeSumamt float64 `json:"medfee_sumamt"`
  4926. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4927. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  4928. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4929. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4930. ActPayDedc float64 `json:"act_pay_dedc"`
  4931. HifpPay float64 `json:"hifp_pay"`
  4932. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  4933. CvlservPay float64 `json:"cvlserv_pay"`
  4934. HifesPay float64 `json:"hifes_pay"`
  4935. HifmiPay float64 `json:"hifmi_pay"`
  4936. MafPay float64 `json:"maf_pay"`
  4937. OthPay float64 `json:"oth_pay"`
  4938. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  4939. PsnPay float64 `json:"psn_pay"`
  4940. AcctPay float64 `json:"acct_pay"`
  4941. CashPayamt float64 `json:"cash_payamt"`
  4942. Balc float64 `json:"balc"`
  4943. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  4944. MedinsSetlId string `json:"medins_setl_id"`
  4945. RefdSetlFlag string `json:"refd_setl_flag"`
  4946. SetlTime string `json:"setl_time"`
  4947. MedType string `json:"med_type"`
  4948. } `json:"setlinfo"`
  4949. } `json:"output"`
  4950. RefmsgTime string `json:"refmsg_time"`
  4951. RespondTime string `json:"respond_time"`
  4952. Signtype interface{} `json:"signtype"`
  4953. WarnMsg interface{} `json:"warn_msg"`
  4954. }
  4955. type Custom struct {
  4956. DetItemFeeSumamt string
  4957. Cut string
  4958. FeedetlSn string
  4959. Price string
  4960. MedListCodg string
  4961. Type int64
  4962. AdviceId int64
  4963. ProjectId int64
  4964. ItemId int64
  4965. }
  4966. //获取个人信息----挂号-----上传就诊信息
  4967. func (c *HisApiController) GetRegisterInfo() {
  4968. id, _ := c.GetInt64("id")
  4969. record_time := c.GetString("record_time")
  4970. settlementValue, _ := c.GetInt64("settlement_value")
  4971. medical_insurance_card := c.GetString("medical_insurance_card")
  4972. name := c.GetString("name")
  4973. id_card_type, _ := c.GetInt64("id_card_type")
  4974. certificates, _ := c.GetInt64("certificates")
  4975. medical_care, _ := c.GetInt64("medical_care")
  4976. birthday := c.GetString("birthday")
  4977. age, _ := c.GetInt64("age")
  4978. id_card := c.GetString("id_card")
  4979. register_type, _ := c.GetInt64("register")
  4980. doctor, _ := c.GetInt64("doctor")
  4981. department, _ := c.GetInt64("department")
  4982. gender, _ := c.GetInt64("sex")
  4983. phone := c.GetString("phone")
  4984. registration_fee, _ := c.GetFloat("registration_fee")
  4985. medical_expenses, _ := c.GetFloat("medical_expenses")
  4986. social_type, _ := c.GetInt64("social_type")
  4987. //diagnosis_id, _ := c.GetInt64("diagnosis")
  4988. diagnosis_ids := c.GetString("diagnosis")
  4989. sick_type, _ := c.GetInt64("sick_type")
  4990. reg_type := c.GetString("p_type")
  4991. timeLayout := "2006-01-02"
  4992. loc, _ := time.LoadLocation("Local")
  4993. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  4994. birthUnix := birthdays.Unix()
  4995. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4996. if err != nil {
  4997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4998. return
  4999. }
  5000. recordDateTime := theTime.Unix()
  5001. adminInfo := c.GetAdminUserInfo()
  5002. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5003. if tempPatient.ID == 0 {
  5004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5005. return
  5006. }
  5007. var patient service.Patients
  5008. if id == 0 {
  5009. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5010. } else {
  5011. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5012. }
  5013. if patient.ID == 0 {
  5014. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5015. return
  5016. }
  5017. if len(patient.IdCardNo) == 0 {
  5018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5019. return
  5020. }
  5021. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5022. if len(his) >= 1 {
  5023. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5024. if len(his) >= 1 && order.ID == 0 {
  5025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5026. return
  5027. }
  5028. }
  5029. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5030. fmt.Println(timeStr)
  5031. timeArr := strings.Split(timeStr, " ")
  5032. fmt.Println(timeArr)
  5033. timeArrTwo := strings.Split(timeArr[0], "-")
  5034. timeArrThree := strings.Split(timeArr[1], ":")
  5035. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5036. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5037. if len(lists) == 0 {
  5038. var hisPatient models.XtHisPatient
  5039. hisPatient = models.XtHisPatient{
  5040. Name: name,
  5041. Age: age,
  5042. Gender: gender,
  5043. Birthday: birthUnix,
  5044. Phone: phone,
  5045. MedicalTreatmentType: medical_care,
  5046. IdType: certificates,
  5047. IdCardNo: id_card,
  5048. BalanceAccountsType: settlementValue,
  5049. SocialType: social_type,
  5050. MedicalInsuranceNumber: medical_insurance_card,
  5051. RegisterType: register_type,
  5052. RegisterCost: registration_fee,
  5053. TreatmentCost: medical_expenses,
  5054. AdminUserId: adminInfo.AdminUser.Id,
  5055. UserOrgId: adminInfo.CurrentOrgId,
  5056. Status: 1,
  5057. RecordDate: recordDateTime,
  5058. IsReturn: 1,
  5059. PatientId: patient.ID,
  5060. Ctime: time.Now().Unix(),
  5061. Mtime: time.Now().Unix(),
  5062. Number: str,
  5063. IdCardType: id_card_type,
  5064. Departments: department,
  5065. Doctor: doctor,
  5066. PType: reg_type,
  5067. Diagnosis: diagnosis_ids,
  5068. SickType: sick_type,
  5069. }
  5070. service.CreateHisPatient(&hisPatient)
  5071. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5072. c.ServeSuccessJSON(map[string]interface{}{
  5073. "his_info": hisPatient,
  5074. })
  5075. } else {
  5076. //chrgBchno := rand.Intn(1000000) + 10000
  5077. var hisPatient models.XtHisPatient
  5078. hisPatient = models.XtHisPatient{
  5079. Name: name,
  5080. Age: age,
  5081. Gender: gender,
  5082. Birthday: birthUnix,
  5083. Phone: phone,
  5084. MedicalTreatmentType: medical_care,
  5085. IdType: certificates,
  5086. IdCardNo: id_card,
  5087. BalanceAccountsType: settlementValue,
  5088. SocialType: social_type,
  5089. MedicalInsuranceNumber: medical_insurance_card,
  5090. RegisterType: register_type,
  5091. RegisterCost: registration_fee,
  5092. TreatmentCost: medical_expenses,
  5093. AdminUserId: adminInfo.AdminUser.Id,
  5094. UserOrgId: adminInfo.CurrentOrgId,
  5095. Status: 1,
  5096. RecordDate: recordDateTime,
  5097. IsReturn: 1,
  5098. PatientId: patient.ID,
  5099. Ctime: time.Now().Unix(),
  5100. Mtime: time.Now().Unix(),
  5101. Number: str,
  5102. IdCardType: id_card_type,
  5103. Departments: department,
  5104. Doctor: doctor,
  5105. PType: reg_type,
  5106. Diagnosis: diagnosis_ids,
  5107. SickType: sick_type,
  5108. }
  5109. service.CreateHisPatient(&hisPatient)
  5110. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5111. c.ServeSuccessJSON(map[string]interface{}{
  5112. "his_info": hisPatient,
  5113. })
  5114. }
  5115. }
  5116. //上传明细----结算
  5117. func (c *HisApiController) GetUploadInfo() {
  5118. id, _ := c.GetInt64("id")
  5119. record_time := c.GetString("record_time")
  5120. his_patient_id, _ := c.GetInt64("his_patient_id")
  5121. pay_way, _ := c.GetInt64("pay_way")
  5122. pay_price, _ := c.GetFloat("pay_price")
  5123. pay_card_no := c.GetString("pay_card_no")
  5124. discount_price, _ := c.GetFloat("discount_price")
  5125. preferential_price, _ := c.GetFloat("preferential_price")
  5126. reality_price, _ := c.GetFloat("reality_price")
  5127. found_price, _ := c.GetFloat("found_price")
  5128. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5129. private_price, _ := c.GetFloat("private_price")
  5130. timeLayout := "2006-01-02"
  5131. loc, _ := time.LoadLocation("Local")
  5132. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5133. fapiao_code := c.GetString("fapiao_code")
  5134. fapiao_number := c.GetString("fapiao_number")
  5135. diagnosis_id := c.GetString("diagnosis")
  5136. sick_type, _ := c.GetInt64("sick_type")
  5137. reg_type, _ := c.GetInt64("p_type")
  5138. order_id, _ := c.GetInt64("order_id")
  5139. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  5140. tmp_decimal := c.GetString("tmp_decimal")
  5141. var decimal float64 //本次使用的押金
  5142. var errmsg error
  5143. tx := service.XTWriteDB().Begin() //开了事务
  5144. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  5145. defer func() {
  5146. if errmsg != nil {
  5147. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  5148. tx.Rollback()
  5149. } else {
  5150. tx.Commit()
  5151. }
  5152. }()
  5153. fmt.Println("dec_way", dec_way)
  5154. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  5155. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  5156. return
  5157. }
  5158. if len(tmp_decimal) > 0 {
  5159. if tmp_decimal[0] == 45 {
  5160. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  5161. return
  5162. }
  5163. }
  5164. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  5165. fmt.Println(errs)
  5166. //if errs != nil {
  5167. // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  5168. // return
  5169. //}
  5170. decimal = tt
  5171. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  5172. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  5173. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5174. if err != nil {
  5175. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5176. return
  5177. }
  5178. recordDateTime := theTime.Unix()
  5179. adminUser := c.GetAdminUserInfo()
  5180. var prescriptions []*models.HisPrescription
  5181. var prescriptionsOne []*models.HisPrescription
  5182. var start_time int64
  5183. var end_time int64
  5184. ids_str := c.GetString("ids")
  5185. ids_arr := strings.Split(ids_str, ",")
  5186. if tempOrder.ID == 0 {
  5187. if settle_accounts_type == 1 { //日结
  5188. fmt.Println(reg_type)
  5189. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5190. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  5191. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  5192. } else {
  5193. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5194. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5195. }
  5196. } else { //月结
  5197. start_time_str := c.GetString("start_time")
  5198. end_time_str := c.GetString("end_time")
  5199. timeLayout := "2006-01-02"
  5200. loc, _ := time.LoadLocation("Local")
  5201. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5202. if err != nil {
  5203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5204. return
  5205. }
  5206. recordStartTime := theStartTime.Unix()
  5207. start_time = recordStartTime
  5208. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5209. if err != nil {
  5210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5211. return
  5212. }
  5213. recordEndTime := theEndTime.Unix()
  5214. end_time = recordEndTime
  5215. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  5216. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5217. }
  5218. var goods []*models.DialysisBeforePrepareGoods
  5219. var newGoods []*models.NewDialysisBeforePrepareGoods
  5220. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5221. var infos []*models.HisDoctorAdviceInfo
  5222. var infoList []*models.HisDoctorAdviceInfo
  5223. var hisAdvice []*models.HisDoctorAdviceInfo
  5224. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5225. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5226. //判断库存不足
  5227. //结算出库开关
  5228. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5229. if settConfig.IsOpen == 1 {
  5230. //判断库存的地方
  5231. for _, info := range prescriptions {
  5232. if info.Type == 1 {
  5233. infos = append(infos, info.HisDoctorAdviceInfo...)
  5234. }
  5235. if info.Type == 2 {
  5236. for _, sumItem := range info.HisPrescriptionProject {
  5237. if sumItem.Type == 3 {
  5238. var good models.DialysisBeforePrepareGoods
  5239. var newGood models.NewDialysisBeforePrepareGoods
  5240. good.GoodId = sumItem.GoodInfo.ID
  5241. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5242. count, _ := strconv.Atoi(sumItem.Count)
  5243. good.Count = int64(count)
  5244. good.StorehouseId = houseConfig.StorehouseOutInfo
  5245. good.ProjectId = sumItem.ID
  5246. goods = append(goods, &good)
  5247. newGood.GoodId = sumItem.GoodInfo.ID
  5248. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5249. count2, _ := strconv.Atoi(sumItem.Count)
  5250. newGood.Count = int64(count2)
  5251. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5252. newGood.ProjectId = sumItem.ID
  5253. newGoods = append(newGoods, &newGood)
  5254. }
  5255. }
  5256. }
  5257. }
  5258. for _, info := range prescriptionsOne {
  5259. if info.Type == 1 {
  5260. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5261. }
  5262. if info.Type == 2 {
  5263. for _, sumItem := range info.HisPrescriptionProject {
  5264. if sumItem.Type == 3 {
  5265. var newGood models.NewDialysisBeforePrepareGoods
  5266. newGood.GoodId = sumItem.GoodInfo.ID
  5267. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5268. count2, _ := strconv.Atoi(sumItem.Count)
  5269. newGood.Count = int64(count2)
  5270. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5271. newGood.ProjectId = sumItem.ID
  5272. newGoodOne = append(newGoodOne, &newGood)
  5273. }
  5274. }
  5275. }
  5276. }
  5277. //判断
  5278. for _, itemOne := range infos {
  5279. for _, itemTwo := range hisAdvice {
  5280. if itemOne.DrugId == itemTwo.DrugId {
  5281. itemTwo.Child = append(itemTwo.ChildDoctorAdvice, itemOne)
  5282. }
  5283. }
  5284. }
  5285. for _, itemTwo := range hisAdvice {
  5286. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5287. var sum_out_count int64
  5288. for _, itemThree := range itemTwo.Child {
  5289. var prescribing_number int64
  5290. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5291. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5292. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5293. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5294. }
  5295. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5296. prescribing_number = parseIntPrescribingNumber
  5297. }
  5298. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5299. prescribing_number = parseIntPrescribingNumber
  5300. }
  5301. sum_out_count += prescribing_number
  5302. }
  5303. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId)
  5304. if sum_out_count > drugStockOut.FlushCount {
  5305. c.ServeSuccessJSON(map[string]interface{}{
  5306. "msg": "2",
  5307. "drug": medical,
  5308. })
  5309. return
  5310. }
  5311. }
  5312. for _, itemOne := range newGoods {
  5313. for _, item := range newGoodOne {
  5314. if itemOne.ProjectId == item.ProjectId {
  5315. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, item)
  5316. }
  5317. }
  5318. }
  5319. for _, item := range newGoodOne {
  5320. var sum_out_count_one int64
  5321. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  5322. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  5323. sum_out_count_one += itemOne.Count
  5324. }
  5325. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId)
  5326. fmt.Println("sum_out_count_one", sum_out_count_one)
  5327. fmt.Println("list.FlushCount", list.FlushCount)
  5328. if sum_out_count_one > list.FlushCount {
  5329. c.ServeSuccessJSON(map[string]interface{}{
  5330. "msg": "3",
  5331. "good": good,
  5332. })
  5333. return
  5334. }
  5335. }
  5336. }
  5337. timestamp := time.Now().Unix()
  5338. tempTime := time.Unix(timestamp, 0)
  5339. timeFormat := tempTime.Format("20060102150405")
  5340. chrgBchno := rand.Intn(100000) + 10000
  5341. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  5342. strconv.FormatInt(his.PatientId, 10)
  5343. var ids []int64
  5344. for _, item := range prescriptions {
  5345. ids = append(ids, item.ID)
  5346. }
  5347. var total float64
  5348. for _, item := range prescriptions {
  5349. fmt.Println(item)
  5350. if item.Type == 1 { //药品
  5351. for _, subItem := range item.HisDoctorAdviceInfo {
  5352. total = total + (subItem.Price * subItem.PrescribingNumber)
  5353. }
  5354. }
  5355. if item.Type == 2 { //项目
  5356. for _, subItem := range item.HisPrescriptionProject {
  5357. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5358. total = total + (subItem.Price * cnt)
  5359. }
  5360. }
  5361. for _, subItem := range item.HisAdditionalCharge {
  5362. total = total + (subItem.Price * float64(subItem.Count))
  5363. }
  5364. }
  5365. if reg_type == 1111 || reg_type == 1112 {
  5366. reg_type = 11
  5367. }
  5368. tm := time.Unix(time.Now().Unix(), 0)
  5369. allTotal := fmt.Sprintf("%.4f", total)
  5370. totals, _ := strconv.ParseFloat(allTotal, 64)
  5371. order := &models.HisOrder{
  5372. UserOrgId: adminUser.CurrentOrgId,
  5373. HisPatientId: his.ID,
  5374. PatientId: id,
  5375. SettleAccountsDate: recordDateTime,
  5376. Ctime: time.Now().Unix(),
  5377. Mtime: time.Now().Unix(),
  5378. Status: 1,
  5379. OrderStatus: 2,
  5380. MdtrtId: his.Number,
  5381. Number: chrg_bchno,
  5382. MedfeeSumamt: totals,
  5383. PayWay: pay_way,
  5384. PayPrice: pay_price,
  5385. MedType: strconv.Itoa(int(reg_type)),
  5386. PayCardNo: pay_card_no,
  5387. DiscountPrice: discount_price,
  5388. PreferentialPrice: preferential_price,
  5389. RealityPrice: reality_price,
  5390. FoundPrice: found_price,
  5391. MedicalInsurancePrice: medical_insurance_price,
  5392. PrivatePrice: private_price,
  5393. SettleEndTime: end_time,
  5394. SettleStartTime: start_time,
  5395. PsnPartAmt: totals,
  5396. PsnCashPay: totals,
  5397. SettleType: settle_accounts_type,
  5398. FaPiaoCode: fapiao_code,
  5399. FaPiaoNumber: fapiao_number,
  5400. Diagnosis: diagnosis_id,
  5401. PType: 2,
  5402. SetlTime: tm.Format("2006-01-02 15:04:05"),
  5403. Decimal: decimal,
  5404. }
  5405. err = service.CreateOrderTX(order, tx)
  5406. if err != nil {
  5407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5408. return
  5409. }
  5410. var customs []*Custom
  5411. for _, item := range prescriptions {
  5412. if item.Type == 1 { //药品a
  5413. for _, subItem := range item.HisDoctorAdviceInfo {
  5414. cus := &Custom{
  5415. AdviceId: subItem.ID,
  5416. ProjectId: 0,
  5417. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  5418. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  5419. FeedetlSn: subItem.FeedetlSn,
  5420. Price: fmt.Sprintf("%.4f", subItem.Price),
  5421. MedListCodg: subItem.MedListCodg,
  5422. Type: 1,
  5423. }
  5424. customs = append(customs, cus)
  5425. }
  5426. }
  5427. if item.Type == 2 { //项目
  5428. for _, subItem := range item.HisPrescriptionProject {
  5429. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5430. cus := &Custom{
  5431. AdviceId: 0,
  5432. ProjectId: subItem.ID,
  5433. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  5434. Cut: fmt.Sprintf("%.4f", cnt),
  5435. FeedetlSn: subItem.FeedetlSn,
  5436. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  5437. MedListCodg: subItem.MedListCodg,
  5438. Type: 2,
  5439. }
  5440. customs = append(customs, cus)
  5441. }
  5442. }
  5443. for _, item := range item.HisAdditionalCharge {
  5444. cus := &Custom{
  5445. ItemId: item.ID,
  5446. AdviceId: 0,
  5447. ProjectId: 0,
  5448. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  5449. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  5450. FeedetlSn: item.FeedetlSn,
  5451. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  5452. MedListCodg: item.XtHisAddtionConfig.Code,
  5453. Type: 3,
  5454. }
  5455. customs = append(customs, cus)
  5456. }
  5457. }
  5458. for _, item := range customs {
  5459. var advice_id int64 = 0
  5460. var project_id int64 = 0
  5461. var item_id int64 = 0
  5462. var types int64 = 0
  5463. if item.Type == 1 {
  5464. advice_id = item.AdviceId
  5465. project_id = 0
  5466. item_id = 0
  5467. } else if item.Type == 2 {
  5468. advice_id = 0
  5469. item_id = 0
  5470. project_id = item.ProjectId
  5471. } else if item.Type == 3 {
  5472. advice_id = 0
  5473. item_id = item.ItemId
  5474. project_id = 0
  5475. }
  5476. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  5477. cut, _ := strconv.ParseFloat(item.Cut, 32)
  5478. pric, _ := strconv.ParseFloat(item.Price, 32)
  5479. info := &models.HisOrderInfo{
  5480. OrderNumber: order.Number,
  5481. UploadDate: time.Now().Unix(),
  5482. AdviceId: advice_id,
  5483. DetItemFeeSumamt: detItemFeeSumamt,
  5484. Cnt: cut,
  5485. Pric: pric,
  5486. PatientId: id,
  5487. Status: 1,
  5488. Mtime: time.Now().Unix(),
  5489. Ctime: time.Now().Unix(),
  5490. UserOrgId: adminUser.CurrentOrgId,
  5491. HisPatientId: his.ID,
  5492. OrderId: order.ID,
  5493. ProjectId: project_id,
  5494. Type: types,
  5495. ItemId: item_id,
  5496. }
  5497. service.CreateOrderInfoTX(info, tx)
  5498. }
  5499. his.Diagnosis = diagnosis_id
  5500. his.SickType = sick_type
  5501. his.RegisterType = reg_type
  5502. his.MedicalTreatmentType = reg_type
  5503. service.UpdataHisPateintTX(&his, tx)
  5504. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  5505. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  5506. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  5507. //判断是否使用了押金
  5508. if dec_way == "true" {
  5509. tmpstring := strconv.FormatInt(order.ID, 10)
  5510. //扣押金
  5511. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  5512. order.Decimal = decimal
  5513. service.UpDateOrderTwo(order)
  5514. if errmsg != nil {
  5515. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  5516. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5517. return
  5518. }
  5519. }
  5520. if err == nil {
  5521. for _, info := range prescriptions {
  5522. if info.Type == 1 {
  5523. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  5524. }
  5525. if info.Type == 2 {
  5526. for _, sumItem := range info.HisPrescriptionProject {
  5527. if sumItem.Type == 3 {
  5528. var good models.DialysisBeforePrepareGoods
  5529. var newGood models.NewDialysisBeforePrepareGoods
  5530. var oldGood models.OldDialysisBeforePrepareGoods
  5531. good.GoodId = sumItem.GoodInfo.ID
  5532. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5533. count, _ := strconv.Atoi(sumItem.Count)
  5534. good.Count = int64(count)
  5535. good.StorehouseId = houseConfig.StorehouseOutInfo
  5536. good.ProjectId = sumItem.ID
  5537. good.PatientId = sumItem.PatientId
  5538. goods = append(goods, &good)
  5539. newGood.GoodId = sumItem.GoodInfo.ID
  5540. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5541. count2, _ := strconv.Atoi(sumItem.Count)
  5542. newGood.Count = int64(count2)
  5543. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5544. newGood.ProjectId = sumItem.ID
  5545. newGood.PatientId = sumItem.HisPatientId
  5546. newGoods = append(newGoods, &newGood)
  5547. oldGood.GoodId = sumItem.GoodInfo.ID
  5548. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5549. count3, _ := strconv.Atoi(sumItem.Count)
  5550. oldGood.Count = int64(count3)
  5551. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  5552. oldGood.ProjectId = sumItem.ID
  5553. oldGood.RecordDate = sumItem.RecordDate
  5554. oldGood.PatientId = sumItem.HisPatientId
  5555. oldGoods = append(oldGoods, &oldGood)
  5556. }
  5557. }
  5558. }
  5559. }
  5560. if settConfig.IsOpen == 1 {
  5561. for _, item := range infoList {
  5562. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5563. //药品出库
  5564. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  5565. //查询默认仓库
  5566. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5567. //查询默认仓库剩余多少库存
  5568. var sum_count int64
  5569. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5570. for _, its := range stockInfo {
  5571. if its.MaxUnit == medical.MaxUnit {
  5572. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5573. }
  5574. sum_count += its.StockMaxNumber + its.StockMinNumber
  5575. }
  5576. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5577. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5578. }
  5579. orgId := c.GetAdminUserInfo().CurrentOrgId
  5580. if len(oldGoods) > 0 {
  5581. timeStr := time.Now().Format("2006-01-02")
  5582. timeArr := strings.Split(timeStr, "-")
  5583. total, _ := service.FindAllWarehouseOut(orgId)
  5584. total = total + 1
  5585. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5586. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5587. number = number + total
  5588. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5589. operation_time := time.Now().Unix()
  5590. creater := c.GetAdminUserInfo().AdminUser.Id
  5591. //查询默认出库仓库库存
  5592. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5593. recordDateStr := time.Now().Format("2006-01-02")
  5594. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5595. nowtime := recordDate.Unix()
  5596. warehouseOut := models.WarehouseOut{
  5597. WarehouseOutOrderNumber: warehousing_out_order,
  5598. OperationTime: operation_time,
  5599. OrgId: orgId,
  5600. Creater: creater,
  5601. Ctime: time.Now().Unix(),
  5602. Status: 1,
  5603. WarehouseOutTime: nowtime,
  5604. Type: 1,
  5605. StorehouseId: storeConfig.StorehouseOutInfo,
  5606. IsCheck: 1,
  5607. OrderId: order.ID,
  5608. IsSys: 5,
  5609. }
  5610. //查询是否生成出库单
  5611. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  5612. if out.ID == 0 {
  5613. service.AddSigleWarehouseOut(&warehouseOut)
  5614. }
  5615. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  5616. for _, item := range oldGoods {
  5617. dialyPrepareOne := models.DialysisBeforePrepare{
  5618. GoodTypeId: item.GoodTypeId,
  5619. GoodId: item.GoodId,
  5620. PatientId: his.PatientId,
  5621. RecordDate: item.RecordDate,
  5622. UserOrgId: adminUser.CurrentOrgId,
  5623. Count: item.Count,
  5624. Ctime: time.Now().Unix(),
  5625. Creater: adminUser.AdminUser.Id,
  5626. CommdityCode: item.CommdityCode,
  5627. Status: 1,
  5628. StorehouseId: houseConfig.StorehouseOutInfo,
  5629. }
  5630. //err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5631. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  5632. //查询剩余库存
  5633. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId)
  5634. var sum_count int64
  5635. for _, item := range goodList {
  5636. sum_count += item.StockCount
  5637. }
  5638. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  5639. //耗材
  5640. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  5641. }
  5642. }
  5643. }
  5644. c.ServeSuccessJSON(map[string]interface{}{
  5645. "msg": "结算成功",
  5646. })
  5647. }
  5648. } else {
  5649. if tempOrder.IsPre > 0 {
  5650. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  5651. totals, _ := strconv.ParseFloat(allTotal, 64)
  5652. tempOrder.OrderStatus = 2
  5653. tempOrder.PayWay = pay_way
  5654. tempOrder.PayPrice = pay_price
  5655. tempOrder.PayCardNo = pay_card_no
  5656. tempOrder.DiscountPrice = discount_price
  5657. tempOrder.PreferentialPrice = preferential_price
  5658. tempOrder.RealityPrice = reality_price
  5659. tempOrder.FoundPrice = found_price
  5660. tempOrder.MedicalInsurancePrice = medical_insurance_price
  5661. tempOrder.PrivatePrice = private_price
  5662. tempOrder.FaPiaoCode = fapiao_code
  5663. tempOrder.FaPiaoNumber = fapiao_number
  5664. tempOrder.PType = 2
  5665. tempOrder.MedfeeSumamt = totals
  5666. tempOrder.Diagnosis = diagnosis_id
  5667. err = service.SaveHisOrder(&tempOrder)
  5668. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  5669. if err != nil {
  5670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5671. return
  5672. }
  5673. if err == nil {
  5674. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5675. var goods []*models.DialysisBeforePrepareGoods
  5676. var newGoods []*models.NewDialysisBeforePrepareGoods
  5677. var infos []*models.HisDoctorAdviceInfo
  5678. var hisAdvice []*models.HisDoctorAdviceInfo
  5679. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5680. var infolist []*models.HisDoctorAdviceInfo
  5681. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5682. for _, info := range prescriptions {
  5683. if info.Type == 1 {
  5684. infos = append(infos, info.HisDoctorAdviceInfo...)
  5685. }
  5686. if info.Type == 2 {
  5687. for _, sumItem := range info.HisPrescriptionProject {
  5688. if sumItem.Type == 3 {
  5689. var good models.DialysisBeforePrepareGoods
  5690. var newGood models.NewDialysisBeforePrepareGoods
  5691. good.GoodId = sumItem.GoodInfo.ID
  5692. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5693. count, _ := strconv.Atoi(sumItem.Count)
  5694. good.Count = int64(count)
  5695. good.StorehouseId = houseConfig.StorehouseOutInfo
  5696. good.ProjectId = sumItem.ID
  5697. goods = append(goods, &good)
  5698. newGood.GoodId = sumItem.GoodInfo.ID
  5699. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5700. count2, _ := strconv.Atoi(sumItem.Count)
  5701. newGood.Count = int64(count2)
  5702. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5703. newGood.ProjectId = sumItem.ID
  5704. newGoods = append(newGoods, &newGood)
  5705. }
  5706. }
  5707. }
  5708. }
  5709. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5710. if settConfig.IsOpen == 1 {
  5711. //判断库存的地方
  5712. for _, info := range prescriptions {
  5713. if info.Type == 1 {
  5714. infolist = append(infolist, info.HisDoctorAdviceInfo...)
  5715. }
  5716. if info.Type == 2 {
  5717. for _, sumItem := range info.HisPrescriptionProject {
  5718. if sumItem.Type == 3 {
  5719. var good models.DialysisBeforePrepareGoods
  5720. var newGood models.NewDialysisBeforePrepareGoods
  5721. var oldGood models.OldDialysisBeforePrepareGoods
  5722. good.GoodId = sumItem.GoodInfo.ID
  5723. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5724. count, _ := strconv.Atoi(sumItem.Count)
  5725. good.Count = int64(count)
  5726. good.StorehouseId = houseConfig.StorehouseOutInfo
  5727. good.ProjectId = sumItem.ID
  5728. goods = append(goods, &good)
  5729. newGood.GoodId = sumItem.GoodInfo.ID
  5730. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5731. count2, _ := strconv.Atoi(sumItem.Count)
  5732. newGood.Count = int64(count2)
  5733. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5734. newGood.ProjectId = sumItem.ID
  5735. newGoods = append(newGoods, &newGood)
  5736. oldGood.GoodId = sumItem.GoodInfo.ID
  5737. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5738. count3, _ := strconv.Atoi(sumItem.Count)
  5739. oldGood.Count = int64(count3)
  5740. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  5741. oldGood.ProjectId = sumItem.ID
  5742. oldGood.RecordDate = sumItem.RecordDate
  5743. oldGoods = append(oldGoods, &oldGood)
  5744. }
  5745. }
  5746. }
  5747. }
  5748. for _, info := range prescriptionsOne {
  5749. if info.Type == 1 {
  5750. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5751. }
  5752. if info.Type == 2 {
  5753. for _, sumItem := range info.HisPrescriptionProject {
  5754. if sumItem.Type == 3 {
  5755. var newGood models.NewDialysisBeforePrepareGoods
  5756. newGood.GoodId = sumItem.GoodInfo.ID
  5757. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5758. count2, _ := strconv.Atoi(sumItem.Count)
  5759. newGood.Count = int64(count2)
  5760. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5761. newGood.ProjectId = sumItem.ID
  5762. newGoodOne = append(newGoodOne, &newGood)
  5763. }
  5764. }
  5765. }
  5766. }
  5767. //判断
  5768. for _, itemOne := range infos {
  5769. for _, itemTwo := range hisAdvice {
  5770. if itemOne.DrugId == itemTwo.DrugId {
  5771. itemTwo.Child = append(itemTwo.ChildDoctorAdvice, itemOne)
  5772. }
  5773. }
  5774. }
  5775. for _, itemTwo := range hisAdvice {
  5776. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5777. var sum_out_count int64
  5778. for _, itemThree := range itemTwo.Child {
  5779. var prescribing_number int64
  5780. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5781. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5782. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5783. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5784. }
  5785. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5786. prescribing_number = parseIntPrescribingNumber
  5787. }
  5788. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5789. prescribing_number = parseIntPrescribingNumber
  5790. }
  5791. sum_out_count += prescribing_number
  5792. }
  5793. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId)
  5794. if sum_out_count > drugStockOut.FlushCount {
  5795. c.ServeSuccessJSON(map[string]interface{}{
  5796. "msg": "2",
  5797. "drug": medical,
  5798. })
  5799. return
  5800. }
  5801. }
  5802. for _, itemOne := range newGoods {
  5803. for _, item := range newGoodOne {
  5804. if itemOne.ProjectId == item.ProjectId {
  5805. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, item)
  5806. }
  5807. }
  5808. }
  5809. for _, item := range newGoodOne {
  5810. var sum_out_count_one int64
  5811. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  5812. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  5813. sum_out_count_one += itemOne.Count
  5814. }
  5815. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId)
  5816. fmt.Println("sum_out_count_one", sum_out_count_one)
  5817. fmt.Println("list.FlushCount", list.FlushCount)
  5818. if sum_out_count_one > list.FlushCount {
  5819. c.ServeSuccessJSON(map[string]interface{}{
  5820. "msg": "3",
  5821. "good": good,
  5822. })
  5823. return
  5824. }
  5825. }
  5826. for _, item := range infolist {
  5827. service.HisDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item)
  5828. }
  5829. for _, item := range oldGoods {
  5830. dialyPrepareOne := models.DialysisBeforePrepare{
  5831. GoodTypeId: item.GoodTypeId,
  5832. GoodId: item.GoodId,
  5833. PatientId: item.PatientId,
  5834. RecordDate: item.RecordDate,
  5835. UserOrgId: item.UserOrgId,
  5836. Count: item.Count,
  5837. Ctime: time.Now().Unix(),
  5838. Creater: adminUser.AdminUser.Id,
  5839. CommdityCode: item.CommdityCode,
  5840. Status: 1,
  5841. StorehouseId: houseConfig.StorehouseOutInfo,
  5842. }
  5843. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5844. }
  5845. service.ConsumablesDeliveryTotal(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, goods, newGoods, adminUser.AdminUser.Id)
  5846. }
  5847. c.ServeSuccessJSON(map[string]interface{}{
  5848. "msg": "结算成功",
  5849. })
  5850. }
  5851. }
  5852. }
  5853. }
  5854. //退款
  5855. func (c *HisApiController) Refund() {
  5856. order_id, _ := c.GetInt64("order_id")
  5857. order, _ := service.GetHisOrderByID(order_id)
  5858. adminUser := c.GetAdminUserInfo()
  5859. orgid := c.GetAdminUserInfo().CurrentOrgId
  5860. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  5861. if err != nil {
  5862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5863. return
  5864. }
  5865. tmp := strconv.FormatInt(order.ID, 10)
  5866. //当押金不为零时产生退费记录
  5867. if order.Decimal != 0 {
  5868. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  5869. if err != nil {
  5870. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5871. return
  5872. }
  5873. }
  5874. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  5875. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  5876. var goods []*models.DialysisBeforePrepareGoods
  5877. var newGoods []*models.NewDialysisBeforePrepareGoods
  5878. var infos []*models.HisDoctorAdviceInfo
  5879. for _, info := range orders {
  5880. if info.AdviceId > 0 && info.ProjectId == 0 {
  5881. infos = append(infos, &info.HisDoctorAdviceInfo)
  5882. }
  5883. if info.ProjectId > 0 && info.AdviceId == 0 {
  5884. fmt.Println("info232323233232233", info.PatientId)
  5885. if info.HisPrescriptionProject.Type == 3 {
  5886. var good models.DialysisBeforePrepareGoods
  5887. var newGood models.NewDialysisBeforePrepareGoods
  5888. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  5889. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  5890. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  5891. good.Count = int64(count)
  5892. good.StorehouseId = houseConfig.StorehouseOutInfo
  5893. good.ProjectId = info.HisPrescriptionProject.ID
  5894. good.PatientId = info.PatientId
  5895. goods = append(goods, &good)
  5896. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  5897. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  5898. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  5899. newGood.Count = int64(count2)
  5900. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5901. newGood.ProjectId = info.HisPrescriptionProject.ID
  5902. newGood.RecordDate = order.SettleAccountsDate
  5903. newGood.UserOrgId = order.UserOrgId
  5904. newGood.PatientId = info.PatientId
  5905. newGoods = append(newGoods, &newGood)
  5906. }
  5907. }
  5908. }
  5909. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5910. if settConfig.IsOpen == 1 {
  5911. for _, item := range infos {
  5912. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  5913. }
  5914. for _, item := range newGoods {
  5915. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  5916. }
  5917. }
  5918. c.ServeSuccessJSON(map[string]interface{}{
  5919. "msg": "退费成功",
  5920. })
  5921. }
  5922. func (c *HisApiController) RefundNumber() {
  5923. his_patient_id, _ := c.GetInt64("id")
  5924. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  5925. info.Status = 0
  5926. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  5927. if count > 0 {
  5928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  5929. return
  5930. }
  5931. err := service.SaveHisPatient(info)
  5932. if err == nil {
  5933. c.ServeSuccessJSON(map[string]interface{}{
  5934. "msg": "退号成功",
  5935. })
  5936. } else {
  5937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5938. return
  5939. }
  5940. }
  5941. func (this *HisApiController) AdditionalCharge() {
  5942. dataBody := make(map[string]interface{}, 0)
  5943. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5944. fmt.Println(err)
  5945. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  5946. patient_id := int64(dataBody["patient_id"].(float64))
  5947. medicineData, _ := dataBody["medicineData"].([]interface{})
  5948. adminUserInfo := this.GetAdminUserInfo()
  5949. orgId := adminUserInfo.CurrentOrgId
  5950. admin_user_id := adminUserInfo.AdminUser.Id
  5951. timeStr := time.Now().Format("2006-01-02")
  5952. timeLayout := "2006-01-02 15:04:05"
  5953. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  5954. timenow := timeStringToTime.Unix()
  5955. var additionalCharges []*models.HisAdditionalCharge
  5956. for _, item := range medicineData {
  5957. var randNum int
  5958. randNum = rand.Intn(10000) + 1000
  5959. timestamp := time.Now().Unix()
  5960. tempTime := time.Unix(timestamp, 0)
  5961. timeFormat := tempTime.Format("20060102150405")
  5962. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5963. items := item.(map[string]interface{})
  5964. money := items["price"].(string)
  5965. item_id_str := items["item_id"].(string)
  5966. name := items["name"].(string)
  5967. id_str := items["id"].(string)
  5968. moneys, _ := strconv.ParseInt(money, 10, 64)
  5969. monStr := strconv.FormatInt(moneys, 10)
  5970. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  5971. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  5972. id, _ := strconv.ParseInt(id_str, 10, 64)
  5973. additionalCharge := &models.HisAdditionalCharge{
  5974. ID: id,
  5975. HisPatientId: his_patient_id,
  5976. UserOrgId: orgId,
  5977. PatientId: patient_id,
  5978. RecordDate: timenow,
  5979. Price: monneyStr,
  5980. Status: 1,
  5981. ItemName: name,
  5982. ItemId: item_id,
  5983. AdminUserId: admin_user_id,
  5984. CreatedTime: time.Now().Unix(),
  5985. OrderStatus: 0,
  5986. PrescriptionNumber: "",
  5987. BatchNumber: "",
  5988. FeedetlSn: p_number,
  5989. }
  5990. service.CreateAdditionalCharge(additionalCharge)
  5991. additionalCharges = append(additionalCharges, additionalCharge)
  5992. }
  5993. this.ServeSuccessJSON(map[string]interface{}{
  5994. "msg": "添加成功",
  5995. "additional_charges": additionalCharges,
  5996. })
  5997. }
  5998. func (this *HisApiController) DeleteAddition() {
  5999. id, _ := this.GetInt64("id")
  6000. //TODO 需要判断是否已经结算
  6001. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6002. if err == nil {
  6003. this.ServeSuccessJSON(map[string]interface{}{
  6004. "msg": "删除成功",
  6005. })
  6006. return
  6007. } else {
  6008. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6009. return
  6010. }
  6011. }
  6012. func (this *HisApiController) GetAdminUsers() {
  6013. adminUser := this.GetAdminUserInfo()
  6014. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6015. this.ServeSuccessJSON(map[string]interface{}{
  6016. "doctors": doctors,
  6017. })
  6018. }
  6019. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6020. change_type, _ := this.GetInt64("type", 0)
  6021. record_date := this.GetString("record_time")
  6022. patient_id, _ := this.GetInt64("patient_id", 0)
  6023. p_type, _ := this.GetInt64("p_type", 0)
  6024. timeLayout := "2006-01-02"
  6025. loc, _ := time.LoadLocation("Local")
  6026. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6027. record_time := theAdviceRecordTime.Unix()
  6028. adminUserInfo := this.GetAdminUserInfo()
  6029. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6030. if err == nil {
  6031. if len(prescriptions) == 0 {
  6032. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6033. return
  6034. } else {
  6035. this.ServeSuccessJSON(map[string]interface{}{
  6036. "prescriptions": prescriptions,
  6037. })
  6038. return
  6039. }
  6040. } else {
  6041. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6042. return
  6043. }
  6044. }
  6045. func (this *HisApiController) GetCallHisPrescription() {
  6046. patient_id, _ := this.GetInt64("patient_id", 0)
  6047. timeLayout := "2006-01-02"
  6048. loc, _ := time.LoadLocation("Local")
  6049. start_time := this.GetString("start_time")
  6050. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6051. end_time := this.GetString("end_time")
  6052. p_type, _ := this.GetInt64("p_type")
  6053. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6054. adminUserInfo := this.GetAdminUserInfo()
  6055. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6056. if err == nil {
  6057. this.ServeSuccessJSON(map[string]interface{}{
  6058. "prescriptions": prescriptions,
  6059. })
  6060. return
  6061. } else {
  6062. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6063. return
  6064. }
  6065. }
  6066. func (this *HisApiController) GetHisDayPrescription() {
  6067. timeLayout := "2006-01-02"
  6068. loc, _ := time.LoadLocation("Local")
  6069. start_time := this.GetString("start_time")
  6070. patient_id, _ := this.GetInt64("patient_id", 0)
  6071. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6072. end_time := this.GetString("end_time")
  6073. p_type, _ := this.GetInt64("p_type")
  6074. order_status, _ := this.GetInt64("type")
  6075. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6076. adminUserInfo := this.GetAdminUserInfo()
  6077. var dayHisPrescription []*models.HisPrescription
  6078. var err error
  6079. if order_status == 1 || order_status == 0 {
  6080. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6081. } else if order_status == 2 {
  6082. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6083. }
  6084. var settle_total float64
  6085. for _, item := range dayHisPrescription {
  6086. if len(item.HisPrescriptionProject) > 0 {
  6087. for _, subItem := range item.HisPrescriptionProject {
  6088. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6089. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6090. settle_total = settle_total + total
  6091. }
  6092. }
  6093. if len(item.HisDoctorAdviceInfo) > 0 {
  6094. for _, subItem := range item.HisDoctorAdviceInfo {
  6095. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6096. settle_total = settle_total + total
  6097. }
  6098. }
  6099. }
  6100. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6101. if err == nil {
  6102. this.ServeSuccessJSON(map[string]interface{}{
  6103. "day_prescription": dayHisPrescription,
  6104. "settle_total": settle_total,
  6105. })
  6106. return
  6107. } else {
  6108. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6109. return
  6110. }
  6111. }
  6112. func (c *HisApiController) GetHisChargePatientList() {
  6113. record_date := c.GetString("record_date")
  6114. order_status, _ := c.GetInt64("type")
  6115. timeLayout := "2006-01-02"
  6116. loc, _ := time.LoadLocation("Local")
  6117. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6118. if err != nil {
  6119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6120. return
  6121. }
  6122. recordDateTime := theTime.Unix()
  6123. adminInfo := c.GetAdminUserInfo()
  6124. var tempPatients []*service.NewTempPatients
  6125. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6126. if order_status != 2 {
  6127. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6128. } else {
  6129. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6130. }
  6131. var patients []*service.NewTempPatients
  6132. var patients_two []*service.NewTempPatients
  6133. for _, item := range tempPatients {
  6134. //过滤掉没挂号的和没开处方的
  6135. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6136. patients = append(patients, item)
  6137. }
  6138. //过滤掉没挂号的
  6139. if len(item.HisPatient) > 0 {
  6140. patients_two = append(patients_two, item)
  6141. }
  6142. }
  6143. c.ServeSuccessJSON(map[string]interface{}{
  6144. "list": patients,
  6145. "list_two": patients_two,
  6146. })
  6147. }
  6148. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6149. record_date := c.GetString("record_date")
  6150. timeLayout := "2006-01-02"
  6151. loc, _ := time.LoadLocation("Local")
  6152. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6153. if err != nil {
  6154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6155. return
  6156. }
  6157. recordDateTime := theTime.Unix()
  6158. adminUser := c.GetAdminUserInfo()
  6159. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6160. var patients []*service.Patients
  6161. for _, item := range tempPatients {
  6162. if item.HisPatient.ID == 0 {
  6163. patients = append(patients, item)
  6164. }
  6165. }
  6166. c.ServeSuccessJSON(map[string]interface{}{
  6167. "list": patients,
  6168. //"list_two": patients_two,
  6169. })
  6170. }
  6171. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6172. newArr = make([]*service.Patients, 0)
  6173. for i := 0; i < len(patient); i++ {
  6174. repeat := false
  6175. for j := i + 1; j < len(patient); j++ {
  6176. if patient[i].ID == patient[j].ID {
  6177. repeat = true
  6178. break
  6179. }
  6180. }
  6181. if !repeat {
  6182. newArr = append(newArr, patient[i])
  6183. }
  6184. }
  6185. return
  6186. }
  6187. func (c *HisApiController) GetHisChargePatientInfo() {
  6188. patient_id, _ := c.GetInt64("patient_id")
  6189. his_patient_id, _ := c.GetInt64("his_patient_id")
  6190. record_date := c.GetString("record_date")
  6191. //start_time := c.GetString("start_time")
  6192. //end_time := c.GetString("end_time")
  6193. order_status, _ := c.GetInt64("type", 0)
  6194. p_type, _ := c.GetInt64("p_type", 0)
  6195. order_id, _ := c.GetInt64("order_id", 0)
  6196. timeLayout := "2006-01-02"
  6197. loc, _ := time.LoadLocation("Local")
  6198. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6199. if err != nil {
  6200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6201. return
  6202. }
  6203. recordDateTime := theTime.Unix()
  6204. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6205. //if err != nil {
  6206. //
  6207. //}
  6208. //startRecordDateTime := startTime.Unix()
  6209. //
  6210. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6211. //if err != nil {
  6212. //
  6213. //}
  6214. //endRecordDateTime := endTime.Unix()
  6215. admin := c.GetAdminUserInfo()
  6216. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6217. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6218. var prescriptions []*models.HisPrescription
  6219. //var unChargeMonthPrescriptions []*models.HisPrescription
  6220. order, _ := service.GetHisOrderByID(order_id)
  6221. if order_status == 1 || order_status == 0 {
  6222. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6223. } else if order_status == 2 {
  6224. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6225. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6226. }
  6227. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6228. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6229. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6230. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6231. //获取所有科室信息
  6232. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6233. c.ServeSuccessJSON(map[string]interface{}{
  6234. "his_info": his_patient_info,
  6235. "xt_info": xt_patient_info,
  6236. "prescription": prescriptions,
  6237. "case_history": case_history,
  6238. "info": patientPrescriptionInfo,
  6239. "last_info": lastPatientPrescriptionInfo,
  6240. "order": order,
  6241. "doctors": doctors,
  6242. "department": department,
  6243. })
  6244. return
  6245. }
  6246. func (c *HisApiController) GetAllOrderDetail() {
  6247. order_id, _ := c.GetInt64("id", 0)
  6248. order, _ := service.GetHisOrderByID(order_id)
  6249. if order.ID == 0 {
  6250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6251. return
  6252. }
  6253. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6254. org_id := c.GetAdminUserInfo().CurrentOrgId
  6255. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6256. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6257. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6258. c.ServeSuccessJSON(map[string]interface{}{
  6259. "order": order,
  6260. "order_info": order_info,
  6261. "patient": patient,
  6262. "admin_info": adminInfo,
  6263. "hospital_record": record,
  6264. })
  6265. return
  6266. }
  6267. func (c *HisApiController) GetAllOrderDetailCollect() {
  6268. order_id, _ := c.GetInt64("id", 0)
  6269. order, _ := service.GetHisOrderByID(order_id)
  6270. if order.ID == 0 {
  6271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6272. return
  6273. }
  6274. org_id := c.GetAdminUserInfo().CurrentOrgId
  6275. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6276. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6277. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6278. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6279. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6280. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6281. var bedCostTotal float64 = 0 //床位总费
  6282. //var bedCostSelfTotal float64 = 0 //床位自费
  6283. var operationCostTotal float64 = 0 //手术费
  6284. //var operationCostSelfTotal float64 = 0 //手术费
  6285. var otherCostTotal float64 = 0 //其他费用
  6286. //var otherCostSelfTotal float64 = 0 //其他费用
  6287. var materialCostTotal float64 = 0 //材料费
  6288. //var materialCostSelfTotal float64 = 0 //材料费
  6289. var westernMedicineCostTotal float64 = 0 //西药费
  6290. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6291. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6292. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6293. var checkCostTotal float64 = 0 //检查费
  6294. //var checkCostSelfTotal float64 = 0 //检查费
  6295. var laboratoryCostTotal float64 = 0 //化验费
  6296. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6297. var treatCostTotal float64 = 0 //治疗费用
  6298. //var treatCostSelfTotal float64 = 0 //治疗费用
  6299. var zhenChaCostTotal float64 = 0 //其他费用
  6300. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6301. decimal.DivisionPrecision = 2
  6302. var BalanceAccountsType int64
  6303. if his.ID > 0 {
  6304. BalanceAccountsType = his.BalanceAccountsType
  6305. } else {
  6306. BalanceAccountsType = record.BalanceAccountsType
  6307. }
  6308. if BalanceAccountsType != 2 {
  6309. for _, item := range order_info {
  6310. if org_id == 10215 {
  6311. if item.MedChrgitmType == "01" { //床位费
  6312. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6313. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6314. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6315. }
  6316. if item.MedChrgitmType == "02" { //诊察费
  6317. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6318. //zhenChaCostSelfTotal = zhenChaCostTotal
  6319. }
  6320. if item.MedChrgitmType == "03" { //检查费
  6321. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6322. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6323. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6324. }
  6325. //if item.MedChrgitmType == "02" { //检查费
  6326. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6327. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6328. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6329. //}
  6330. if item.MedChrgitmType == "04" { //化验费
  6331. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6332. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6333. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6334. }
  6335. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6336. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6337. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6338. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6339. }
  6340. if item.MedChrgitmType == "06" { //手术费
  6341. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6342. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6343. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6344. }
  6345. if item.MedChrgitmType == "08" { //材料费
  6346. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6347. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6348. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6349. }
  6350. if item.MedChrgitmType == "09" { //西药费
  6351. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6352. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6353. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6354. }
  6355. if item.MedChrgitmType == "11" { //中成费
  6356. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6357. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6358. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6359. }
  6360. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6361. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6362. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6363. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6364. }
  6365. } else if org_id == 10188 || org_id == 10217 {
  6366. if item.MedChrgitmType == "01" { //床位费
  6367. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6368. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6369. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6370. }
  6371. if item.MedChrgitmType == "02" { //诊察费
  6372. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6373. //zhenChaCostSelfTotal = zhenChaCostTotal
  6374. }
  6375. if item.MedChrgitmType == "03" { //检查费
  6376. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6377. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6378. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6379. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6380. }
  6381. //if item.MedChrgitmType == "02" { //检查费
  6382. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6383. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6384. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6385. //}
  6386. if item.MedChrgitmType == "04" { //化验费
  6387. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6388. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6389. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6390. }
  6391. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6392. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6393. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6394. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6395. }
  6396. if item.MedChrgitmType == "06" { //手术费
  6397. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6398. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6399. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6400. }
  6401. if item.MedChrgitmType == "08" { //材料费
  6402. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6403. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6404. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6405. }
  6406. if item.MedChrgitmType == "09" { //西药费
  6407. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6408. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6409. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6410. }
  6411. if item.MedChrgitmType == "11" { //中成费
  6412. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6413. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6414. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6415. }
  6416. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6417. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6418. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6419. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6420. }
  6421. } else {
  6422. if item.MedChrgitmType == "01" { //床位费
  6423. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6424. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6425. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6426. }
  6427. //if item.MedChrgitmType == "02" { //诊察费
  6428. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6429. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6430. //}
  6431. if item.MedChrgitmType == "03" { //检查费
  6432. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6433. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6434. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6435. }
  6436. //if item.MedChrgitmType == "02" { //检查费
  6437. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6438. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6439. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6440. //}
  6441. if item.MedChrgitmType == "04" { //化验费
  6442. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6443. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6444. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6445. }
  6446. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6447. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6448. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6449. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6450. }
  6451. if item.MedChrgitmType == "06" { //手术费
  6452. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6453. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6454. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6455. }
  6456. if item.MedChrgitmType == "08" { //材料费
  6457. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6458. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6459. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6460. }
  6461. if item.MedChrgitmType == "09" { //西药费
  6462. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6463. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6464. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6465. }
  6466. if item.MedChrgitmType == "11" { //中成费
  6467. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6468. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6469. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6470. }
  6471. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6472. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6473. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6474. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6475. }
  6476. }
  6477. }
  6478. c.ServeSuccessJSON(map[string]interface{}{
  6479. "order": order,
  6480. "order_info": order_info,
  6481. "patient": patient,
  6482. "admin_info": adminInfo,
  6483. "his_hospital": record,
  6484. "bedCostTotal": bedCostTotal,
  6485. "operationCostTotal": operationCostTotal,
  6486. "otherCostTotal": otherCostTotal,
  6487. "materialCostTotal": materialCostTotal,
  6488. "westernMedicineCostTotal": westernMedicineCostTotal,
  6489. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6490. "checkCostTotal": checkCostTotal,
  6491. "zhenChaCostTotal": zhenChaCostTotal,
  6492. "laboratoryCostTotal": laboratoryCostTotal,
  6493. "treatCostTotal": treatCostTotal,
  6494. })
  6495. } else {
  6496. for _, item := range order_info {
  6497. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  6498. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  6499. item.MedChrgitmType = "09"
  6500. }
  6501. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  6502. if item.HisPrescriptionProject.Type == 2 {
  6503. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  6504. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6505. case 0:
  6506. item.MedChrgitmType = "0"
  6507. break
  6508. case 1:
  6509. item.MedChrgitmType = "14"
  6510. break
  6511. case 2:
  6512. item.MedChrgitmType = "05"
  6513. break
  6514. case 3:
  6515. item.MedChrgitmType = "03"
  6516. break
  6517. case 4:
  6518. item.MedChrgitmType = "03"
  6519. break
  6520. case 5:
  6521. item.MedChrgitmType = "08"
  6522. break
  6523. case 6:
  6524. item.MedChrgitmType = "14"
  6525. break
  6526. case 7:
  6527. item.MedChrgitmType = "14"
  6528. break
  6529. case 8:
  6530. item.MedChrgitmType = "03"
  6531. break
  6532. case 9:
  6533. item.MedChrgitmType = "14"
  6534. break
  6535. case 10:
  6536. item.MedChrgitmType = "14"
  6537. break
  6538. case 11:
  6539. item.MedChrgitmType = "06"
  6540. break
  6541. case 12:
  6542. item.MedChrgitmType = "12"
  6543. break
  6544. case 13:
  6545. item.MedChrgitmType = "01"
  6546. break
  6547. case 14:
  6548. item.MedChrgitmType = "04"
  6549. break
  6550. case 15:
  6551. item.MedChrgitmType = "14"
  6552. break
  6553. }
  6554. } else {
  6555. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6556. case 1:
  6557. item.MedChrgitmType = "14"
  6558. break
  6559. case 2:
  6560. item.MedChrgitmType = "05"
  6561. break
  6562. case 3:
  6563. item.MedChrgitmType = "04"
  6564. break
  6565. case 4:
  6566. item.MedChrgitmType = "14"
  6567. break
  6568. case 5:
  6569. item.MedChrgitmType = "08"
  6570. break
  6571. case 6:
  6572. item.MedChrgitmType = "14"
  6573. break
  6574. case 7:
  6575. item.MedChrgitmType = "14"
  6576. break
  6577. case 8:
  6578. item.MedChrgitmType = "03"
  6579. break
  6580. case 9:
  6581. item.MedChrgitmType = "14"
  6582. break
  6583. }
  6584. }
  6585. } else if item.HisPrescriptionProject.Type == 3 {
  6586. item.MedChrgitmType = "08"
  6587. }
  6588. }
  6589. }
  6590. for _, item := range order_info {
  6591. if org_id == 10215 {
  6592. if item.MedChrgitmType == "01" { //床位费
  6593. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6594. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6595. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6596. }
  6597. if item.MedChrgitmType == "02" { //诊察费
  6598. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6599. //zhenChaCostSelfTotal = zhenChaCostTotal
  6600. }
  6601. if item.MedChrgitmType == "03" { //检查费
  6602. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6603. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6604. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6605. }
  6606. //if item.MedChrgitmType == "02" { //检查费
  6607. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6608. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6609. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6610. //}
  6611. if item.MedChrgitmType == "04" { //化验费
  6612. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6613. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6614. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6615. }
  6616. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6617. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6618. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6619. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6620. }
  6621. if item.MedChrgitmType == "06" { //手术费
  6622. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6623. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6624. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6625. }
  6626. if item.MedChrgitmType == "08" { //材料费
  6627. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6628. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6629. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6630. }
  6631. if item.MedChrgitmType == "09" { //西药费
  6632. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6633. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6634. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6635. }
  6636. if item.MedChrgitmType == "11" { //中成费
  6637. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6638. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6639. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6640. }
  6641. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6642. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6643. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6644. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6645. }
  6646. } else {
  6647. if item.MedChrgitmType == "01" { //床位费
  6648. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6649. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6650. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6651. }
  6652. //if item.MedChrgitmType == "02" { //诊察费
  6653. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6654. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6655. //}
  6656. if item.MedChrgitmType == "03" { //检查费
  6657. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6658. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6659. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6660. }
  6661. //if item.MedChrgitmType == "02" { //检查费
  6662. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6663. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6664. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6665. //}
  6666. if item.MedChrgitmType == "04" { //化验费
  6667. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6668. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6669. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6670. }
  6671. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6672. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6673. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6674. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6675. }
  6676. if item.MedChrgitmType == "06" { //手术费
  6677. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6678. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6679. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6680. }
  6681. if item.MedChrgitmType == "08" { //材料费
  6682. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6683. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6684. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6685. }
  6686. if item.MedChrgitmType == "09" { //西药费
  6687. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6688. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6689. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6690. }
  6691. if item.MedChrgitmType == "11" { //中成费
  6692. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6693. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6694. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6695. }
  6696. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6697. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6698. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6699. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6700. }
  6701. }
  6702. }
  6703. c.ServeSuccessJSON(map[string]interface{}{
  6704. "order": order,
  6705. "order_info": order_info,
  6706. "patient": patient,
  6707. "admin_info": adminInfo,
  6708. "his_hospital": record,
  6709. "bedCostTotal": bedCostTotal,
  6710. "operationCostTotal": operationCostTotal,
  6711. "otherCostTotal": otherCostTotal,
  6712. "materialCostTotal": materialCostTotal,
  6713. "westernMedicineCostTotal": westernMedicineCostTotal,
  6714. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6715. "checkCostTotal": checkCostTotal,
  6716. "zhenChaCostTotal": zhenChaCostTotal,
  6717. "laboratoryCostTotal": laboratoryCostTotal,
  6718. "treatCostTotal": treatCostTotal,
  6719. })
  6720. }
  6721. }
  6722. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  6723. page, _ := c.GetInt64("page")
  6724. limit, _ := c.GetInt64("limit")
  6725. keywords := c.GetString("keywords")
  6726. start_time := c.GetString("start_time")
  6727. end_time := c.GetString("end_time")
  6728. //clr_type := c.GetString("clr_type")
  6729. insutype := c.GetString("insutype")
  6730. timeLayout := "2006-01-02"
  6731. loc, _ := time.LoadLocation("Local")
  6732. var theStartTIme int64
  6733. if len(start_time) > 0 {
  6734. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6735. theStartTIme = theTime.Unix()
  6736. }
  6737. var theEndtTIme int64
  6738. if len(end_time) > 0 {
  6739. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6740. theEndtTIme = theTime.Unix()
  6741. }
  6742. if page <= 0 {
  6743. page = 1
  6744. }
  6745. if limit <= 0 {
  6746. limit = 10
  6747. }
  6748. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  6749. c.ServeSuccessJSON(map[string]interface{}{
  6750. "total": total,
  6751. "list": list,
  6752. })
  6753. return
  6754. }
  6755. func (c *HisApiController) GetPutOnRecordList() {
  6756. page, _ := c.GetInt64("page")
  6757. limit, _ := c.GetInt64("limit")
  6758. keywords := c.GetString("keywords")
  6759. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  6760. if page <= 0 {
  6761. page = 1
  6762. }
  6763. if limit <= 0 {
  6764. limit = 10
  6765. }
  6766. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  6767. c.ServeSuccessJSON(map[string]interface{}{
  6768. "total": total,
  6769. "list": list,
  6770. })
  6771. return
  6772. }
  6773. func (c *HisApiController) GetCompareData() {
  6774. start_time := c.GetString("start_time")
  6775. end_time := c.GetString("end_time")
  6776. insutype := c.GetString("insutype")
  6777. clr_type := c.GetString("clr_type")
  6778. timeLayout := "2006-01-02"
  6779. loc, _ := time.LoadLocation("Local")
  6780. var theStartTIme int64
  6781. if len(start_time) > 0 {
  6782. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6783. if err != nil {
  6784. theStartTIme = 0
  6785. }
  6786. theStartTIme = theTime.Unix()
  6787. }
  6788. var theEndtTIme int64
  6789. if len(end_time) > 0 {
  6790. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6791. if err != nil {
  6792. theEndtTIme = 0
  6793. }
  6794. theEndtTIme = theTime.Unix()
  6795. }
  6796. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  6797. fmt.Println(err)
  6798. if err == nil {
  6799. c.ServeSuccessJSON(map[string]interface{}{
  6800. "list": formData,
  6801. })
  6802. } else {
  6803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6804. return
  6805. }
  6806. }
  6807. func (c *HisApiController) GetFaPiaoData() {
  6808. order_id, _ := c.GetInt64("order_id")
  6809. patient_id, _ := c.GetInt64("patient_id")
  6810. number := c.GetString("number")
  6811. adminUser := c.GetAdminUserInfo()
  6812. order, _ := service.GetHisOrderByID(order_id)
  6813. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  6814. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  6815. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  6816. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  6817. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6818. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  6819. var bedCostTotal float64 = 0 //床位总费
  6820. var bedCostSelfTotal float64 = 0 //床位自费
  6821. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  6822. var operationCostTotal float64 = 0 //手术费
  6823. var operationCostSelfTotal float64 = 0 //手术费
  6824. var operationCostPartSelfTotal float64 = 0 //手术费
  6825. var otherCostTotal float64 = 0 //其他费用
  6826. var otherCostSelfTotal float64 = 0 //其他费用
  6827. var otherCostPartSelfTotal float64 = 0 //其他费用
  6828. var materialCostTotal float64 = 0 //材料费
  6829. var materialCostSelfTotal float64 = 0 //材料费
  6830. var materialCostPartSelfTotal float64 = 0 //材料费
  6831. var westernMedicineCostTotal float64 = 0 //西药费
  6832. var westernMedicineCostSelfTotal float64 = 0 //西药费
  6833. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  6834. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6835. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6836. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  6837. var checkCostTotal float64 = 0 //检查费
  6838. var checkCostSelfTotal float64 = 0 //检查费
  6839. var checkCostPartSelfTotal float64 = 0 //检查费
  6840. var laboratoryCostTotal float64 = 0 //化验费
  6841. var laboratoryCostSelfTotal float64 = 0 //化验费
  6842. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  6843. var treatCostTotal float64 = 0 //治疗费用
  6844. var treatCostSelfTotal float64 = 0 //治疗费用
  6845. var treatCostPartSelfTotal float64 = 0 //治疗费用
  6846. var zhenChaCostTotal float64 = 0 //其他费用
  6847. var zhenChaCostSelfTotal float64 = 0 //其他费用
  6848. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6849. decimal.DivisionPrecision = 2
  6850. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  6851. var balanceAccountsType int64
  6852. if his.ID > 0 {
  6853. balanceAccountsType = his.BalanceAccountsType
  6854. } else {
  6855. balanceAccountsType = his_hospital_record.BalanceAccountsType
  6856. }
  6857. if balanceAccountsType == 2 {
  6858. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  6859. for _, item := range orderInfos_two {
  6860. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  6861. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  6862. item.MedChrgitmType = "09"
  6863. }
  6864. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  6865. if item.HisPrescriptionProject.Type == 2 {
  6866. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  6867. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6868. case 0:
  6869. item.MedChrgitmType = "0"
  6870. break
  6871. case 1:
  6872. item.MedChrgitmType = "14"
  6873. break
  6874. case 2:
  6875. item.MedChrgitmType = "05"
  6876. break
  6877. case 3:
  6878. item.MedChrgitmType = "03"
  6879. break
  6880. case 4:
  6881. item.MedChrgitmType = "03"
  6882. break
  6883. case 5:
  6884. item.MedChrgitmType = "08"
  6885. break
  6886. case 6:
  6887. item.MedChrgitmType = "14"
  6888. break
  6889. case 7:
  6890. item.MedChrgitmType = "14"
  6891. break
  6892. case 8:
  6893. item.MedChrgitmType = "03"
  6894. break
  6895. case 9:
  6896. item.MedChrgitmType = "14"
  6897. break
  6898. case 10:
  6899. item.MedChrgitmType = "14"
  6900. break
  6901. case 11:
  6902. item.MedChrgitmType = "06"
  6903. break
  6904. case 12:
  6905. item.MedChrgitmType = "12"
  6906. break
  6907. case 13:
  6908. item.MedChrgitmType = "01"
  6909. break
  6910. case 14:
  6911. item.MedChrgitmType = "04"
  6912. break
  6913. case 15:
  6914. item.MedChrgitmType = "02"
  6915. break
  6916. }
  6917. } else {
  6918. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6919. case 1:
  6920. item.MedChrgitmType = "14"
  6921. break
  6922. case 2:
  6923. item.MedChrgitmType = "05"
  6924. break
  6925. case 3:
  6926. item.MedChrgitmType = "03"
  6927. break
  6928. case 4:
  6929. item.MedChrgitmType = "03"
  6930. break
  6931. case 5:
  6932. item.MedChrgitmType = "08"
  6933. break
  6934. case 6:
  6935. item.MedChrgitmType = "14"
  6936. break
  6937. case 7:
  6938. item.MedChrgitmType = "14"
  6939. break
  6940. case 8:
  6941. item.MedChrgitmType = "03"
  6942. break
  6943. case 9:
  6944. item.MedChrgitmType = "14"
  6945. break
  6946. }
  6947. }
  6948. } else if item.HisPrescriptionProject.Type == 3 {
  6949. item.MedChrgitmType = "08"
  6950. }
  6951. }
  6952. }
  6953. for _, item := range orderInfos_two {
  6954. fmt.Println(item.MedChrgitmType)
  6955. if item.MedChrgitmType == "01" { //床位费
  6956. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6957. bedCostSelfTotal = bedCostTotal
  6958. }
  6959. if item.MedChrgitmType == "02" { //诊察费
  6960. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6961. zhenChaCostSelfTotal = zhenChaCostTotal
  6962. }
  6963. if item.MedChrgitmType == "03" { //检查费
  6964. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6965. checkCostSelfTotal = checkCostTotal
  6966. }
  6967. if item.MedChrgitmType == "04" { //化验费
  6968. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6969. laboratoryCostSelfTotal = laboratoryCostTotal
  6970. }
  6971. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  6972. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6973. treatCostSelfTotal = treatCostTotal
  6974. }
  6975. if item.MedChrgitmType == "06" { //手术费
  6976. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6977. operationCostSelfTotal = treatCostTotal
  6978. }
  6979. if item.MedChrgitmType == "08" { //材料费
  6980. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6981. materialCostSelfTotal = materialCostTotal
  6982. }
  6983. if item.MedChrgitmType == "09" { //西药费
  6984. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6985. westernMedicineCostSelfTotal = westernMedicineCostTotal
  6986. }
  6987. if item.MedChrgitmType == "11" { //中成费
  6988. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6989. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  6990. }
  6991. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  6992. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6993. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6994. otherCostSelfTotal = otherCostTotal
  6995. }
  6996. } else {
  6997. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6998. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6999. otherCostSelfTotal = otherCostTotal
  7000. }
  7001. }
  7002. }
  7003. } else {
  7004. for _, item := range orderInfos {
  7005. if item.MedChrgitmType == "01" { //床位费
  7006. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7007. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7008. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7009. }
  7010. if item.MedChrgitmType == "02" { //诊察费
  7011. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7012. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7013. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7014. }
  7015. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7016. if item.MedChrgitmType == "03" { //检查费
  7017. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7018. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7019. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7020. }
  7021. } else {
  7022. if item.MedChrgitmType == "03" { //检查费
  7023. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7024. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7025. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7026. }
  7027. }
  7028. if item.MedChrgitmType == "04" { //化验费
  7029. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7030. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7031. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7032. }
  7033. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7034. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7035. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7036. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7037. }
  7038. if item.MedChrgitmType == "06" { //手术费
  7039. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7040. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7041. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7042. }
  7043. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7044. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7045. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7046. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7047. }
  7048. if item.MedChrgitmType == "09" { //西药费
  7049. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7050. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7051. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7052. }
  7053. if item.MedChrgitmType == "11" { //中成费
  7054. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7055. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7056. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7057. }
  7058. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7059. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7060. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7061. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7062. }
  7063. }
  7064. }
  7065. timeLayout := "2006-01-02"
  7066. loc, _ := time.LoadLocation("Local")
  7067. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7068. if err != nil {
  7069. }
  7070. startRecordDateTime := startTime.Unix()
  7071. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7072. if err != nil {
  7073. }
  7074. endRecordDateTime := endTime.Unix()
  7075. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7076. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7077. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7078. c.ServeSuccessJSON(map[string]interface{}{
  7079. "order_number": order.Number, //业务流水号
  7080. "id_card_no": his.IdCardNo, //社会保障号
  7081. "department_name": department.Name, //科室
  7082. "number": his.Number, //门诊号
  7083. "date": order.SettleAccountsDate, //结算日期
  7084. "name": order.PsnName, //姓名
  7085. "gender": patient.Gender, //性别
  7086. "psn_cash_money": order.PsnCashPay, //个人支付
  7087. "pay_way": "门诊", //结算方式
  7088. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7089. "admin_user_name": admin.UserName, //收款员
  7090. "order": order,
  7091. "order_info": orderInfos_two,
  7092. "his": his,
  7093. "bedCostTotal": bedCostTotal,
  7094. "bedCostSelfTotal": bedCostSelfTotal,
  7095. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7096. "operationCostTotal": operationCostTotal,
  7097. "operationCostSelfTotal": operationCostSelfTotal,
  7098. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7099. "otherCostTotal": otherCostTotal,
  7100. "otherCostSelfTotal": otherCostSelfTotal,
  7101. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7102. "materialCostTotal": materialCostTotal,
  7103. "materialCostSelfTotal": materialCostSelfTotal,
  7104. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7105. "westernMedicineCostTotal": westernMedicineCostTotal,
  7106. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7107. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7108. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7109. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7110. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7111. "checkCostTotal": checkCostTotal,
  7112. "checkCostSelfTotal": checkCostSelfTotal,
  7113. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7114. "laboratoryCostTotal": laboratoryCostTotal,
  7115. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7116. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7117. "treatCostTotal": treatCostTotal,
  7118. "treatCostSelfTotal": treatCostSelfTotal,
  7119. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7120. "zhenChaCostTotal": zhenChaCostTotal,
  7121. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7122. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7123. "his_hospital_record": his_hospital_record,
  7124. "pre_pay_money": pre_pay_money,
  7125. "refund_sum": sum,
  7126. })
  7127. }
  7128. func (this *HisApiController) GetIncomeStatisticsData() {
  7129. start_time := this.GetString("start_time")
  7130. end_time := this.GetString("end_time")
  7131. key_words := this.GetString("key_words")
  7132. limit, _ := this.GetInt64("limit")
  7133. page, _ := this.GetInt64("page")
  7134. if page <= 0 {
  7135. page = 1
  7136. }
  7137. if limit <= 0 {
  7138. limit = 10
  7139. }
  7140. statistics_type, _ := this.GetInt64("statistics_type")
  7141. admin := this.GetAdminUserInfo()
  7142. timeLayout := "2006-01-02"
  7143. loc, _ := time.LoadLocation("Local")
  7144. var theStartTIme int64
  7145. if len(start_time) > 0 {
  7146. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7147. if err != nil {
  7148. theStartTIme = 0
  7149. }
  7150. theStartTIme = theTime.Unix()
  7151. }
  7152. var theEndtTIme int64
  7153. if len(end_time) > 0 {
  7154. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7155. if err != nil {
  7156. theEndtTIme = 0
  7157. }
  7158. theEndtTIme = theTime.Unix()
  7159. }
  7160. if statistics_type == 1 {
  7161. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7162. this.ServeSuccessJSON(map[string]interface{}{
  7163. "list": list,
  7164. "total": total,
  7165. })
  7166. } else {
  7167. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7168. this.ServeSuccessJSON(map[string]interface{}{
  7169. "list": list,
  7170. "total": total,
  7171. })
  7172. }
  7173. }
  7174. func (c *HisApiController) PostProjectInformation() {
  7175. adminUser := c.GetAdminUserInfo()
  7176. orgId := adminUser.CurrentOrgId
  7177. dataBody := make(map[string]interface{}, 0)
  7178. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7179. if err != nil {
  7180. utils.ErrorLog(err.Error())
  7181. return
  7182. }
  7183. utils.ErrorLog("%v", dataBody)
  7184. var projectList []*models.HisProject
  7185. var total_goods []interface{}
  7186. tempProjects := dataBody["projects"].([]interface{})
  7187. total_goods = tempProjects
  7188. for index, projectMap := range tempProjects {
  7189. projectM := projectMap.(map[string]interface{})
  7190. var project models.HisProject
  7191. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7192. utils.ErrorLog("project_name")
  7193. return
  7194. }
  7195. project_name, _ := projectM["project_name"].(string)
  7196. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7197. err_log := models.ExportErrLog{
  7198. LogType: 6,
  7199. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7200. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7201. Status: 1,
  7202. CreateTime: time.Now().Unix(),
  7203. UpdateTime: time.Now().Unix(),
  7204. ExportTime: time.Now().Unix(),
  7205. }
  7206. service.CreateExportErrLog(&err_log)
  7207. continue
  7208. }
  7209. project.ProjectName = project_name
  7210. prices := projectM["price"].(string)
  7211. price, _ := strconv.ParseFloat(prices, 64)
  7212. if price <= 0 { //名字为空则生成一条导入错误日志
  7213. err_log := models.ExportErrLog{
  7214. LogType: 6,
  7215. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7216. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7217. Status: 1,
  7218. CreateTime: time.Now().Unix(),
  7219. UpdateTime: time.Now().Unix(),
  7220. ExportTime: time.Now().Unix(),
  7221. }
  7222. service.CreateExportErrLog(&err_log)
  7223. continue
  7224. }
  7225. project.Price = price
  7226. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7227. utils.ErrorLog("unit_id")
  7228. return
  7229. }
  7230. unit := projectM["unit"].(string)
  7231. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7232. err_log := models.ExportErrLog{
  7233. LogType: 6,
  7234. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7235. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7236. Status: 1,
  7237. CreateTime: time.Now().Unix(),
  7238. UpdateTime: time.Now().Unix(),
  7239. ExportTime: time.Now().Unix(),
  7240. }
  7241. service.CreateExportErrLog(&err_log)
  7242. continue
  7243. }
  7244. project.Unit = unit
  7245. cost_classify := projectM["cost_classify"].(string)
  7246. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7247. err_log := models.ExportErrLog{
  7248. LogType: 6,
  7249. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7250. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7251. Status: 1,
  7252. CreateTime: time.Now().Unix(),
  7253. UpdateTime: time.Now().Unix(),
  7254. ExportTime: time.Now().Unix(),
  7255. }
  7256. service.CreateExportErrLog(&err_log)
  7257. continue
  7258. }
  7259. var costClassify = "费用类别"
  7260. var cost_classify_id int64
  7261. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7262. if len(cost_classify) != 0 {
  7263. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7264. if errcode == gorm.ErrRecordNotFound {
  7265. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7266. dataconfig := models.DictDataconfig{
  7267. ParentId: costClassifyConfig.ID,
  7268. Module: "system",
  7269. OrgId: orgId,
  7270. Name: cost_classify,
  7271. FieldName: "",
  7272. Value: costConfig.Value + 1,
  7273. CreatedTime: "",
  7274. UpdatedTime: "",
  7275. CreateUserId: adminUser.AdminUser.Id,
  7276. Status: 1,
  7277. Remark: "",
  7278. DeleteIdSystem: 0,
  7279. Title: "",
  7280. Content: "",
  7281. Order: 0,
  7282. Code: "",
  7283. }
  7284. service.CreatedDicConfig(&dataconfig)
  7285. }
  7286. }
  7287. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7288. for _, it := range costClassList {
  7289. if cost_classify == it.Name {
  7290. cost_classify_id = int64(it.Value)
  7291. }
  7292. }
  7293. project.CostClassify = cost_classify_id
  7294. executive_section := projectM["executive_section"].(string)
  7295. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7296. err_log := models.ExportErrLog{
  7297. LogType: 6,
  7298. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7299. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7300. Status: 1,
  7301. CreateTime: time.Now().Unix(),
  7302. UpdateTime: time.Now().Unix(),
  7303. ExportTime: time.Now().Unix(),
  7304. }
  7305. service.CreateExportErrLog(&err_log)
  7306. continue
  7307. }
  7308. if len(executive_section) != 0 {
  7309. //查找科室是否有内容
  7310. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  7311. if errcodedepart == gorm.ErrRecordNotFound {
  7312. department := models.XtHisDepartment{
  7313. Name: executive_section,
  7314. Status: 1,
  7315. UserOrgId: adminUser.CurrentOrgId,
  7316. CreatedTime: time.Now().Unix(),
  7317. }
  7318. service.CreateDePartment(&department)
  7319. }
  7320. }
  7321. var executive_section_id int64
  7322. departMentList, _ := service.GetAllDepartMent(orgId)
  7323. for _, it := range departMentList {
  7324. if executive_section == it.Name {
  7325. executive_section_id = it.ID
  7326. }
  7327. }
  7328. project.ExecutiveSection = executive_section_id
  7329. medical_coverage := projectM["medical_coverage"].(string)
  7330. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  7331. err_log := models.ExportErrLog{
  7332. LogType: 6,
  7333. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7334. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7335. Status: 1,
  7336. CreateTime: time.Now().Unix(),
  7337. UpdateTime: time.Now().Unix(),
  7338. ExportTime: time.Now().Unix(),
  7339. }
  7340. service.CreateExportErrLog(&err_log)
  7341. continue
  7342. }
  7343. var medicalCoverage = "医保等级"
  7344. var medical_coverage_id int64
  7345. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  7346. if len(medical_coverage) != 0 {
  7347. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  7348. if errormedicalcoverage == gorm.ErrRecordNotFound {
  7349. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  7350. dataconfig := models.DictDataconfig{
  7351. ParentId: medicalCoverageConfig.ID,
  7352. Module: "system",
  7353. OrgId: orgId,
  7354. Name: medical_coverage,
  7355. FieldName: "",
  7356. Value: medicalCoverageConfig.Value + 1,
  7357. CreatedTime: "",
  7358. UpdatedTime: "",
  7359. CreateUserId: adminUser.AdminUser.Id,
  7360. Status: 1,
  7361. Remark: "",
  7362. DeleteIdSystem: 0,
  7363. Title: "",
  7364. Content: "",
  7365. Order: 0,
  7366. Code: "",
  7367. }
  7368. service.CreatedDicConfig(&dataconfig)
  7369. }
  7370. }
  7371. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  7372. for _, it := range medicalCoverageList {
  7373. if medical_coverage == it.Name {
  7374. medical_coverage_id = int64(it.Value)
  7375. }
  7376. }
  7377. project.MedicalCoverage = medical_coverage_id
  7378. pinyin := projectM["pinyin"].(string)
  7379. project.Pinyin = pinyin
  7380. wubi := projectM["wubi"].(string)
  7381. project.Wubi = wubi
  7382. statistical_classification := projectM["statistical_classification"].(string)
  7383. var statisticalClassification = "统计分类"
  7384. var statistical_classification_id int64
  7385. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  7386. if len(statistical_classification) != 0 {
  7387. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  7388. if classificationerrcodes == gorm.ErrRecordNotFound {
  7389. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  7390. dataconfig := models.DictDataconfig{
  7391. ParentId: classiFication.ID,
  7392. Module: "system",
  7393. OrgId: orgId,
  7394. Name: statistical_classification,
  7395. FieldName: "",
  7396. Value: classiFicationConfig.Value + 1,
  7397. CreatedTime: "",
  7398. UpdatedTime: "",
  7399. CreateUserId: adminUser.AdminUser.Id,
  7400. Status: 1,
  7401. Remark: "",
  7402. DeleteIdSystem: 0,
  7403. Title: "",
  7404. Content: "",
  7405. Order: 0,
  7406. Code: "",
  7407. }
  7408. service.CreatedDicConfig(&dataconfig)
  7409. }
  7410. }
  7411. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  7412. for _, it := range classiFicationList {
  7413. if statistical_classification == it.Name {
  7414. statistical_classification_id = int64(it.Value)
  7415. }
  7416. }
  7417. project.StatisticalClassification = statistical_classification_id
  7418. disease_directory := int64(projectM["disease_directory"].(float64))
  7419. project.DiseaseDirectory = disease_directory
  7420. is_record := int64(projectM["is_record"].(float64))
  7421. project.IsRecord = is_record
  7422. medical_code := projectM["medical_code"].(string)
  7423. project.MedicalCode = medical_code
  7424. tube_color := projectM["tube_color"].(string)
  7425. var tubeColor = "试管颜色"
  7426. var tube_color_id int64
  7427. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  7428. if len(tube_color) != 0 {
  7429. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  7430. if errcodetube == gorm.ErrRecordNotFound {
  7431. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  7432. dataconfig := models.DictDataconfig{
  7433. ParentId: tubeColorConfig.ID,
  7434. Module: "system",
  7435. OrgId: orgId,
  7436. Name: tube_color,
  7437. FieldName: "",
  7438. Value: tubeConfig.Value + 1,
  7439. CreatedTime: "",
  7440. UpdatedTime: "",
  7441. CreateUserId: adminUser.AdminUser.Id,
  7442. Status: 1,
  7443. Remark: "",
  7444. DeleteIdSystem: 0,
  7445. Title: "",
  7446. Content: "",
  7447. Order: 0,
  7448. Code: "",
  7449. }
  7450. service.CreatedDicConfig(&dataconfig)
  7451. }
  7452. }
  7453. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  7454. for _, it := range tubeColorList {
  7455. if tube_color == it.Name {
  7456. tube_color_id = int64(it.Value)
  7457. }
  7458. }
  7459. project.TubeColor = tube_color_id
  7460. single_dose := projectM["single_dose"].(string)
  7461. project.SingleDose = single_dose
  7462. execution_frequency := projectM["execution_frequency"].(string)
  7463. project.ExecutionFrequency = execution_frequency
  7464. delivery_way := projectM["delivery_way"].(string)
  7465. project.DeliveryWay = delivery_way
  7466. number_days := projectM["number_days"].(string)
  7467. project.NumberDays = number_days
  7468. total := projectM["total"].(string)
  7469. project.Total = total
  7470. medical_status := int64(projectM["medical_status"].(float64))
  7471. project.MedicalStatus = medical_status
  7472. category := int64(projectM["category"].(float64))
  7473. project.Category = category
  7474. specail_project := int64(projectM["specail_project"].(float64))
  7475. project.SpecailProject = specail_project
  7476. social_security_directory_code := projectM["social_security_directory_code"].(string)
  7477. project.SocialSecurityDirectoryCode = social_security_directory_code
  7478. remark := projectM["remark"].(string)
  7479. project.Remark = remark
  7480. record_date := projectM["record_date"].(string)
  7481. timeLayout := "2006-01-02"
  7482. loc, _ := time.LoadLocation("Local")
  7483. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7484. project.RecordDate = theTime.Unix()
  7485. projectList = append(projectList, &project)
  7486. }
  7487. export_time := time.Now().Unix()
  7488. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  7489. if len(projectList) > 0 {
  7490. for _, item := range projectList {
  7491. project := models.HisProject{
  7492. ProjectName: item.ProjectName,
  7493. Price: item.Price,
  7494. Unit: item.Unit,
  7495. CostClassify: item.CostClassify,
  7496. ExecutiveSection: item.ExecutiveSection,
  7497. MedicalCoverage: item.MedicalCoverage,
  7498. UserOrgId: orgId,
  7499. Status: 1,
  7500. CreatedTime: time.Now().Unix(),
  7501. Pinyin: item.Pinyin,
  7502. Wubi: item.Wubi,
  7503. StatisticalClassification: item.StatisticalClassification,
  7504. DiseaseDirectory: item.DiseaseDirectory,
  7505. IsRecord: item.IsRecord,
  7506. MedicalCode: item.MedicalCode,
  7507. TubeColor: item.TubeColor,
  7508. SingleDose: item.SingleDose,
  7509. DeliveryWay: item.DeliveryWay,
  7510. NumberDays: item.NumberDays,
  7511. Total: item.Total,
  7512. Category: item.Category,
  7513. MedicalStatus: item.MedicalStatus,
  7514. SpecailProject: item.SpecailProject,
  7515. RecordDate: item.RecordDate,
  7516. Remark: item.Remark,
  7517. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  7518. ExecutionFrequency: item.ExecutionFrequency,
  7519. }
  7520. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  7521. if errcodeproject == gorm.ErrRecordNotFound {
  7522. service.CreateProjectInfomation(&project)
  7523. } else if errcodeproject == nil {
  7524. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  7525. }
  7526. log := models.ExportLog{
  7527. LogType: 6,
  7528. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7529. TotalNum: int64(len(total_goods)),
  7530. FailNum: int64(len(errLogs)),
  7531. SuccessNum: int64(len(projectList)),
  7532. CreateTime: time.Now().Unix(),
  7533. UpdateTime: time.Now().Unix(),
  7534. ExportTime: export_time,
  7535. Status: 1,
  7536. }
  7537. service.CreateExportLog(&log)
  7538. c.ServeSuccessJSON(map[string]interface{}{
  7539. "msg": "导入成功",
  7540. "total_num": len(total_goods),
  7541. "success_num": len(projectList),
  7542. "fail_num": int64(len(errLogs)),
  7543. })
  7544. }
  7545. } else {
  7546. log := models.ExportLog{
  7547. LogType: 6,
  7548. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7549. TotalNum: int64(len(total_goods)),
  7550. FailNum: int64(len(errLogs)),
  7551. SuccessNum: int64(len(projectList)),
  7552. CreateTime: time.Now().Unix(),
  7553. UpdateTime: time.Now().Unix(),
  7554. ExportTime: export_time,
  7555. Status: 1,
  7556. }
  7557. service.CreateExportLog(&log)
  7558. c.ServeSuccessJSON(map[string]interface{}{
  7559. "msg": "导入成功",
  7560. "total_num": len(total_goods),
  7561. "success_num": len(projectList),
  7562. "fail_num": int64(len(errLogs)),
  7563. })
  7564. }
  7565. }
  7566. //func (this *HisApiController) EditProjectInformation(){
  7567. //
  7568. // id, _ := this.GetInt64("id")
  7569. // project_team := this.GetString("project_team")
  7570. // price := this.GetString("price")
  7571. // price_float, _ := strconv.ParseFloat(price, 64)
  7572. // pinyin := this.GetString("pinyin")
  7573. // wubi := this.GetString("wubi")
  7574. // tube_color, _ := this.GetInt64("tube_color")
  7575. // team_type, _ := this.GetInt64("team_type")
  7576. // remark := this.GetString("remark")
  7577. // ids := this.GetString("ids")
  7578. // item_id := this.GetString("item_id")
  7579. // projectTeam := models.XtHisProjectTeam{
  7580. // ProjectTeam: project_team,
  7581. // Price: price_float,
  7582. // Pinyin: pinyin,
  7583. // Wubi: wubi,
  7584. // TubeColor: tube_color,
  7585. // TeamType: team_type,
  7586. // Remark: remark,
  7587. // ProjectId: ids,
  7588. // ItemId: item_id,
  7589. // }
  7590. //
  7591. //
  7592. // dataBody := make(map[string]interface{}, 0)
  7593. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  7594. // if err != nil {
  7595. // utils.ErrorLog(err.Error())
  7596. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7597. // return
  7598. // }
  7599. //
  7600. // err = service.UpdatedProjectTeam(id, &projectTeam)
  7601. //
  7602. //
  7603. // if err != nil {
  7604. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7605. // return
  7606. // }
  7607. //
  7608. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  7609. // infos, _ := dataBody["info"].([]interface{})
  7610. // if len(infos) > 0 {
  7611. // var ids []string
  7612. //
  7613. // for _, item := range infos {
  7614. // items := item.(map[string]interface{})
  7615. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  7616. // utils.ErrorLog("id")
  7617. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7618. // return
  7619. // }
  7620. // id := int64(items["id"].(float64))
  7621. //
  7622. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  7623. // utils.ErrorLog("type")
  7624. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7625. // return
  7626. // }
  7627. // types := int64(items["type"].(float64))
  7628. //
  7629. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  7630. // utils.ErrorLog("number")
  7631. // }
  7632. //
  7633. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  7634. //
  7635. // projectList := models.XtHisProjectList{
  7636. // Number: number,
  7637. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  7638. // ProjectId: id,
  7639. // Status: 1,
  7640. // CreatedTime: time.Now().Unix(),
  7641. // UpdatedTime: time.Now().Unix(),
  7642. // TeamId: projectTeam.ID,
  7643. // Type: types,
  7644. // }
  7645. // list := projectList
  7646. //
  7647. // service.CreateProjectList(&list)
  7648. //
  7649. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  7650. //
  7651. // }
  7652. // ids_str := strings.Join(ids, ",")
  7653. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  7654. // service.SaveProjectTeam(&projectTeam)
  7655. // this.ServeSuccessJSON(map[string]interface{}{
  7656. // "projectTeam": projectTeam,
  7657. // })
  7658. // }
  7659. // }
  7660. //}
  7661. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  7662. name := c.GetString("name")
  7663. mode_id, _ := c.GetInt64("mode", 0)
  7664. types, _ := c.GetInt64("type", 0)
  7665. patient_id, _ := c.GetInt64("patient_id", 0)
  7666. types = 1
  7667. adminInfo := c.GetAdminUserInfo()
  7668. template := &models.HisPrescriptionTemplate{
  7669. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7670. PatientId: patient_id,
  7671. Type: types,
  7672. Status: 1,
  7673. Ctime: time.Now().Unix(),
  7674. Mtime: time.Now().Unix(),
  7675. Name: name,
  7676. Mode: mode_id,
  7677. }
  7678. dataBody := make(map[string]interface{}, 0)
  7679. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7680. if err != nil {
  7681. utils.ErrorLog(err.Error())
  7682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7683. return
  7684. }
  7685. err = service.CreateHisPrescriptionTemplate(template)
  7686. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  7687. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  7688. if len(prescriptions) > 0 {
  7689. for _, item := range prescriptions {
  7690. items := item.(map[string]interface{})
  7691. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  7692. utils.ErrorLog("type")
  7693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7694. return
  7695. }
  7696. types := int64(items["type"].(float64))
  7697. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  7698. utils.ErrorLog("med_type")
  7699. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7700. return
  7701. }
  7702. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  7703. ctime := time.Now().Unix()
  7704. prescription := &models.HisPrescriptionInfoTemplate{
  7705. PatientId: patient_id,
  7706. UserOrgId: adminInfo.CurrentOrgId,
  7707. Ctime: ctime,
  7708. Mtime: ctime,
  7709. Type: types,
  7710. Modifier: adminInfo.AdminUser.Id,
  7711. Creator: adminInfo.AdminUser.Id,
  7712. Status: 1,
  7713. PTemplateId: template.ID,
  7714. MedType: med_type,
  7715. }
  7716. service.CreateHisPrescriptionInfoTemplate(prescription)
  7717. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  7718. advices := items["advices"].([]interface{})
  7719. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  7720. ctime := time.Now().Unix()
  7721. mtime := ctime
  7722. if len(advices) > 0 {
  7723. for _, advice := range advices {
  7724. var s models.HisPrescriptionAdviceTemplate
  7725. s.PrescriptionId = prescription.ID
  7726. s.AdviceType = 2
  7727. s.StopState = 2
  7728. s.ExecutionState = 2
  7729. s.Status = 1
  7730. s.UserOrgId = adminInfo.CurrentOrgId
  7731. s.CreatedTime = ctime
  7732. s.UpdatedTime = mtime
  7733. s.PatientId = patient_id
  7734. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  7735. if errcode > 0 {
  7736. c.ServeFailJSONWithSGJErrorCode(errcode)
  7737. return
  7738. }
  7739. service.CreateHisPrescriptionAdviceTemplate(&s)
  7740. }
  7741. }
  7742. }
  7743. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  7744. projects := items["project"].([]interface{})
  7745. if len(projects) > 0 {
  7746. for _, project := range projects {
  7747. var p models.HisPrescriptionProjectTemplate
  7748. p.PrescriptionId = prescription.ID
  7749. p.Ctime = time.Now().Unix()
  7750. p.Mtime = time.Now().Unix()
  7751. p.PatientId = patient_id
  7752. p.UserOrgId = adminInfo.CurrentOrgId
  7753. p.Status = 1
  7754. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  7755. if errcode > 0 {
  7756. c.ServeFailJSONWithSGJErrorCode(errcode)
  7757. return
  7758. }
  7759. service.CreateHisPrescriptionProjectTemplate(&p)
  7760. }
  7761. }
  7762. }
  7763. }
  7764. c.ServeSuccessJSON(map[string]interface{}{
  7765. "msg": "创建成功",
  7766. })
  7767. }
  7768. }
  7769. }
  7770. func (c *HisApiController) PreSettle() {
  7771. id, _ := c.GetInt64("id")
  7772. record_time := c.GetString("record_time")
  7773. his_patient_id, _ := c.GetInt64("his_patient_id")
  7774. timeLayout := "2006-01-02"
  7775. loc, _ := time.LoadLocation("Local")
  7776. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7777. diagnosis_id := c.GetString("diagnosis")
  7778. sick_type, _ := c.GetInt64("sick_type")
  7779. reg_type, _ := c.GetInt64("p_type")
  7780. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  7781. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7782. if err != nil {
  7783. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7784. return
  7785. }
  7786. recordDateTime := theTime.Unix()
  7787. adminUser := c.GetAdminUserInfo()
  7788. var prescriptions []*models.HisPrescription
  7789. var start_time int64
  7790. var end_time int64
  7791. ids_str := c.GetString("ids")
  7792. ids_arr := strings.Split(ids_str, ",")
  7793. fmt.Println(reg_type)
  7794. if settle_accounts_type == 1 { //日结
  7795. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7796. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  7797. } else {
  7798. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  7799. }
  7800. fmt.Println(prescriptions)
  7801. } else { //月结
  7802. start_time_str := c.GetString("start_time")
  7803. end_time_str := c.GetString("end_time")
  7804. timeLayout := "2006-01-02"
  7805. loc, _ := time.LoadLocation("Local")
  7806. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7807. if err != nil {
  7808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7809. return
  7810. }
  7811. recordStartTime := theStartTime.Unix()
  7812. start_time = recordStartTime
  7813. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7814. if err != nil {
  7815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7816. return
  7817. }
  7818. recordEndTime := theEndTime.Unix()
  7819. end_time = recordEndTime
  7820. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  7821. }
  7822. if reg_type == 1111 || reg_type == 1112 {
  7823. reg_type = 11
  7824. }
  7825. timestamp := time.Now().Unix()
  7826. tempTime := time.Unix(timestamp, 0)
  7827. timeFormat := tempTime.Format("20060102150405")
  7828. chrgBchno := rand.Intn(100000) + 10000
  7829. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7830. strconv.FormatInt(his.PatientId, 10)
  7831. var ids []int64
  7832. for _, item := range prescriptions {
  7833. ids = append(ids, item.ID)
  7834. }
  7835. fmt.Println(ids)
  7836. var total float64
  7837. for _, item := range prescriptions {
  7838. fmt.Println(item)
  7839. if item.Type == 1 { //药品
  7840. for _, subItem := range item.HisDoctorAdviceInfo {
  7841. total = total + (subItem.Price * subItem.PrescribingNumber)
  7842. }
  7843. }
  7844. if item.Type == 2 { //项目
  7845. for _, subItem := range item.HisPrescriptionProject {
  7846. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7847. total = total + (subItem.Price * cnt)
  7848. }
  7849. }
  7850. for _, subItem := range item.HisAdditionalCharge {
  7851. total = total + (subItem.Price * float64(subItem.Count))
  7852. }
  7853. }
  7854. allTotal := fmt.Sprintf("%.2f", total)
  7855. totals, _ := strconv.ParseFloat(allTotal, 64)
  7856. order := &models.HisOrder{
  7857. UserOrgId: adminUser.CurrentOrgId,
  7858. HisPatientId: his.ID,
  7859. PatientId: id,
  7860. SettleAccountsDate: recordDateTime,
  7861. Ctime: time.Now().Unix(),
  7862. Mtime: time.Now().Unix(),
  7863. Status: 1,
  7864. OrderStatus: 1,
  7865. MdtrtId: his.Number,
  7866. Number: chrg_bchno,
  7867. MedfeeSumamt: totals,
  7868. SettleEndTime: end_time,
  7869. SettleStartTime: start_time,
  7870. SettleType: settle_accounts_type,
  7871. PsnPartAmt: totals,
  7872. PsnCashPay: totals,
  7873. PType: 2,
  7874. IsPre: 1,
  7875. MedType: strconv.Itoa(int(reg_type)),
  7876. Diagnosis: diagnosis_id,
  7877. }
  7878. err = service.CreateOrder(order)
  7879. if err != nil {
  7880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7881. return
  7882. }
  7883. var customs []*Custom
  7884. for _, item := range prescriptions {
  7885. fmt.Println(item.Type)
  7886. if item.Type == 1 { //药品
  7887. for _, subItem := range item.HisDoctorAdviceInfo {
  7888. cus := &Custom{
  7889. AdviceId: subItem.ID,
  7890. ProjectId: 0,
  7891. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  7892. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  7893. FeedetlSn: subItem.FeedetlSn,
  7894. Price: fmt.Sprintf("%.2f", subItem.Price),
  7895. MedListCodg: subItem.MedListCodg,
  7896. Type: 1,
  7897. }
  7898. customs = append(customs, cus)
  7899. }
  7900. }
  7901. if item.Type == 2 { //项目
  7902. for _, subItem := range item.HisPrescriptionProject {
  7903. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7904. cus := &Custom{
  7905. AdviceId: 0,
  7906. ProjectId: subItem.ID,
  7907. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  7908. Cut: fmt.Sprintf("%.2f", cnt),
  7909. FeedetlSn: subItem.FeedetlSn,
  7910. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  7911. MedListCodg: subItem.MedListCodg,
  7912. Type: 2,
  7913. }
  7914. customs = append(customs, cus)
  7915. }
  7916. }
  7917. for _, item := range item.HisAdditionalCharge {
  7918. cus := &Custom{
  7919. ItemId: item.ID,
  7920. AdviceId: 0,
  7921. ProjectId: 0,
  7922. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  7923. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  7924. FeedetlSn: item.FeedetlSn,
  7925. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  7926. MedListCodg: item.XtHisAddtionConfig.Code,
  7927. Type: 3,
  7928. }
  7929. customs = append(customs, cus)
  7930. }
  7931. }
  7932. fmt.Println(customs)
  7933. for _, item := range customs {
  7934. var advice_id int64 = 0
  7935. var project_id int64 = 0
  7936. var item_id int64 = 0
  7937. var types int64 = 0
  7938. if item.Type == 1 {
  7939. advice_id = item.AdviceId
  7940. project_id = 0
  7941. item_id = 0
  7942. } else if item.Type == 2 {
  7943. advice_id = 0
  7944. item_id = 0
  7945. project_id = item.ProjectId
  7946. } else if item.Type == 3 {
  7947. advice_id = 0
  7948. item_id = item.ItemId
  7949. project_id = 0
  7950. }
  7951. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  7952. cut, _ := strconv.ParseFloat(item.Cut, 32)
  7953. pric, _ := strconv.ParseFloat(item.Price, 32)
  7954. info := &models.HisOrderInfo{
  7955. OrderNumber: order.Number,
  7956. UploadDate: time.Now().Unix(),
  7957. AdviceId: advice_id,
  7958. DetItemFeeSumamt: detItemFeeSumamt,
  7959. Cnt: cut,
  7960. Pric: pric,
  7961. PatientId: id,
  7962. Status: 1,
  7963. Mtime: time.Now().Unix(),
  7964. Ctime: time.Now().Unix(),
  7965. UserOrgId: adminUser.CurrentOrgId,
  7966. HisPatientId: his.ID,
  7967. OrderId: order.ID,
  7968. ProjectId: project_id,
  7969. Type: types,
  7970. ItemId: item_id,
  7971. }
  7972. service.CreateOrderInfo(info)
  7973. }
  7974. his.SickType = sick_type
  7975. service.UpdataHisPateint(&his)
  7976. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  7977. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  7978. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  7979. if err == nil {
  7980. c.ServeSuccessJSON(map[string]interface{}{
  7981. "msg": "结算成功",
  7982. })
  7983. }
  7984. }
  7985. type CustomOrderInfo struct {
  7986. Name string
  7987. Spec string
  7988. Unit string
  7989. Count float64
  7990. Price float64
  7991. Total float64
  7992. }
  7993. func (c *HisApiController) GetPrivateExpensesInfo() {
  7994. order_id, _ := c.GetInt64("id", 0)
  7995. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  7996. order, _ := service.GetHisOrderByID(order_id)
  7997. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  7998. if order.ID == 0 {
  7999. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8000. return
  8001. }
  8002. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8003. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8004. org_id := c.GetAdminUserInfo().CurrentOrgId
  8005. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8006. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8007. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8008. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8009. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8010. var orderInfos_four []*models.HisOrderInfoTwo
  8011. for _, item := range orderInfos_three {
  8012. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8013. item.HisPrescriptionProject.IsCheckTeam = 1
  8014. orderInfos_four = append(orderInfos_four, item)
  8015. }
  8016. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8017. item.HisPrescriptionProject.IsCheckTeam = 2
  8018. orderInfos_two = append(orderInfos_two, item)
  8019. }
  8020. }
  8021. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8022. var cus_slice []CustomOrderInfo
  8023. for _, item := range new_order_info {
  8024. var cus CustomOrderInfo
  8025. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8026. cus.Unit = ""
  8027. cus.Spec = ""
  8028. var total float64
  8029. for _, subItem := range orderInfos_four {
  8030. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8031. total = total + subItem.DetItemFeeSumamt
  8032. fmt.Println(subItem.DetItemFeeSumamt)
  8033. }
  8034. }
  8035. cus.Count = 1
  8036. cus.Total = total
  8037. cus_slice = append(cus_slice, cus)
  8038. }
  8039. orderInfos = append(orderInfos, orderInfos_two...)
  8040. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  8041. orderInfos = append(orderInfos, orderInfos_three...)
  8042. }
  8043. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  8044. c.ServeSuccessJSON(map[string]interface{}{
  8045. "order": order,
  8046. "order_info": orderInfos,
  8047. "patient": patient,
  8048. "admin_info": adminInfo,
  8049. "his": his,
  8050. "current_admin": role,
  8051. "org_config": miConfig,
  8052. "new_order_info": cus_slice,
  8053. })
  8054. }
  8055. func (this *HisApiController) ChangeMedType() {
  8056. med_type := this.GetString("med_type")
  8057. old_med_type := this.GetString("old_med_type")
  8058. ids := this.GetString("ids")
  8059. settle_type, _ := this.GetInt64("settle_type")
  8060. start_time := this.GetString("start_time")
  8061. end_time := this.GetString("end_time")
  8062. ids_arr := strings.Split(ids, ",")
  8063. if settle_type == 1 { //日结
  8064. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8065. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8066. prescription.MedType = med_type
  8067. err := service.SaveHisPrescription(&prescription)
  8068. if err == nil {
  8069. this.ServeSuccessJSON(map[string]interface{}{
  8070. "msg": "修改成功",
  8071. })
  8072. } else {
  8073. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8074. return
  8075. }
  8076. } else if settle_type == 2 {
  8077. timeLayout := "2006-01-02"
  8078. loc, _ := time.LoadLocation("Local")
  8079. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8080. if err != nil {
  8081. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8082. return
  8083. }
  8084. recordStartTime := theStartTime.Unix()
  8085. start_time_timestamp := recordStartTime
  8086. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8087. if err != nil {
  8088. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8089. return
  8090. }
  8091. recordEndTime := theEndTime.Unix()
  8092. end_time_timestamp := recordEndTime
  8093. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8094. if updateErr == nil {
  8095. this.ServeSuccessJSON(map[string]interface{}{
  8096. "msg": "修改成功",
  8097. })
  8098. } else {
  8099. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8100. return
  8101. }
  8102. }
  8103. }
  8104. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8105. patient_id, _ := c.GetInt64("patient_id")
  8106. his_patient_id, _ := c.GetInt64("his_patient_id")
  8107. record_date := c.GetString("record_date")
  8108. start_time := c.GetString("start_time")
  8109. end_time := c.GetString("end_time")
  8110. order_status, _ := c.GetInt64("type", 0)
  8111. p_type, _ := c.GetInt64("p_type", 0)
  8112. order_id, _ := c.GetInt64("order_id", 0)
  8113. timeLayout := "2006-01-02"
  8114. loc, _ := time.LoadLocation("Local")
  8115. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8116. if err != nil {
  8117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8118. return
  8119. }
  8120. recordDateTime := theTime.Unix()
  8121. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8122. if err != nil {
  8123. }
  8124. startRecordDateTime := startTime.Unix()
  8125. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8126. if err != nil {
  8127. }
  8128. endRecordDateTime := endTime.Unix()
  8129. admin := c.GetAdminUserInfo()
  8130. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8131. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8132. order, _ := service.GetHisOrderByID(order_id)
  8133. var monthPrescriptions []*models.HisPrescription
  8134. if order_status == 1 || order_status == 0 {
  8135. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8136. } else if order_status == 2 {
  8137. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8138. }
  8139. var settle_total float64
  8140. for _, item := range monthPrescriptions {
  8141. if len(item.HisPrescriptionProject) > 0 {
  8142. for _, subItem := range item.HisPrescriptionProject {
  8143. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8144. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8145. settle_total = settle_total + total
  8146. }
  8147. }
  8148. if len(item.HisDoctorAdviceInfo) > 0 {
  8149. for _, subItem := range item.HisDoctorAdviceInfo {
  8150. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8151. settle_total = settle_total + total
  8152. }
  8153. }
  8154. }
  8155. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8156. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8157. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8158. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8159. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8160. //获取所有科室信息
  8161. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8162. c.ServeSuccessJSON(map[string]interface{}{
  8163. "his_info": his_patient_info,
  8164. "xt_info": xt_patient_info,
  8165. "case_history": case_history,
  8166. "info": patientPrescriptionInfo,
  8167. "last_info": lastPatientPrescriptionInfo,
  8168. "month_prescriptions": monthPrescriptions,
  8169. "order": order,
  8170. "doctors": doctors,
  8171. "department": department,
  8172. "settle_total": settle_total,
  8173. })
  8174. return
  8175. }
  8176. func (c *HisApiController) GetHisMonthPatientInfo() {
  8177. patient_id, _ := c.GetInt64("patient_id")
  8178. his_patient_id, _ := c.GetInt64("his_patient_id")
  8179. record_date := c.GetString("record_date")
  8180. number := c.GetString("number")
  8181. start_time := c.GetString("start_time")
  8182. end_time := c.GetString("end_time")
  8183. p_type, _ := c.GetInt64("p_type")
  8184. timeLayout := "2006-01-02"
  8185. loc, _ := time.LoadLocation("Local")
  8186. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8187. if err != nil {
  8188. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8189. return
  8190. }
  8191. recordDateTime := theTime.Unix()
  8192. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8193. if err != nil {
  8194. }
  8195. startRecordDateTime := startTime.Unix()
  8196. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8197. if err != nil {
  8198. }
  8199. endRecordDateTime := endTime.Unix()
  8200. admin := c.GetAdminUserInfo()
  8201. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8202. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8203. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8204. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8205. var settle_total float64
  8206. for _, item := range monthPrescriptions {
  8207. if len(item.HisPrescriptionProject) > 0 {
  8208. for _, subItem := range item.HisPrescriptionProject {
  8209. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8210. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8211. settle_total = settle_total + total
  8212. }
  8213. }
  8214. if len(item.HisDoctorAdviceInfo) > 0 {
  8215. for _, subItem := range item.HisDoctorAdviceInfo {
  8216. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8217. settle_total = settle_total + total
  8218. }
  8219. }
  8220. }
  8221. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8222. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8223. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8224. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8225. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  8226. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8227. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  8228. //获取所有科室信息
  8229. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8230. c.ServeSuccessJSON(map[string]interface{}{
  8231. "his_info": his_patient_info,
  8232. "xt_info": xt_patient_info,
  8233. "case_history": case_history,
  8234. "info": patientPrescriptionInfo,
  8235. "month_prescriptions": monthPrescriptions,
  8236. "order": order,
  8237. "doctors": doctors,
  8238. "department": department,
  8239. "count": count,
  8240. "drugStockConfig": drugStockConfig,
  8241. "last_info": lastPatientPrescriptionInfo,
  8242. "settle_total": settle_total,
  8243. })
  8244. return
  8245. }
  8246. func (c *HisApiController) GetAllOrder() {
  8247. org_id := c.GetAdminUserInfo().CurrentOrgId
  8248. orders, _ := service.GetNewHisOrderList(org_id)
  8249. c.ServeSuccessJSON(map[string]interface{}{
  8250. "order": orders,
  8251. })
  8252. return
  8253. }
  8254. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  8255. newArr = make([]*models.HisOrderInfoTwo, 0)
  8256. for i := 0; i < len(arr); i++ {
  8257. repeat := false
  8258. for j := i + 1; j < len(arr); j++ {
  8259. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  8260. repeat = true
  8261. break
  8262. }
  8263. }
  8264. if !repeat {
  8265. newArr = append(newArr, arr[i])
  8266. }
  8267. }
  8268. return
  8269. }
  8270. //修改处方退库操作 参数传修改之前的处方数据
  8271. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  8272. if advice.ExecutionState == 1 {
  8273. //查询该病人该药品是否有库存记录
  8274. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  8275. if errcode == gorm.ErrRecordNotFound {
  8276. } else {
  8277. //退库
  8278. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8279. if advice.PrescribingNumberUnit == drug.MinUnit {
  8280. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8281. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8282. //退库
  8283. warehouseInfo := models.DrugWarehouseInfo{
  8284. StockMinNumber: prescribingNumber,
  8285. }
  8286. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  8287. operation_time := time.Now().Unix()
  8288. creater := advice.AdviceDoctor
  8289. ctime := time.Now().Unix()
  8290. timeStr := time.Now().Format("2006-01-02")
  8291. timeArr := strings.Split(timeStr, "-")
  8292. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8293. total = total + 1
  8294. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8295. cancelStock := models.DrugCancelStock{
  8296. OrderNumber: orderNumber,
  8297. OperaTime: operation_time,
  8298. OrgId: advice.UserOrgId,
  8299. Creater: creater,
  8300. Ctime: ctime,
  8301. Status: 1,
  8302. ReturnTime: advice.AdviceDate,
  8303. Dealer: info.Dealer,
  8304. Manufacturer: info.Manufacturer,
  8305. Type: 1,
  8306. }
  8307. service.AddSigleDrugCancelStock(&cancelStock)
  8308. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8309. dealer, _ := service.GetDealerById(info.Dealer)
  8310. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8311. cancelStockInfo := models.DrugCancelStockInfo{
  8312. OrderNumber: cancelInfo.OrderNumber,
  8313. CancelStockId: cancelInfo.ID,
  8314. DrugId: info.DrugId,
  8315. Count: info.Count,
  8316. Status: 1,
  8317. Ctime: ctime,
  8318. OrgId: advice.UserOrgId,
  8319. Type: 1,
  8320. Manufacturer: manufactureName.ManufacturerName,
  8321. Dealer: dealer.DealerName,
  8322. Total: 0,
  8323. RetailPrice: info.RetailPrice,
  8324. RetailTotalPrice: info.RetailTotalPrice,
  8325. Price: info.Price,
  8326. RegisterAccount: "",
  8327. Remark: info.Remark,
  8328. BatchNumber: info.BatchNumber,
  8329. MaxUnit: info.CountUnit,
  8330. ProductDate: info.ProductDate,
  8331. ExpiryDate: info.ExpiryDate,
  8332. BatchNumberId: info.WarehouseInfoId,
  8333. }
  8334. flow := models.DrugFlow{
  8335. WarehousingId: 0,
  8336. DrugId: info.DrugId,
  8337. Number: "",
  8338. BatchNumber: info.BatchNumber,
  8339. Count: info.Count,
  8340. UserOrgId: advice.UserOrgId,
  8341. PatientId: 0,
  8342. SystemTime: ctime,
  8343. ConsumableType: 4,
  8344. IsSys: 0,
  8345. WarehousingOrder: "",
  8346. WarehouseOutId: 0,
  8347. WarehouseOutOrderNumber: "",
  8348. IsEdit: 0,
  8349. CancelStockId: cancelStock.ID,
  8350. CancelOrderNumber: cancelStock.OrderNumber,
  8351. Manufacturer: info.Manufacturer,
  8352. Dealer: info.Dealer,
  8353. Creator: advice.UserOrgId,
  8354. UpdateCreator: 0,
  8355. Status: 1,
  8356. Ctime: time.Now().Unix(),
  8357. Mtime: 0,
  8358. Price: info.Price,
  8359. WarehousingDetailId: 0,
  8360. WarehouseOutDetailId: 0,
  8361. CancelOutDetailId: 0,
  8362. ExpireDate: info.ExpiryDate,
  8363. ProductDate: info.ProductDate,
  8364. MaxUnit: info.CountUnit,
  8365. MinUnit: "",
  8366. }
  8367. service.CreatedCancelStock(cancelStockInfo)
  8368. service.CreateDrugFlowOne(flow)
  8369. } else {
  8370. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8371. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8372. if advice.PrescribingNumberUnit == drug.MaxUnit {
  8373. warehouseInfo := models.DrugWarehouseInfo{
  8374. StockMinNumber: prescribingNumber,
  8375. }
  8376. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  8377. }
  8378. operation_time := time.Now().Unix()
  8379. creater := advice.AdviceDoctor
  8380. ctime := time.Now().Unix()
  8381. timeStr := time.Now().Format("2006-01-02")
  8382. timeArr := strings.Split(timeStr, "-")
  8383. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8384. total = total + 1
  8385. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8386. cancelStock := models.DrugCancelStock{
  8387. OrderNumber: orderNumber,
  8388. OperaTime: operation_time,
  8389. OrgId: advice.UserOrgId,
  8390. Creater: creater,
  8391. Ctime: ctime,
  8392. Status: 1,
  8393. ReturnTime: advice.AdviceDate,
  8394. Dealer: info.Dealer,
  8395. Manufacturer: info.Manufacturer,
  8396. Type: 1,
  8397. }
  8398. service.AddSigleDrugCancelStock(&cancelStock)
  8399. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8400. dealer, _ := service.GetDealerById(info.Dealer)
  8401. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8402. cancelStockInfo := models.DrugCancelStockInfo{
  8403. OrderNumber: cancelInfo.OrderNumber,
  8404. CancelStockId: cancelInfo.ID,
  8405. DrugId: info.DrugId,
  8406. Count: info.Count,
  8407. Status: 1,
  8408. Ctime: ctime,
  8409. OrgId: advice.UserOrgId,
  8410. Type: 1,
  8411. Manufacturer: manufactureName.ManufacturerName,
  8412. Dealer: dealer.DealerName,
  8413. Total: 0,
  8414. RetailPrice: info.RetailPrice,
  8415. RetailTotalPrice: info.RetailTotalPrice,
  8416. Price: info.Price,
  8417. RegisterAccount: "",
  8418. Remark: info.Remark,
  8419. BatchNumber: info.BatchNumber,
  8420. MaxUnit: info.CountUnit,
  8421. ProductDate: info.ProductDate,
  8422. ExpiryDate: info.ExpiryDate,
  8423. BatchNumberId: info.WarehouseInfoId,
  8424. }
  8425. flow := models.DrugFlow{
  8426. WarehousingId: 0,
  8427. DrugId: info.DrugId,
  8428. Number: "",
  8429. BatchNumber: info.BatchNumber,
  8430. Count: info.Count,
  8431. UserOrgId: advice.UserOrgId,
  8432. PatientId: 0,
  8433. SystemTime: ctime,
  8434. ConsumableType: 4,
  8435. IsSys: 0,
  8436. WarehousingOrder: "",
  8437. WarehouseOutId: 0,
  8438. WarehouseOutOrderNumber: "",
  8439. IsEdit: 0,
  8440. CancelStockId: cancelStock.ID,
  8441. CancelOrderNumber: cancelStock.OrderNumber,
  8442. Manufacturer: info.Manufacturer,
  8443. Dealer: info.Dealer,
  8444. Creator: advice.AdviceDoctor,
  8445. UpdateCreator: 0,
  8446. Status: 1,
  8447. Ctime: time.Now().Unix(),
  8448. Mtime: 0,
  8449. Price: info.Price,
  8450. WarehousingDetailId: 0,
  8451. WarehouseOutDetailId: 0,
  8452. CancelOutDetailId: 0,
  8453. ExpireDate: info.ExpiryDate,
  8454. ProductDate: info.ProductDate,
  8455. MaxUnit: info.CountUnit,
  8456. MinUnit: "",
  8457. }
  8458. service.CreatedCancelStock(cancelStockInfo)
  8459. service.CreateDrugFlowOne(flow)
  8460. }
  8461. }
  8462. }
  8463. return err
  8464. }
  8465. func (this *HisApiController) DeleteNCDS() {
  8466. id, _ := this.GetInt64("id", 0)
  8467. if id > 0 {
  8468. service.DeletePsnNCDSRecordById(id)
  8469. this.ServeSuccessJSON(map[string]interface{}{
  8470. "msg": "删除成功",
  8471. })
  8472. } else {
  8473. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  8474. return
  8475. }
  8476. }
  8477. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  8478. id, _ := c.GetInt64("id")
  8479. advice, _ := service.GetHisDoctorAdviceInfo(id)
  8480. c.ServeSuccessJSON(map[string]interface{}{
  8481. "advice": advice,
  8482. })
  8483. return
  8484. }
  8485. func (c *HisApiController) GetHisMonthChargePatientList() {
  8486. record_date := c.GetString("record_date")
  8487. start_time := c.GetString("start_time")
  8488. end_time := c.GetString("end_time")
  8489. timeLayout := "2006-01-02"
  8490. loc, _ := time.LoadLocation("Local")
  8491. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8492. if err != nil {
  8493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8494. return
  8495. }
  8496. if err != nil {
  8497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8498. return
  8499. }
  8500. recordDateTime := theTime.Unix()
  8501. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8502. if err != nil {
  8503. }
  8504. startRecordDateTime := startTime.Unix()
  8505. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8506. if err != nil {
  8507. }
  8508. endRecordDateTime := endTime.Unix()
  8509. adminInfo := c.GetAdminUserInfo()
  8510. var tempMonthChargePatients []*service.MonthChargePatients
  8511. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  8512. for _, item := range tempPatients {
  8513. //过滤没有处方的
  8514. if len(item.HisPrescription) == 0 {
  8515. tempMonthChargePatients = append(tempMonthChargePatients, item)
  8516. }
  8517. }
  8518. c.ServeSuccessJSON(map[string]interface{}{
  8519. "list": tempMonthChargePatients,
  8520. })
  8521. }