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