his_api_controller.go 364KB

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