his_api_controller.go 367KB

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