his_api_controller.go 478KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319
  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. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. }
  91. func (c *HisApiController) CheckHisPatient() {
  92. record_date := c.GetString("record_date")
  93. patient_id, _ := c.GetInt64("patient_id")
  94. timeLayout := "2006-01-02"
  95. loc, _ := time.LoadLocation("Local")
  96. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. if err != nil {
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. recordDateTime := theTime.Unix()
  102. adminInfo := c.GetAdminUserInfo()
  103. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. if len(patients) > 1 {
  105. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  107. c.ServeSuccessJSON(map[string]interface{}{
  108. "status": 1,
  109. "msg": "关联",
  110. "ps": ps,
  111. "his_patient_id": patients[len(patients)-1].ID,
  112. "patient_id": patients[len(patients)-1].PatientId,
  113. })
  114. } else {
  115. c.ServeSuccessJSON(map[string]interface{}{
  116. "status": 0,
  117. "msg": "无需关联",
  118. })
  119. }
  120. } else {
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "status": 0,
  123. "msg": "无需关联",
  124. })
  125. return
  126. }
  127. }
  128. func (c *HisApiController) AssociationHisPrescription() {
  129. record_date := c.GetString("record_date")
  130. his_patient_id, _ := c.GetInt64("his_patient_id")
  131. patient_id, _ := c.GetInt64("patient_id")
  132. p_ids := c.GetString("p_ids")
  133. p_ids_arr := strings.Split(p_ids, ",")
  134. timeLayout := "2006-01-02"
  135. loc, _ := time.LoadLocation("Local")
  136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  137. if err != nil {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. return
  140. }
  141. recordDateTime := theTime.Unix()
  142. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  143. if his_patient_id == 0 || his_patient.ID == 0 {
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  148. if err == nil {
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "msg": "关联处方成功",
  151. })
  152. return
  153. } else {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  155. return
  156. }
  157. }
  158. //func (c *HisApiController) AssociationHisPrescription() {
  159. // record_date, _ := c.GetInt64("record_date")
  160. // his_patient_id, _ := c.GetInt64("his_patient_id")
  161. // patient_id, _ := c.GetInt64("patient_id")
  162. // p_ids := c.GetString("p_ids")
  163. // p_ids_arr := strings.Split(p_ids, ",")
  164. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  165. // if his_patient_id == 0 || his_patient.ID == 0 {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. // return
  168. // }
  169. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  170. // if err == nil {
  171. // c.ServeSuccessJSON(map[string]interface{}{
  172. // "msg": "关联处方成功",
  173. // })
  174. // return
  175. // } else {
  176. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  177. // return
  178. // }
  179. //}
  180. func (c *HisApiController) GetFaPiaoNumber() {
  181. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  182. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  183. fmt.Println(count)
  184. var zero string
  185. number := count + 1
  186. if number >= 1000 {
  187. zero = "0000" + strconv.FormatInt(number, 10)
  188. } else if number >= 10000 {
  189. zero = "000" + strconv.FormatInt(number, 10)
  190. } else if number >= 100000 {
  191. zero = "00" + strconv.FormatInt(number, 10)
  192. } else if number >= 1000000 {
  193. zero = "0" + strconv.FormatInt(number, 10)
  194. } else {
  195. zero = strconv.FormatInt(number, 10)
  196. }
  197. c.ServeSuccessJSON(map[string]interface{}{
  198. "fapiao_number": zero,
  199. })
  200. return
  201. }
  202. func (c *HisApiController) ChangeOrderDesc() {
  203. id, _ := c.GetInt64("id")
  204. desc := c.GetString("desc")
  205. change_type := c.GetString("change_type")
  206. order, _ := service.GetHisOrderByID(id)
  207. if order.ID == 0 {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. switch change_type {
  212. case "oth_desc":
  213. order.OthDesc = desc
  214. break
  215. case "cash_pay":
  216. order.CashPay = desc
  217. break
  218. case "jifen_pay":
  219. order.JifenPay = desc
  220. break
  221. case "band_card_pay":
  222. order.BandCardPay = desc
  223. break
  224. case "ali_pay":
  225. order.AliPay = desc
  226. break
  227. case "wechat_pay":
  228. order.WechatPay = desc
  229. break
  230. case "fa_piao_number":
  231. order.FaPiaoNumber = desc
  232. break
  233. case "fa_piao_code":
  234. order.FaPiaoCode = desc
  235. break
  236. }
  237. err := service.SaveHisOrder(&order)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "msg": "修改成功",
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisApiController) GetMonthHisPatient() {
  249. record_date := c.GetString("record_date")
  250. //order_status, _ := c.GetInt64("type")
  251. timeLayout := "2006-01-02"
  252. loc, _ := time.LoadLocation("Local")
  253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  254. if err != nil {
  255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  256. return
  257. }
  258. recordDateTime := theTime.Unix()
  259. adminInfo := c.GetAdminUserInfo()
  260. var tempPatients []service.NewTempPatients
  261. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  262. // 获取当前时间
  263. now := time.Now()
  264. // 获取本月的第一天
  265. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  266. // 获取下个月的第一天
  267. nextMonth := firstDay.AddDate(0, 1, 0)
  268. // 获取本月的最后一天
  269. lastDay := nextMonth.Add(-time.Nanosecond)
  270. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  271. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  272. var patients []service.NewTempPatients
  273. var patients_two []service.NewTempPatients
  274. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  275. for _, item := range tempPatients {
  276. //过滤掉没挂号的和没开处方的
  277. if len(item.HisPrescription) > 0 {
  278. patients = append(patients, item)
  279. patients_two = append(patients_two, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. //}
  284. }
  285. } else {
  286. for _, item := range tempPatients {
  287. //过滤掉没挂号的和没开处方的
  288. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  289. patients = append(patients, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. // patients_two = append(patients_two, item)
  294. //}
  295. }
  296. }
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "list": patients,
  299. "list_two": patients_two,
  300. "chargePatients": chargePatients,
  301. })
  302. }
  303. func (c *HisApiController) GetBatchSettleAccounts() {
  304. order_ids := c.GetString("order_ids")
  305. admin_user_id, _ := c.GetInt64("admin_user_id")
  306. adminUser := c.GetAdminUserInfo()
  307. orders := strings.Split(order_ids, ",")
  308. var newOrders []models.Orders
  309. for _, item := range orders {
  310. order, _ := service.GetHisOrderByIDTenOne(item)
  311. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  312. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  313. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  314. orderInfos = append(orderInfos, orderInfos_two...)
  315. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  316. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  317. var diagnosis_ids []string
  318. if his.ID > 0 {
  319. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  320. } else {
  321. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  322. }
  323. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  324. var dia_config []*models.HisXtDiagnoseConfig
  325. var name string
  326. for _, item := range diagnosis_ids {
  327. id, _ := strconv.ParseInt(item, 10, 64)
  328. diagnosisConfig, _ := service.FindDiagnoseById(id)
  329. dia_config = append(dia_config, diagnosisConfig)
  330. if len(name) == 0 {
  331. name = diagnosisConfig.ClassName
  332. } else {
  333. name = name + "," + diagnosisConfig.ClassName
  334. }
  335. }
  336. var bedCostTotal float64 = 0 //床位总费
  337. var bedCostSelfTotal float64 = 0 //床位自费
  338. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  339. var bedSelfTotal float64 = 0 //床位部分项目自费
  340. var bedInscpTotal float64 = 0 //床位部分项目自费
  341. var operationCostTotal float64 = 0 //手术费
  342. var operationCostSelfTotal float64 = 0 //手术费
  343. var operationCostPartSelfTotal float64 = 0 //手术费
  344. var operationSelfTotal float64 = 0 //床位部分项目自费
  345. var operationInscpTotal float64 = 0 //床位部分项目自费
  346. var otherCostTotal float64 = 0 //其他费用
  347. var otherCostSelfTotal float64 = 0 //其他费用
  348. var otherCostPartSelfTotal float64 = 0 //其他费用
  349. var otherSelfTotal float64 = 0 //床位部分项目自费
  350. var otherInscpTotal float64 = 0 //床位部分项目自费
  351. var materialCostTotal float64 = 0 //材料费
  352. var materialCostSelfTotal float64 = 0 //材料费
  353. var materialCostPartSelfTotal float64 = 0 //材料费
  354. var materialSelfTotal float64 = 0 //床位部分项目自费
  355. var materialInscpTotal float64 = 0 //床位部分项目自费
  356. var westernMedicineCostTotal float64 = 0 //西药费
  357. var westernMedicineCostSelfTotal float64 = 0 //西药费
  358. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  359. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  360. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  361. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  365. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  366. var checkCostTotal float64 = 0 //检查费
  367. var checkCostSelfTotal float64 = 0 //检查费
  368. var checkCostPartSelfTotal float64 = 0 //检查费
  369. var checkSelfTotal float64 = 0 //床位部分项目自费
  370. var checkInscpTotal float64 = 0 //床位部分项目自费
  371. var laboratoryCostTotal float64 = 0 //化验费
  372. var laboratoryCostSelfTotal float64 = 0 //化验费
  373. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  374. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  375. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  376. var treatCostTotal float64 = 0 //治疗费用
  377. var treatCostSelfTotal float64 = 0 //治疗费用
  378. var treatCostPartSelfTotal float64 = 0 //治疗费用
  379. var treatSelfTotal float64 = 0 //床位部分项目自费
  380. var treatInscpTotal float64 = 0 //床位部分项目自费
  381. decimal.DivisionPrecision = 2
  382. for _, item := range orderInfos {
  383. if item.MedChrgitmType == "01" { //床位费
  384. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  385. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  386. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  387. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  388. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  389. }
  390. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  391. if item.MedChrgitmType == "03" { //检查费
  392. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  393. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  394. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  395. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  396. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  397. }
  398. } else {
  399. if item.MedChrgitmType == "03" { //检查费
  400. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. }
  407. if item.MedChrgitmType == "04" { //化验费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. if item.MedChrgitmType == "05" { //治疗费
  415. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "06" { //手术费
  422. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  429. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "09" { //西药费
  436. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "11" { //中成费
  443. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  450. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. }
  457. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  458. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  459. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  460. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  461. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  462. var doctor_name string
  463. if roles.ID == 0 {
  464. doctor_name = "管理员"
  465. } else {
  466. doctor_name = roles.UserName
  467. }
  468. yiliao_leibie := ""
  469. switch order.MedType {
  470. case "11":
  471. yiliao_leibie = "普通门诊"
  472. break
  473. case "12":
  474. yiliao_leibie = "门诊挂号"
  475. break
  476. case "13":
  477. yiliao_leibie = "急诊"
  478. break
  479. case "14":
  480. yiliao_leibie = "门诊特殊病"
  481. break
  482. case "15":
  483. yiliao_leibie = "门诊统筹"
  484. break
  485. case "16":
  486. yiliao_leibie = "门诊慢性病"
  487. break
  488. case "21":
  489. yiliao_leibie = "普通住院"
  490. break
  491. }
  492. var newOrder models.Orders
  493. newOrder.Diagnosis = name
  494. newOrder.OrderInfos = orderInfos
  495. newOrder.Number = order.MdtrtId
  496. newOrder.Date = order.SettleAccountsDate
  497. newOrder.ChargeAdmin = charge_admin
  498. newOrder.PrintorAdmin = printor_admin
  499. newOrder.Order = order
  500. newOrder.BedCostTotal = bedCostTotal
  501. newOrder.BedCostSelfTotal = bedCostSelfTotal
  502. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  503. newOrder.BedSelfTotal = bedSelfTotal
  504. newOrder.BedInscpTotal = bedInscpTotal
  505. newOrder.OperationCostTotal = operationCostTotal
  506. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  507. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  508. newOrder.OperationSelfTotal = operationSelfTotal
  509. newOrder.OperationInscpTotal = operationInscpTotal
  510. newOrder.OtherCostTotal = otherCostTotal
  511. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  512. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  513. newOrder.OtherSelfTotal = otherSelfTotal
  514. newOrder.OtherInscpTotal = otherInscpTotal
  515. newOrder.MaterialCostTotal = materialCostTotal
  516. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  517. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  518. newOrder.MaterialSelfTotal = materialSelfTotal
  519. newOrder.MaterialInscpTotal = materialInscpTotal
  520. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  521. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  522. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  523. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  524. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  525. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  526. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  527. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  528. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  529. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  530. newOrder.CheckCostTotal = checkCostTotal
  531. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  532. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  533. newOrder.CheckSelfTotal = checkSelfTotal
  534. newOrder.CheckInscpTotal = checkInscpTotal
  535. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  536. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  537. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  538. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  539. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  540. newOrder.TreatCostTotal = treatCostTotal
  541. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  542. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  543. newOrder.TreatSelfTotal = treatSelfTotal
  544. newOrder.TreatInscpTotal = treatInscpTotal
  545. newOrder.DoctorInfo = doctor_info
  546. newOrder.DoctorName = doctor_name
  547. newOrder.HealthCardNo = order.PsnNo
  548. newOrder.YiliaoLeibie = yiliao_leibie
  549. newOrder.Patient = patient
  550. newOrder.OrgName = miConfig.OrgName
  551. newOrder.OrgCode = miConfig.Code
  552. newOrder.OrderNumber = order.Number
  553. newOrder.HisPatient = his
  554. newOrder.DiaConfig = dia_config
  555. newOrders = append(newOrders, newOrder)
  556. }
  557. c.ServeSuccessJSON(map[string]interface{}{
  558. "orders": newOrders,
  559. })
  560. }
  561. func (c *HisApiController) GetTestOrder() {
  562. order_id, _ := c.GetInt64("order_id")
  563. admin_user_id, _ := c.GetInt64("admin_user_id")
  564. adminUser := c.GetAdminUserInfo()
  565. order, _ := service.GetHisOrderByID(order_id)
  566. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  567. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  568. orderInfos = append(orderInfos, orderInfos_two...)
  569. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  570. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  571. var dia_config []*models.HisXtDiagnoseConfig
  572. var name string
  573. var bedCostTotal float64 = 0 //床位总费
  574. var bedCostSelfTotal float64 = 0 //床位自费
  575. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  576. var bedSelfTotal float64 = 0 //床位部分项目自费
  577. var bedInscpTotal float64 = 0 //床位部分项目自费
  578. var operationCostTotal float64 = 0 //手术费
  579. var operationCostSelfTotal float64 = 0 //手术费
  580. var operationCostPartSelfTotal float64 = 0 //手术费
  581. var operationSelfTotal float64 = 0 //床位部分项目自费
  582. var operationInscpTotal float64 = 0 //床位部分项目自费
  583. var otherCostTotal float64 = 0 //其他费用
  584. var otherCostSelfTotal float64 = 0 //其他费用
  585. var otherCostPartSelfTotal float64 = 0 //其他费用
  586. var otherSelfTotal float64 = 0 //床位部分项目自费
  587. var otherInscpTotal float64 = 0 //床位部分项目自费
  588. var materialCostTotal float64 = 0 //材料费
  589. var materialCostSelfTotal float64 = 0 //材料费
  590. var materialCostPartSelfTotal float64 = 0 //材料费
  591. var materialSelfTotal float64 = 0 //床位部分项目自费
  592. var materialInscpTotal float64 = 0 //床位部分项目自费
  593. var westernMedicineCostTotal float64 = 0 //西药费
  594. var westernMedicineCostSelfTotal float64 = 0 //西药费
  595. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  596. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  597. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  598. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  602. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  603. var checkCostTotal float64 = 0 //检查费
  604. var checkCostSelfTotal float64 = 0 //检查费
  605. var checkCostPartSelfTotal float64 = 0 //检查费
  606. var checkSelfTotal float64 = 0 //床位部分项目自费
  607. var checkInscpTotal float64 = 0 //床位部分项目自费
  608. var laboratoryCostTotal float64 = 0 //化验费
  609. var laboratoryCostSelfTotal float64 = 0 //化验费
  610. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  611. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  612. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  613. var treatCostTotal float64 = 0 //治疗费用
  614. var treatCostSelfTotal float64 = 0 //治疗费用
  615. var treatCostPartSelfTotal float64 = 0 //治疗费用
  616. var treatSelfTotal float64 = 0 //床位部分项目自费
  617. var treatInscpTotal float64 = 0 //床位部分项目自费
  618. decimal.DivisionPrecision = 2
  619. for _, item := range orderInfos {
  620. if item.MedChrgitmType == "01" { //床位费
  621. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  622. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  623. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  624. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  625. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  626. }
  627. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  628. if item.MedChrgitmType == "03" { //检查费
  629. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  630. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  631. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  633. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  634. }
  635. } else {
  636. if item.MedChrgitmType == "03" { //检查费
  637. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. }
  644. if item.MedChrgitmType == "04" { //化验费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. if item.MedChrgitmType == "05" { //治疗费
  652. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "06" { //手术费
  659. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  666. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "09" { //西药费
  673. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "11" { //中成费
  680. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  687. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. }
  694. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  695. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  696. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  697. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  698. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  699. var doctor_name string
  700. if roles.ID == 0 {
  701. doctor_name = "管理员"
  702. } else {
  703. doctor_name = roles.UserName
  704. }
  705. yiliao_leibie := ""
  706. switch order.MedType {
  707. case "11":
  708. yiliao_leibie = "普通门诊"
  709. break
  710. case "12":
  711. yiliao_leibie = "门诊挂号"
  712. break
  713. case "13":
  714. yiliao_leibie = "急诊"
  715. break
  716. case "14":
  717. yiliao_leibie = "门诊特殊病"
  718. break
  719. case "15":
  720. yiliao_leibie = "门诊统筹"
  721. break
  722. case "16":
  723. yiliao_leibie = "门诊慢性病"
  724. break
  725. case "21":
  726. yiliao_leibie = "普通住院"
  727. break
  728. }
  729. c.ServeSuccessJSON(map[string]interface{}{
  730. "diagnosis": name,
  731. "order_infos": orderInfos,
  732. "number": order.MdtrtId,
  733. "date": order.SettleAccountsDate,
  734. "charge_admin": charge_admin,
  735. "printor_admin": printor_admin,
  736. "info": order,
  737. "order": order,
  738. "bedCostTotal": bedCostTotal,
  739. "bedCostSelfTotal": bedCostSelfTotal,
  740. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  741. "bedSelfTotal": bedSelfTotal,
  742. "bedInscpTotal": bedInscpTotal,
  743. "operationCostTotal": operationCostTotal,
  744. "operationCostSelfTotal": operationCostSelfTotal,
  745. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  746. "operationSelfTotal": operationSelfTotal,
  747. "operationInscpTotal": operationInscpTotal,
  748. "otherCostTotal": otherCostTotal,
  749. "otherCostSelfTotal": otherCostSelfTotal,
  750. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  751. "otherSelfTotal": otherSelfTotal,
  752. "otherInscpTotal": otherInscpTotal,
  753. "materialCostTotal": materialCostTotal,
  754. "materialCostSelfTotal": materialCostSelfTotal,
  755. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  756. "materialSelfTotal": materialSelfTotal,
  757. "materialInscpTotal": materialInscpTotal,
  758. "westernMedicineCostTotal": westernMedicineCostTotal,
  759. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  760. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  761. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  762. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  763. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  764. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  765. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  766. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  767. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  768. "checkCostTotal": checkCostTotal,
  769. "checkCostSelfTotal": checkCostSelfTotal,
  770. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  771. "checkSelfTotal": checkSelfTotal,
  772. "checkInscpTotal": checkInscpTotal,
  773. "laboratoryCostTotal": laboratoryCostTotal,
  774. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  775. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  776. "laboratorySelfTotal": laboratorySelfTotal,
  777. "laboratoryInscpTotal": laboratoryInscpTotal,
  778. "treatCostTotal": treatCostTotal,
  779. "treatCostSelfTotal": treatCostSelfTotal,
  780. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  781. "treatSelfTotal": treatSelfTotal,
  782. "treatInscpTotal": treatInscpTotal,
  783. "doctor_info": doctor_info,
  784. "doctor_name": doctor_name,
  785. "health_card_no": order.PsnNo,
  786. "yiliao_leibie": yiliao_leibie,
  787. "patient": patient,
  788. "org_name": miConfig.OrgName,
  789. "org_code": miConfig.Code,
  790. "order_number": order.Number,
  791. "his_hospital": his_hospital,
  792. "dia_config": dia_config,
  793. })
  794. }
  795. type CustomFundPay struct {
  796. FundPayType string `json:"fund_pay_type"`
  797. FundPayamt float64 `json:"fund_payamt"`
  798. InscpScpAmt float64 `json:"inscp_scp_amt"`
  799. }
  800. func (c *PublicApiController) GetBaiLinExportData() {
  801. data := service.GetBaiLinOrderData()
  802. fmt.Println(len(data))
  803. var new_data []*models.NewCustomHisOrder
  804. for _, item := range data {
  805. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  806. new_data = append(new_data, item)
  807. }
  808. }
  809. fmt.Println(len(new_data))
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "list": new_data,
  812. })
  813. }
  814. func (c *HisApiController) GetHisUnChargePatientList() {
  815. record_date := c.GetString("record_date")
  816. sch_type, _ := c.GetInt64("sch_type")
  817. timeLayout := "2006-01-02"
  818. loc, _ := time.LoadLocation("Local")
  819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  820. if err != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. recordDateTime := theTime.Unix()
  825. adminInfo := c.GetAdminUserInfo()
  826. var tempPatients []*service.NewTempPatients
  827. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  828. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  829. var patients []*service.NewTempPatients
  830. var patients_two []*service.NewTempPatients
  831. for _, item := range tempPatients {
  832. //过滤掉没挂号的和没开处方的
  833. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  834. patients = append(patients, item)
  835. }
  836. //过滤掉没挂号的
  837. if len(item.HisPatient) > 0 {
  838. patients_two = append(patients_two, item)
  839. }
  840. }
  841. c.ServeSuccessJSON(map[string]interface{}{
  842. "list": patients,
  843. "list_two": patients_two,
  844. })
  845. }
  846. func (c *HisApiController) GetPrivateExpensesOrder() {
  847. //id, _ := c.GetInt64("id")
  848. //record_time := c.GetString("record_time")
  849. order_id, _ := c.GetInt64("order_id")
  850. admin_user_id, _ := c.GetInt64("admin_user_id")
  851. //timeLayout := "2006-01-02"
  852. //loc, _ := time.LoadLocation("Local")
  853. //
  854. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  855. //if err != nil {
  856. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. // return
  858. //}
  859. //recordDateTime := theTime.Unix()
  860. adminUser := c.GetAdminUserInfo()
  861. order, _ := service.GetHisOrderByID(order_id)
  862. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  863. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  864. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  866. //var config []*models.HisXtDiagnoseConfig
  867. var name string
  868. if order.PType == 1 {
  869. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  870. for _, item := range diagnosis_ids {
  871. id, _ := strconv.ParseInt(item, 10, 64)
  872. diagnosisConfig, _ := service.FindDiagnoseById(id)
  873. if len(name) == 0 {
  874. name = diagnosisConfig.ClassName
  875. } else {
  876. name = name + "," + diagnosisConfig.ClassName
  877. }
  878. }
  879. } else {
  880. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  881. for _, item := range diagnosis_ids {
  882. id, _ := strconv.ParseInt(item, 10, 64)
  883. diagnosisConfig, _ := service.FindDiagnoseById(id)
  884. if len(name) == 0 {
  885. name = diagnosisConfig.ClassName
  886. } else {
  887. name = name + "," + diagnosisConfig.ClassName
  888. }
  889. }
  890. }
  891. var bedCostTotal float64 = 0 //床位总费
  892. //var bedCostSelfTotal float64 = 0 //床位自费
  893. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  894. var operationCostTotal float64 = 0 //手术费
  895. //var operationCostSelfTotal float64 = 0 //手术费
  896. var operationCostPartSelfTotal float64 = 0 //手术费
  897. var otherCostTotal float64 = 0 //其他费用
  898. //var otherCostSelfTotal float64 = 0 //其他费用
  899. var otherCostPartSelfTotal float64 = 0 //其他费用
  900. var materialCostTotal float64 = 0 //材料费
  901. //var materialCostSelfTotal float64 = 0 //材料费
  902. var materialCostPartSelfTotal float64 = 0 //材料费
  903. var westernMedicineCostTotal float64 = 0 //西药费
  904. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  905. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  906. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  907. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  908. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  909. var checkCostTotal float64 = 0 //检查费
  910. //var checkCostSelfTotal float64 = 0 //检查费
  911. var checkCostPartSelfTotal float64 = 0 //检查费
  912. var laboratoryCostTotal float64 = 0 //化验费
  913. //var laboratoryCostSelfTotal float64 = 0 //化验费
  914. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  915. var treatCostTotal float64 = 0 //治疗费用
  916. //var treatCostSelfTotal float64 = 0 //治疗费用
  917. var treatCostPartSelfTotal float64 = 0 //治疗费用
  918. var zhenChaCostTotal float64 = 0 //其他费用
  919. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  920. decimal.DivisionPrecision = 2
  921. for _, item := range orderInfos {
  922. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  923. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  924. item.MedChrgitmType = "09"
  925. }
  926. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  927. if item.HisPrescriptionProject.Type == 2 {
  928. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  929. fmt.Println("CostClassify")
  930. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  931. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  932. case 0:
  933. item.MedChrgitmType = "0"
  934. break
  935. case 1:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 2:
  939. item.MedChrgitmType = "05"
  940. break
  941. case 3:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 4:
  945. item.MedChrgitmType = "03"
  946. break
  947. case 5:
  948. item.MedChrgitmType = "08"
  949. break
  950. case 6:
  951. item.MedChrgitmType = "14"
  952. break
  953. case 7:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 8:
  957. item.MedChrgitmType = "03"
  958. break
  959. case 9:
  960. item.MedChrgitmType = "14"
  961. break
  962. case 10:
  963. item.MedChrgitmType = "14"
  964. break
  965. case 11:
  966. item.MedChrgitmType = "06"
  967. break
  968. case 12:
  969. item.MedChrgitmType = "12"
  970. break
  971. case 13:
  972. item.MedChrgitmType = "01"
  973. break
  974. case 14:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 15:
  978. item.MedChrgitmType = "14"
  979. break
  980. }
  981. } else {
  982. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  983. case 1:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 2:
  987. item.MedChrgitmType = "05"
  988. break
  989. case 3:
  990. item.MedChrgitmType = "04"
  991. break
  992. case 4:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 5:
  996. item.MedChrgitmType = "08"
  997. break
  998. case 6:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 7:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. case 8:
  1005. item.MedChrgitmType = "03"
  1006. break
  1007. case 9:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. default:
  1011. item.MedChrgitmType = "14"
  1012. break
  1013. }
  1014. }
  1015. } else if item.HisPrescriptionProject.Type == 3 {
  1016. item.MedChrgitmType = "08"
  1017. }
  1018. }
  1019. }
  1020. order.PsnCashPay = order.MedfeeSumamt
  1021. for _, item := range orderInfos {
  1022. if item.MedChrgitmType == "01" { //床位费
  1023. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1024. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1025. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1026. }
  1027. if item.MedChrgitmType == "02" { //诊察费
  1028. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1029. //zhenChaCostSelfTotal = zhenChaCostTotal
  1030. }
  1031. if item.MedChrgitmType == "03" { //检查费
  1032. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1033. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1034. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1035. }
  1036. if item.MedChrgitmType == "02" { //检查费
  1037. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1038. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1039. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1040. }
  1041. if item.MedChrgitmType == "04" { //化验费
  1042. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1043. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1044. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1045. }
  1046. if item.MedChrgitmType == "05" { //治疗费
  1047. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1048. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1049. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1050. }
  1051. if item.MedChrgitmType == "06" { //手术费
  1052. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1053. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1054. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1055. }
  1056. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1057. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1058. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1059. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1060. }
  1061. if item.MedChrgitmType == "09" { //西药费
  1062. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1063. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1064. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1065. }
  1066. if item.MedChrgitmType == "11" { //中成费
  1067. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1068. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1069. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1070. }
  1071. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1072. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1073. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1074. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1075. }
  1076. }
  1077. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1078. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1079. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1080. var dia_config []*models.HisXtDiagnoseConfig
  1081. var diagnosis_ids []string
  1082. if his.ID > 0 {
  1083. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1084. } else {
  1085. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1086. }
  1087. for _, item := range diagnosis_ids {
  1088. id, _ := strconv.ParseInt(item, 10, 64)
  1089. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1090. dia_config = append(dia_config, diagnosisConfig)
  1091. }
  1092. var rf []CustomFundPay
  1093. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1094. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1095. c.ServeSuccessJSON(map[string]interface{}{
  1096. "patient": patient,
  1097. "order_infos": orderInfos,
  1098. "diagnosis": name,
  1099. "bedCostTotal": bedCostTotal,
  1100. "bedCostSelfTotal": bedCostTotal,
  1101. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1102. "operationCostTotal": operationCostTotal,
  1103. "operationCostSelfTotal": operationCostTotal,
  1104. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1105. "otherCostTotal": otherCostTotal,
  1106. "otherCostSelfTotal": otherCostTotal,
  1107. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1108. "materialCostTotal": materialCostTotal,
  1109. "materialCostSelfTotal": materialCostTotal,
  1110. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1111. "westernMedicineCostTotal": westernMedicineCostTotal,
  1112. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1113. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1114. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1115. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1116. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1117. "checkCostTotal": checkCostTotal,
  1118. "checkCostSelfTotal": checkCostTotal,
  1119. "zhenChaCostTotal": zhenChaCostTotal,
  1120. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1121. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1122. "laboratoryCostTotal": laboratoryCostTotal,
  1123. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1124. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1125. "treatCostTotal": treatCostTotal,
  1126. "treatCostSelfTotal": treatCostTotal,
  1127. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1128. "charge_admin": charge_admin,
  1129. "printor_admin": printor_admin,
  1130. "org_name": org.OrgName,
  1131. "org_code": miConfig.Code,
  1132. "name": patient.Name,
  1133. "number": order.MdtrtId,
  1134. "date": order.SettleAccountsDate,
  1135. "info": order,
  1136. "new_order": order,
  1137. "his_hospital": his_hospital,
  1138. "his": his,
  1139. "funds": rf,
  1140. "dia_config": dia_config,
  1141. })
  1142. }
  1143. func (c *HisApiController) RefudDetail() {
  1144. order_id, _ := c.GetInt64("order_id")
  1145. order, _ := service.GetHisOrderByID(order_id)
  1146. adminUser := c.GetAdminUserInfo()
  1147. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1148. c.ServeSuccessJSON(map[string]interface{}{
  1149. "msg": "撤销成功",
  1150. })
  1151. }
  1152. func (c *HisApiController) Sscard() {
  1153. //r := CardInit()
  1154. //if r == 0 {
  1155. // GetBaseInfo()
  1156. //}
  1157. //c.ServeSuccessJSON(map[string]interface{}{
  1158. // "list": "11",
  1159. //})
  1160. }
  1161. func GetBaseInfo() error {
  1162. //handle := syscall.MustLoadDLL("SSCard.dll")
  1163. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1164. //
  1165. //str := make([]byte, 256)
  1166. //str1 := make([]byte, 256)
  1167. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1168. //if ferr != nil {
  1169. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1170. // return ferr
  1171. //}
  1172. //
  1173. //fmt.Println(string(str))
  1174. //
  1175. //fmt.Println(r)
  1176. return nil
  1177. }
  1178. func CardInit() int {
  1179. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1180. //add := DllTestDef.MustFindProc("Init")
  1181. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1182. //if err != nil {
  1183. // fmt.Println("SSCard的运算结果为:", ret)
  1184. //}
  1185. //result := int(ret)
  1186. return 0
  1187. }
  1188. func IntPtr(n int) uintptr {
  1189. return uintptr(n)
  1190. }
  1191. func StrPtr(s string) uintptr {
  1192. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1193. }
  1194. func (c *HisApiController) GetHisPatientList() {
  1195. //types, _ := c.GetInt64("type", 0)
  1196. record_date := c.GetString("record_date")
  1197. sch_type, _ := c.GetInt64("sch_type")
  1198. timeLayout := "2006-01-02"
  1199. loc, _ := time.LoadLocation("Local")
  1200. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1201. if err != nil {
  1202. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1203. return
  1204. }
  1205. recordDateTime := theTime.Unix()
  1206. adminInfo := c.GetAdminUserInfo()
  1207. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1208. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1209. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1210. //获取当前用户的信息
  1211. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1212. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1213. //获取所有科室信息
  1214. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1215. c.ServeSuccessJSON(map[string]interface{}{
  1216. "list": patients,
  1217. "list_two": patients_two,
  1218. "info": adminUserInfo,
  1219. "doctors": doctors,
  1220. "department": department,
  1221. })
  1222. }
  1223. type CustomTemplate struct {
  1224. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1225. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1226. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1227. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1228. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1229. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1230. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1231. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1232. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1233. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1234. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1235. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1236. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1237. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1238. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1239. }
  1240. func (c *HisApiController) GetHisPatientInfo() {
  1241. patient_id, _ := c.GetInt64("patient_id")
  1242. his_patient_id, _ := c.GetInt64("his_patient_id")
  1243. record_date := c.GetString("record_date")
  1244. number := c.GetString("number")
  1245. //start_time := c.GetString("start_time")
  1246. //end_time := c.GetString("end_time")
  1247. p_type, _ := c.GetInt64("p_type")
  1248. timeLayout := "2006-01-02"
  1249. loc, _ := time.LoadLocation("Local")
  1250. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1251. if err != nil {
  1252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1253. return
  1254. }
  1255. recordDateTime := theTime.Unix()
  1256. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1257. //if err != nil {
  1258. //
  1259. //}
  1260. //startRecordDateTime := startTime.Unix()
  1261. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1262. //if err != nil {
  1263. //
  1264. //}
  1265. //endRecordDateTime := endTime.Unix()
  1266. admin := c.GetAdminUserInfo()
  1267. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1268. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1269. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1270. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1271. var prescriptions []*models.HisPrescription
  1272. var last_prescriptions []*models.HisPrescription
  1273. var sch_prescriptions []CustomTemplate
  1274. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1275. if p_type == 1 { //住院
  1276. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1277. for _, item := range prescriptions {
  1278. for _, subItem := range item.HisDoctorAdviceInfo {
  1279. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1280. if info.RetailPrice > 0 {
  1281. subItem.Drug.MinPrice = info.RetailPrice
  1282. }
  1283. }
  1284. }
  1285. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1286. } else { //门诊
  1287. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1288. for _, item := range prescriptions {
  1289. for _, subItem := range item.HisDoctorAdviceInfo {
  1290. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1291. if info.RetailPrice > 0 {
  1292. subItem.Drug.MinPrice = info.RetailPrice
  1293. }
  1294. }
  1295. }
  1296. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1297. }
  1298. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1299. if sch.ID > 0 {
  1300. var week string
  1301. t := time.Now()
  1302. switch t.Weekday().String() {
  1303. case "Monday":
  1304. week = "周一"
  1305. break
  1306. case "Tuesday":
  1307. week = "周二"
  1308. break
  1309. case "Wednesday":
  1310. week = "周三"
  1311. break
  1312. case "Thursday":
  1313. week = "周四"
  1314. break
  1315. case "Friday":
  1316. week = "周五"
  1317. break
  1318. case "Saturday":
  1319. week = "周六"
  1320. break
  1321. case "Sunday":
  1322. week = "周日"
  1323. break
  1324. }
  1325. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1326. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1327. //根据推送频率组装新的数组
  1328. for _, item := range temp_sch_prescriptions {
  1329. var cus CustomTemplate
  1330. cus.ID = item.ID
  1331. cus.UserOrgId = item.UserOrgId
  1332. cus.PatientId = item.PatientId
  1333. cus.MedType = item.MedType
  1334. cus.RecordDate = item.RecordDate
  1335. cus.Type = item.Type
  1336. cus.PType = item.PType
  1337. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1338. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1339. if subItem.FrequencyType == 1 { //每次必推
  1340. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1341. }
  1342. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1343. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 2 { //按照天数频率
  1346. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1347. now := p.Unix()
  1348. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1349. dayStr2 := "-" + dayStr
  1350. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1351. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1352. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1353. if len(advices) == 0 {
  1354. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1355. }
  1356. }
  1357. }
  1358. }
  1359. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1360. if subItem.Type == 2 {
  1361. if subItem.XtHisProject.MedicalStatus != 1 {
  1362. if subItem.FrequencyType == 1 {
  1363. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1364. }
  1365. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. if subItem.FrequencyType == 2 {
  1369. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1370. now := p.Unix()
  1371. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1372. dayStr2 := "-" + dayStr
  1373. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1374. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1375. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1376. if len(projects) == 0 {
  1377. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1378. }
  1379. }
  1380. }
  1381. } else if subItem.Type == 3 {
  1382. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1383. if subItem.FrequencyType == 1 {
  1384. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1385. }
  1386. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1387. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1388. }
  1389. if subItem.FrequencyType == 2 {
  1390. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1391. now := p.Unix()
  1392. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1393. dayStr2 := "-" + dayStr
  1394. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1395. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1396. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1397. if len(projects) == 0 {
  1398. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1399. }
  1400. }
  1401. }
  1402. }
  1403. }
  1404. sch_prescriptions = append(sch_prescriptions, cus)
  1405. }
  1406. for _, item := range sch_prescriptions {
  1407. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1408. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1409. }
  1410. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1411. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1412. }
  1413. }
  1414. }
  1415. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1416. if config.ID > 0 && config.IsOpen == 1 {
  1417. for _, item := range sch_prescriptions {
  1418. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1419. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1420. if info.RetailPrice > 0 {
  1421. subItem.Drug.MinPrice = info.RetailPrice
  1422. }
  1423. }
  1424. }
  1425. }
  1426. if config.ID > 0 && config.IsOpen == 1 {
  1427. for _, item := range sch_prescriptions {
  1428. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1429. if subItem.Type == 3 {
  1430. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1431. if info.Price > 0 {
  1432. subItem.GoodInfo.PackingPrice = info.Price
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1439. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1440. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1441. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1442. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1443. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1444. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1445. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1446. //获取所有科室信息
  1447. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1448. c.ServeSuccessJSON(map[string]interface{}{
  1449. "his_info": his_patient_info,
  1450. "xt_info": xt_patient_info,
  1451. "prescription": prescriptions,
  1452. "case_history": case_history,
  1453. "info": patientPrescriptionInfo,
  1454. //"month_prescriptions": monthPrescriptions,
  1455. "order": order,
  1456. "doctors": doctors,
  1457. "department": department,
  1458. "sch_prescriptions": sch_prescriptions,
  1459. "last_prescriptions": last_prescriptions,
  1460. "schedule": sch,
  1461. "count": count,
  1462. "drugStockConfig": drugStockConfig,
  1463. "last_info": lastPatientPrescriptionInfo,
  1464. })
  1465. return
  1466. }
  1467. func (c *HisApiController) GetHisPrescriptionConfig() {
  1468. adminInfo := c.GetAdminUserInfo()
  1469. //获取医嘱模版
  1470. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1471. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1472. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1473. //获取所有基础药
  1474. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1475. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1476. if config.ID > 0 && config.IsOpen == 1 {
  1477. for _, item := range drugs {
  1478. var index = 0
  1479. for _, subItem := range item.OtherDrugWarehouseInfo {
  1480. if index == 0 {
  1481. index = index + 1
  1482. if subItem.RetailPrice > 0 {
  1483. item.MinPrice = subItem.RetailPrice
  1484. }
  1485. }
  1486. }
  1487. }
  1488. }
  1489. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1490. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1491. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1492. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1493. //获取所有科室信息
  1494. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1495. //获取诊断信息
  1496. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1497. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1498. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1499. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1500. //获取是否开启保存耗材出库的开关
  1501. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1502. c.ServeSuccessJSON(map[string]interface{}{
  1503. "drugs": drugs,
  1504. "advices_template": advices,
  1505. "drugways": drugways,
  1506. "efs": efs,
  1507. "doctors": doctors,
  1508. "department": department,
  1509. "sick": sick,
  1510. "additions": additions,
  1511. "diagnose": diagnose,
  1512. "manufacturers": manufacturers,
  1513. "goodOutOpen": goodOutOpen,
  1514. "patientDiagnose": patientDiagnose,
  1515. })
  1516. }
  1517. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1518. //获取所有基础药
  1519. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1520. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1521. if config.ID > 0 && config.IsOpen == 1 {
  1522. for _, item := range drugs {
  1523. var index = 0
  1524. for _, subItem := range item.OtherDrugWarehouseInfo {
  1525. if index == 0 {
  1526. index = index + 1
  1527. if subItem.RetailPrice > 0 {
  1528. item.MinPrice = subItem.RetailPrice
  1529. }
  1530. }
  1531. }
  1532. }
  1533. }
  1534. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1535. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1536. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1537. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1538. //获取所有科室信息
  1539. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1540. //获取诊断信息
  1541. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1542. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1543. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1544. //获取是否开启保存耗材出库的开关
  1545. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1546. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1547. c.ServeSuccessJSON(map[string]interface{}{
  1548. "drugs": drugs,
  1549. "advices_template": advices,
  1550. "drugways": drugways,
  1551. "efs": efs,
  1552. "doctors": doctors,
  1553. "department": department,
  1554. "sick": sick,
  1555. "additions": additions,
  1556. "diagnose": diagnose,
  1557. "manufacturers": manufacturers,
  1558. "goodOutOpen": goodOutOpen,
  1559. "patientDiagnose": patientDiagnose,
  1560. })
  1561. }
  1562. }
  1563. func (c *HisApiController) CreateHisPrescription() {
  1564. record_date := c.GetString("record_date")
  1565. patient_id, _ := c.GetInt64("patient_id")
  1566. reg_type, _ := c.GetInt64("reg_type")
  1567. diagnose := c.GetString("diagnose")
  1568. sick_type, _ := c.GetInt64("sick_type")
  1569. sick_history := c.GetString("sick_history")
  1570. doctor_id, _ := c.GetInt64("doctor", 0)
  1571. department, _ := c.GetInt64("department", 0)
  1572. his_patient_id, _ := c.GetInt64("his_patient_id")
  1573. p_type, _ := c.GetInt64("p_type")
  1574. patient_diagnose := c.GetString("patient_diagnose")
  1575. dataBody := make(map[string]interface{}, 0)
  1576. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1577. if err != nil {
  1578. utils.ErrorLog(err.Error())
  1579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1580. return
  1581. }
  1582. //edit, src := GetCompareData(dataBody)
  1583. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1584. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1585. //fmt.Println(drugResult)
  1586. //fmt.Println(goodResult)
  1587. timeLayout := "2006-01-02"
  1588. loc, _ := time.LoadLocation("Local")
  1589. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1590. if err != nil {
  1591. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1592. return
  1593. }
  1594. adminInfo := c.GetAdminUserInfo()
  1595. recordDateTime := theTime.Unix()
  1596. //查询默认出库仓库库存
  1597. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1598. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1599. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1600. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1601. if len(lists) == 1 {
  1602. his_patient_id = lists[0].ID
  1603. }
  1604. }
  1605. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1606. //保存处方出库
  1607. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1608. //自动出库
  1609. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1610. //耗材保存处方出库
  1611. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1612. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1613. //已发药和已收费限制逻辑
  1614. isMidicine := false
  1615. isCharge := false
  1616. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1617. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1618. if len(prescriptions) > 0 {
  1619. for _, item := range prescriptions {
  1620. items := item.(map[string]interface{})
  1621. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1622. utils.ErrorLog("id")
  1623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1624. return
  1625. }
  1626. id := int64(items["id"].(float64))
  1627. if id > 0 {
  1628. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1629. if err != nil {
  1630. if new_prescription.OrderStatus == 4 {
  1631. isCharge = true
  1632. }
  1633. }
  1634. }
  1635. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1636. advices := items["advices"].([]interface{})
  1637. if len(advices) > 0 {
  1638. for _, advice := range advices {
  1639. var adviceId int64
  1640. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1641. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1642. }
  1643. if adviceId > 0 {
  1644. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1645. if err == nil {
  1646. if his_advice_info.IsMedicine == 1 {
  1647. isMidicine = true
  1648. }
  1649. }
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. if isMidicine == true {
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1659. return
  1660. }
  1661. if isCharge == true {
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1663. return
  1664. }
  1665. // 开始主事务
  1666. db := service.XTWriteDB()
  1667. tx := db.Begin()
  1668. // 在函数结束时处理事务回滚
  1669. defer func() {
  1670. if r := recover(); r != nil {
  1671. tx.Rollback()
  1672. }
  1673. }()
  1674. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1675. //药品发药出库
  1676. if pharmacyConfig.IsOpen == 1 {
  1677. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1678. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1679. if len(prescriptions) > 0 {
  1680. for _, item := range prescriptions {
  1681. items := item.(map[string]interface{})
  1682. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1683. advices := items["advices"].([]interface{})
  1684. if len(advices) > 0 {
  1685. for _, advice := range advices {
  1686. var drug_id int64
  1687. var prescribing_number float64
  1688. var prescribingNumberUnit string
  1689. var adviceId int64
  1690. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1691. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1692. }
  1693. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1694. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1695. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1696. }
  1697. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1698. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1699. }
  1700. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1701. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1702. }
  1703. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1704. if drug.ID == 0 {
  1705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1706. return
  1707. }
  1708. //查询药品的所有库存
  1709. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1710. var total_count int64
  1711. for _, it := range list {
  1712. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1713. }
  1714. totals := strconv.FormatInt(total_count, 10)
  1715. //查询该药品是否存在开药记录
  1716. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1717. //新增处方
  1718. if advicelist.ID == 0 {
  1719. all_count, _ := strconv.ParseFloat(totals, 64)
  1720. if prescribingNumberUnit == drug.MinUnit {
  1721. if drug.IsUse != 1 {
  1722. if drug.IsProject == 0 || drug.IsProject == 2 {
  1723. if all_count == 0 {
  1724. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1725. return
  1726. }
  1727. if prescribing_number > all_count {
  1728. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1729. return
  1730. }
  1731. }
  1732. }
  1733. }
  1734. if prescribingNumberUnit == drug.MaxUnit {
  1735. num := prescribing_number * float64(drug.MinNumber)
  1736. if drug.IsUse != 1 {
  1737. if drug.IsProject == 0 || drug.IsProject == 2 {
  1738. if all_count == 0 {
  1739. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1740. return
  1741. }
  1742. if num > all_count {
  1743. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1744. return
  1745. }
  1746. }
  1747. }
  1748. }
  1749. }
  1750. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1751. if drugOutConfig.IsOpen != 1 {
  1752. //修改处方
  1753. for _, advice := range advices {
  1754. var drug_id int64
  1755. var prescribing_number float64
  1756. var prescribingNumberUnit string
  1757. var prescribingNumber string
  1758. var adviceId int64
  1759. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1760. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1761. }
  1762. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1763. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1764. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1765. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1766. }
  1767. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1768. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1769. }
  1770. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1771. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1772. }
  1773. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1774. if drug.ID == 0 {
  1775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1776. return
  1777. }
  1778. //查询药品的所有库存
  1779. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1780. var total_count int64
  1781. for _, it := range list {
  1782. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1783. }
  1784. totals := strconv.FormatInt(total_count, 10)
  1785. //查询该药品是否存在开药记录
  1786. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1787. //新增处方
  1788. if advicelist.ID == 0 {
  1789. all_count, _ := strconv.ParseFloat(totals, 64)
  1790. if prescribingNumberUnit == drug.MinUnit {
  1791. if drug.IsUse != 1 {
  1792. if drug.IsProject == 0 || drug.IsProject == 2 {
  1793. if all_count == 0 {
  1794. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1795. return
  1796. }
  1797. if prescribing_number > all_count {
  1798. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1799. return
  1800. }
  1801. }
  1802. }
  1803. } else {
  1804. if prescribingNumberUnit == drug.MaxUnit {
  1805. num := prescribing_number * float64(drug.MinNumber)
  1806. if drug.IsUse != 1 {
  1807. if drug.IsProject == 0 || drug.IsProject == 2 {
  1808. if all_count == 0 {
  1809. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1810. return
  1811. }
  1812. if num > all_count {
  1813. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1814. return
  1815. }
  1816. }
  1817. }
  1818. }
  1819. }
  1820. }
  1821. //修改处方
  1822. if advicelist.ID > 0 {
  1823. var device_number int64
  1824. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1825. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1826. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1827. device_number = prescribingNumberInt * drug.MinNumber
  1828. }
  1829. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1830. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1831. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1832. device_number = prescribingNumberInt
  1833. }
  1834. var number_count int64
  1835. if prescribingNumberUnit == drug.MaxUnit {
  1836. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1837. number_count = prescribingNumberInt * drug.MinNumber
  1838. }
  1839. if prescribingNumberUnit == drug.MinUnit {
  1840. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1841. number_count = prescribingNumberInt
  1842. }
  1843. //如果修改的数量大于之前修改的数量
  1844. if (number_count - device_number) > 0 {
  1845. //如果修改的差数量 大于库存数量
  1846. if drug.IsUse != 1 {
  1847. if (number_count - device_number) > total_count {
  1848. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1849. return
  1850. }
  1851. }
  1852. }
  1853. }
  1854. }
  1855. }
  1856. }
  1857. }
  1858. }
  1859. }
  1860. }
  1861. }
  1862. }
  1863. //已发药和已收费限制逻辑
  1864. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1865. //校验库存总量
  1866. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1867. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1868. if len(prescriptions) > 0 {
  1869. for _, item := range prescriptions {
  1870. items := item.(map[string]interface{})
  1871. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1872. advices := items["advices"].([]interface{})
  1873. if len(advices) > 0 {
  1874. for _, advice := range advices {
  1875. var drug_id int64
  1876. var prescribing_number float64
  1877. var prescribingNumberUnit string
  1878. var adviceId int64
  1879. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1880. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1881. }
  1882. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1883. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1884. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1885. }
  1886. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1887. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1888. }
  1889. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1890. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1891. }
  1892. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1893. if drug.ID == 0 {
  1894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1895. return
  1896. }
  1897. //查询药品的所有库存
  1898. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1899. var total_count int64
  1900. for _, it := range list {
  1901. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1902. }
  1903. totals := strconv.FormatInt(total_count, 10)
  1904. //查询该药品是否存在开药记录
  1905. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1906. //查询最新批次库存
  1907. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1908. var batch_number_count int64
  1909. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1910. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1911. //新增处方
  1912. if advicelist.ID == 0 {
  1913. all_count, _ := strconv.ParseFloat(totals, 64)
  1914. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1915. if prescribingNumberUnit == drug.MinUnit {
  1916. if drug.IsUse != 1 {
  1917. if drug.IsProject == 0 || drug.IsProject == 2 {
  1918. if all_count == 0 {
  1919. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1920. return
  1921. }
  1922. if prescribing_number > all_count {
  1923. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1924. return
  1925. }
  1926. }
  1927. if adminInfo.CurrentOrgId == 10215 {
  1928. if prescribing_number > batch_number_all_count {
  1929. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1930. return
  1931. }
  1932. }
  1933. }
  1934. }
  1935. if prescribingNumberUnit == drug.MaxUnit {
  1936. num := prescribing_number * float64(drug.MinNumber)
  1937. if drug.IsUse != 1 {
  1938. if drug.IsProject == 0 || drug.IsProject == 2 {
  1939. if all_count == 0 {
  1940. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1941. return
  1942. }
  1943. if num > all_count {
  1944. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1945. return
  1946. }
  1947. }
  1948. if adminInfo.CurrentOrgId == 10215 {
  1949. if num > batch_number_all_count {
  1950. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1951. return
  1952. }
  1953. }
  1954. }
  1955. }
  1956. }
  1957. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1958. if drugOutConfig.IsOpen != 1 {
  1959. //修改处方
  1960. for _, advice := range advices {
  1961. var drug_id int64
  1962. var prescribing_number float64
  1963. var prescribingNumberUnit string
  1964. var prescribingNumber string
  1965. var adviceId int64
  1966. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1967. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1968. }
  1969. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1970. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1971. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1972. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1973. }
  1974. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1975. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1976. }
  1977. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1978. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1979. }
  1980. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1981. if drug.ID == 0 {
  1982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1983. return
  1984. }
  1985. //查询药品的所有库存
  1986. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1987. var total_count int64
  1988. for _, it := range list {
  1989. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1990. }
  1991. totals := strconv.FormatInt(total_count, 10)
  1992. //查询该药品是否存在开药记录
  1993. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1994. //新增处方
  1995. if advicelist.ID == 0 {
  1996. //查询最新批次库存
  1997. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1998. var batch_number_count int64
  1999. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2000. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2001. all_count, _ := strconv.ParseFloat(totals, 64)
  2002. if prescribingNumberUnit == drug.MinUnit {
  2003. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2004. if drug.IsUse != 1 {
  2005. if drug.IsProject == 0 || drug.IsProject == 2 {
  2006. if all_count == 0 {
  2007. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2008. return
  2009. }
  2010. if prescribing_number > all_count {
  2011. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2012. return
  2013. }
  2014. }
  2015. if adminInfo.CurrentOrgId == 10215 {
  2016. if prescribing_number > batch_number_all_count {
  2017. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2018. return
  2019. }
  2020. }
  2021. }
  2022. } else {
  2023. if prescribingNumberUnit == drug.MaxUnit {
  2024. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2025. num := prescribing_number * float64(drug.MinNumber)
  2026. if drug.IsUse != 1 {
  2027. if drug.IsProject == 0 || drug.IsProject == 2 {
  2028. if all_count == 0 {
  2029. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2030. return
  2031. }
  2032. if num > all_count {
  2033. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2034. return
  2035. }
  2036. }
  2037. if adminInfo.CurrentOrgId == 10215 {
  2038. if prescribing_number > batch_number_all_count {
  2039. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2040. return
  2041. }
  2042. }
  2043. }
  2044. }
  2045. }
  2046. }
  2047. //修改处方
  2048. if advicelist.ID > 0 {
  2049. //查询最新批次库存
  2050. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2051. var batch_number_count int64
  2052. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2053. var device_number int64
  2054. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2055. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2056. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2057. device_number = prescribingNumberInt * drug.MinNumber
  2058. }
  2059. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2060. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2061. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2062. device_number = prescribingNumberInt
  2063. }
  2064. var number_count int64
  2065. if prescribingNumberUnit == drug.MaxUnit {
  2066. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2067. number_count = prescribingNumberInt * drug.MinNumber
  2068. }
  2069. if prescribingNumberUnit == drug.MinUnit {
  2070. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2071. number_count = prescribingNumberInt
  2072. }
  2073. //如果修改的数量大于之前修改的数量
  2074. if (number_count - device_number) > 0 {
  2075. //如果修改的差数量 大于库存数量
  2076. if drug.IsUse != 1 {
  2077. if drug.IsProject == 0 || drug.IsProject == 2 {
  2078. if total_count == 0 {
  2079. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2080. return
  2081. }
  2082. if (number_count - device_number) > total_count {
  2083. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2084. return
  2085. }
  2086. if (number_count - device_number) > batch_number_count {
  2087. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2088. return
  2089. }
  2090. }
  2091. if adminInfo.CurrentOrgId == 10215 {
  2092. // 查询该药品最后一次出库记录
  2093. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2094. var out_count int64
  2095. var in_count int64
  2096. var stock_max_number int64
  2097. var stock_min_number int64
  2098. for _, it := range outInfo {
  2099. if it.CountUnit == drug.MaxUnit {
  2100. it.Count = it.Count * drug.MinNumber
  2101. }
  2102. out_count += it.Count
  2103. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2104. stock_max_number = warehouseInfoList.StockMaxNumber
  2105. stock_min_number = warehouseInfoList.StockMinNumber
  2106. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2107. }
  2108. if out_count > 0 {
  2109. if (number_count - device_number) > in_count {
  2110. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2111. return
  2112. }
  2113. }
  2114. // 未出库
  2115. if out_count == 0 {
  2116. var sum_in_count int64
  2117. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2118. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2119. fmt.Println("sum_in_count", sum_in_count)
  2120. //如果修改的数量大于有库存的第一个批次
  2121. if number_count > sum_in_count {
  2122. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2123. return
  2124. }
  2125. }
  2126. }
  2127. }
  2128. }
  2129. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2130. if pharmacyConfig.IsOpen != 1 {
  2131. if device_number != number_count {
  2132. // 查询该药品最后一次出库记录
  2133. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2134. //回退库存
  2135. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2136. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2137. }
  2138. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2139. var stock_max_number int64
  2140. var stock_min_number int64
  2141. if number_count >= drug.MinNumber {
  2142. stock_max_number = device_number / drug.MinNumber
  2143. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2144. stock_min_number = device_number % drug.MinNumber
  2145. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2146. } else {
  2147. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2148. }
  2149. }
  2150. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2151. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2152. }
  2153. //删除记录
  2154. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2155. //查询默认仓库剩余多少库存
  2156. var sum_count int64
  2157. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2158. for _, its := range stockInfo {
  2159. if its.MaxUnit == drug.MaxUnit {
  2160. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2161. }
  2162. sum_count += its.StockMaxNumber + its.StockMinNumber
  2163. }
  2164. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2165. }
  2166. }
  2167. }
  2168. }
  2169. }
  2170. //保存处方开药
  2171. if drugOutConfig.IsOpen == 1 {
  2172. //修改处方
  2173. for _, advice := range advices {
  2174. var drug_id int64
  2175. var prescribing_number float64
  2176. var prescribingNumberUnit string
  2177. var prescribingNumber string
  2178. var adviceId int64
  2179. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2180. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2181. }
  2182. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2183. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2184. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2185. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2186. }
  2187. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2188. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2189. }
  2190. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2191. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2192. }
  2193. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2194. if drug.ID == 0 {
  2195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2196. return
  2197. }
  2198. //查询药品的所有库存
  2199. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2200. var total_count int64
  2201. for _, it := range list {
  2202. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2203. }
  2204. totals := strconv.FormatInt(total_count, 10)
  2205. //查询该药品是否存在开药记录
  2206. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2207. //新增处方
  2208. if advicelist.ID == 0 {
  2209. //查询最新批次库存
  2210. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2211. var batch_number_count int64
  2212. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2213. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2214. all_count, _ := strconv.ParseFloat(totals, 64)
  2215. if prescribingNumberUnit == drug.MinUnit {
  2216. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2217. if drug.IsUse != 1 {
  2218. if drug.IsProject == 0 || drug.IsProject == 2 {
  2219. if all_count == 0 {
  2220. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2221. return
  2222. }
  2223. if prescribing_number > all_count {
  2224. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2225. return
  2226. }
  2227. }
  2228. if adminInfo.CurrentOrgId == 10215 {
  2229. if prescribing_number > batch_number_all_count {
  2230. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2231. return
  2232. }
  2233. }
  2234. }
  2235. } else {
  2236. if prescribingNumberUnit == drug.MaxUnit {
  2237. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2238. num := prescribing_number * float64(drug.MinNumber)
  2239. if drug.IsUse != 1 {
  2240. if drug.IsProject == 0 || drug.IsProject == 2 {
  2241. if all_count == 0 {
  2242. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2243. return
  2244. }
  2245. if num > all_count {
  2246. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2247. return
  2248. }
  2249. }
  2250. if adminInfo.CurrentOrgId == 10215 {
  2251. if prescribing_number > batch_number_all_count {
  2252. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2253. return
  2254. }
  2255. }
  2256. }
  2257. }
  2258. }
  2259. }
  2260. //修改处方
  2261. if advicelist.ID > 0 {
  2262. //查询最新批次库存
  2263. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2264. var batch_number_count int64
  2265. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2266. var device_number int64
  2267. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2268. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2269. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2270. device_number = prescribingNumberInt * drug.MinNumber
  2271. }
  2272. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2273. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2274. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2275. device_number = prescribingNumberInt
  2276. }
  2277. var number_count int64
  2278. if prescribingNumberUnit == drug.MaxUnit {
  2279. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2280. number_count = prescribingNumberInt * drug.MinNumber
  2281. }
  2282. if prescribingNumberUnit == drug.MinUnit {
  2283. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2284. number_count = prescribingNumberInt
  2285. }
  2286. //如果修改的数量大于之前修改的数量
  2287. if (number_count - device_number) > 0 {
  2288. //如果修改的差数量 大于库存数量
  2289. if drug.IsUse != 1 {
  2290. if drug.IsProject == 0 || drug.IsProject == 2 {
  2291. if total_count == 0 {
  2292. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2293. return
  2294. }
  2295. if (number_count - device_number) > total_count {
  2296. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2297. return
  2298. }
  2299. }
  2300. if adminInfo.CurrentOrgId == 10215 {
  2301. if (number_count - device_number) > batch_number_count {
  2302. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2303. return
  2304. }
  2305. }
  2306. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2307. //查询历史出库数据总批次
  2308. // 查询该药品最后一次出库记录
  2309. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2310. var out_count int64
  2311. var in_count int64
  2312. var stock_max_number int64
  2313. var stock_min_number int64
  2314. for _, it := range outInfo {
  2315. if it.CountUnit == drug.MaxUnit {
  2316. it.Count = it.Count * drug.MinNumber
  2317. }
  2318. out_count += it.Count
  2319. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2320. stock_max_number = warehouseInfoList.StockMaxNumber
  2321. stock_min_number = warehouseInfoList.StockMinNumber
  2322. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2323. }
  2324. if out_count > 0 {
  2325. if (number_count - device_number) > in_count {
  2326. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2327. return
  2328. }
  2329. }
  2330. // 未出库
  2331. if out_count == 0 {
  2332. var sum_in_count int64
  2333. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2334. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2335. if sum_in_count == 0 {
  2336. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2337. return
  2338. }
  2339. //如果修改的数量大于有库存的第一个批次
  2340. if number_count > sum_in_count {
  2341. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2342. return
  2343. }
  2344. }
  2345. }
  2346. }
  2347. }
  2348. }
  2349. }
  2350. }
  2351. }
  2352. }
  2353. }
  2354. }
  2355. }
  2356. }
  2357. }
  2358. //校验耗材库存
  2359. if goodOutConfig.IsOpen == 1 {
  2360. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2361. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2362. if len(prescriptions) > 0 {
  2363. for _, item := range prescriptions {
  2364. items := item.(map[string]interface{})
  2365. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2366. projects := items["project"].([]interface{})
  2367. if len(projects) > 0 {
  2368. for _, project := range projects {
  2369. var project_id int64
  2370. var project_type int64
  2371. var totals float64
  2372. var project_name string
  2373. var parsetotal int64
  2374. var id int64
  2375. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2376. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2377. }
  2378. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2379. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2380. }
  2381. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2382. total, _ := project.(map[string]interface{})["total"].(string)
  2383. totals, _ = strconv.ParseFloat(total, 64)
  2384. }
  2385. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2386. project_name = project.(map[string]interface{})["project_name"].(string)
  2387. }
  2388. if project_type == 3 {
  2389. //查找该耗材的出库记录
  2390. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2391. if len(goodWarehouseInfo) == 0 {
  2392. //查询耗材库存
  2393. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2394. var stock_count int64
  2395. for _, it := range list {
  2396. stock_count += it.StockCount
  2397. }
  2398. stock_counts := strconv.FormatInt(stock_count, 10)
  2399. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2400. if stock_total_count == 0 {
  2401. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2402. return
  2403. }
  2404. if totals > stock_total_count {
  2405. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2406. return
  2407. }
  2408. }
  2409. if len(goodWarehouseInfo) > 0 {
  2410. //查询该患者耗材的历史数据
  2411. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2412. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2413. //数量发生改变
  2414. if parsetotal != count {
  2415. //如果现在的数量大于历史数量,就要看库存是否足够
  2416. if parsetotal > count {
  2417. //查询耗材所有库存
  2418. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2419. var stock_count int64
  2420. for _, it := range list {
  2421. stock_count += it.StockCount
  2422. }
  2423. //库存不足
  2424. if stock_count == 0 {
  2425. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2426. return
  2427. }
  2428. if (parsetotal - count) > stock_count {
  2429. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2430. return
  2431. }
  2432. }
  2433. }
  2434. }
  2435. }
  2436. }
  2437. }
  2438. }
  2439. }
  2440. }
  2441. }
  2442. }
  2443. //不使用耗材保存处方出库
  2444. if goodOutConfig.IsOpen != 1 {
  2445. if stockConfig.IsOpen == 1 {
  2446. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2447. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2448. if len(prescriptions) > 0 {
  2449. for _, item := range prescriptions {
  2450. items := item.(map[string]interface{})
  2451. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2452. projects := items["project"].([]interface{})
  2453. if len(projects) > 0 {
  2454. for _, project := range projects {
  2455. var project_id int64
  2456. var project_type int64
  2457. var totals float64
  2458. var project_name string
  2459. var parsetotal int64
  2460. var id int64
  2461. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2462. id = int64(project.(map[string]interface{})["id"].(float64))
  2463. }
  2464. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2465. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2466. }
  2467. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2468. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2469. }
  2470. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2471. total, _ := project.(map[string]interface{})["total"].(string)
  2472. totals, _ = strconv.ParseFloat(total, 64)
  2473. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2474. }
  2475. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2476. project_name = project.(map[string]interface{})["project_name"].(string)
  2477. }
  2478. if project_type == 3 {
  2479. //查找该耗材的出库记录
  2480. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2481. //没有出库记录
  2482. if len(goodWarehouseInfo) == 0 {
  2483. //查询耗材库存
  2484. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2485. var stock_count int64
  2486. for _, it := range list {
  2487. stock_count += it.StockCount
  2488. }
  2489. stock_counts := strconv.FormatInt(stock_count, 10)
  2490. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2491. if stock_total_count == 0 {
  2492. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2493. return
  2494. }
  2495. if totals > stock_total_count {
  2496. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2497. return
  2498. }
  2499. //查找今日该患者已经出库的所有耗材
  2500. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2501. for _, item := range goodList {
  2502. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2503. var flush_count int64
  2504. for _, it := range goodListSix {
  2505. flush_count += it.StockCount
  2506. }
  2507. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2508. creater := adminInfo.AdminUser.Id
  2509. if errs != nil {
  2510. goodErrcode := models.XtGoodErrcode{
  2511. UserOrgId: item.OrgId,
  2512. Errcode: "手动出库更新剩余出库失败",
  2513. GoodId: item.GoodId,
  2514. Status: 1,
  2515. Ctime: time.Now().Unix(),
  2516. Mtime: 0,
  2517. Count: 0,
  2518. StockCount: 0,
  2519. Creater: creater,
  2520. BatchNumberId: 0,
  2521. WarehouseOutId: 0,
  2522. }
  2523. service.CreateGoodErrcode(goodErrcode)
  2524. }
  2525. }
  2526. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2527. }
  2528. //有出库记录
  2529. if len(goodWarehouseInfo) > 0 {
  2530. //查询该患者耗材的历史数据
  2531. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2532. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2533. //数量发生改变
  2534. if parsetotal != count {
  2535. //查找今日该患者已经出库的所有耗材
  2536. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2537. for _, item := range goodList {
  2538. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2539. var flush_count int64
  2540. for _, it := range goodListSix {
  2541. flush_count += it.StockCount
  2542. }
  2543. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2544. //减少出库数量
  2545. creater := adminInfo.AdminUser.Id
  2546. if errs != nil {
  2547. goodErrcode := models.XtGoodErrcode{
  2548. UserOrgId: item.OrgId,
  2549. Errcode: "手动出库更新剩余出库失败",
  2550. GoodId: item.GoodId,
  2551. Status: 1,
  2552. Ctime: time.Now().Unix(),
  2553. Mtime: 0,
  2554. Count: 0,
  2555. StockCount: 0,
  2556. Creater: creater,
  2557. BatchNumberId: 0,
  2558. WarehouseOutId: 0,
  2559. }
  2560. service.CreateGoodErrcode(goodErrcode)
  2561. }
  2562. //查询默认仓库
  2563. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2564. var total_count int64
  2565. for _, it := range stockList {
  2566. total_count += it.StockCount
  2567. }
  2568. //基础库插入数据
  2569. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2570. }
  2571. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2572. }
  2573. }
  2574. }
  2575. }
  2576. }
  2577. }
  2578. }
  2579. }
  2580. }
  2581. }
  2582. }
  2583. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2584. var hpInfo models.HisPrescriptionInfo
  2585. if info.ID == 0 {
  2586. var randNum int
  2587. randNum = rand.Intn(10000) + 1000
  2588. timestamp := time.Now().Unix()
  2589. tempTime := time.Unix(timestamp, 0)
  2590. timeFormat := tempTime.Format("20060102150405")
  2591. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2592. hpInfo = models.HisPrescriptionInfo{
  2593. HisPatientId: his_patient_id,
  2594. UserOrgId: adminInfo.CurrentOrgId,
  2595. RecordDate: theTime.Unix(),
  2596. PatientId: patient_id,
  2597. Status: 1,
  2598. Ctime: time.Now().Unix(),
  2599. Mtime: time.Now().Unix(),
  2600. Creator: adminInfo.AdminUser.Id,
  2601. Modifier: adminInfo.AdminUser.Id,
  2602. Diagnosis: diagnose,
  2603. SickHistory: sick_history,
  2604. Departments: department,
  2605. RegisterType: reg_type,
  2606. PrescriptionNumber: p_number,
  2607. PrescriptionStatus: 1,
  2608. Doctor: role.UserName,
  2609. DoctorId: doctor_id,
  2610. SickType: sick_type,
  2611. PType: p_type,
  2612. PatientDiagnosis: patient_diagnose,
  2613. }
  2614. service.SavePatientPrescriptionInfo(hpInfo)
  2615. //创建步骤表
  2616. finish := models.XtDialysisFinish{
  2617. IsFinish: 1,
  2618. UserOrgId: adminInfo.CurrentOrgId,
  2619. Status: 1,
  2620. Ctime: time.Now().Unix(),
  2621. Mtime: 0,
  2622. Module: 4,
  2623. RecordDate: theTime.Unix(),
  2624. Sourse: 1,
  2625. PatientId: patient_id,
  2626. }
  2627. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2628. if dialysisFinish.ID == 0 {
  2629. service.CreateDialysisFinish(finish)
  2630. }
  2631. redis := service.RedisClient()
  2632. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2633. redis.Set(key, "", time.Second)
  2634. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2635. redis.Set(keyOne, "", time.Second)
  2636. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2637. redis.Set(keySeven, "", time.Second)
  2638. defer redis.Close()
  2639. } else {
  2640. hpInfo = models.HisPrescriptionInfo{
  2641. ID: info.ID,
  2642. UserOrgId: adminInfo.CurrentOrgId,
  2643. RecordDate: info.RecordDate,
  2644. PatientId: info.PatientId,
  2645. Status: 1,
  2646. Ctime: info.Ctime,
  2647. Mtime: time.Now().Unix(),
  2648. Creator: info.Creator,
  2649. Modifier: adminInfo.AdminUser.Id,
  2650. Diagnosis: diagnose,
  2651. SickHistory: sick_history,
  2652. Departments: department,
  2653. RegisterType: reg_type,
  2654. PrescriptionNumber: info.PrescriptionNumber,
  2655. Doctor: role.UserName,
  2656. PrescriptionStatus: info.PrescriptionStatus,
  2657. DoctorId: doctor_id,
  2658. SickType: sick_type,
  2659. PType: info.PType,
  2660. HisPatientId: info.HisPatientId,
  2661. PatientDiagnosis: patient_diagnose,
  2662. }
  2663. service.SavePatientPrescriptionInfo(hpInfo)
  2664. //创建步骤表
  2665. finish := models.XtDialysisFinish{
  2666. IsFinish: 1,
  2667. UserOrgId: adminInfo.CurrentOrgId,
  2668. Status: 1,
  2669. Ctime: time.Now().Unix(),
  2670. Mtime: 0,
  2671. Module: 4,
  2672. RecordDate: info.RecordDate,
  2673. Sourse: 1,
  2674. PatientId: info.PatientId,
  2675. }
  2676. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2677. if dialysisFinish.ID == 0 {
  2678. service.CreateDialysisFinish(finish)
  2679. }
  2680. redis := service.RedisClient()
  2681. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2682. redis.Set(key, "", time.Second)
  2683. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2684. redis.Set(keyOne, "", time.Second)
  2685. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2686. redis.Set(keySeven, "", time.Second)
  2687. defer redis.Close()
  2688. }
  2689. //定义切片
  2690. var adviceList []models.HisDoctorAdviceInfo
  2691. var projectList []models.HisPrescriptionProject
  2692. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2693. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2694. var tempPrescription *models.HisPrescription
  2695. if len(prescriptions) > 0 {
  2696. for _, item := range prescriptions {
  2697. // 开始外部循环的事务
  2698. tx := db.Begin()
  2699. // 在函数结束时处理事务回滚
  2700. defer func() {
  2701. if r := recover(); r != nil {
  2702. tx.Rollback()
  2703. }
  2704. }()
  2705. items := item.(map[string]interface{})
  2706. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2707. utils.ErrorLog("id")
  2708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2709. return
  2710. }
  2711. id := int64(items["id"].(float64))
  2712. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2713. tempPrescription = &new_prescription
  2714. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2715. utils.ErrorLog("type")
  2716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2717. return
  2718. }
  2719. types := int64(items["type"].(float64))
  2720. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2721. utils.ErrorLog("med_type")
  2722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2723. return
  2724. }
  2725. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2726. if med_type == "0" {
  2727. med_type = "14"
  2728. }
  2729. //if order_status == 0 {
  2730. // order_status = 1
  2731. //}
  2732. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2733. utils.ErrorLog("pre_time")
  2734. }
  2735. preTime, _ := items["pre_time"].(string)
  2736. timeLayout := "2006-01-02"
  2737. loc, _ := time.LoadLocation("Local")
  2738. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2739. if err != nil {
  2740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2741. return
  2742. }
  2743. pTime := theTime2.Unix()
  2744. ctime := time.Now().Unix()
  2745. if tempPrescription.ID == 0 {
  2746. prescription := &models.HisPrescription{
  2747. ID: 0,
  2748. PatientId: patient_id,
  2749. UserOrgId: adminInfo.CurrentOrgId,
  2750. RecordDate: recordDateTime,
  2751. Ctime: ctime,
  2752. Mtime: ctime,
  2753. Type: types,
  2754. Modifier: adminInfo.AdminUser.Id,
  2755. Creator: adminInfo.AdminUser.Id,
  2756. Status: 1,
  2757. Doctor: role.UserName,
  2758. HisPatientId: his_patient_id,
  2759. OrderStatus: 1,
  2760. BatchNumber: "",
  2761. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2762. PreTime: pTime,
  2763. PType: p_type,
  2764. MedType: med_type,
  2765. }
  2766. tempPrescription = prescription
  2767. service.SaveHisPrescription(tx, tempPrescription)
  2768. redis := service.RedisClient()
  2769. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2770. redis.Set(key, "", time.Second)
  2771. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2772. redis.Set(keyOne, "", time.Second)
  2773. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2774. redis.Set(keySeven, "", time.Second)
  2775. defer redis.Close()
  2776. } else {
  2777. tempPrescription.ID = id
  2778. tempPrescription.Type = types
  2779. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2780. tempPrescription.Mtime = time.Now().Unix()
  2781. tempPrescription.Doctor = role.UserName
  2782. //tempPrescription.OrderStatus = order_status
  2783. tempPrescription.PreTime = pTime
  2784. tempPrescription.MedType = med_type
  2785. service.SaveHisPrescription(tx, tempPrescription)
  2786. redis := service.RedisClient()
  2787. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2788. redis.Set(key, "", time.Second)
  2789. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2790. redis.Set(keyOne, "", time.Second)
  2791. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2792. redis.Set(keySeven, "", time.Second)
  2793. defer redis.Close()
  2794. }
  2795. //service.SaveHisPrescription(prescription)
  2796. //更改患者挂号状态
  2797. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2798. fmt.Println("更改失败", err2)
  2799. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2800. advices := items["advices"].([]interface{})
  2801. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2802. groupNo := int64(0)
  2803. ctime := time.Now().Unix()
  2804. mtime := ctime
  2805. if len(advices) > 0 {
  2806. for _, advice := range advices {
  2807. tx := db.Begin()
  2808. // 在函数结束时处理事务回滚
  2809. defer func() {
  2810. if r := recover(); r != nil {
  2811. tx.Rollback()
  2812. }
  2813. }()
  2814. var s models.HisDoctorAdviceInfo
  2815. s.PrescriptionId = tempPrescription.ID
  2816. s.AdviceType = 2
  2817. s.AdviceDoctor = doctor_id
  2818. s.StopState = 2
  2819. s.ExecutionState = 2
  2820. s.AdviceDate = recordDateTime
  2821. s.Status = 1
  2822. s.UserOrgId = adminInfo.CurrentOrgId
  2823. s.RecordDate = recordDateTime
  2824. s.StartTime = tempPrescription.PreTime
  2825. s.Groupno = groupNo
  2826. s.CreatedTime = ctime
  2827. s.UpdatedTime = mtime
  2828. s.PatientId = patient_id
  2829. s.HisPatientId = his_patient_id
  2830. s.StartTime = pTime
  2831. s.IsSettle = 2
  2832. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2833. if errcode > 0 {
  2834. c.ServeFailJSONWithSGJErrorCode(errcode)
  2835. return
  2836. }
  2837. s.StartTime = pTime
  2838. var total_count int64 //处方总库存
  2839. //查询改药品信息
  2840. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2841. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2842. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2843. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2844. total_count += prescribingNumberSeven * medical.MinNumber
  2845. }
  2846. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2847. total_count += prescribingNumberSeven
  2848. }
  2849. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2850. total_count += prescribingNumberSeven
  2851. }
  2852. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2853. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2854. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2855. if s.Price != lastWarehouse.RetailPrice {
  2856. s.Price = lastWarehouse.RetailPrice
  2857. }
  2858. if s.Price == 0 {
  2859. s.Price = lastWarehouse.RetailPrice
  2860. }
  2861. }
  2862. //查询保存处方出库开关是否打开
  2863. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2864. if drugOutConfig.IsOpen == 1 {
  2865. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2866. // 查询该药品最后一次出库记录
  2867. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2868. if len(druginfo) > 0 {
  2869. //回退库存
  2870. for _, it := range druginfo {
  2871. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2872. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2873. }
  2874. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2875. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2876. }
  2877. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2878. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2879. }
  2880. }
  2881. //删除记录
  2882. service.DeleteDrugAutoWarehouseSeven(s.DrugId, patient_id, recordDateTime, s.ID)
  2883. }
  2884. service.CreateHisDoctorAdvice(&s, tx)
  2885. advicelast, _ := service.GetLastHisAdvicesList(s.PatientId, s.AdviceDate, s.UserOrgId, tx)
  2886. //出库
  2887. if drug.IsUse == 2 {
  2888. creater := adminInfo.AdminUser.Id
  2889. newadviceInfo := &models.HisDoctorAdviceInfo{
  2890. ID: advicelast.ID,
  2891. UserOrgId: s.UserOrgId,
  2892. PatientId: s.PatientId,
  2893. HisPatientId: s.HisPatientId,
  2894. AdviceType: s.AdviceType,
  2895. AdviceDate: s.AdviceDate,
  2896. StartTime: s.StartTime,
  2897. AdviceName: s.AdviceName,
  2898. AdviceDesc: s.AdviceDesc,
  2899. ReminderDate: s.ReminderDate,
  2900. SingleDose: s.SingleDose,
  2901. SingleDoseUnit: s.SingleDoseUnit,
  2902. PrescribingNumber: s.PrescribingNumber,
  2903. PrescribingNumberUnit: s.PrescribingNumberUnit,
  2904. DeliveryWay: s.DeliveryWay,
  2905. ExecutionFrequency: s.ExecutionFrequency,
  2906. AdviceDoctor: s.AdviceDoctor,
  2907. Status: s.Status,
  2908. CreatedTime: s.CreatedTime,
  2909. UpdatedTime: s.UpdatedTime,
  2910. AdviceAffirm: s.AdviceAffirm,
  2911. Remark: s.Remark,
  2912. StopTime: s.StopTime,
  2913. StopReason: s.StopReason,
  2914. StopDoctor: s.StopDoctor,
  2915. StopState: s.StopState,
  2916. ParentId: s.ParentId,
  2917. ExecutionTime: s.ExecutionTime,
  2918. ExecutionStaff: s.ExecutionStaff,
  2919. ExecutionState: s.ExecutionState,
  2920. Checker: s.Checker,
  2921. RecordDate: s.RecordDate,
  2922. DialysisOrderId: s.DialysisOrderId,
  2923. CheckTime: s.CheckTime,
  2924. CheckState: s.CheckState,
  2925. DrugSpec: s.DrugSpec,
  2926. DrugSpecUnit: s.DrugSpecUnit,
  2927. Groupno: s.Groupno,
  2928. RemindType: s.RemindType,
  2929. FrequencyType: s.FrequencyType,
  2930. DayCount: s.DayCount,
  2931. WeekDay: s.WeekDay,
  2932. TemplateId: s.TemplateId,
  2933. Modifier: s.Modifier,
  2934. DrugId: s.DrugId,
  2935. Price: s.Price,
  2936. PrescriptionId: s.PrescriptionId,
  2937. MedListCodg: s.MedListCodg,
  2938. FeedetlSn: s.FeedetlSn,
  2939. Day: s.DayCount,
  2940. ChildDoctorAdvice: nil,
  2941. Drug: models.Drug{},
  2942. Diagnosis: s.Diagnosis,
  2943. Way: s.Way,
  2944. HospApprFlag: s.HospApprFlag,
  2945. LmtUsedFlag: s.LmtUsedFlag,
  2946. HisOrderInfo: models.HisOrderInfo{},
  2947. IsMedicine: s.IsMedicine,
  2948. ExecutionFrequencyId: s.ExecutionFrequencyId,
  2949. Child: nil,
  2950. IsSettle: s.IsSettle,
  2951. IsMobile: s.IsMobile,
  2952. IsSelfDrug: s.IsSelfDrug,
  2953. DrugWayCount: s.DrugWayCount,
  2954. }
  2955. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  2956. }
  2957. //更新字典里面的库存
  2958. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  2959. var sum_count int64
  2960. for _, its := range stockInfo {
  2961. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  2962. if its.MaxUnit == baseDrug.MaxUnit {
  2963. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2964. }
  2965. sum_count += its.StockMaxNumber + its.StockMinNumber
  2966. }
  2967. //更新基础库存
  2968. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  2969. //剩余库存
  2970. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  2971. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  2972. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  2973. }
  2974. //记录日志
  2975. byterequest, _ := json.Marshal(s)
  2976. adviceLog := models.XtDoctorAdviceLog{
  2977. UserOrgId: s.UserOrgId,
  2978. PatientId: s.PatientId,
  2979. AdminUserId: adminInfo.AdminUser.Id,
  2980. Module: 1,
  2981. ErrLog: string(byterequest),
  2982. Status: 1,
  2983. Ctime: time.Now().Unix(),
  2984. Mtime: 0,
  2985. Source: "电脑端新建his医嘱",
  2986. RecordDate: s.AdviceDate,
  2987. }
  2988. service.CreateDoctorAdviceLog(adviceLog)
  2989. //存储切片中
  2990. adviceList = append(adviceList, s)
  2991. redis := service.RedisClient()
  2992. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2993. redis.Set(key, "", time.Second)
  2994. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2995. redis.Set(keyOne, "", time.Second)
  2996. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2997. redis.Set(keySeven, "", time.Second)
  2998. var randNum int
  2999. randNum = rand.Intn(10000) + 1000
  3000. timestamp := time.Now().Unix()
  3001. tempTime := time.Unix(timestamp, 0)
  3002. timeFormat := tempTime.Format("20060102150405")
  3003. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3004. service.CreateHisDoctorAdvice(&s, tx)
  3005. tx.Commit()
  3006. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3007. redis.Set(keySix, "", time.Second)
  3008. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3009. redis.Set(keyFive, "", time.Second)
  3010. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3011. redis.Set(keyEight, "", time.Second)
  3012. defer redis.Close()
  3013. }
  3014. }
  3015. }
  3016. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3017. projects := items["project"].([]interface{})
  3018. if len(projects) > 0 {
  3019. for _, project := range projects {
  3020. tx := db.Begin()
  3021. // 在函数结束时处理事务回滚
  3022. defer func() {
  3023. if r := recover(); r != nil {
  3024. tx.Rollback()
  3025. }
  3026. }()
  3027. var p models.HisPrescriptionProject
  3028. p.PrescriptionId = tempPrescription.ID
  3029. p.Ctime = time.Now().Unix()
  3030. p.Mtime = time.Now().Unix()
  3031. p.PatientId = patient_id
  3032. p.RecordDate = recordDateTime
  3033. p.Doctor = doctor_id
  3034. p.UserOrgId = adminInfo.CurrentOrgId
  3035. p.HisPatientId = his_patient_id
  3036. p.Status = 1
  3037. p.StartTime = pTime
  3038. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3039. if errcode > 0 {
  3040. c.ServeFailJSONWithSGJErrorCode(errcode)
  3041. return
  3042. }
  3043. if p.ID == 0 {
  3044. p.IsOut = 2
  3045. }
  3046. if p.ID > 0 {
  3047. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3048. p.IsOut = projectDetail.IsOut
  3049. }
  3050. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3051. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3052. if p.Type == 3 {
  3053. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3054. if p.Price != lastWarehouse.PackingPrice {
  3055. p.Price = lastWarehouse.PackingPrice
  3056. }
  3057. if p.Unit == "" {
  3058. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3059. p.Unit = goodInfoOne.PackingUnit
  3060. }
  3061. }
  3062. }
  3063. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3064. //
  3065. // if p.Type == 3 {
  3066. // //查询该耗材是否停用
  3067. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3068. // //表示该耗材已经停用,不能保存
  3069. // if goodInfoSeven.ID == 0 {
  3070. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3071. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3072. // return
  3073. // }
  3074. // }
  3075. //
  3076. //}
  3077. service.CreateHisProjectTwo(&p, tx)
  3078. //查询保存耗材出库开关是否打开
  3079. if goodOutConfig.IsOpen == 1 {
  3080. //耗材出库
  3081. if p.Type == 3 {
  3082. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx)
  3083. //查询历史出库数据
  3084. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3085. var out_count_five int64
  3086. for _, item := range flowGood {
  3087. out_count_five += item.Count
  3088. }
  3089. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3090. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3091. if out_count_five != parseIntCount {
  3092. //查询耗材最后一次出库记录
  3093. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3094. fmt.Println("wareout---------------------------", wareOut)
  3095. //查询默认出库仓库库存
  3096. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3097. if len(wareOut) > 0 {
  3098. for _, it := range wareOut {
  3099. //回退库存
  3100. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3101. //删除出库记录
  3102. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3103. }
  3104. }
  3105. timeStr := time.Now().Format("2006-01-02")
  3106. timeArr := strings.Split(timeStr, "-")
  3107. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3108. total = total + 1
  3109. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3110. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3111. number = number + total
  3112. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3113. operation_time := time.Now().Unix()
  3114. creater := c.GetAdminUserInfo().AdminUser.Id
  3115. recordDateStr := time.Now().Format("2006-01-02")
  3116. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3117. nowtime := recordDate.Unix()
  3118. warehouseOut := models.WarehouseOut{
  3119. WarehouseOutOrderNumber: warehousing_out_order,
  3120. OperationTime: operation_time,
  3121. OrgId: adminInfo.CurrentOrgId,
  3122. Creater: creater,
  3123. Ctime: time.Now().Unix(),
  3124. Status: 1,
  3125. WarehouseOutTime: nowtime,
  3126. Type: 1,
  3127. StorehouseId: storeConfig.StorehouseOutInfo,
  3128. IsCheck: 1,
  3129. IsSys: 1,
  3130. }
  3131. //查询是否生成出库单
  3132. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3133. if out.ID == 0 {
  3134. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3135. }
  3136. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3137. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3138. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3139. dialyPrepareOne := models.DialysisBeforePrepare{
  3140. GoodTypeId: goodObj.GoodTypeId,
  3141. GoodId: p.ProjectId,
  3142. PatientId: p.PatientId,
  3143. RecordDate: p.RecordDate,
  3144. UserOrgId: adminInfo.CurrentOrgId,
  3145. Count: parseIntCount,
  3146. Ctime: time.Now().Unix(),
  3147. Creater: creater,
  3148. Status: 1,
  3149. StorehouseId: houseConfig.StorehouseOutInfo,
  3150. ProjectId: lastHisProject.ID,
  3151. }
  3152. //判断是否是零用耗材(非零用)
  3153. if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3154. //查询历史出库数据
  3155. flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3156. var out_count int64
  3157. for _, item := range flowGood {
  3158. out_count += item.Count
  3159. }
  3160. //如果历史数和当前数据不想等才进行退库出库
  3161. if out_count != parseIntCount {
  3162. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3163. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3164. detail := models.AutomaticReduceDetail{
  3165. WarehouseOutId: 0,
  3166. WarehouseOutOrderNumber: "",
  3167. PatientId: p.PatientId,
  3168. Ctime: time.Now().Unix(),
  3169. Mtime: 0,
  3170. Status: 1,
  3171. RecordTime: p.RecordDate,
  3172. OrgId: p.UserOrgId,
  3173. GoodId: p.ProjectId,
  3174. GoodTypeId: 0,
  3175. Count: parseIntCount,
  3176. Type: 0,
  3177. ProjectId: lastHisProject.ID,
  3178. StorehouseId: 0,
  3179. }
  3180. service.CreateNewAutoDetail(detail, tx)
  3181. //查询剩余库存
  3182. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3183. var sum_count int64
  3184. for _, item := range goodList {
  3185. sum_count += item.StockCount
  3186. }
  3187. //更新剩余库存
  3188. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3189. //耗材
  3190. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3191. }
  3192. //判断是否是零用耗材(零用但是是出库耗材)
  3193. if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3194. //查询历史出库数据
  3195. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3196. var out_count int64
  3197. for _, item := range flowGood {
  3198. out_count += item.Count
  3199. }
  3200. //如果历史数和当前数据不想等才进行退库出库
  3201. if out_count != parseIntCount {
  3202. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3203. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3204. detail := models.AutomaticReduceDetail{
  3205. WarehouseOutId: 0,
  3206. WarehouseOutOrderNumber: "",
  3207. PatientId: p.PatientId,
  3208. Ctime: time.Now().Unix(),
  3209. Mtime: 0,
  3210. Status: 1,
  3211. RecordTime: p.RecordDate,
  3212. OrgId: p.UserOrgId,
  3213. GoodId: p.ProjectId,
  3214. GoodTypeId: 0,
  3215. Count: parseIntCount,
  3216. Type: 0,
  3217. ProjectId: p.ID,
  3218. StorehouseId: 0,
  3219. }
  3220. service.CreateNewAutoDetail(detail, tx)
  3221. //查询剩余库存
  3222. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3223. var sum_count int64
  3224. for _, item := range goodList {
  3225. sum_count += item.StockCount
  3226. }
  3227. //更新剩余库存
  3228. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3229. //耗材
  3230. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3231. }
  3232. }
  3233. }
  3234. }
  3235. //记录日志
  3236. byterequest, _ := json.Marshal(p)
  3237. adviceLog := models.XtDoctorAdviceLog{
  3238. UserOrgId: p.UserOrgId,
  3239. PatientId: p.PatientId,
  3240. AdminUserId: adminInfo.AdminUser.Id,
  3241. Module: 1,
  3242. ErrLog: string(byterequest),
  3243. Status: 1,
  3244. Ctime: time.Now().Unix(),
  3245. Mtime: 0,
  3246. Source: "电脑端新建his项目",
  3247. RecordDate: p.RecordDate,
  3248. }
  3249. service.CreateDoctorAdviceLog(adviceLog)
  3250. projectList = append(projectList, p)
  3251. var randNum int
  3252. randNum = rand.Intn(10000) + 1000
  3253. timestamp := time.Now().Unix()
  3254. tempTime := time.Unix(timestamp, 0)
  3255. timeFormat := tempTime.Format("20060102150405")
  3256. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3257. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3258. //新增或者编辑项目,修改对应的标签数据
  3259. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3260. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3261. var label models.HisLabelPrintInfo
  3262. project, _ := service.GetProjectDetail(p.ProjectId)
  3263. if project.CostClassify == 3 { //类别为检验检查
  3264. if p.TeamId > 0 { //检验检查组套
  3265. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3266. if tempLabel.ID == 0 {
  3267. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3268. label.Number = tempPrescription.PrescriptionNumber
  3269. label.ProjectId = project.ID
  3270. label.Status = 1
  3271. label.IsPrint = 2
  3272. label.DoctorId = info.DoctorId
  3273. label.UserOrgId = p.UserOrgId
  3274. label.PatientId = patient_id
  3275. label.RecordDate = recordDateTime
  3276. label.Ctime = time.Now().Unix()
  3277. label.Mtime = time.Now().Unix()
  3278. label.ItemId = p.TeamId
  3279. label.FeedetlSn = p.FeedetlSn
  3280. label.PProjectId = p.ID
  3281. label.ProjectName = team.ProjectTeam
  3282. label.PatientName = patient.Name
  3283. service.CreateHisLabelRecord(&label, tx)
  3284. }
  3285. } else { //单条检验检查项目
  3286. label.Number = tempPrescription.PrescriptionNumber
  3287. label.ProjectId = project.ID
  3288. label.Status = 1
  3289. label.DoctorId = info.DoctorId
  3290. label.UserOrgId = p.UserOrgId
  3291. label.PatientId = patient_id
  3292. label.RecordDate = recordDateTime
  3293. label.IsPrint = 2
  3294. label.Ctime = time.Now().Unix()
  3295. label.Mtime = time.Now().Unix()
  3296. label.FeedetlSn = p.FeedetlSn
  3297. label.PProjectId = p.ID
  3298. label.ItemId = p.TeamId
  3299. label.ProjectName = project.ProjectName
  3300. label.PatientName = patient.Name
  3301. service.CreateHisLabelRecord(&label, tx)
  3302. }
  3303. }
  3304. }
  3305. }
  3306. service.SaveHisProjectTwo(&p, tx)
  3307. }
  3308. }
  3309. tx.Commit()
  3310. }
  3311. }
  3312. }
  3313. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3314. // addition := items["addition"].([]interface{})
  3315. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3316. // ctime := time.Now().Unix()
  3317. // mtime := ctime
  3318. // if len(addition) > 0 {
  3319. // for _, item := range addition {
  3320. // var s models.HisAdditionalCharge
  3321. // s.PrescriptionId = tempPrescription.ID
  3322. // s.Status = 1
  3323. // s.UserOrgId = adminInfo.CurrentOrgId
  3324. // s.RecordDate = recordDateTime
  3325. // s.CreatedTime = ctime
  3326. // s.UpdatedTime = mtime
  3327. // s.PatientId = patient_id
  3328. // s.HisPatientId = his_patient_id
  3329. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3330. // if errcode > 0 {
  3331. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3332. // return
  3333. // }
  3334. // service.CreateAdditionalCharge(&s)
  3335. // var randNum int
  3336. // randNum = rand.Intn(10000) + 1000
  3337. // timestamp := time.Now().Unix()
  3338. // tempTime := time.Unix(timestamp, 0)
  3339. // timeFormat := tempTime.Format("20060102150405")
  3340. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3341. // service.CreateAdditionalCharge(&s)
  3342. //
  3343. // }
  3344. // }
  3345. //}
  3346. }
  3347. }
  3348. //查询今日该患者开的药品处方
  3349. //hisdoctorlist, _ := service.GetNewHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  3350. //drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3351. //药品出库
  3352. //if drugOutConfig.IsOpen == 1 {
  3353. // for _, item := range hisdoctorlist {
  3354. // drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3355. //
  3356. // // 查询该药品最后一次出库记录
  3357. // druginfo, _ := service.GetLastNewDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3358. //
  3359. // if len(druginfo) > 0 {
  3360. // //回退库存
  3361. // for _, it := range druginfo {
  3362. //
  3363. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3364. //
  3365. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3366. //
  3367. // }
  3368. // if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3369. //
  3370. // service.ModifyNewDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3371. //
  3372. // }
  3373. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3374. //
  3375. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3376. //
  3377. // }
  3378. // }
  3379. // }
  3380. //
  3381. // //删除记录
  3382. // service.DeleteNewDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3383. // //查询最后一次数据
  3384. // if drugOutConfig.IsOpen == 1 {
  3385. // //出库
  3386. // if drug.IsUse == 2 {
  3387. // creater := adminInfo.AdminUser.Id
  3388. //
  3389. // service.NewHisDrugsDelivery(item.UserOrgId, creater, item, tx)
  3390. //
  3391. // }
  3392. //
  3393. // //更新字典里面的库存
  3394. // stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
  3395. // var sum_count int64
  3396. // for _, its := range stockInfo {
  3397. // baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3398. // if its.MaxUnit == baseDrug.MaxUnit {
  3399. // its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3400. // }
  3401. // sum_count += its.StockMaxNumber + its.StockMinNumber
  3402. // }
  3403. // //更新基础库存
  3404. // service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
  3405. // //剩余库存
  3406. // service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3407. //
  3408. // over, _ := service.FindNewOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3409. // service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3410. //
  3411. // }
  3412. // }
  3413. //}
  3414. //耗材保存处方出库
  3415. //if goodOutConfig.IsOpen == 1 {
  3416. //
  3417. // //查询今日耗材出库数量
  3418. // hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3419. //
  3420. // for _, item := range hisgoodlist {
  3421. //
  3422. // //查询历史出库数据
  3423. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3424. // var out_count_five int64
  3425. // for _, item := range flowGood {
  3426. // out_count_five += item.Count
  3427. // }
  3428. //
  3429. // parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3430. //
  3431. // if out_count_five != parseIntCount {
  3432. //
  3433. // //查询耗材最后一次出库记录
  3434. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3435. // //查询默认出库仓库库存
  3436. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3437. // if len(wareOut) > 0 {
  3438. //
  3439. // for _, it := range wareOut {
  3440. // //回退库存
  3441. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3442. //
  3443. // //删除出库记录
  3444. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3445. //
  3446. // }
  3447. // }
  3448. //
  3449. // timeStr := time.Now().Format("2006-01-02")
  3450. // timeArr := strings.Split(timeStr, "-")
  3451. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3452. //
  3453. // total = total + 1
  3454. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3455. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3456. // number = number + total
  3457. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3458. //
  3459. // operation_time := time.Now().Unix()
  3460. // creater := c.GetAdminUserInfo().AdminUser.Id
  3461. //
  3462. // recordDateStr := time.Now().Format("2006-01-02")
  3463. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3464. // nowtime := recordDate.Unix()
  3465. // warehouseOut := models.WarehouseOut{
  3466. // WarehouseOutOrderNumber: warehousing_out_order,
  3467. // OperationTime: operation_time,
  3468. // OrgId: adminInfo.CurrentOrgId,
  3469. // Creater: creater,
  3470. // Ctime: time.Now().Unix(),
  3471. // Status: 1,
  3472. // WarehouseOutTime: nowtime,
  3473. // Type: 1,
  3474. // StorehouseId: storeConfig.StorehouseOutInfo,
  3475. // IsCheck: 1,
  3476. // IsSys: 1,
  3477. // }
  3478. // //查询是否生成出库单
  3479. // out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3480. //
  3481. // if out.ID == 0 {
  3482. // service.AddSigleWarehouseOut(&warehouseOut)
  3483. // }
  3484. //
  3485. // lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3486. //
  3487. // goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3488. // houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3489. //
  3490. // dialyPrepareOne := models.DialysisBeforePrepare{
  3491. // GoodTypeId: goodObj.GoodTypeId,
  3492. // GoodId: item.ProjectId,
  3493. // PatientId: item.PatientId,
  3494. // RecordDate: item.RecordDate,
  3495. // UserOrgId: adminInfo.CurrentOrgId,
  3496. // Count: parseIntCount,
  3497. // Ctime: time.Now().Unix(),
  3498. // Creater: creater,
  3499. // Status: 1,
  3500. // StorehouseId: houseConfig.StorehouseOutInfo,
  3501. // ProjectId: item.ID,
  3502. // }
  3503. // goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3504. // if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3505. //
  3506. // //查询历史出库数据
  3507. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3508. // var out_count int64
  3509. // for _, item := range flowGood {
  3510. // out_count += item.Count
  3511. // }
  3512. //
  3513. // //如果历史数和当前数据不想等才进行退库出库
  3514. // if out_count != parseIntCount {
  3515. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3516. //
  3517. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3518. // detail := models.AutomaticReduceDetail{
  3519. // WarehouseOutId: 0,
  3520. // WarehouseOutOrderNumber: "",
  3521. // PatientId: item.PatientId,
  3522. // Ctime: time.Now().Unix(),
  3523. // Mtime: 0,
  3524. // Status: 1,
  3525. // RecordTime: item.RecordDate,
  3526. // OrgId: item.UserOrgId,
  3527. // GoodId: item.ProjectId,
  3528. // GoodTypeId: 0,
  3529. // Count: parseIntCount,
  3530. // Type: 0,
  3531. // ProjectId: item.ID,
  3532. // StorehouseId: 0,
  3533. // }
  3534. //
  3535. // service.CreateAutoDetail(detail)
  3536. //
  3537. // //查询剩余库存
  3538. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3539. // var sum_count int64
  3540. // for _, item := range goodList {
  3541. // sum_count += item.StockCount
  3542. // }
  3543. //
  3544. // //更新剩余库存
  3545. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3546. //
  3547. // //耗材
  3548. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3549. // }
  3550. //
  3551. // }
  3552. //
  3553. // if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3554. // //查询历史出库数据
  3555. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3556. // var out_count int64
  3557. // for _, item := range flowGood {
  3558. // out_count += item.Count
  3559. // }
  3560. // //如果历史数和当前数据不想等才进行退库出库
  3561. // if out_count != parseIntCount {
  3562. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3563. //
  3564. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3565. // detail := models.AutomaticReduceDetail{
  3566. // WarehouseOutId: 0,
  3567. // WarehouseOutOrderNumber: "",
  3568. // PatientId: item.PatientId,
  3569. // Ctime: time.Now().Unix(),
  3570. // Mtime: 0,
  3571. // Status: 1,
  3572. // RecordTime: item.RecordDate,
  3573. // OrgId: item.UserOrgId,
  3574. // GoodId: item.ProjectId,
  3575. // GoodTypeId: 0,
  3576. // Count: parseIntCount,
  3577. // Type: 0,
  3578. // ProjectId: item.ID,
  3579. // StorehouseId: 0,
  3580. // }
  3581. //
  3582. // service.CreateAutoDetail(detail)
  3583. //
  3584. // //查询剩余库存
  3585. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3586. // var sum_count int64
  3587. // for _, item := range goodList {
  3588. // sum_count += item.StockCount
  3589. // }
  3590. //
  3591. // //更新剩余库存
  3592. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3593. //
  3594. // //耗材
  3595. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3596. // }
  3597. //
  3598. // }
  3599. //
  3600. // }
  3601. // }
  3602. //}
  3603. }
  3604. tx.Commit()
  3605. if err == nil {
  3606. c.ServeSuccessJSON(map[string]interface{}{
  3607. "msg": "保存成功",
  3608. })
  3609. return
  3610. } else {
  3611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3612. return
  3613. }
  3614. }
  3615. //func (c *HisApiController) EditHisPrescription() {
  3616. // record_date := c.GetString("record_date")
  3617. // patient_id, _ := c.GetInt64("patient_id")
  3618. // reg_type, _ := c.GetInt64("reg_type")
  3619. // //diagnose, _ := c.GetInt64("diagnose", 0)
  3620. // diagnose := c.GetString("diagnose")
  3621. // sick_type, _ := c.GetInt64("sick_type")
  3622. // sick_history := c.GetString("sick_history")
  3623. // doctor_id, _ := c.GetInt64("doctor", 0)
  3624. // department, _ := c.GetInt64("department", 0)
  3625. // his_patient_id, _ := c.GetInt64("his_patient_id")
  3626. // p_type, _ := c.GetInt64("p_type")
  3627. //
  3628. // dataBody := make(map[string]interface{}, 0)
  3629. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3630. // if err != nil {
  3631. // utils.ErrorLog(err.Error())
  3632. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3633. // return
  3634. // }
  3635. //
  3636. // timeLayout := "2006-01-02"
  3637. // loc, _ := time.LoadLocation("Local")
  3638. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3639. // if err != nil {
  3640. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3641. // return
  3642. // }
  3643. // adminInfo := c.GetAdminUserInfo()
  3644. // recordDateTime := theTime.Unix()
  3645. //
  3646. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3647. //
  3648. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3649. // var hpInfo models.HisPrescriptionInfo
  3650. // if info.ID == 0 {
  3651. // var randNum int
  3652. // randNum = rand.Intn(10000) + 1000
  3653. // timestamp := time.Now().Unix()
  3654. // tempTime := time.Unix(timestamp, 0)
  3655. // timeFormat := tempTime.Format("20060102150405")
  3656. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3657. //
  3658. // hpInfo = models.HisPrescriptionInfo{
  3659. // UserOrgId: adminInfo.CurrentOrgId,
  3660. // RecordDate: theTime.Unix(),
  3661. // PatientId: patient_id,
  3662. // Status: 1,
  3663. // Ctime: time.Now().Unix(),
  3664. // Mtime: time.Now().Unix(),
  3665. // Creator: adminInfo.AdminUser.Id,
  3666. // Modifier: adminInfo.AdminUser.Id,
  3667. // Diagnosis: diagnose,
  3668. // SickHistory: sick_history,
  3669. // Departments: department,
  3670. // RegisterType: reg_type,
  3671. // PrescriptionNumber: p_number,
  3672. // PrescriptionStatus: 1,
  3673. // Doctor: role.UserName,
  3674. // DoctorId: doctor_id,
  3675. // SickType: sick_type,
  3676. // PType: p_type,
  3677. // }
  3678. // service.SavePatientPrescriptionInfo(hpInfo)
  3679. //
  3680. // } else {
  3681. // hpInfo = models.HisPrescriptionInfo{
  3682. // ID: info.ID,
  3683. // UserOrgId: adminInfo.CurrentOrgId,
  3684. // RecordDate: info.RecordDate,
  3685. // PatientId: info.PatientId,
  3686. // Status: 1,
  3687. // Ctime: info.Ctime,
  3688. // Mtime: time.Now().Unix(),
  3689. // Creator: info.Creator,
  3690. // Modifier: adminInfo.AdminUser.Id,
  3691. // Diagnosis: diagnose,
  3692. // SickHistory: sick_history,
  3693. // Departments: department,
  3694. // RegisterType: reg_type,
  3695. // PrescriptionNumber: info.PrescriptionNumber,
  3696. // Doctor: role.UserName,
  3697. // PrescriptionStatus: info.PrescriptionStatus,
  3698. // DoctorId: doctor_id,
  3699. // SickType: sick_type,
  3700. // PType: info.PType,
  3701. // }
  3702. // service.SavePatientPrescriptionInfo(hpInfo)
  3703. // }
  3704. //
  3705. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3706. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3707. //
  3708. // if len(prescriptions) > 0 {
  3709. // for _, item := range prescriptions {
  3710. // items := item.(map[string]interface{})
  3711. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3712. // utils.ErrorLog("id")
  3713. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3714. // return
  3715. // }
  3716. // id := int64(items["id"].(float64))
  3717. //
  3718. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3719. // utils.ErrorLog("type")
  3720. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3721. // return
  3722. // }
  3723. // types := int64(items["type"].(float64))
  3724. //
  3725. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3726. // utils.ErrorLog("med_type")
  3727. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3728. // return
  3729. // }
  3730. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3731. //
  3732. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3733. //
  3734. // ctime := time.Now().Unix()
  3735. //
  3736. // prescription := &models.HisPrescription{
  3737. // ID: id,
  3738. // PatientId: patient_id,
  3739. // UserOrgId: adminInfo.CurrentOrgId,
  3740. // RecordDate: recordDateTime,
  3741. // Ctime: ctime,
  3742. // Mtime: ctime,
  3743. // Type: types,
  3744. // Modifier: adminInfo.AdminUser.Id,
  3745. // Creator: adminInfo.AdminUser.Id,
  3746. // Status: 1,
  3747. // Doctor: role.UserName,
  3748. // HisPatientId: his_patient_id,
  3749. // OrderStatus: 1,
  3750. // BatchNumber: "",
  3751. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  3752. // PType: hpInfo.PType,
  3753. // MedType: med_type,
  3754. // }
  3755. //
  3756. // if historyPrescription.ID > 0 {
  3757. // prescription.PreTime = historyPrescription.PreTime
  3758. //
  3759. // }
  3760. //
  3761. // service.SaveHisPrescription(prescription)
  3762. //
  3763. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3764. // advices := items["advices"].([]interface{})
  3765. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3766. // groupNo := int64(0)
  3767. // ctime := time.Now().Unix()
  3768. // mtime := ctime
  3769. // if len(advices) > 0 {
  3770. // for _, advice := range advices {
  3771. // var s models.HisDoctorAdviceInfo
  3772. // s.PrescriptionId = prescription.ID
  3773. // s.AdviceType = 2
  3774. // s.AdviceDoctor = adminInfo.AdminUser.Id
  3775. // s.StopState = 2
  3776. // s.ExecutionState = 2
  3777. // s.AdviceDate = recordDateTime
  3778. // s.Status = 1
  3779. // s.UserOrgId = adminInfo.CurrentOrgId
  3780. // s.RecordDate = recordDateTime
  3781. // s.StartTime = prescription.PreTime
  3782. // s.Groupno = groupNo
  3783. // s.CreatedTime = ctime
  3784. // s.UpdatedTime = mtime
  3785. // s.PatientId = patient_id
  3786. // s.HisPatientId = his_patient_id
  3787. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3788. // if errcode > 0 {
  3789. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3790. // return
  3791. // }
  3792. //
  3793. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3794. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3795. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3796. // if s.Price == 0 {
  3797. // s.Price = lastWarehouse.RetailPrice
  3798. // }
  3799. // }
  3800. //
  3801. // service.CreateHisDoctorAdvice(&s)
  3802. // //记录日志
  3803. // byterequest, _ := json.Marshal(s)
  3804. // adviceLog := models.XtDoctorAdviceLog{
  3805. // UserOrgId: s.UserOrgId,
  3806. // PatientId: s.PatientId,
  3807. // AdminUserId: adminInfo.AdminUser.Id,
  3808. // Module: 1,
  3809. // ErrLog: string(byterequest),
  3810. // Status: 1,
  3811. // Ctime: time.Now().Unix(),
  3812. // Mtime: 0,
  3813. // Source: "电脑端his医嘱修改",
  3814. // RecordDate: s.AdviceDate,
  3815. // }
  3816. // service.CreateDoctorAdviceLog(adviceLog)
  3817. // redis := service.RedisClient()
  3818. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3819. // redis.Set(key, "", time.Second)
  3820. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3821. // fmt.Println("keyOne", keyOne)
  3822. // redis.Set(keyOne, "", time.Second)
  3823. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3824. // redis.Set(keySeven, "", time.Second)
  3825. // redis.Close()
  3826. //
  3827. // }
  3828. // }
  3829. // }
  3830. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3831. // projects := items["project"].([]interface{})
  3832. // if len(projects) > 0 {
  3833. // for _, project := range projects {
  3834. // var p models.HisPrescriptionProject
  3835. // p.PrescriptionId = prescription.ID
  3836. // p.Ctime = time.Now().Unix()
  3837. // p.Mtime = time.Now().Unix()
  3838. // p.PatientId = patient_id
  3839. // p.RecordDate = recordDateTime
  3840. // p.UserOrgId = adminInfo.CurrentOrgId
  3841. // p.HisPatientId = his_patient_id
  3842. // p.Status = 1
  3843. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3844. // if errcode > 0 {
  3845. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3846. // return
  3847. // }
  3848. // service.CreateHisProjectTwo(&p)
  3849. //
  3850. // //记录日志
  3851. // byterequest, _ := json.Marshal(p)
  3852. // adviceLog := models.XtDoctorAdviceLog{
  3853. // UserOrgId: p.UserOrgId,
  3854. // PatientId: p.PatientId,
  3855. // AdminUserId: adminInfo.AdminUser.Id,
  3856. // Module: 1,
  3857. // ErrLog: string(byterequest),
  3858. // Status: 1,
  3859. // Ctime: time.Now().Unix(),
  3860. // Mtime: 0,
  3861. // Source: "电脑端his项目修改",
  3862. // RecordDate: p.RecordDate,
  3863. // }
  3864. // service.CreateDoctorAdviceLog(adviceLog)
  3865. // }
  3866. // }
  3867. // }
  3868. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3869. // addition := items["addition"].([]interface{})
  3870. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3871. // ctime := time.Now().Unix()
  3872. // mtime := ctime
  3873. // if len(addition) > 0 {
  3874. // for _, item := range addition {
  3875. // var s models.HisAdditionalCharge
  3876. // s.PrescriptionId = prescription.ID
  3877. // s.Status = 1
  3878. // s.UserOrgId = adminInfo.CurrentOrgId
  3879. // s.RecordDate = recordDateTime
  3880. // s.CreatedTime = ctime
  3881. // s.UpdatedTime = mtime
  3882. // s.PatientId = patient_id
  3883. // s.HisPatientId = his_patient_id
  3884. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3885. // if errcode > 0 {
  3886. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3887. // return
  3888. // }
  3889. // service.CreateAdditionalCharge(&s)
  3890. // }
  3891. // }
  3892. // }
  3893. //
  3894. // }
  3895. // }
  3896. // }
  3897. // if err == nil {
  3898. // c.ServeSuccessJSON(map[string]interface{}{
  3899. // "msg": "保存成功",
  3900. // })
  3901. // return
  3902. //
  3903. // } else {
  3904. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3905. // return
  3906. // }
  3907. //}
  3908. func (c *HisApiController) DeletePrescription() {
  3909. prescription_id, _ := c.GetInt64("id")
  3910. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3911. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3912. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3913. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3914. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3915. //耗材保存处方出库
  3916. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3917. //已收费和已发药限制逻辑
  3918. isCharge := false
  3919. isMedicine := false
  3920. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3921. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3922. for _, item := range new_prescriptions {
  3923. if item.IsMedicine == 1 {
  3924. isMedicine = true
  3925. }
  3926. }
  3927. for _, item := range new_prescriptions {
  3928. if item.OrderStatus == 4 {
  3929. isCharge = true
  3930. }
  3931. }
  3932. if p_err != nil {
  3933. if new_prescription.ID > 0 {
  3934. if new_prescription.OrderStatus == 2 {
  3935. isCharge = true
  3936. }
  3937. }
  3938. }
  3939. for _, item := range advices {
  3940. if item.IsMedicine == 1 {
  3941. isMedicine = true
  3942. }
  3943. }
  3944. if isCharge {
  3945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3946. return
  3947. }
  3948. if isMedicine {
  3949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3950. return
  3951. }
  3952. //已收费和已发药限制逻辑
  3953. if len(projects) > 0 {
  3954. for _, item := range projects {
  3955. service.DeletePrintInfo(item.ID) //删除打印信息
  3956. if goodOutConfig.IsOpen != 1 {
  3957. if stockConfig.IsOpen == 1 {
  3958. if item.Type == 3 && item.IsOut == 1 {
  3959. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3960. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3961. good.Total = good.Total + f_count
  3962. service.UpdateGoodInfo(&good)
  3963. operation_time := time.Now().Unix()
  3964. creater := c.GetAdminUserInfo().AdminUser.Id
  3965. //创建退库单
  3966. timeStr := time.Now().Format("2006-01-02")
  3967. timeArr := strings.Split(timeStr, "-")
  3968. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3969. total = total + 1
  3970. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3971. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3972. cancelStock := models.CancelStock{
  3973. OrderNumber: orderNumber,
  3974. OperaTime: operation_time,
  3975. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3976. Creater: creater,
  3977. Ctime: time.Now().Unix(),
  3978. Status: 1,
  3979. ReturnTime: item.RecordDate,
  3980. Type: 1,
  3981. StorehouseId: houseConfig.StorehouseOutInfo,
  3982. IsCheck: 1,
  3983. }
  3984. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3985. if msgerrkonde == gorm.ErrRecordNotFound {
  3986. service.AddSigleCancelStock(&cancelStock)
  3987. }
  3988. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3989. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3990. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3991. //查询该耗材是否出库
  3992. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3993. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3994. deaerler, _ := service.GetDealerById(info.Dealer)
  3995. var total_count int64
  3996. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3997. total_count += count
  3998. if info.ID > 0 {
  3999. if info.Count >= total_count {
  4000. //回退库存
  4001. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4002. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4003. var flush_count int64
  4004. for _, it := range goodList {
  4005. flush_count += it.StockCount
  4006. }
  4007. cancelStockInfo := models.CancelStockInfo{
  4008. GoodId: item.ProjectId,
  4009. CancelStockId: cancel.ID,
  4010. GoodTypeId: good.GoodTypeId,
  4011. Count: prescribingNumber,
  4012. Price: info.Price,
  4013. Total: 0,
  4014. ProductDate: info.ProductDate,
  4015. ExpiryDate: info.ExpiryDate,
  4016. Ctime: time.Now().Unix(),
  4017. Status: 1,
  4018. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4019. OrderNumber: cancel.OrderNumber,
  4020. Type: 0,
  4021. Dealer: deaerler.DealerName,
  4022. Manufacturer: manufacturer.ManufacturerName,
  4023. Number: info.Number,
  4024. RegisterAccount: "",
  4025. Remark: "",
  4026. WarehouseInfoId: info.WarehouseInfotId,
  4027. PatientId: info.PatientId,
  4028. RecordDate: info.SysRecordTime,
  4029. StorehouseId: houseConfig.StorehouseOutInfo,
  4030. IsCheck: 1,
  4031. }
  4032. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4033. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4034. flow := models.VmStockFlow{
  4035. WarehousingId: info.WarehouseInfotId,
  4036. GoodId: item.ProjectId,
  4037. Number: info.Number,
  4038. LicenseNumber: info.LicenseNumber,
  4039. Count: prescribingNumber,
  4040. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4041. PatientId: item.PatientId,
  4042. SystemTime: info.SysRecordTime,
  4043. ConsumableType: 7,
  4044. IsSys: 0,
  4045. WarehousingOrder: "",
  4046. WarehouseOutId: info.WarehouseOutId,
  4047. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4048. IsEdit: 0,
  4049. CancelStockId: cancel.ID,
  4050. CancelOrderNumber: cancel.OrderNumber,
  4051. Manufacturer: manufacturer.ID,
  4052. Dealer: 0,
  4053. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4054. UpdateCreator: 0,
  4055. Status: 1,
  4056. Ctime: time.Now().Unix(),
  4057. Mtime: 0,
  4058. Price: info.Price,
  4059. WarehousingDetailId: info.WarehouseInfotId,
  4060. WarehouseOutDetailId: info.ID,
  4061. CancelOutDetailId: cancelInfo.ID,
  4062. ProductDate: info.ProductDate,
  4063. ExpireDate: info.ExpiryDate,
  4064. StorehouseId: houseConfig.StorehouseOutInfo,
  4065. OverCount: flush_count,
  4066. }
  4067. service.CreateStockFlowOne(flow)
  4068. //退库数量增加
  4069. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4070. //出库数量减少
  4071. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4072. }
  4073. if info.Count < total_count {
  4074. //回退库存
  4075. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4076. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4077. var flush_count int64
  4078. for _, it := range goodList {
  4079. flush_count += it.StockCount
  4080. }
  4081. cancelStockInfo := models.CancelStockInfo{
  4082. GoodId: item.ProjectId,
  4083. CancelStockId: cancel.ID,
  4084. GoodTypeId: good.GoodTypeId,
  4085. Count: info.Count,
  4086. Price: info.Price,
  4087. Total: 0,
  4088. ProductDate: info.ProductDate,
  4089. ExpiryDate: info.ExpiryDate,
  4090. Ctime: time.Now().Unix(),
  4091. Status: 1,
  4092. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4093. OrderNumber: cancel.OrderNumber,
  4094. Type: 0,
  4095. Dealer: deaerler.DealerName,
  4096. Manufacturer: manufacturer.ManufacturerName,
  4097. Number: info.Number,
  4098. RegisterAccount: "",
  4099. Remark: "",
  4100. WarehouseInfoId: info.WarehouseInfotId,
  4101. PatientId: info.PatientId,
  4102. RecordDate: info.SysRecordTime,
  4103. StorehouseId: houseConfig.StorehouseOutInfo,
  4104. IsCheck: 1,
  4105. }
  4106. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4107. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4108. flow := models.VmStockFlow{
  4109. WarehousingId: info.WarehouseInfotId,
  4110. GoodId: item.ProjectId,
  4111. Number: info.Number,
  4112. LicenseNumber: info.LicenseNumber,
  4113. Count: info.Count,
  4114. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4115. PatientId: item.PatientId,
  4116. SystemTime: info.SysRecordTime,
  4117. ConsumableType: 7,
  4118. IsSys: 0,
  4119. WarehousingOrder: "",
  4120. WarehouseOutId: info.WarehouseOutId,
  4121. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4122. IsEdit: 0,
  4123. CancelStockId: cancel.ID,
  4124. CancelOrderNumber: cancel.OrderNumber,
  4125. Manufacturer: manufacturer.ID,
  4126. Dealer: 0,
  4127. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4128. UpdateCreator: 0,
  4129. Status: 1,
  4130. Ctime: time.Now().Unix(),
  4131. Mtime: 0,
  4132. Price: info.Price,
  4133. WarehousingDetailId: info.WarehouseInfotId,
  4134. WarehouseOutDetailId: info.ID,
  4135. CancelOutDetailId: cancelInfo.ID,
  4136. ProductDate: info.ProductDate,
  4137. ExpireDate: info.ExpiryDate,
  4138. StorehouseId: houseConfig.StorehouseOutInfo,
  4139. OverCount: flush_count,
  4140. }
  4141. service.CreateStockFlowOne(flow)
  4142. //退库数量增加
  4143. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4144. //出库数量减少
  4145. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4146. }
  4147. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4148. var flush_count int64
  4149. for _, it := range goodList {
  4150. flush_count += it.StockCount
  4151. }
  4152. //查询已出库数量
  4153. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4154. if prescribingNumber < dialysisInfo.Count {
  4155. //改变数量
  4156. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4157. }
  4158. if prescribingNumber >= dialysisInfo.Count {
  4159. //删除出库表
  4160. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4161. }
  4162. //更新库存
  4163. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4164. //更新基础库库存
  4165. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4166. }
  4167. }
  4168. }
  4169. }
  4170. //保存耗材出库
  4171. if goodOutConfig.IsOpen == 1 {
  4172. if item.Type == 3 {
  4173. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4174. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4175. good.Total = good.Total + f_count
  4176. service.UpdateGoodInfo(&good)
  4177. operation_time := time.Now().Unix()
  4178. creater := c.GetAdminUserInfo().AdminUser.Id
  4179. //创建退库单
  4180. timeStr := time.Now().Format("2006-01-02")
  4181. timeArr := strings.Split(timeStr, "-")
  4182. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4183. total = total + 1
  4184. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4185. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4186. cancelStock := models.CancelStock{
  4187. OrderNumber: orderNumber,
  4188. OperaTime: operation_time,
  4189. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4190. Creater: creater,
  4191. Ctime: time.Now().Unix(),
  4192. Status: 1,
  4193. ReturnTime: item.RecordDate,
  4194. Type: 1,
  4195. StorehouseId: houseConfig.StorehouseOutInfo,
  4196. IsCheck: 1,
  4197. }
  4198. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4199. if msgerrkonde == gorm.ErrRecordNotFound {
  4200. service.AddSigleCancelStock(&cancelStock)
  4201. }
  4202. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4203. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4204. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4205. //查询该耗材是否出库
  4206. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4207. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4208. deaerler, _ := service.GetDealerById(info.Dealer)
  4209. var total_count int64
  4210. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4211. total_count += count
  4212. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4213. var flush_count int64
  4214. for _, it := range goodList {
  4215. flush_count += it.StockCount
  4216. }
  4217. fmt.Println("历史出库数据", info.Count)
  4218. fmt.Println("出库数量", total_count)
  4219. if info.ID > 0 {
  4220. cancelStockInfo := models.CancelStockInfo{
  4221. GoodId: item.ProjectId,
  4222. CancelStockId: cancel.ID,
  4223. GoodTypeId: good.GoodTypeId,
  4224. Count: prescribingNumber,
  4225. Price: info.Price,
  4226. Total: 0,
  4227. ProductDate: info.ProductDate,
  4228. ExpiryDate: info.ExpiryDate,
  4229. Ctime: time.Now().Unix(),
  4230. Status: 1,
  4231. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4232. OrderNumber: cancel.OrderNumber,
  4233. Type: 0,
  4234. Dealer: deaerler.DealerName,
  4235. Manufacturer: manufacturer.ManufacturerName,
  4236. Number: info.Number,
  4237. RegisterAccount: "",
  4238. Remark: "",
  4239. WarehouseInfoId: info.WarehouseInfotId,
  4240. PatientId: info.PatientId,
  4241. RecordDate: info.SysRecordTime,
  4242. StorehouseId: houseConfig.StorehouseOutInfo,
  4243. IsCheck: 1,
  4244. }
  4245. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4246. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4247. //查询出库数量
  4248. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4249. //出库数据 大于 退库数量
  4250. if len(list) > 0 {
  4251. for _, it := range list {
  4252. //回退库存
  4253. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4254. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4255. var flush_count_one int64
  4256. for _, it := range goodList {
  4257. flush_count_one += it.StockCount
  4258. }
  4259. //查询该批次是否有退库数据
  4260. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4261. creater := c.GetAdminUserInfo().AdminUser.Id
  4262. flow := models.VmStockFlow{
  4263. WarehousingId: it.WarehouseInfotId,
  4264. GoodId: it.GoodId,
  4265. Number: it.Number,
  4266. LicenseNumber: it.LicenseNumber,
  4267. Count: it.Count,
  4268. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4269. PatientId: it.PatientId,
  4270. SystemTime: it.SysRecordTime,
  4271. ConsumableType: 7,
  4272. IsSys: 0,
  4273. WarehousingOrder: "",
  4274. WarehouseOutId: it.WarehouseOutId,
  4275. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4276. IsEdit: 0,
  4277. CancelStockId: cancel.ID,
  4278. CancelOrderNumber: cancel.OrderNumber,
  4279. Manufacturer: manufacturer.ID,
  4280. Dealer: 0,
  4281. Creator: creater,
  4282. UpdateCreator: 0,
  4283. Status: 1,
  4284. Ctime: time.Now().Unix(),
  4285. Mtime: 0,
  4286. Price: it.Price,
  4287. WarehousingDetailId: it.WarehouseInfotId,
  4288. WarehouseOutDetailId: it.ID,
  4289. CancelOutDetailId: cancelInfo.ID,
  4290. ProductDate: it.ProductDate,
  4291. ExpireDate: it.ExpiryDate,
  4292. StorehouseId: houseConfig.StorehouseOutInfo,
  4293. OverCount: flush_count_one,
  4294. }
  4295. service.CreateStockFlowOne(flow)
  4296. //if flow.ID > 0 {
  4297. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  4298. //}
  4299. }
  4300. }
  4301. //flow := models.VmStockFlow{
  4302. // WarehousingId: info.WarehouseInfotId,
  4303. // GoodId: item.ProjectId,
  4304. // Number: info.Number,
  4305. // LicenseNumber: info.LicenseNumber,
  4306. // Count: prescribingNumber,
  4307. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4308. // PatientId: item.PatientId,
  4309. // SystemTime: info.SysRecordTime,
  4310. // ConsumableType: 7,
  4311. // IsSys: 0,
  4312. // WarehousingOrder: "",
  4313. // WarehouseOutId: info.WarehouseOutId,
  4314. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4315. // IsEdit: 0,
  4316. // CancelStockId: cancel.ID,
  4317. // CancelOrderNumber: cancel.OrderNumber,
  4318. // Manufacturer: manufacturer.ID,
  4319. // Dealer: 0,
  4320. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  4321. // UpdateCreator: 0,
  4322. // Status: 1,
  4323. // Ctime: time.Now().Unix(),
  4324. // Mtime: 0,
  4325. // Price: info.Price,
  4326. // WarehousingDetailId: info.WarehouseInfotId,
  4327. // WarehouseOutDetailId: info.ID,
  4328. // CancelOutDetailId: cancelInfo.ID,
  4329. // ProductDate: info.ProductDate,
  4330. // ExpireDate: info.ExpiryDate,
  4331. // StorehouseId: houseConfig.StorehouseOutInfo,
  4332. // OverCount: flush_count,
  4333. //}
  4334. //service.CreateStockFlowOne(flow)
  4335. //退库数量增加
  4336. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4337. //出库数量减少
  4338. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4339. //查询已出库数量
  4340. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4341. if prescribingNumber < dialysisInfo.Count {
  4342. //改变数量
  4343. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4344. }
  4345. if prescribingNumber >= dialysisInfo.Count {
  4346. //删除出库表
  4347. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4348. }
  4349. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4350. var flush_count_one int64
  4351. for _, it := range goodList {
  4352. flush_count_one += it.StockCount
  4353. }
  4354. //更新库存
  4355. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4356. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4357. //更新基础库库存
  4358. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4359. }
  4360. }
  4361. }
  4362. }
  4363. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4364. fmt.Println(err)
  4365. }
  4366. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4367. fmt.Println(err)
  4368. if len(advices) > 0 {
  4369. for _, item := range advices {
  4370. redis := service.RedisClient()
  4371. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4372. redis.Set(keyFive, "", time.Second)
  4373. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4374. redis.Set(keyOne, "", time.Second)
  4375. redis.Close()
  4376. }
  4377. }
  4378. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4379. if len(advices) > 0 {
  4380. for _, item := range advices {
  4381. creater := c.GetAdminUserInfo().AdminUser.Id
  4382. service.DrugAutoAddCancelInfo(item, creater)
  4383. }
  4384. }
  4385. } else {
  4386. if drugOutConfig.IsOpen == 1 {
  4387. if len(advices) > 0 {
  4388. for _, item := range advices {
  4389. creater := c.GetAdminUserInfo().AdminUser.Id
  4390. service.DrugAutoAddCancelInfo(item, creater)
  4391. }
  4392. }
  4393. } else {
  4394. if len(advices) > 0 {
  4395. for _, item := range advices {
  4396. creater := c.GetAdminUserInfo().AdminUser.Id
  4397. service.DrugAutoAddCancelInfo(item, creater)
  4398. }
  4399. }
  4400. }
  4401. }
  4402. c.ServeSuccessJSON(map[string]interface{}{
  4403. "msg": "删除成功",
  4404. })
  4405. return
  4406. }
  4407. func (c *HisApiController) DeleteDoctorAdvice() {
  4408. id, _ := c.GetInt64("id")
  4409. advice, _ := service.GetHisDoctorAdvicesById(id)
  4410. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4411. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4412. //已收费和已发药的限制逻辑
  4413. isCharge := false
  4414. isMedicine := false
  4415. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4416. //获取今天该患者所有处方,判断是否发药或者收费
  4417. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4418. for _, item := range new_prescriptions {
  4419. if item.IsMedicine == 1 {
  4420. isMedicine = true
  4421. }
  4422. }
  4423. for _, item := range new_prescriptions {
  4424. if item.OrderStatus == 4 {
  4425. isCharge = true
  4426. }
  4427. }
  4428. if isMedicine {
  4429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4430. return
  4431. }
  4432. if isCharge {
  4433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4434. return
  4435. }
  4436. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  4437. for _, item := range advices {
  4438. if item.IsMedicine == 1 {
  4439. isMedicine = true
  4440. }
  4441. }
  4442. if isMedicine {
  4443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  4444. return
  4445. }
  4446. if new_prescription.ID > 0 {
  4447. if new_prescription.OrderStatus == 2 {
  4448. isCharge = true
  4449. }
  4450. }
  4451. if isCharge {
  4452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4453. return
  4454. }
  4455. //已收费和已发药的限制逻辑
  4456. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  4457. redis := service.RedisClient()
  4458. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  4459. redis.Set(keyFive, "", time.Second)
  4460. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  4461. redis.Set(keyOne, "", time.Second)
  4462. defer redis.Close()
  4463. if err == nil {
  4464. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4465. //查询是否在处方中出库
  4466. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4467. if openConfig.IsOpen != 1 {
  4468. //判断该医嘱是否执行了
  4469. if advice.ExecutionState == 1 {
  4470. creater := c.GetAdminUserInfo().AdminUser.Id
  4471. service.DrugAutoAddCancelInfo(&advice, creater)
  4472. }
  4473. }
  4474. //开启保存处方扣减功能
  4475. if openConfig.IsOpen == 1 {
  4476. creater := c.GetAdminUserInfo().AdminUser.Id
  4477. service.DrugAutoAddCancelInfo(&advice, creater)
  4478. }
  4479. } else {
  4480. if drugOutConfig.IsOpen == 1 {
  4481. //查询是否在处方中出库
  4482. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4483. if openConfig.IsOpen != 1 {
  4484. //判断该医嘱是否执行了
  4485. if advice.ExecutionState == 1 {
  4486. creater := c.GetAdminUserInfo().AdminUser.Id
  4487. service.DrugAutoAddCancelInfo(&advice, creater)
  4488. }
  4489. }
  4490. //开启保存处方扣减功能
  4491. if openConfig.IsOpen == 1 {
  4492. creater := c.GetAdminUserInfo().AdminUser.Id
  4493. service.DrugAutoAddCancelInfo(&advice, creater)
  4494. }
  4495. } else {
  4496. //判断该医嘱是否执行了
  4497. if advice.ExecutionState == 1 {
  4498. creater := c.GetAdminUserInfo().AdminUser.Id
  4499. service.DrugAutoAddCancelInfo(&advice, creater)
  4500. }
  4501. }
  4502. }
  4503. c.ServeSuccessJSON(map[string]interface{}{
  4504. "msg": "删除成功",
  4505. })
  4506. return
  4507. } else {
  4508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4509. return
  4510. }
  4511. }
  4512. func (c *HisApiController) DeleteProject() {
  4513. id, _ := c.GetInt64("id")
  4514. adminInfo := c.GetAdminUserInfo()
  4515. project, _ := service.GetHisProjectByID(id)
  4516. // var consumable models.DialysisBeforePrepare
  4517. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4518. //耗材保存处方出库
  4519. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4520. isCharge := false
  4521. isMedicine := false
  4522. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4523. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4524. for _, item := range new_prescriptions {
  4525. if item.IsMedicine == 1 {
  4526. isMedicine = true
  4527. }
  4528. }
  4529. for _, item := range new_prescriptions {
  4530. if item.OrderStatus == 4 {
  4531. isCharge = true
  4532. }
  4533. }
  4534. if isMedicine {
  4535. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4536. return
  4537. }
  4538. if isCharge {
  4539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4540. return
  4541. }
  4542. if new_prescription.ID > 0 {
  4543. if new_prescription.OrderStatus == 2 {
  4544. isCharge = true
  4545. }
  4546. }
  4547. if isCharge {
  4548. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4549. return
  4550. }
  4551. service.DeletePrintInfo(id)
  4552. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4553. label.Status = 0
  4554. service.CreateHisLabelRecordTwo(&label)
  4555. fmt.Println(goodOutConfig.IsOpen)
  4556. if goodOutConfig.IsOpen != 1 {
  4557. if stockConfig.IsOpen == 1 {
  4558. if project.Type == 2 {
  4559. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4560. fmt.Println(err)
  4561. }
  4562. if project.Type == 3 && project.IsOut == 1 {
  4563. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4564. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4565. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4566. operation_time := time.Now().Unix()
  4567. creater := adminInfo.AdminUser.Id
  4568. //创建退库单
  4569. timeStr := time.Now().Format("2006-01-02")
  4570. timeArr := strings.Split(timeStr, "-")
  4571. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4572. total = total + 1
  4573. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4574. cancelStock := models.CancelStock{
  4575. OrderNumber: orderNumber,
  4576. OperaTime: operation_time,
  4577. OrgId: adminInfo.CurrentOrgId,
  4578. Creater: creater,
  4579. Ctime: time.Now().Unix(),
  4580. Status: 1,
  4581. ReturnTime: project.RecordDate,
  4582. Type: 1,
  4583. StorehouseId: houseConfig.StorehouseOutInfo,
  4584. IsCheck: 1,
  4585. }
  4586. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4587. if msgerrkonde == gorm.ErrRecordNotFound {
  4588. service.AddSigleCancelStock(&cancelStock)
  4589. }
  4590. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4591. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4592. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4593. //查询是否有出库
  4594. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4595. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4596. deaerler, _ := service.GetDealerById(info.Dealer)
  4597. if info.ID > 0 {
  4598. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4599. if info.Count >= prescribingNumber {
  4600. cancelStockInfo := models.CancelStockInfo{
  4601. GoodId: project.ProjectId,
  4602. CancelStockId: cancel.ID,
  4603. GoodTypeId: good.GoodTypeId,
  4604. Count: prescribingNumber,
  4605. Price: info.Price,
  4606. Total: 0,
  4607. ProductDate: info.ProductDate,
  4608. ExpiryDate: info.ExpiryDate,
  4609. Ctime: time.Now().Unix(),
  4610. Status: 1,
  4611. OrgId: adminInfo.CurrentOrgId,
  4612. OrderNumber: cancel.OrderNumber,
  4613. Type: 0,
  4614. Dealer: deaerler.DealerName,
  4615. Manufacturer: manufacturer.ManufacturerName,
  4616. Number: info.Number,
  4617. RegisterAccount: "",
  4618. Remark: "",
  4619. WarehouseInfoId: info.WarehouseInfotId,
  4620. PatientId: info.PatientId,
  4621. RecordDate: info.SysRecordTime,
  4622. StorehouseId: houseConfig.StorehouseOutInfo,
  4623. IsCheck: 1,
  4624. }
  4625. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4626. //回退库存
  4627. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4628. //退库数量增加
  4629. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4630. //出库数量减少
  4631. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4632. }
  4633. if info.Count < prescribingNumber {
  4634. cancelStockInfo := models.CancelStockInfo{
  4635. GoodId: project.ProjectId,
  4636. CancelStockId: cancel.ID,
  4637. GoodTypeId: good.GoodTypeId,
  4638. Count: info.Count,
  4639. Price: info.Price,
  4640. Total: 0,
  4641. ProductDate: info.ProductDate,
  4642. ExpiryDate: info.ExpiryDate,
  4643. Ctime: time.Now().Unix(),
  4644. Status: 1,
  4645. OrgId: adminInfo.CurrentOrgId,
  4646. OrderNumber: cancel.OrderNumber,
  4647. Type: 0,
  4648. Dealer: deaerler.DealerName,
  4649. Manufacturer: manufacturer.ManufacturerName,
  4650. Number: info.Number,
  4651. RegisterAccount: "",
  4652. Remark: "",
  4653. WarehouseInfoId: info.WarehouseInfotId,
  4654. PatientId: info.PatientId,
  4655. RecordDate: info.SysRecordTime,
  4656. StorehouseId: houseConfig.StorehouseOutInfo,
  4657. IsCheck: 1,
  4658. }
  4659. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4660. //回退库存
  4661. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4662. //退库数量增加
  4663. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4664. //出库数量减少
  4665. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4666. }
  4667. //查询剩余库存
  4668. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4669. var over_count int64
  4670. for _, it := range goodList {
  4671. over_count += it.StockCount
  4672. }
  4673. //出库数据 大于 退库数量
  4674. if info.Count >= prescribingNumber {
  4675. flow := models.VmStockFlow{
  4676. WarehousingId: info.WarehouseInfotId,
  4677. GoodId: project.ProjectId,
  4678. Number: info.Number,
  4679. LicenseNumber: info.LicenseNumber,
  4680. Count: prescribingNumber,
  4681. UserOrgId: adminInfo.CurrentOrgId,
  4682. PatientId: project.PatientId,
  4683. SystemTime: info.SysRecordTime,
  4684. ConsumableType: 7,
  4685. IsSys: 0,
  4686. WarehousingOrder: "",
  4687. WarehouseOutId: info.WarehouseOutId,
  4688. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4689. IsEdit: 0,
  4690. CancelStockId: cancel.ID,
  4691. CancelOrderNumber: cancel.OrderNumber,
  4692. Manufacturer: manufacturer.ID,
  4693. Dealer: 0,
  4694. Creator: adminInfo.AdminUser.Id,
  4695. UpdateCreator: 0,
  4696. Status: 1,
  4697. Ctime: time.Now().Unix(),
  4698. Mtime: 0,
  4699. Price: info.Price,
  4700. WarehousingDetailId: info.WarehouseInfotId,
  4701. WarehouseOutDetailId: info.ID,
  4702. CancelOutDetailId: cancelInfo.ID,
  4703. ProductDate: info.ProductDate,
  4704. ExpireDate: info.ExpiryDate,
  4705. StorehouseId: houseConfig.StorehouseOutInfo,
  4706. OverCount: over_count,
  4707. }
  4708. service.CreateStockFlowOne(flow)
  4709. }
  4710. //出库数据小于退库数据
  4711. if info.Count < prescribingNumber {
  4712. flow := models.VmStockFlow{
  4713. WarehousingId: info.WarehouseInfotId,
  4714. GoodId: project.ProjectId,
  4715. Number: info.Number,
  4716. LicenseNumber: info.LicenseNumber,
  4717. Count: info.Count,
  4718. UserOrgId: adminInfo.CurrentOrgId,
  4719. PatientId: project.PatientId,
  4720. SystemTime: info.SysRecordTime,
  4721. ConsumableType: 7,
  4722. IsSys: 0,
  4723. WarehousingOrder: "",
  4724. WarehouseOutId: info.WarehouseOutId,
  4725. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4726. IsEdit: 0,
  4727. CancelStockId: cancel.ID,
  4728. CancelOrderNumber: cancel.OrderNumber,
  4729. Manufacturer: manufacturer.ID,
  4730. Dealer: 0,
  4731. Creator: adminInfo.AdminUser.Id,
  4732. UpdateCreator: 0,
  4733. Status: 1,
  4734. Ctime: time.Now().Unix(),
  4735. Mtime: 0,
  4736. Price: info.Price,
  4737. WarehousingDetailId: info.WarehouseInfotId,
  4738. WarehouseOutDetailId: info.ID,
  4739. CancelOutDetailId: cancelInfo.ID,
  4740. ProductDate: info.ProductDate,
  4741. ExpireDate: info.ExpiryDate,
  4742. StorehouseId: houseConfig.StorehouseOutInfo,
  4743. OverCount: over_count,
  4744. }
  4745. service.CreateStockFlowOne(flow)
  4746. }
  4747. //查询已出库数量
  4748. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4749. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4750. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4751. if prescribingNumber < dialysisInfo.Count {
  4752. //改变数量
  4753. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4754. }
  4755. if prescribingNumber >= dialysisInfo.Count {
  4756. //删除出库表
  4757. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4758. }
  4759. //更新剩余库存
  4760. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4761. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4762. var total_count_one int64
  4763. for _, it := range stockList {
  4764. total_count_one += it.StockCount
  4765. }
  4766. //基础库插入数据
  4767. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4768. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4769. var flush_count int64
  4770. for _, it := range goodListOne {
  4771. flush_count += it.StockCount
  4772. }
  4773. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4774. if errs != nil {
  4775. goodErrcode := models.XtGoodErrcode{
  4776. UserOrgId: project.UserOrgId,
  4777. Errcode: "手动出库更新剩余出库失败",
  4778. GoodId: project.ProjectId,
  4779. Status: 1,
  4780. Ctime: time.Now().Unix(),
  4781. Mtime: 0,
  4782. Count: 0,
  4783. StockCount: 0,
  4784. Creater: creater,
  4785. BatchNumberId: 0,
  4786. WarehouseOutId: 0,
  4787. }
  4788. service.CreateGoodErrcode(goodErrcode)
  4789. }
  4790. }
  4791. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4792. fmt.Println(err)
  4793. } else {
  4794. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4795. fmt.Println(err)
  4796. }
  4797. } else {
  4798. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4799. fmt.Println(err)
  4800. }
  4801. }
  4802. //保存处方出库
  4803. if goodOutConfig.IsOpen == 1 {
  4804. if project.Type == 3 {
  4805. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4806. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4807. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4808. operation_time := time.Now().Unix()
  4809. creater := adminInfo.AdminUser.Id
  4810. //创建退库单
  4811. timeStr := time.Now().Format("2006-01-02")
  4812. timeArr := strings.Split(timeStr, "-")
  4813. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4814. total = total + 1
  4815. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4816. cancelStock := models.CancelStock{
  4817. OrderNumber: orderNumber,
  4818. OperaTime: operation_time,
  4819. OrgId: adminInfo.CurrentOrgId,
  4820. Creater: creater,
  4821. Ctime: time.Now().Unix(),
  4822. Status: 1,
  4823. ReturnTime: project.RecordDate,
  4824. Type: 1,
  4825. StorehouseId: houseConfig.StorehouseOutInfo,
  4826. IsCheck: 1,
  4827. }
  4828. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4829. if msgerrkonde == gorm.ErrRecordNotFound {
  4830. service.AddSigleCancelStock(&cancelStock)
  4831. }
  4832. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4833. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4834. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4835. //获取出库数据
  4836. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4837. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4838. deaerler, _ := service.GetDealerById(info.Dealer)
  4839. if info.ID > 0 {
  4840. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4841. if info.Count >= prescribingNumber {
  4842. cancelStockInfo := models.CancelStockInfo{
  4843. GoodId: project.ProjectId,
  4844. CancelStockId: cancel.ID,
  4845. GoodTypeId: good.GoodTypeId,
  4846. Count: prescribingNumber,
  4847. Price: info.Price,
  4848. Total: 0,
  4849. ProductDate: info.ProductDate,
  4850. ExpiryDate: info.ExpiryDate,
  4851. Ctime: time.Now().Unix(),
  4852. Status: 1,
  4853. OrgId: adminInfo.CurrentOrgId,
  4854. OrderNumber: cancel.OrderNumber,
  4855. Type: 0,
  4856. Dealer: deaerler.DealerName,
  4857. Manufacturer: manufacturer.ManufacturerName,
  4858. Number: info.Number,
  4859. RegisterAccount: "",
  4860. Remark: "",
  4861. WarehouseInfoId: info.WarehouseInfotId,
  4862. PatientId: info.PatientId,
  4863. RecordDate: info.SysRecordTime,
  4864. StorehouseId: houseConfig.StorehouseOutInfo,
  4865. IsCheck: 1,
  4866. }
  4867. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4868. //退库数量增加
  4869. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4870. //出库数量减少
  4871. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4872. }
  4873. if info.Count < prescribingNumber {
  4874. cancelStockInfo := models.CancelStockInfo{
  4875. GoodId: project.ProjectId,
  4876. CancelStockId: cancel.ID,
  4877. GoodTypeId: good.GoodTypeId,
  4878. Count: prescribingNumber,
  4879. Price: info.Price,
  4880. Total: 0,
  4881. ProductDate: info.ProductDate,
  4882. ExpiryDate: info.ExpiryDate,
  4883. Ctime: time.Now().Unix(),
  4884. Status: 1,
  4885. OrgId: adminInfo.CurrentOrgId,
  4886. OrderNumber: cancel.OrderNumber,
  4887. Type: 0,
  4888. Dealer: deaerler.DealerName,
  4889. Manufacturer: manufacturer.ManufacturerName,
  4890. Number: info.Number,
  4891. RegisterAccount: "",
  4892. Remark: "",
  4893. WarehouseInfoId: info.WarehouseInfotId,
  4894. PatientId: info.PatientId,
  4895. RecordDate: info.SysRecordTime,
  4896. StorehouseId: houseConfig.StorehouseOutInfo,
  4897. IsCheck: 1,
  4898. }
  4899. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4900. //回退库存
  4901. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4902. }
  4903. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4904. var over_count int64
  4905. for _, it := range goodList {
  4906. over_count += it.StockCount
  4907. }
  4908. //查询出库数量
  4909. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4910. //出库数据 大于 退库数量
  4911. if len(list) > 0 {
  4912. for _, it := range list {
  4913. //回退库存
  4914. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4915. //退库数量增加
  4916. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4917. //出库数量减少
  4918. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4919. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4920. var over_count_one int64
  4921. for _, it := range goodList {
  4922. over_count_one += it.StockCount
  4923. }
  4924. //查询该批次是否有退库数据
  4925. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4926. flow := models.VmStockFlow{
  4927. WarehousingId: it.WarehouseInfotId,
  4928. GoodId: it.GoodId,
  4929. Number: it.Number,
  4930. LicenseNumber: it.LicenseNumber,
  4931. Count: it.Count,
  4932. UserOrgId: adminInfo.CurrentOrgId,
  4933. PatientId: it.PatientId,
  4934. SystemTime: it.SysRecordTime,
  4935. ConsumableType: 7,
  4936. IsSys: 0,
  4937. WarehousingOrder: "",
  4938. WarehouseOutId: it.WarehouseOutId,
  4939. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4940. IsEdit: 0,
  4941. CancelStockId: cancel.ID,
  4942. CancelOrderNumber: cancel.OrderNumber,
  4943. Manufacturer: manufacturer.ID,
  4944. Dealer: 0,
  4945. Creator: adminInfo.AdminUser.Id,
  4946. UpdateCreator: 0,
  4947. Status: 1,
  4948. Ctime: time.Now().Unix(),
  4949. Mtime: 0,
  4950. Price: it.Price,
  4951. WarehousingDetailId: it.WarehouseInfotId,
  4952. WarehouseOutDetailId: it.ID,
  4953. CancelOutDetailId: cancelInfo.ID,
  4954. ProductDate: it.ProductDate,
  4955. ExpireDate: it.ExpiryDate,
  4956. StorehouseId: houseConfig.StorehouseOutInfo,
  4957. OverCount: over_count_one,
  4958. }
  4959. service.CreateStockFlowOne(flow)
  4960. }
  4961. }
  4962. //查询已出库数量
  4963. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4964. if prescribingNumber < dialysisInfo.Count {
  4965. //改变数量
  4966. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4967. }
  4968. if prescribingNumber >= dialysisInfo.Count {
  4969. //删除出库表
  4970. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4971. }
  4972. //更新剩余库存
  4973. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4974. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4975. var total_count_one int64
  4976. for _, it := range stockList {
  4977. total_count_one += it.StockCount
  4978. }
  4979. //基础库插入数据
  4980. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4981. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4982. var flush_count int64
  4983. for _, it := range goodListOne {
  4984. flush_count += it.StockCount
  4985. }
  4986. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4987. if errs != nil {
  4988. goodErrcode := models.XtGoodErrcode{
  4989. UserOrgId: project.UserOrgId,
  4990. Errcode: "手动出库更新剩余出库失败",
  4991. GoodId: project.ProjectId,
  4992. Status: 1,
  4993. Ctime: time.Now().Unix(),
  4994. Mtime: 0,
  4995. Count: 0,
  4996. StockCount: 0,
  4997. Creater: creater,
  4998. BatchNumberId: 0,
  4999. WarehouseOutId: 0,
  5000. }
  5001. service.CreateGoodErrcode(goodErrcode)
  5002. }
  5003. }
  5004. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5005. fmt.Println(err)
  5006. } else {
  5007. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5008. fmt.Println(err)
  5009. }
  5010. }
  5011. c.ServeSuccessJSON(map[string]interface{}{
  5012. "msg": "删除成功",
  5013. })
  5014. return
  5015. }
  5016. func (c *HisApiController) CreateHisAdditionalCharge() {
  5017. his_patient_id, _ := c.GetInt64("his_patient_id")
  5018. patient_id, _ := c.GetInt64("patient_id")
  5019. record_date := c.GetString("record_date")
  5020. timeLayout := "2006-01-02"
  5021. loc, _ := time.LoadLocation("Local")
  5022. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5023. if err != nil {
  5024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5025. return
  5026. }
  5027. adminInfo := c.GetAdminUserInfo()
  5028. recordDateTime := theTime.Unix()
  5029. dataBody := make(map[string]interface{}, 0)
  5030. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5031. if err != nil {
  5032. utils.ErrorLog(err.Error())
  5033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5034. return
  5035. }
  5036. var additions []*models.HisAdditionalCharge
  5037. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5038. additions, _ := dataBody["addition"].([]interface{})
  5039. if len(additions) > 0 {
  5040. for _, item := range additions {
  5041. items := item.(map[string]interface{})
  5042. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5043. utils.ErrorLog("item_id")
  5044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5045. return
  5046. }
  5047. item_id := int64(items["item_id"].(float64))
  5048. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5049. utils.ErrorLog("item_name")
  5050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5051. return
  5052. }
  5053. item_name := items["item_name"].(string)
  5054. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5055. utils.ErrorLog("price")
  5056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5057. return
  5058. }
  5059. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5060. ctime := time.Now().Unix()
  5061. additional := &models.HisAdditionalCharge{
  5062. PatientId: patient_id,
  5063. HisPatientId: his_patient_id,
  5064. UserOrgId: adminInfo.CurrentOrgId,
  5065. RecordDate: recordDateTime,
  5066. CreatedTime: ctime,
  5067. UpdatedTime: ctime,
  5068. Modifier: adminInfo.AdminUser.Id,
  5069. Creator: adminInfo.AdminUser.Id,
  5070. Price: price,
  5071. ItemName: item_name,
  5072. ItemId: item_id,
  5073. Status: 1,
  5074. }
  5075. additions = append(additions, additional)
  5076. }
  5077. }
  5078. }
  5079. for _, item := range additions {
  5080. service.CreateAddtionalCharge(item)
  5081. }
  5082. c.ServeSuccessJSON(map[string]interface{}{
  5083. "msg": "创建成功",
  5084. })
  5085. }
  5086. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5087. blood_fat := c.GetString("blood_fat")
  5088. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5089. blood_sugar := c.GetString("blood_sugar")
  5090. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5091. chief_conplaint := c.GetString("chief_conplaint")
  5092. dbp := c.GetString("dbp")
  5093. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5094. delivery_way, _ := c.GetInt64("delivery_way")
  5095. diagnostic := c.GetString("diagnostic")
  5096. family_history := c.GetString("family_history")
  5097. height := c.GetString("height")
  5098. history_of_present_illness := c.GetString("history_of_present_illness")
  5099. is_infect, _ := c.GetInt64("is_infect")
  5100. past_history := c.GetString("past_history")
  5101. patient_id, _ := c.GetInt64("patient_id")
  5102. his_patient_id, _ := c.GetInt64("his_patient_id")
  5103. personal_history := c.GetString("personal_history")
  5104. pulse := c.GetString("pulse")
  5105. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5106. sbp := c.GetString("sbp")
  5107. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5108. heightfloat, _ := strconv.ParseFloat(height, 64)
  5109. sicktype := c.GetString("sick_type")
  5110. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5111. symptom := c.GetString("symptom")
  5112. sick_date := c.GetString("sick_date")
  5113. temperatures := c.GetString("temperature")
  5114. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5115. record_date := c.GetString("record_date")
  5116. breathing := c.GetString("breathing")
  5117. doctor_advice := c.GetString("doctor_advice")
  5118. remark := c.GetString("remark")
  5119. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5120. sick, _ := c.GetInt64("sick")
  5121. diagnose, _ := c.GetInt64("diagnose")
  5122. //id, _ := c.GetInt64("id")
  5123. timeLayout := "2006-01-02"
  5124. loc, _ := time.LoadLocation("Local")
  5125. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5126. allergic_history := c.GetString("allergic_history")
  5127. if err != nil {
  5128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5129. return
  5130. }
  5131. recordDateTime := theTime.Unix()
  5132. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5133. if err != nil {
  5134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5135. return
  5136. }
  5137. sickTimes := sickTime.Unix()
  5138. ctime := time.Now().Unix()
  5139. primary_disease := c.GetString("primary_disease")
  5140. confirm_failure_date := c.GetString("confirm_failure_date")
  5141. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5142. drug_allergy_history := c.GetString("drug_allergy_history")
  5143. physical_examination := c.GetString("physical_examination")
  5144. special_inspection := c.GetString("special_inspection")
  5145. lab_apparatus := c.GetString("lab_apparatus")
  5146. caseHistory := models.HisPatientCaseHistory{
  5147. HisPatientId: his_patient_id,
  5148. PatientId: patient_id,
  5149. Temperature: temperature,
  5150. BloodSugar: bloodsugarfloat,
  5151. Pulse: pulsefloat,
  5152. Sbp: sbpfloat,
  5153. Dbp: dbpfloat,
  5154. Height: heightfloat,
  5155. BloodFat: bloodfatfloat,
  5156. SickType: sick_type,
  5157. Symptom: symptom,
  5158. SickDate: sickTimes,
  5159. IsInfect: is_infect,
  5160. HistoryOfPresentIllness: history_of_present_illness,
  5161. PastHistory: past_history,
  5162. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5163. ChiefConplaint: chief_conplaint,
  5164. PersonalHistory: personal_history,
  5165. FamilyHistory: family_history,
  5166. Diagnostic: diagnostic,
  5167. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5168. Status: 1,
  5169. Ctime: ctime,
  5170. Mtime: ctime,
  5171. RecordDate: recordDateTime,
  5172. DeliveryWay: delivery_way,
  5173. Breathing: breathingfloat,
  5174. DoctorAdvice: doctor_advice,
  5175. Remark: remark,
  5176. Sick: sick,
  5177. Diagnose: diagnose,
  5178. AllergicHistory: allergic_history,
  5179. PrimaryDisease: primary_disease,
  5180. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5181. DrugAllergyHistory: drug_allergy_history,
  5182. PhysicalExamination: physical_examination,
  5183. SpecialInspection: special_inspection,
  5184. LabApparatus: lab_apparatus,
  5185. }
  5186. //查询该患者是否有病历
  5187. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5188. if errcodes == gorm.ErrRecordNotFound {
  5189. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5190. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5191. if err != nil {
  5192. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5193. return
  5194. }
  5195. c.ServeSuccessJSON(map[string]interface{}{
  5196. "caseHistory": caseHistory,
  5197. "historyInfo": historyInfo,
  5198. })
  5199. return
  5200. } else if errcodes == nil {
  5201. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5202. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5203. if err != nil {
  5204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5205. return
  5206. }
  5207. c.ServeSuccessJSON(map[string]interface{}{
  5208. "caseHistory": caseHistory,
  5209. "historyInfo": historyInfo,
  5210. })
  5211. }
  5212. //查询该患者是否有病历
  5213. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5214. //if errcode == gorm.ErrRecordNotFound {
  5215. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5216. // if err != nil {
  5217. // c.ServeSuccessJSON(map[string]interface{}{
  5218. // "msg": "保存成功",
  5219. // })
  5220. // }
  5221. //} else if errcode == nil {
  5222. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5223. // return
  5224. //}
  5225. }
  5226. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5227. patient_id, _ := c.GetInt64("patient_id", 0)
  5228. adminUser := c.GetAdminUserInfo()
  5229. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5230. c.ServeSuccessJSON(map[string]interface{}{
  5231. "list": caseHistorys,
  5232. })
  5233. }
  5234. func (c *HisApiController) GetHisPatientCaseHistory() {
  5235. record_date, _ := c.GetInt64("record_date", 0)
  5236. patient_id, _ := c.GetInt64("patient_id", 0)
  5237. admin := c.GetAdminUserInfo()
  5238. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5239. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5240. c.ServeSuccessJSON(map[string]interface{}{
  5241. "info": info,
  5242. "case_history": case_history,
  5243. })
  5244. }
  5245. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5246. template_name := c.GetString("template_name")
  5247. template_remark := c.GetString("template_remark")
  5248. doctor := c.GetAdminUserInfo().AdminUser.Id
  5249. diagnostic := c.GetString("diagnostic")
  5250. chief_conplaint := c.GetString("chief_conplain")
  5251. history_of_present_illness := c.GetString("history_of_present_illness")
  5252. past_history := c.GetString("past_history")
  5253. personal_history := c.GetString("personal_history")
  5254. family_history := c.GetString("family_history")
  5255. user_name := c.GetString("user_name")
  5256. doctor_advice := c.GetString("doctor_advice")
  5257. remark := c.GetString("remark")
  5258. //record_date := c.GetString("record_date")
  5259. //fmt.Println("record_date--------",record_date)
  5260. //timeLayout := "2006-01-02"
  5261. //loc, _ := time.LoadLocation("Local")
  5262. //
  5263. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5264. //if err != nil {
  5265. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5266. // return
  5267. //}
  5268. //recordDateTime := theTime.Unix()
  5269. ctime := time.Now().Unix()
  5270. template := models.HisCaseHistoryTemplate{
  5271. HistoryOfPresentIllness: history_of_present_illness,
  5272. PastHistory: past_history,
  5273. ChiefConplaint: chief_conplaint,
  5274. PersonalHistory: personal_history,
  5275. FamilyHistory: family_history,
  5276. Diagnostic: diagnostic,
  5277. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5278. Status: 1,
  5279. Ctime: ctime,
  5280. Mtime: ctime,
  5281. RecordDate: time.Now().Unix(),
  5282. TemplateName: template_name,
  5283. TemplateRemark: template_remark,
  5284. Creator: doctor,
  5285. Modifier: doctor,
  5286. UserName: user_name,
  5287. DoctorAdvice: doctor_advice,
  5288. Remark: remark,
  5289. }
  5290. err := service.SaveHisPatientCaseHistoryTemplate(template)
  5291. if err == nil {
  5292. c.ServeSuccessJSON(map[string]interface{}{
  5293. "msg": "保存成功",
  5294. })
  5295. } else {
  5296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5297. return
  5298. }
  5299. }
  5300. func (c *HisApiController) GetCaseHistoryTemplate() {
  5301. timeLayout := "2006-01-02"
  5302. loc, _ := time.LoadLocation("Local")
  5303. keyword := c.GetString("keyword")
  5304. start_time := c.GetString("start_time")
  5305. end_time := c.GetString("end_time")
  5306. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5307. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5308. admin := c.GetAdminUserInfo()
  5309. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  5310. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  5311. c.ServeSuccessJSON(map[string]interface{}{
  5312. "template": template,
  5313. //"history": history,
  5314. })
  5315. }
  5316. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5317. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5318. utils.ErrorLog("drug_name")
  5319. return enums.ErrorCodeParamWrong
  5320. }
  5321. adviceName, _ := json["drug_name"].(string)
  5322. if len(adviceName) == 0 {
  5323. utils.ErrorLog("len(advice_name) == 0")
  5324. return enums.ErrorCodeParamWrong
  5325. }
  5326. advice.AdviceName = adviceName
  5327. adviceDesc, _ := json["advice_desc"].(string)
  5328. advice.AdviceDesc = adviceDesc
  5329. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5330. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5331. advice.DrugSpec = drugSpec
  5332. }
  5333. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5334. remark, _ := json["remark"].(string)
  5335. advice.Remark = remark
  5336. }
  5337. if json["id"] == nil {
  5338. advice.DrugId = 0
  5339. } else {
  5340. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5341. drug_id := int64(json["id"].(float64))
  5342. advice.DrugId = drug_id
  5343. }
  5344. }
  5345. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5346. advice_id := int64(json["advice_id"].(float64))
  5347. advice.ID = advice_id
  5348. if advice.ID > 0 {
  5349. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5350. if err == nil {
  5351. if hisAdvice.ID > 0 {
  5352. advice.ExecutionTime = hisAdvice.ExecutionTime
  5353. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5354. advice.ExecutionState = hisAdvice.ExecutionState
  5355. advice.CheckTime = hisAdvice.CheckTime
  5356. advice.Checker = hisAdvice.Checker
  5357. advice.CheckState = hisAdvice.CheckState
  5358. advice.StartTime = hisAdvice.StartTime
  5359. advice.FeedetlSn = hisAdvice.FeedetlSn
  5360. }
  5361. }
  5362. }
  5363. }
  5364. //
  5365. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5366. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5367. // advice.ExecutionTime = execution_time
  5368. //}
  5369. //
  5370. //
  5371. //
  5372. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5373. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5374. // advice.ExecutionStaff = execution_staff
  5375. //}
  5376. //
  5377. //
  5378. //
  5379. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5380. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5381. // advice.ExecutionState = execution_state
  5382. //}
  5383. //
  5384. //
  5385. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5386. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5387. // advice.CheckTime = check_time
  5388. //}
  5389. //
  5390. //
  5391. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5392. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5393. // advice.CheckState = check_state
  5394. //}
  5395. //
  5396. //
  5397. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5398. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5399. // advice.Checker = checker
  5400. //}
  5401. //
  5402. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5403. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5404. // advice.StartTime = start_time
  5405. //}
  5406. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5407. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5408. advice.IsSelfDrug = is_self_drug
  5409. }
  5410. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5411. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5412. drug_way_count, _ := json["drug_way_count"].(string)
  5413. advice.DrugWayCount = drug_way_count
  5414. }
  5415. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5416. drugSpecUnit, _ := json["min_unit"].(string)
  5417. advice.DrugSpecUnit = drugSpecUnit
  5418. }
  5419. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5420. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5421. advice.SingleDose = singleDose
  5422. }
  5423. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5424. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5425. advice.SingleDoseUnit = singleDoseUnit
  5426. }
  5427. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5428. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5429. advice.PrescribingNumber = prescribingNumber
  5430. }
  5431. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5432. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5433. advice.PrescribingNumberUnit = prescribingNumberUnit
  5434. }
  5435. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5436. deliveryWay, _ := json["delivery_way"].(string)
  5437. advice.DeliveryWay = deliveryWay
  5438. }
  5439. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5440. executionFrequency, _ := json["execution_frequency"].(string)
  5441. advice.ExecutionFrequency = executionFrequency
  5442. }
  5443. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5444. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5445. advice.Price = price
  5446. }
  5447. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5448. med_list_codg, _ := json["medical_insurance_number"].(string)
  5449. advice.MedListCodg = med_list_codg
  5450. }
  5451. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5452. day := int64(json["day"].(float64))
  5453. advice.Day = day
  5454. }
  5455. return 0
  5456. }
  5457. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5458. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5459. id := int64(json["id"].(float64))
  5460. project.ID = id
  5461. historyProject, _ := service.GetHisProjectByID(id)
  5462. project.FeedetlSn = historyProject.FeedetlSn
  5463. }
  5464. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5465. project_id := int64(json["project_id"].(float64))
  5466. project.ProjectId = project_id
  5467. }
  5468. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5469. // price := int64(json["price"].(float64))
  5470. // formatInt_price := strconv.FormatInt(price, 10)
  5471. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5472. // project.Price = float_price
  5473. // }
  5474. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5475. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5476. project.Price = price
  5477. }
  5478. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5479. total, _ := json["total"].(string)
  5480. project.Count = total
  5481. }
  5482. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5483. medical_code, _ := json["medical_code"].(string)
  5484. project.MedListCodg = medical_code
  5485. }
  5486. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5487. single_dose, _ := json["single_dose"].(string)
  5488. project.SingleDose = single_dose
  5489. }
  5490. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5491. delivery_way, _ := json["delivery_way"].(string)
  5492. project.DeliveryWay = delivery_way
  5493. }
  5494. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5495. execution_frequency, _ := json["execution_frequency"].(string)
  5496. project.ExecutionFrequency = execution_frequency
  5497. }
  5498. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5499. remark, _ := json["remark"].(string)
  5500. project.Remark = remark
  5501. }
  5502. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5503. day, _ := json["number_days"].(string)
  5504. project.Day = day
  5505. }
  5506. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5507. unit, _ := json["unit"].(string)
  5508. project.Unit = unit
  5509. }
  5510. return 0
  5511. }
  5512. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5513. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5514. id := int64(json["id"].(float64))
  5515. historyAddtions, _ := service.GetHisAdditionByID(id)
  5516. additionalCharge.ID = id
  5517. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5518. }
  5519. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5520. item_id := int64(json["item_id"].(float64))
  5521. additionalCharge.ItemId = item_id
  5522. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5523. if config.ID > 0 {
  5524. if len(config.Code) > 0 {
  5525. additionalCharge.MedListCodg = config.Code
  5526. }
  5527. }
  5528. }
  5529. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5530. // price := int64(json["price"].(float64))
  5531. // formatInt_price := strconv.FormatInt(price, 10)
  5532. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5533. // additionalCharge.Price = float_price
  5534. // }
  5535. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5536. // price := int64(json["price"].(float64))
  5537. // formatInt_price := strconv.FormatInt(price, 10)
  5538. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5539. // additionalCharge.Price = float_price
  5540. //}
  5541. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5542. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5543. additionalCharge.Price = price
  5544. }
  5545. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5546. count, _ := json["count"].(string)
  5547. counts, _ := strconv.ParseInt(count, 10, 64)
  5548. additionalCharge.Count = counts
  5549. }
  5550. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5551. item_name, _ := json["item_name"].(string)
  5552. additionalCharge.ItemName = item_name
  5553. }
  5554. return 0
  5555. }
  5556. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5557. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5558. utils.ErrorLog("drug_name")
  5559. return enums.ErrorCodeParamWrong
  5560. }
  5561. adviceName, _ := json["drug_name"].(string)
  5562. if len(adviceName) == 0 {
  5563. utils.ErrorLog("len(advice_name) == 0")
  5564. return enums.ErrorCodeParamWrong
  5565. }
  5566. advice.AdviceName = adviceName
  5567. adviceDesc, _ := json["advice_desc"].(string)
  5568. advice.AdviceDesc = adviceDesc
  5569. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5570. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5571. advice.DrugSpec = drugSpec
  5572. }
  5573. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5574. remark, _ := json["remark"].(string)
  5575. advice.Remark = remark
  5576. }
  5577. if json["id"] == nil {
  5578. advice.DrugId = 0
  5579. } else {
  5580. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5581. drug_id := int64(json["id"].(float64))
  5582. advice.DrugId = drug_id
  5583. }
  5584. }
  5585. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5586. groupno := int64(json["groupno"].(float64))
  5587. advice.Groupno = groupno
  5588. }
  5589. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5590. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5591. advice.IsSelfDrug = is_self_drug
  5592. }
  5593. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5594. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5595. drug_way_count, _ := json["drug_way_count"].(string)
  5596. advice.DrugWayCount = drug_way_count
  5597. }
  5598. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5599. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5600. advice.HospApprFlag = hosp_appr_flag
  5601. }
  5602. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5603. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5604. advice.PrescribingNumber = prescribingNumber
  5605. }
  5606. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5607. // frequency_type := int64(json["frequency_type"].(float64))
  5608. // advice.FrequencyType = frequency_type
  5609. //}
  5610. //
  5611. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5612. // day_count := int64(json["day_count"].(float64))
  5613. // advice.DayCount = day_count
  5614. //}
  5615. //
  5616. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5617. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5618. // week_day, _ := json["week_day"].(string)
  5619. // advice.WeekDay = week_day
  5620. //}
  5621. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5622. drugSpecUnit, _ := json["min_unit"].(string)
  5623. advice.DrugSpecUnit = drugSpecUnit
  5624. }
  5625. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5626. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5627. advice.SingleDose = singleDose
  5628. }
  5629. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5630. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5631. advice.SingleDoseUnit = singleDoseUnit
  5632. }
  5633. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5634. deliveryWay, _ := json["delivery_way"].(string)
  5635. advice.DeliveryWay = deliveryWay
  5636. }
  5637. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5638. executionFrequency, _ := json["execution_frequency"].(string)
  5639. advice.ExecutionFrequency = executionFrequency
  5640. }
  5641. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5642. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5643. advice.Price = price
  5644. }
  5645. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5646. med_list_codg, _ := json["medical_insurance_number"].(string)
  5647. advice.MedListCodg = med_list_codg
  5648. }
  5649. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5650. day := int64(json["day"].(float64))
  5651. advice.Day = day
  5652. }
  5653. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5654. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5655. advice.PrescribingNumberUnit = prescribingNumberUnit
  5656. }
  5657. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5658. advice_id := int64(json["advice_id"].(float64))
  5659. advice.ID = advice_id
  5660. if advice.ID > 0 {
  5661. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5662. if err == nil {
  5663. if hisAdvice.ID > 0 {
  5664. advice.ExecutionTime = hisAdvice.ExecutionTime
  5665. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5666. advice.ExecutionState = hisAdvice.ExecutionState
  5667. advice.CheckTime = hisAdvice.CheckTime
  5668. advice.Checker = hisAdvice.Checker
  5669. advice.CheckState = hisAdvice.CheckState
  5670. advice.StartTime = hisAdvice.StartTime
  5671. advice.HospApprFlag = hisAdvice.HospApprFlag
  5672. advice.IsMedicine = hisAdvice.IsMedicine
  5673. if hisAdvice.UserOrgId == 10028 {
  5674. 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 {
  5675. advice.ExecutionTime = 0
  5676. advice.ExecutionStaff = 0
  5677. advice.ExecutionState = 2
  5678. advice.CheckTime = 0
  5679. advice.Checker = 0
  5680. advice.CheckState = 2
  5681. }
  5682. } else {
  5683. 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 {
  5684. advice.ExecutionTime = 0
  5685. advice.ExecutionStaff = 0
  5686. advice.ExecutionState = 2
  5687. advice.CheckTime = 0
  5688. advice.Checker = 0
  5689. advice.CheckState = 2
  5690. }
  5691. }
  5692. //advice.Groupno = hisAdvice.Groupno
  5693. }
  5694. }
  5695. }
  5696. }
  5697. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5698. //
  5699. //if drugStockConfig.IsOpen == 1 {
  5700. //
  5701. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5702. // if advice.ID == 0 { //医嘱不存在
  5703. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5704. // drug.Total = drug.Total - advice.PrescribingNumber
  5705. // service.UpdateBaseDrugLib(&drug)
  5706. //
  5707. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5708. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5709. // drug.Total = drug.Total - num
  5710. // service.UpdateBaseDrugLib(&drug)
  5711. // }
  5712. //
  5713. // } else if advice.ID > 0 { //医嘱存在
  5714. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5715. // var num float64
  5716. //
  5717. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5718. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5719. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5720. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5721. // drug.Total = drug.Total + num
  5722. // service.UpdateBaseDrugLib(&drug)
  5723. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5724. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5725. // drug.Total = drug.Total - num
  5726. // service.UpdateBaseDrugLib(&drug)
  5727. // }
  5728. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5729. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5730. // if num2 > advice.PrescribingNumber {
  5731. // num = num2 - advice.PrescribingNumber
  5732. // drug.Total = drug.Total + num
  5733. // service.UpdateBaseDrugLib(&drug)
  5734. // } else if num2 < advice.PrescribingNumber {
  5735. // num = advice.PrescribingNumber - num2
  5736. // drug.Total = drug.Total - num
  5737. // service.UpdateBaseDrugLib(&drug)
  5738. // }
  5739. //
  5740. // }
  5741. //
  5742. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5743. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5744. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5745. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5746. // if num1 > num2 {
  5747. // num = num1 - num2
  5748. // drug.Total = drug.Total + num
  5749. // service.UpdateBaseDrugLib(&drug)
  5750. // } else if num1 < num2 {
  5751. // num = num2 - num1
  5752. // drug.Total = drug.Total - num
  5753. // service.UpdateBaseDrugLib(&drug)
  5754. // }
  5755. //
  5756. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5757. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5758. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5759. // if hisAdvice.PrescribingNumber > num2 {
  5760. // num = hisAdvice.PrescribingNumber - num2
  5761. // drug.Total = drug.Total + num
  5762. // service.UpdateBaseDrugLib(&drug)
  5763. // } else if num2 < advice.PrescribingNumber {
  5764. // num = num2 - hisAdvice.PrescribingNumber
  5765. // drug.Total = drug.Total - num
  5766. // service.UpdateBaseDrugLib(&drug)
  5767. // }
  5768. //
  5769. // }
  5770. // }
  5771. // }
  5772. //}
  5773. //
  5774. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5775. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5776. // advice.ExecutionTime = execution_time
  5777. //}
  5778. //
  5779. //
  5780. //
  5781. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5782. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5783. // advice.ExecutionStaff = execution_staff
  5784. //}
  5785. //
  5786. //
  5787. //
  5788. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5789. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5790. // advice.ExecutionState = execution_state
  5791. //}
  5792. //
  5793. //
  5794. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5795. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5796. // advice.CheckTime = check_time
  5797. //}
  5798. //
  5799. //
  5800. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5801. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5802. // advice.CheckState = check_state
  5803. //}
  5804. //
  5805. //
  5806. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5807. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5808. // advice.Checker = checker
  5809. //}
  5810. //
  5811. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5812. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5813. // advice.StartTime = start_time
  5814. //}
  5815. return 0
  5816. }
  5817. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5818. project.ExecutionStaff = 0
  5819. project.ExecutionState = 2
  5820. project.ExecutionTime = 0
  5821. project.Checker = 0
  5822. project.CheckState = 2
  5823. project.CheckTime = 0
  5824. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5825. id := int64(json["id"].(float64))
  5826. project.ID = id
  5827. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5828. project.ExecutionStaff = temp_project.ExecutionStaff
  5829. project.ExecutionState = temp_project.ExecutionState
  5830. project.ExecutionTime = temp_project.ExecutionTime
  5831. project.Checker = temp_project.Checker
  5832. project.CheckState = temp_project.CheckState
  5833. project.CheckTime = temp_project.CheckTime
  5834. project.TeamId = temp_project.TeamId
  5835. }
  5836. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5837. types := int64(json["type"].(float64))
  5838. project.Type = types
  5839. }
  5840. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5841. project_id := int64(json["project_id"].(float64))
  5842. project.ProjectId = project_id
  5843. }
  5844. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5845. team_id := int64(json["team_id"].(float64))
  5846. project.TeamId = team_id
  5847. }
  5848. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5849. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5850. project.Price = price
  5851. }
  5852. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5853. total, _ := json["total"].(string)
  5854. //totals, _ := strconv.ParseInt(total, 10, 64)
  5855. project.Count = total
  5856. }
  5857. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5858. medical_code, _ := json["medical_code"].(string)
  5859. project.MedListCodg = medical_code
  5860. }
  5861. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5862. single_dose, _ := json["single_dose"].(string)
  5863. project.SingleDose = single_dose
  5864. }
  5865. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5866. delivery_way, _ := json["delivery_way"].(string)
  5867. project.DeliveryWay = delivery_way
  5868. }
  5869. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5870. execution_frequency, _ := json["execution_frequency"].(string)
  5871. project.ExecutionFrequency = execution_frequency
  5872. }
  5873. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5874. remark, _ := json["remark"].(string)
  5875. project.Remark = remark
  5876. }
  5877. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5878. day, _ := json["number_days"].(string)
  5879. project.Day = day
  5880. }
  5881. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5882. unit, _ := json["unit"].(string)
  5883. project.Unit = unit
  5884. }
  5885. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5886. // frequency_type := int64(json["frequency_type"].(float64))
  5887. // project.FrequencyType = frequency_type
  5888. //}
  5889. //
  5890. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5891. // day_count := int64(json["day_count"].(float64))
  5892. // project.DayCount = day_count
  5893. //}
  5894. //
  5895. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5896. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5897. // week_day, _ := json["week_day"].(string)
  5898. // project.WeekDay = week_day
  5899. //}
  5900. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5901. //
  5902. //if project.ID == 0 {
  5903. // if stockConfig.IsOpen == 1 {
  5904. // if project.Type == 3 {
  5905. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5906. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5907. // good.Total = good.Total - f_count
  5908. // service.UpdateGoodInfo(&good)
  5909. // }
  5910. // }
  5911. //
  5912. //} else {
  5913. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5914. //
  5915. // if stockConfig.IsOpen == 1 {
  5916. // if project.Type == 3 {
  5917. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5918. // if project.Count < temp_project.Count {
  5919. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5920. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5921. //
  5922. // other_count := f_count_two - f_count_one
  5923. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5924. // good.Total = good.Total + other_count_two
  5925. // service.UpdateGoodInfo(&good)
  5926. // } else if project.Count > temp_project.Count {
  5927. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5928. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5929. //
  5930. // other_count := f_count_one - f_count_two
  5931. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5932. // good.Total = good.Total - other_count_two
  5933. // service.UpdateGoodInfo(&good)
  5934. // }
  5935. //
  5936. // }
  5937. // }
  5938. //
  5939. //}
  5940. return 0
  5941. }
  5942. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5943. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5944. utils.ErrorLog("drug_name")
  5945. return enums.ErrorCodeParamWrong
  5946. }
  5947. adviceName, _ := json["drug_name"].(string)
  5948. if len(adviceName) == 0 {
  5949. utils.ErrorLog("len(advice_name) == 0")
  5950. return enums.ErrorCodeParamWrong
  5951. }
  5952. advice.AdviceName = adviceName
  5953. adviceDesc, _ := json["advice_desc"].(string)
  5954. advice.AdviceDesc = adviceDesc
  5955. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5956. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5957. advice.DrugSpec = drugSpec
  5958. }
  5959. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5960. remark, _ := json["remark"].(string)
  5961. advice.Remark = remark
  5962. }
  5963. if json["id"] == nil {
  5964. advice.DrugId = 0
  5965. } else {
  5966. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5967. drug_id := int64(json["id"].(float64))
  5968. advice.DrugId = drug_id
  5969. }
  5970. }
  5971. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5972. groupno := int64(json["groupno"].(float64))
  5973. advice.Groupno = groupno
  5974. }
  5975. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5976. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5977. advice.IsSelfDrug = is_self_drug
  5978. }
  5979. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5980. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5981. drug_way_count, _ := json["drug_way_count"].(string)
  5982. advice.DrugWayCount = drug_way_count
  5983. }
  5984. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5985. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5986. advice.HospApprFlag = hosp_appr_flag
  5987. }
  5988. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5989. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5990. advice.PrescribingNumber = prescribingNumber
  5991. }
  5992. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5993. // frequency_type := int64(json["frequency_type"].(float64))
  5994. // advice.FrequencyType = frequency_type
  5995. //}
  5996. //
  5997. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5998. // day_count := int64(json["day_count"].(float64))
  5999. // advice.DayCount = day_count
  6000. //}
  6001. //
  6002. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6003. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6004. // week_day, _ := json["week_day"].(string)
  6005. // advice.WeekDay = week_day
  6006. //}
  6007. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6008. drugSpecUnit, _ := json["min_unit"].(string)
  6009. advice.DrugSpecUnit = drugSpecUnit
  6010. }
  6011. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6012. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6013. advice.SingleDose = singleDose
  6014. }
  6015. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6016. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6017. advice.SingleDoseUnit = singleDoseUnit
  6018. }
  6019. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6020. deliveryWay, _ := json["delivery_way"].(string)
  6021. advice.DeliveryWay = deliveryWay
  6022. }
  6023. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6024. executionFrequency, _ := json["execution_frequency"].(string)
  6025. advice.ExecutionFrequency = executionFrequency
  6026. }
  6027. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6028. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6029. advice.Price = price
  6030. }
  6031. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6032. med_list_codg, _ := json["medical_insurance_number"].(string)
  6033. advice.MedListCodg = med_list_codg
  6034. }
  6035. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6036. day := int64(json["day"].(float64))
  6037. advice.Day = day
  6038. }
  6039. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6040. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6041. advice.PrescribingNumberUnit = prescribingNumberUnit
  6042. }
  6043. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6044. advice_id := int64(json["advice_id"].(float64))
  6045. advice.ID = advice_id
  6046. if advice.ID > 0 {
  6047. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6048. if err == nil {
  6049. if hisAdvice.ID > 0 {
  6050. advice.ExecutionTime = hisAdvice.ExecutionTime
  6051. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6052. advice.ExecutionState = hisAdvice.ExecutionState
  6053. advice.CheckTime = hisAdvice.CheckTime
  6054. advice.Checker = hisAdvice.Checker
  6055. advice.CheckState = hisAdvice.CheckState
  6056. advice.StartTime = hisAdvice.StartTime
  6057. advice.HospApprFlag = hisAdvice.HospApprFlag
  6058. advice.IsMedicine = hisAdvice.IsMedicine
  6059. if hisAdvice.UserOrgId == 10028 {
  6060. 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 {
  6061. advice.ExecutionTime = 0
  6062. advice.ExecutionStaff = 0
  6063. advice.ExecutionState = 2
  6064. advice.CheckTime = 0
  6065. advice.Checker = 0
  6066. advice.CheckState = 2
  6067. }
  6068. } else {
  6069. 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 {
  6070. advice.ExecutionTime = 0
  6071. advice.ExecutionStaff = 0
  6072. advice.ExecutionState = 2
  6073. advice.CheckTime = 0
  6074. advice.Checker = 0
  6075. advice.CheckState = 2
  6076. }
  6077. }
  6078. //advice.Groupno = hisAdvice.Groupno
  6079. }
  6080. }
  6081. }
  6082. }
  6083. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6084. //
  6085. //if drugStockConfig.IsOpen == 1 {
  6086. //
  6087. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6088. // if advice.ID == 0 { //医嘱不存在
  6089. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6090. // drug.Total = drug.Total - advice.PrescribingNumber
  6091. // service.UpdateBaseDrugLib(&drug)
  6092. //
  6093. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6094. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6095. // drug.Total = drug.Total - num
  6096. // service.UpdateBaseDrugLib(&drug)
  6097. // }
  6098. //
  6099. // } else if advice.ID > 0 { //医嘱存在
  6100. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6101. // var num float64
  6102. //
  6103. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6104. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6105. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6106. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6107. // drug.Total = drug.Total + num
  6108. // service.UpdateBaseDrugLib(&drug)
  6109. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6110. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6111. // drug.Total = drug.Total - num
  6112. // service.UpdateBaseDrugLib(&drug)
  6113. // }
  6114. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6115. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6116. // if num2 > advice.PrescribingNumber {
  6117. // num = num2 - advice.PrescribingNumber
  6118. // drug.Total = drug.Total + num
  6119. // service.UpdateBaseDrugLib(&drug)
  6120. // } else if num2 < advice.PrescribingNumber {
  6121. // num = advice.PrescribingNumber - num2
  6122. // drug.Total = drug.Total - num
  6123. // service.UpdateBaseDrugLib(&drug)
  6124. // }
  6125. //
  6126. // }
  6127. //
  6128. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6129. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6130. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6131. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6132. // if num1 > num2 {
  6133. // num = num1 - num2
  6134. // drug.Total = drug.Total + num
  6135. // service.UpdateBaseDrugLib(&drug)
  6136. // } else if num1 < num2 {
  6137. // num = num2 - num1
  6138. // drug.Total = drug.Total - num
  6139. // service.UpdateBaseDrugLib(&drug)
  6140. // }
  6141. //
  6142. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6143. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6144. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6145. // if hisAdvice.PrescribingNumber > num2 {
  6146. // num = hisAdvice.PrescribingNumber - num2
  6147. // drug.Total = drug.Total + num
  6148. // service.UpdateBaseDrugLib(&drug)
  6149. // } else if num2 < advice.PrescribingNumber {
  6150. // num = num2 - hisAdvice.PrescribingNumber
  6151. // drug.Total = drug.Total - num
  6152. // service.UpdateBaseDrugLib(&drug)
  6153. // }
  6154. //
  6155. // }
  6156. // }
  6157. // }
  6158. //}
  6159. //
  6160. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6161. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6162. // advice.ExecutionTime = execution_time
  6163. //}
  6164. //
  6165. //
  6166. //
  6167. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6168. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6169. // advice.ExecutionStaff = execution_staff
  6170. //}
  6171. //
  6172. //
  6173. //
  6174. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6175. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6176. // advice.ExecutionState = execution_state
  6177. //}
  6178. //
  6179. //
  6180. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6181. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6182. // advice.CheckTime = check_time
  6183. //}
  6184. //
  6185. //
  6186. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6187. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6188. // advice.CheckState = check_state
  6189. //}
  6190. //
  6191. //
  6192. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6193. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6194. // advice.Checker = checker
  6195. //}
  6196. //
  6197. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6198. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6199. // advice.StartTime = start_time
  6200. //}
  6201. return 0
  6202. }
  6203. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6204. project.ExecutionStaff = 0
  6205. project.ExecutionState = 2
  6206. project.ExecutionTime = 0
  6207. project.Checker = 0
  6208. project.CheckState = 2
  6209. project.CheckTime = 0
  6210. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6211. id := int64(json["id"].(float64))
  6212. project.ID = id
  6213. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6214. project.ExecutionStaff = temp_project.ExecutionStaff
  6215. project.ExecutionState = temp_project.ExecutionState
  6216. project.ExecutionTime = temp_project.ExecutionTime
  6217. project.Checker = temp_project.Checker
  6218. project.CheckState = temp_project.CheckState
  6219. project.CheckTime = temp_project.CheckTime
  6220. project.TeamId = temp_project.TeamId
  6221. }
  6222. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6223. types := int64(json["type"].(float64))
  6224. project.Type = types
  6225. }
  6226. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6227. project_id := int64(json["project_id"].(float64))
  6228. project.ProjectId = project_id
  6229. }
  6230. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6231. team_id := int64(json["team_id"].(float64))
  6232. project.TeamId = team_id
  6233. }
  6234. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6235. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6236. project.Price = price
  6237. }
  6238. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6239. total, _ := json["total"].(string)
  6240. //totals, _ := strconv.ParseInt(total, 10, 64)
  6241. project.Count = total
  6242. }
  6243. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6244. medical_code, _ := json["medical_code"].(string)
  6245. project.MedListCodg = medical_code
  6246. }
  6247. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6248. single_dose, _ := json["single_dose"].(string)
  6249. project.SingleDose = single_dose
  6250. }
  6251. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6252. delivery_way, _ := json["delivery_way"].(string)
  6253. project.DeliveryWay = delivery_way
  6254. }
  6255. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6256. execution_frequency, _ := json["execution_frequency"].(string)
  6257. project.ExecutionFrequency = execution_frequency
  6258. }
  6259. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6260. remark, _ := json["remark"].(string)
  6261. project.Remark = remark
  6262. }
  6263. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6264. day, _ := json["number_days"].(string)
  6265. project.Day = day
  6266. }
  6267. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6268. unit, _ := json["unit"].(string)
  6269. project.Unit = unit
  6270. }
  6271. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6272. // frequency_type := int64(json["frequency_type"].(float64))
  6273. // project.FrequencyType = frequency_type
  6274. //}
  6275. //
  6276. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6277. // day_count := int64(json["day_count"].(float64))
  6278. // project.DayCount = day_count
  6279. //}
  6280. //
  6281. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6282. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6283. // week_day, _ := json["week_day"].(string)
  6284. // project.WeekDay = week_day
  6285. //}
  6286. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6287. //
  6288. //if project.ID == 0 {
  6289. // if stockConfig.IsOpen == 1 {
  6290. // if project.Type == 3 {
  6291. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6292. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6293. // good.Total = good.Total - f_count
  6294. // service.UpdateGoodInfo(&good)
  6295. // }
  6296. // }
  6297. //
  6298. //} else {
  6299. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6300. //
  6301. // if stockConfig.IsOpen == 1 {
  6302. // if project.Type == 3 {
  6303. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6304. // if project.Count < temp_project.Count {
  6305. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6306. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6307. //
  6308. // other_count := f_count_two - f_count_one
  6309. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6310. // good.Total = good.Total + other_count_two
  6311. // service.UpdateGoodInfo(&good)
  6312. // } else if project.Count > temp_project.Count {
  6313. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6314. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6315. //
  6316. // other_count := f_count_one - f_count_two
  6317. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6318. // good.Total = good.Total - other_count_two
  6319. // service.UpdateGoodInfo(&good)
  6320. // }
  6321. //
  6322. // }
  6323. // }
  6324. //
  6325. //}
  6326. return 0
  6327. }
  6328. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6329. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6330. id := int64(json["id"].(float64))
  6331. additionalCharge.ID = id
  6332. }
  6333. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6334. item_id := int64(json["item_id"].(float64))
  6335. additionalCharge.ItemId = item_id
  6336. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6337. if config.ID > 0 {
  6338. if len(config.Code) > 0 {
  6339. additionalCharge.MedListCodg = config.Code
  6340. }
  6341. }
  6342. }
  6343. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6344. // price := int64(json["price"].(float64))
  6345. // formatInt_price := strconv.FormatInt(price, 10)
  6346. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6347. // additionalCharge.Price = float_price
  6348. // }
  6349. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6350. // price := int64(json["price"].(float64))
  6351. // formatInt_price := strconv.FormatInt(price, 10)
  6352. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6353. // additionalCharge.Price = float_price
  6354. //}
  6355. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6356. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6357. additionalCharge.Price = price
  6358. }
  6359. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6360. count, _ := json["count"].(string)
  6361. counts, _ := strconv.ParseInt(count, 10, 64)
  6362. additionalCharge.Count = counts
  6363. }
  6364. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6365. item_name, _ := json["item_name"].(string)
  6366. additionalCharge.ItemName = item_name
  6367. }
  6368. return 0
  6369. }
  6370. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  6371. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6372. utils.ErrorLog("drug_name")
  6373. return enums.ErrorCodeParamWrong
  6374. }
  6375. adviceName, _ := json["drug_name"].(string)
  6376. if len(adviceName) == 0 {
  6377. utils.ErrorLog("len(advice_name) == 0")
  6378. return enums.ErrorCodeParamWrong
  6379. }
  6380. advice.AdviceName = adviceName
  6381. adviceDesc, _ := json["advice_desc"].(string)
  6382. advice.AdviceDesc = adviceDesc
  6383. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6384. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6385. advice.DrugSpec = drugSpec
  6386. }
  6387. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6388. remark, _ := json["remark"].(string)
  6389. advice.Remark = remark
  6390. }
  6391. if json["id"] == nil {
  6392. advice.DrugId = 0
  6393. } else {
  6394. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6395. drug_id := int64(json["id"].(float64))
  6396. advice.DrugId = drug_id
  6397. }
  6398. }
  6399. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6400. groupno := int64(json["groupno"].(float64))
  6401. advice.Groupno = groupno
  6402. }
  6403. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6404. drugSpecUnit, _ := json["min_unit"].(string)
  6405. advice.DrugSpecUnit = drugSpecUnit
  6406. }
  6407. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6408. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6409. advice.SingleDose = singleDose
  6410. }
  6411. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6412. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6413. advice.SingleDoseUnit = singleDoseUnit
  6414. }
  6415. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6416. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6417. advice.PrescribingNumber = prescribingNumber
  6418. }
  6419. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6420. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6421. advice.PrescribingNumberUnit = prescribingNumberUnit
  6422. }
  6423. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6424. deliveryWay, _ := json["delivery_way"].(string)
  6425. advice.DeliveryWay = deliveryWay
  6426. }
  6427. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6428. executionFrequency, _ := json["execution_frequency"].(string)
  6429. advice.ExecutionFrequency = executionFrequency
  6430. }
  6431. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6432. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6433. advice.Price = price
  6434. }
  6435. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6436. med_list_codg, _ := json["medical_insurance_number"].(string)
  6437. advice.MedListCodg = med_list_codg
  6438. }
  6439. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6440. day := int64(json["day"].(float64))
  6441. advice.Day = day
  6442. }
  6443. advice.FrequencyType = 1
  6444. return 0
  6445. }
  6446. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  6447. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6448. types := int64(json["type"].(float64))
  6449. project.Type = types
  6450. }
  6451. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6452. project_id := int64(json["project_id"].(float64))
  6453. project.ProjectId = project_id
  6454. }
  6455. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6456. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6457. project.Price = price
  6458. }
  6459. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6460. total, _ := json["total"].(string)
  6461. //totals, _ := strconv.ParseInt(total, 10, 64)
  6462. project.Count = total
  6463. }
  6464. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6465. medical_code, _ := json["medical_code"].(string)
  6466. project.MedListCodg = medical_code
  6467. }
  6468. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6469. single_dose, _ := json["single_dose"].(string)
  6470. project.SingleDose = single_dose
  6471. }
  6472. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6473. delivery_way, _ := json["delivery_way"].(string)
  6474. project.DeliveryWay = delivery_way
  6475. }
  6476. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6477. execution_frequency, _ := json["execution_frequency"].(string)
  6478. project.ExecutionFrequency = execution_frequency
  6479. }
  6480. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6481. remark, _ := json["remark"].(string)
  6482. project.Remark = remark
  6483. }
  6484. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6485. day, _ := json["number_days"].(string)
  6486. project.Day = day
  6487. }
  6488. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6489. unit, _ := json["unit"].(string)
  6490. project.Unit = unit
  6491. }
  6492. project.FrequencyType = 1
  6493. return 0
  6494. }
  6495. func (c *HisApiController) GetHisOrderListTwo() {
  6496. start_time := c.GetString("start_time")
  6497. end_time := c.GetString("end_time")
  6498. timeLayout := "2006-01-02"
  6499. loc, _ := time.LoadLocation("Local")
  6500. var startTime int64
  6501. if len(start_time) > 0 {
  6502. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6503. if err != nil {
  6504. //fmt.Println(err)
  6505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6506. return
  6507. }
  6508. startTime = theTime.Unix()
  6509. }
  6510. var endTime int64
  6511. if len(end_time) > 0 {
  6512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6513. if err != nil {
  6514. utils.ErrorLog(err.Error())
  6515. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6516. return
  6517. }
  6518. endTime = theTime.Unix()
  6519. }
  6520. adminUser := c.GetAdminUserInfo()
  6521. org_id := adminUser.CurrentOrgId
  6522. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  6523. if err == nil {
  6524. c.ServeSuccessJSON(map[string]interface{}{
  6525. "order2": order,
  6526. })
  6527. } else {
  6528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6529. return
  6530. }
  6531. }
  6532. func (c *HisApiController) GetHisOrderList() {
  6533. page, _ := c.GetInt64("page", -1)
  6534. limit, _ := c.GetInt64("limit", -1)
  6535. start_time := c.GetString("start_time")
  6536. end_time := c.GetString("end_time")
  6537. types, _ := c.GetInt64("type", 0)
  6538. keywords := c.GetString("keywords")
  6539. p_type, _ := c.GetInt64("p_type", 0)
  6540. sort_type, _ := c.GetInt64("sort_type", 0)
  6541. charge_type, _ := c.GetInt64("charge_type", 0)
  6542. sch_type, _ := c.GetInt64("sch_type", 0)
  6543. zone_type, _ := c.GetInt64("zone_type", 0)
  6544. med_type, _ := c.GetInt64("med_type", 0)
  6545. timeLayout := "2006-01-02"
  6546. loc, _ := time.LoadLocation("Local")
  6547. var startTime int64
  6548. if len(start_time) > 0 {
  6549. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6550. if err != nil {
  6551. //fmt.Println(err)
  6552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6553. return
  6554. }
  6555. startTime = theTime.Unix()
  6556. }
  6557. var endTime int64
  6558. if len(end_time) > 0 {
  6559. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6560. if err != nil {
  6561. utils.ErrorLog(err.Error())
  6562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6563. return
  6564. }
  6565. endTime = theTime.Unix()
  6566. }
  6567. adminUser := c.GetAdminUserInfo()
  6568. org_id := adminUser.CurrentOrgId
  6569. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  6570. for _, item := range order {
  6571. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  6572. item.DoctorName = info.Doctor
  6573. item.DepartmentName = info.XtHisDepartment.Name
  6574. }
  6575. if err == nil {
  6576. c.ServeSuccessJSON(map[string]interface{}{
  6577. "order": order,
  6578. "total": total,
  6579. })
  6580. } else {
  6581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6582. return
  6583. }
  6584. }
  6585. func (c *HisApiController) GetHisOrder() {
  6586. patient_id, _ := c.GetInt64("patient_id", 0)
  6587. number := c.GetString("number")
  6588. adminInfo := c.GetAdminUserInfo()
  6589. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  6590. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  6591. if err == nil {
  6592. c.ServeSuccessJSON(map[string]interface{}{
  6593. "order": order,
  6594. "prescription": prescriptions,
  6595. })
  6596. } else {
  6597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6598. return
  6599. }
  6600. }
  6601. func (c *HisApiController) GetHisPrescriptionList() {
  6602. record_date := c.GetString("record_date")
  6603. keywords := c.GetString("keywords")
  6604. page, _ := c.GetInt64("page")
  6605. limit, _ := c.GetInt64("limit")
  6606. sch_type, _ := c.GetInt64("sch_type")
  6607. timeLayout := "2006-01-02"
  6608. loc, _ := time.LoadLocation("Local")
  6609. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6610. if err != nil {
  6611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6612. return
  6613. }
  6614. recordDateTime := theTime.Unix()
  6615. adminInfo := c.GetAdminUserInfo()
  6616. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  6617. //adminInfo := c.GetAdminUserInfo()
  6618. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  6619. //fmt.Println(prescriptionOrder)
  6620. if err == nil {
  6621. c.ServeSuccessJSON(map[string]interface{}{
  6622. "order": prescriptionOrder,
  6623. "total": total,
  6624. })
  6625. } else {
  6626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6627. return
  6628. }
  6629. }
  6630. func (c *HisApiController) GetHisPrescriptionInfo() {
  6631. id, _ := c.GetInt64("id")
  6632. adminInfo := c.GetAdminUserInfo()
  6633. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  6634. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  6635. if err == nil {
  6636. c.ServeSuccessJSON(map[string]interface{}{
  6637. "order": prescriptionOrder,
  6638. "prescription": prescription,
  6639. })
  6640. } else {
  6641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6642. return
  6643. }
  6644. }
  6645. func (c *HisApiController) GetMedicalInsuranceConfig() {
  6646. adminUser := c.GetAdminUserInfo()
  6647. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  6648. c.ServeSuccessJSON(map[string]interface{}{
  6649. "config": config,
  6650. })
  6651. }
  6652. type ResultTwo struct {
  6653. ErrMsg interface{} `json:"err_msg"`
  6654. InfRefmsgid string `json:"inf_refmsgid"`
  6655. Infcode int64 `json:"infcode"`
  6656. Output struct {
  6657. Baseinfo struct {
  6658. Age float64 `json:"age"`
  6659. Brdy string `json:"brdy"`
  6660. Certno string `json:"certno"`
  6661. Gend string `json:"gend"`
  6662. Naty string `json:"naty"`
  6663. PsnCertType string `json:"psn_cert_type"`
  6664. PsnName string `json:"psn_name"`
  6665. PsnNo string `json:"psn_no"`
  6666. } `json:"baseinfo"`
  6667. Idetinfo []interface{} `json:"idetinfo"`
  6668. Iinfo []struct {
  6669. Balc float64 `json:"balc"`
  6670. CvlservFlag string `json:"cvlserv_flag"`
  6671. EmpName string `json:"emp_name"`
  6672. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  6673. Insutype string `json:"insutype"`
  6674. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  6675. PausInsuDate interface{} `json:"paus_insu_date"`
  6676. PsnInsuDate string `json:"psn_insu_date"`
  6677. PsnInsuStas string `json:"psn_insu_stas"`
  6678. PsnType string `json:"psn_type"`
  6679. } `json:"insuinfo"`
  6680. } `json:"output"`
  6681. RefmsgTime string `json:"refmsg_time"`
  6682. RespondTime string `json:"respond_time"`
  6683. Signtype interface{} `json:"signtype"`
  6684. WarnInfo interface{} `json:"warn_info"`
  6685. }
  6686. type ResultThree struct {
  6687. Cainfo interface{} `json:"cainfo"`
  6688. ErrMsg interface{} `json:"err_msg"`
  6689. InfRefmsgid string `json:"inf_refmsgid"`
  6690. Infcode int64 `json:"infcode"`
  6691. Output struct {
  6692. Data struct {
  6693. IptOtpNo string `json:"ipt_otp_no"`
  6694. MdtrtID string `json:"mdtrt_id"`
  6695. PsnNo string `json:"psn_no"`
  6696. } `json:"data"`
  6697. } `json:"output"`
  6698. RefmsgTime string `json:"refmsg_time"`
  6699. RespondTime string `json:"respond_time"`
  6700. Signtype interface{} `json:"signtype"`
  6701. WarnMsg interface{} `json:"warn_msg"`
  6702. }
  6703. type ResultFour struct {
  6704. Cainfo string `json:"cainfo"`
  6705. ErrMsg string `json:"err_msg"`
  6706. InfRefmsgid string `json:"inf_refmsgid"`
  6707. Infcode int64 `json:"infcode"`
  6708. Output struct {
  6709. Result []struct {
  6710. BasMednFlag string `json:"bas_medn_flag"`
  6711. ChldMedcFlag string `json:"chld_medc_flag"`
  6712. ChrgitmLv string `json:"chrgitm_lv"`
  6713. Cnt float64 `json:"cnt"`
  6714. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  6715. DrtReimFlag string `json:"drt_reim_flag"`
  6716. FeedetlSn string `json:"feedetl_sn"`
  6717. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6718. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  6719. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6720. ListSpItemFlag string `json:"list_sp_item_flag"`
  6721. LmtUsedFlag string `json:"lmt_used_flag"`
  6722. MedChrgitmType string `json:"med_chrgitm_type"`
  6723. Memo string `json:"memo"`
  6724. OverlmtAmt float64 `json:"overlmt_amt"`
  6725. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6726. Pric float64 `json:"pric"`
  6727. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  6728. SelfpayProp float64 `json:"selfpay_prop"`
  6729. } `json:"result"`
  6730. } `json:"output"`
  6731. RefmsgTime string `json:"refmsg_time"`
  6732. RespondTime string `json:"respond_time"`
  6733. Signtype string `json:"signtype"`
  6734. WarnMsg string `json:"warn_msg"`
  6735. }
  6736. type ResultFive struct {
  6737. Insutype string `json:"insutype"`
  6738. }
  6739. type ResultSix struct {
  6740. Cainfo interface{} `json:"cainfo"`
  6741. ErrMsg interface{} `json:"err_msg"`
  6742. InfRefmsgid string `json:"inf_refmsgid"`
  6743. Infcode int64 `json:"infcode"`
  6744. Output struct {
  6745. } `json:"output"`
  6746. RefmsgTime string `json:"refmsg_time"`
  6747. RespondTime string `json:"respond_time"`
  6748. Signtype interface{} `json:"signtype"`
  6749. WarnMsg interface{} `json:"warn_msg"`
  6750. }
  6751. type ResultSeven struct {
  6752. Cainfo string `json:"cainfo"`
  6753. ErrMsg string `json:"err_msg"`
  6754. InfRefmsgid string `json:"inf_refmsgid"`
  6755. Infcode int64 `json:"infcode"`
  6756. Output struct {
  6757. Setldetail []interface{} `json:"setldetail"`
  6758. Setlinfo struct {
  6759. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6760. AcctPay float64 `json:"acct_pay"`
  6761. ActPayDedc float64 `json:"act_pay_dedc"`
  6762. Age float64 `json:"age"`
  6763. Balc float64 `json:"balc"`
  6764. Brdy string `json:"brdy"`
  6765. Certno string `json:"certno"`
  6766. ClrOptins string `json:"clr_optins"`
  6767. ClrType string `json:"clr_type"`
  6768. ClrWay string `json:"clr_way"`
  6769. CvlservFlag string `json:"cvlserv_flag"`
  6770. CvlservPay float64 `json:"cvlserv_pay"`
  6771. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6772. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6773. Gend string `json:"gend"`
  6774. HifesPay float64 `json:"hifes_pay"`
  6775. HifmiPay float64 `json:"hifmi_pay"`
  6776. HifobPay float64 `json:"hifob_pay"`
  6777. HifpPay float64 `json:"hifp_pay"`
  6778. HospPartAmt float64 `json:"hosp_part_amt"`
  6779. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6780. Insutype string `json:"insutype"`
  6781. MafPay float64 `json:"maf_pay"`
  6782. MdtrtCertType string `json:"mdtrt_cert_type"`
  6783. MdtrtID string `json:"mdtrt_id"`
  6784. MedType string `json:"med_type"`
  6785. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6786. MedinsSetlID string `json:"medins_setl_id"`
  6787. Naty string `json:"naty"`
  6788. OthPay float64 `json:"oth_pay"`
  6789. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6790. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6791. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6792. PsnCashPay float64 `json:"psn_cash_pay"`
  6793. PsnCertType string `json:"psn_cert_type"`
  6794. PsnName string `json:"psn_name"`
  6795. PsnNo string `json:"psn_no"`
  6796. PsnPartAmt float64 `json:"psn_part_amt"`
  6797. PsnType string `json:"psn_type"`
  6798. SetlID string `json:"setl_id"`
  6799. SetlTime string `json:"setl_time"`
  6800. } `json:"setlinfo"`
  6801. } `json:"output"`
  6802. RefmsgTime string `json:"refmsg_time"`
  6803. RespondTime string `json:"respond_time"`
  6804. Signtype interface{} `json:"signtype"`
  6805. WarnMsg interface{} `json:"warn_msg"`
  6806. }
  6807. type ResultEight struct {
  6808. Cainfo string `json:"cainfo"`
  6809. ErrMsg string `json:"err_msg"`
  6810. InfRefmsgid string `json:"inf_refmsgid"`
  6811. Infcode int64 `json:"infcode"`
  6812. Output struct {
  6813. Stmtinfo struct {
  6814. SetlOptins string `json:"setl_optins"`
  6815. StmtRslt string `json:"stmt_rslt"`
  6816. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  6817. } `json:"stmtinfo"`
  6818. } `json:"output"`
  6819. RefmsgTime string `json:"refmsg_time"`
  6820. RespondTime string `json:"respond_time"`
  6821. Signtype interface{} `json:"signtype"`
  6822. WarnMsg interface{} `json:"warn_msg"`
  6823. }
  6824. type ResultNine struct {
  6825. Cainfo string `json:"cainfo"`
  6826. ErrMsg string `json:"err_msg"`
  6827. InfRefmsgid string `json:"inf_refmsgid"`
  6828. Infcode int64 `json:"infcode"`
  6829. Output struct {
  6830. FileQuryNo string `json:"file_qury_no"`
  6831. } `json:"output"`
  6832. RefmsgTime string `json:"refmsg_time"`
  6833. RespondTime string `json:"respond_time"`
  6834. Signtype interface{} `json:"signtype"`
  6835. WarnMsg interface{} `json:"warn_msg"`
  6836. }
  6837. type ResultTen struct {
  6838. Cainfo string `json:"cainfo"`
  6839. ErrMsg string `json:"err_msg"`
  6840. InfRefmsgid string `json:"inf_refmsgid"`
  6841. Infcode int64 `json:"infcode"`
  6842. Output struct {
  6843. DldEndtime string `json:"dld_endtime"`
  6844. FileQuryNo string `json:"file_qury_no"`
  6845. Filename string `json:"filename"`
  6846. } `json:"output"`
  6847. RefmsgTime string `json:"refmsg_time"`
  6848. RespondTime string `json:"respond_time"`
  6849. Signtype interface{} `json:"signtype"`
  6850. WarnMsg interface{} `json:"warn_msg"`
  6851. }
  6852. type ResultEleven struct {
  6853. Cainfo string `json:"cainfo"`
  6854. ErrMsg string `json:"err_msg"`
  6855. InfRefmsgid string `json:"inf_refmsgid"`
  6856. Infcode int64 `json:"infcode"`
  6857. Output struct {
  6858. Setlinfo struct {
  6859. FixmedinsName string `json:"fixmedins_name"`
  6860. FixmedinsCode string `json:"fixmedins_code"`
  6861. PsnNo string `json:"psn_no"`
  6862. PsnName string `json:"psn_name"`
  6863. HifobPay float64 `json:"hifob_pay"`
  6864. Gend string `json:"gend"`
  6865. Brdy string `json:"brdy"`
  6866. PsnCertType string `json:"psn_cert_type"`
  6867. PsnType string `json:"psn_type"`
  6868. EmpName string `json:"emp_name"`
  6869. Certno string `json:"certno"`
  6870. Insutype string `json:"insutype"`
  6871. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6872. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6873. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6874. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6875. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6876. ActPayDedc float64 `json:"act_pay_dedc"`
  6877. HifpPay float64 `json:"hifp_pay"`
  6878. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6879. CvlservPay float64 `json:"cvlserv_pay"`
  6880. HifesPay float64 `json:"hifes_pay"`
  6881. HifmiPay float64 `json:"hifmi_pay"`
  6882. MafPay float64 `json:"maf_pay"`
  6883. OthPay float64 `json:"oth_pay"`
  6884. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6885. PsnPay float64 `json:"psn_pay"`
  6886. AcctPay float64 `json:"acct_pay"`
  6887. CashPayamt float64 `json:"cash_payamt"`
  6888. Balc float64 `json:"balc"`
  6889. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6890. MedinsSetlId string `json:"medins_setl_id"`
  6891. RefdSetlFlag string `json:"refd_setl_flag"`
  6892. SetlTime string `json:"setl_time"`
  6893. MedType string `json:"med_type"`
  6894. } `json:"setlinfo"`
  6895. } `json:"output"`
  6896. RefmsgTime string `json:"refmsg_time"`
  6897. RespondTime string `json:"respond_time"`
  6898. Signtype interface{} `json:"signtype"`
  6899. WarnMsg interface{} `json:"warn_msg"`
  6900. }
  6901. type Custom struct {
  6902. DetItemFeeSumamt string
  6903. Cut string
  6904. FeedetlSn string
  6905. Price string
  6906. MedListCodg string
  6907. Type int64
  6908. AdviceId int64
  6909. ProjectId int64
  6910. ItemId int64
  6911. }
  6912. // 获取个人信息----挂号-----上传就诊信息
  6913. func (c *HisApiController) GetRegisterInfo() {
  6914. id, _ := c.GetInt64("id")
  6915. record_time := c.GetString("record_time")
  6916. settlementValue, _ := c.GetInt64("settlement_value")
  6917. medical_insurance_card := c.GetString("medical_insurance_card")
  6918. name := c.GetString("name")
  6919. id_card_type, _ := c.GetInt64("id_card_type")
  6920. certificates, _ := c.GetInt64("certificates")
  6921. medical_care, _ := c.GetInt64("medical_care")
  6922. birthday := c.GetString("birthday")
  6923. age, _ := c.GetInt64("age")
  6924. id_card := c.GetString("id_card")
  6925. register_type, _ := c.GetInt64("register")
  6926. doctor, _ := c.GetInt64("doctor")
  6927. department, _ := c.GetInt64("department")
  6928. gender, _ := c.GetInt64("sex")
  6929. phone := c.GetString("phone")
  6930. registration_fee, _ := c.GetFloat("registration_fee")
  6931. medical_expenses, _ := c.GetFloat("medical_expenses")
  6932. social_type, _ := c.GetInt64("social_type")
  6933. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6934. diagnosis_ids := c.GetString("diagnosis")
  6935. sick_type, _ := c.GetInt64("sick_type")
  6936. reg_type := c.GetString("p_type")
  6937. timeLayout := "2006-01-02"
  6938. loc, _ := time.LoadLocation("Local")
  6939. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6940. birthUnix := birthdays.Unix()
  6941. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6942. if err != nil {
  6943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6944. return
  6945. }
  6946. recordDateTime := theTime.Unix()
  6947. adminInfo := c.GetAdminUserInfo()
  6948. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6949. if tempPatient.ID == 0 {
  6950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6951. return
  6952. }
  6953. var patient service.Patients
  6954. if id == 0 {
  6955. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6956. } else {
  6957. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6958. }
  6959. if patient.ID == 0 {
  6960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6961. return
  6962. }
  6963. if len(patient.IdCardNo) == 0 {
  6964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6965. return
  6966. }
  6967. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6968. if len(his) >= 1 {
  6969. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6970. if len(his) >= 1 && order.ID == 0 {
  6971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6972. return
  6973. }
  6974. }
  6975. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6976. fmt.Println(timeStr)
  6977. timeArr := strings.Split(timeStr, " ")
  6978. fmt.Println(timeArr)
  6979. timeArrTwo := strings.Split(timeArr[0], "-")
  6980. timeArrThree := strings.Split(timeArr[1], ":")
  6981. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6982. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6983. if len(lists) == 0 {
  6984. var hisPatient models.XtHisPatient
  6985. hisPatient = models.XtHisPatient{
  6986. Name: name,
  6987. Age: age,
  6988. Gender: gender,
  6989. Birthday: birthUnix,
  6990. Phone: phone,
  6991. MedicalTreatmentType: medical_care,
  6992. IdType: certificates,
  6993. IdCardNo: id_card,
  6994. BalanceAccountsType: settlementValue,
  6995. SocialType: social_type,
  6996. MedicalInsuranceNumber: medical_insurance_card,
  6997. RegisterType: register_type,
  6998. RegisterCost: registration_fee,
  6999. TreatmentCost: medical_expenses,
  7000. AdminUserId: adminInfo.AdminUser.Id,
  7001. UserOrgId: adminInfo.CurrentOrgId,
  7002. Status: 1,
  7003. RecordDate: recordDateTime,
  7004. IsReturn: 1,
  7005. PatientId: patient.ID,
  7006. Ctime: time.Now().Unix(),
  7007. Mtime: time.Now().Unix(),
  7008. Number: str,
  7009. IdCardType: id_card_type,
  7010. Departments: department,
  7011. Doctor: doctor,
  7012. PType: reg_type,
  7013. Diagnosis: diagnosis_ids,
  7014. SickType: sick_type,
  7015. }
  7016. service.CreateHisPatient(&hisPatient)
  7017. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7018. c.ServeSuccessJSON(map[string]interface{}{
  7019. "his_info": hisPatient,
  7020. })
  7021. } else {
  7022. //chrgBchno := rand.Intn(1000000) + 10000
  7023. var hisPatient models.XtHisPatient
  7024. hisPatient = models.XtHisPatient{
  7025. Name: name,
  7026. Age: age,
  7027. Gender: gender,
  7028. Birthday: birthUnix,
  7029. Phone: phone,
  7030. MedicalTreatmentType: medical_care,
  7031. IdType: certificates,
  7032. IdCardNo: id_card,
  7033. BalanceAccountsType: settlementValue,
  7034. SocialType: social_type,
  7035. MedicalInsuranceNumber: medical_insurance_card,
  7036. RegisterType: register_type,
  7037. RegisterCost: registration_fee,
  7038. TreatmentCost: medical_expenses,
  7039. AdminUserId: adminInfo.AdminUser.Id,
  7040. UserOrgId: adminInfo.CurrentOrgId,
  7041. Status: 1,
  7042. RecordDate: recordDateTime,
  7043. IsReturn: 1,
  7044. PatientId: patient.ID,
  7045. Ctime: time.Now().Unix(),
  7046. Mtime: time.Now().Unix(),
  7047. Number: str,
  7048. IdCardType: id_card_type,
  7049. Departments: department,
  7050. Doctor: doctor,
  7051. PType: reg_type,
  7052. Diagnosis: diagnosis_ids,
  7053. SickType: sick_type,
  7054. }
  7055. service.CreateHisPatient(&hisPatient)
  7056. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7057. c.ServeSuccessJSON(map[string]interface{}{
  7058. "his_info": hisPatient,
  7059. })
  7060. }
  7061. }
  7062. // 上传明细----结算
  7063. func (c *HisApiController) GetUploadInfo() {
  7064. id, _ := c.GetInt64("id")
  7065. record_time := c.GetString("record_time")
  7066. his_patient_id, _ := c.GetInt64("his_patient_id")
  7067. oth_desc := c.GetString("oth_desc")
  7068. pay_way, _ := c.GetInt64("pay_way")
  7069. pay_ways := c.GetString("pay_ways")
  7070. pay_price, _ := c.GetFloat("pay_price")
  7071. pay_card_no := c.GetString("pay_card_no")
  7072. discount_price, _ := c.GetFloat("discount_price")
  7073. preferential_price, _ := c.GetFloat("preferential_price")
  7074. reality_price, _ := c.GetFloat("reality_price")
  7075. found_price, _ := c.GetFloat("found_price")
  7076. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7077. private_price, _ := c.GetFloat("private_price")
  7078. timeLayout := "2006-01-02"
  7079. loc, _ := time.LoadLocation("Local")
  7080. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7081. fapiao_code := c.GetString("fapiao_code")
  7082. fapiao_number := c.GetString("fapiao_number")
  7083. diagnosis_id := c.GetString("diagnosis")
  7084. sick_type, _ := c.GetInt64("sick_type")
  7085. reg_type, _ := c.GetInt64("p_type")
  7086. order_id, _ := c.GetInt64("order_id")
  7087. cash_pay := c.GetString("cash_pay")
  7088. wechat_pay := c.GetString("wechat_pay")
  7089. ali_pay := c.GetString("ali_pay")
  7090. jifen_pay := c.GetString("jifen_pay")
  7091. band_card_pay := c.GetString("band_card_pay")
  7092. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7093. tmp_decimal := c.GetString("tmp_decimal")
  7094. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7095. var decimal float64 //本次使用的押金
  7096. var errmsg error
  7097. tx := service.XTWriteDB().Begin() //开了事务
  7098. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7099. defer func() {
  7100. if errmsg != nil {
  7101. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7102. tx.Rollback()
  7103. } else {
  7104. tx.Commit()
  7105. }
  7106. }()
  7107. fmt.Println("dec_way", dec_way)
  7108. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7109. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7110. return
  7111. }
  7112. if len(tmp_decimal) > 0 {
  7113. if tmp_decimal[0] == 45 {
  7114. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7115. return
  7116. }
  7117. }
  7118. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7119. fmt.Println(errs)
  7120. decimal = tt
  7121. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7122. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7123. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7124. if err != nil {
  7125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7126. return
  7127. }
  7128. recordDateTime := theTime.Unix()
  7129. adminUser := c.GetAdminUserInfo()
  7130. var prescriptions []*models.HisPrescription
  7131. var prescriptionsOne []*models.HisPrescription
  7132. var start_time int64
  7133. var end_time int64
  7134. ids_str := c.GetString("ids")
  7135. ids_arr := strings.Split(ids_str, ",")
  7136. if tempOrder.ID == 0 {
  7137. if settle_accounts_type == 1 { //日结
  7138. fmt.Println(reg_type)
  7139. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7140. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7141. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7142. } else {
  7143. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7144. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7145. }
  7146. } else { //月结
  7147. start_time_str := c.GetString("start_time")
  7148. end_time_str := c.GetString("end_time")
  7149. timeLayout := "2006-01-02"
  7150. loc, _ := time.LoadLocation("Local")
  7151. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7152. if err != nil {
  7153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7154. return
  7155. }
  7156. recordStartTime := theStartTime.Unix()
  7157. start_time = recordStartTime
  7158. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7159. if err != nil {
  7160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7161. return
  7162. }
  7163. recordEndTime := theEndTime.Unix()
  7164. end_time = recordEndTime
  7165. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7166. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7167. }
  7168. var goods []*models.DialysisBeforePrepareGoods
  7169. var newGoods []*models.NewDialysisBeforePrepareGoods
  7170. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7171. var infos []*models.HisDoctorAdviceInfo
  7172. var infoList []*models.HisDoctorAdviceInfo
  7173. var hisAdvice []*models.HisDoctorAdviceInfo
  7174. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7175. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7176. //判断库存不足
  7177. //结算出库开关
  7178. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7179. if settConfig.IsOpen == 1 {
  7180. //判断库存的地方
  7181. for _, info := range prescriptions {
  7182. if info.Type == 1 {
  7183. infos = append(infos, info.HisDoctorAdviceInfo...)
  7184. }
  7185. if info.Type == 2 {
  7186. for _, sumItem := range info.HisPrescriptionProject {
  7187. if sumItem.Type == 3 {
  7188. var good models.DialysisBeforePrepareGoods
  7189. var newGood models.NewDialysisBeforePrepareGoods
  7190. good.GoodId = sumItem.GoodInfo.ID
  7191. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7192. count, _ := strconv.Atoi(sumItem.Count)
  7193. good.Count = int64(count)
  7194. good.StorehouseId = houseConfig.StorehouseOutInfo
  7195. good.ProjectId = sumItem.ID
  7196. goods = append(goods, &good)
  7197. newGood.GoodId = sumItem.GoodInfo.ID
  7198. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7199. count2, _ := strconv.Atoi(sumItem.Count)
  7200. newGood.Count = int64(count2)
  7201. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7202. newGood.ProjectId = sumItem.ID
  7203. newGoods = append(newGoods, &newGood)
  7204. }
  7205. }
  7206. }
  7207. }
  7208. for _, info := range prescriptionsOne {
  7209. if info.Type == 1 {
  7210. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7211. }
  7212. if info.Type == 2 {
  7213. for _, sumItem := range info.HisPrescriptionProject {
  7214. if sumItem.Type == 3 {
  7215. var newGood models.NewDialysisBeforePrepareGoods
  7216. newGood.GoodId = sumItem.GoodInfo.ID
  7217. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7218. count2, _ := strconv.Atoi(sumItem.Count)
  7219. newGood.Count = int64(count2)
  7220. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7221. newGood.ProjectId = sumItem.ID
  7222. newGoodOne = append(newGoodOne, &newGood)
  7223. }
  7224. }
  7225. }
  7226. }
  7227. //判断
  7228. for _, itemOne := range infos {
  7229. for _, itemTwo := range hisAdvice {
  7230. if itemOne.DrugId == itemTwo.DrugId {
  7231. itemTwo.Child = append(itemTwo.Child, itemOne)
  7232. }
  7233. }
  7234. }
  7235. for _, itemTwo := range hisAdvice {
  7236. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7237. var sum_out_count int64
  7238. for _, itemThree := range itemTwo.Child {
  7239. var prescribing_number int64
  7240. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7241. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7242. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7243. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7244. }
  7245. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7246. prescribing_number = parseIntPrescribingNumber
  7247. }
  7248. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7249. prescribing_number = parseIntPrescribingNumber
  7250. }
  7251. sum_out_count += prescribing_number
  7252. }
  7253. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  7254. if sum_out_count > drugStockOut.FlushCount {
  7255. c.ServeSuccessJSON(map[string]interface{}{
  7256. "msg": "2",
  7257. "drug": medical,
  7258. })
  7259. return
  7260. }
  7261. }
  7262. for _, itemOne := range newGoods {
  7263. for _, item := range newGoodOne {
  7264. if itemOne.GoodId == item.GoodId {
  7265. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  7266. }
  7267. }
  7268. }
  7269. for _, item := range newGoodOne {
  7270. var sum_out_count_one int64
  7271. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  7272. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  7273. sum_out_count_one += itemOne.Count
  7274. }
  7275. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7276. fmt.Println("sum_out_count_one", sum_out_count_one)
  7277. fmt.Println("list.FlushCount", list.FlushCount)
  7278. if sum_out_count_one > list.FlushCount {
  7279. c.ServeSuccessJSON(map[string]interface{}{
  7280. "msg": "3",
  7281. "good": good,
  7282. })
  7283. return
  7284. }
  7285. }
  7286. }
  7287. timestamp := time.Now().Unix()
  7288. tempTime := time.Unix(timestamp, 0)
  7289. timeFormat := tempTime.Format("20060102150405")
  7290. chrgBchno := rand.Intn(100000) + 10000
  7291. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7292. strconv.FormatInt(his.PatientId, 10)
  7293. var ids []int64
  7294. for _, item := range prescriptions {
  7295. ids = append(ids, item.ID)
  7296. }
  7297. var total float64
  7298. for _, item := range prescriptions {
  7299. fmt.Println(item)
  7300. if item.Type == 1 { //药品
  7301. for _, subItem := range item.HisDoctorAdviceInfo {
  7302. total = total + (subItem.Price * subItem.PrescribingNumber)
  7303. }
  7304. }
  7305. if item.Type == 2 { //项目
  7306. for _, subItem := range item.HisPrescriptionProject {
  7307. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7308. total = total + (subItem.Price * cnt)
  7309. }
  7310. }
  7311. for _, subItem := range item.HisAdditionalCharge {
  7312. total = total + (subItem.Price * float64(subItem.Count))
  7313. }
  7314. }
  7315. if reg_type == 1111 || reg_type == 1112 {
  7316. reg_type = 11
  7317. }
  7318. tm := time.Unix(time.Now().Unix(), 0)
  7319. allTotal := fmt.Sprintf("%.4f", total)
  7320. totals, _ := strconv.ParseFloat(allTotal, 64)
  7321. order := &models.HisOrder{
  7322. UserOrgId: adminUser.CurrentOrgId,
  7323. HisPatientId: his.ID,
  7324. PatientId: id,
  7325. SettleAccountsDate: recordDateTime,
  7326. Ctime: time.Now().Unix(),
  7327. Mtime: time.Now().Unix(),
  7328. Status: 1,
  7329. OrderStatus: 2,
  7330. MdtrtId: his.Number,
  7331. Number: chrg_bchno,
  7332. MedfeeSumamt: totals,
  7333. PayWay: pay_way,
  7334. PayWays: pay_ways,
  7335. PayPrice: pay_price,
  7336. MedType: strconv.Itoa(int(reg_type)),
  7337. PayCardNo: pay_card_no,
  7338. DiscountPrice: discount_price,
  7339. PreferentialPrice: preferential_price,
  7340. RealityPrice: reality_price,
  7341. FoundPrice: found_price,
  7342. MedicalInsurancePrice: medical_insurance_price,
  7343. PrivatePrice: private_price,
  7344. SettleEndTime: end_time,
  7345. SettleStartTime: start_time,
  7346. PsnPartAmt: totals,
  7347. PsnCashPay: totals,
  7348. SettleType: settle_accounts_type,
  7349. FaPiaoCode: fapiao_code,
  7350. FaPiaoNumber: fapiao_number,
  7351. Diagnosis: diagnosis_id,
  7352. PType: 2,
  7353. SetlTime: tm.Format("2006-01-02 15:04:05"),
  7354. Decimal: decimal,
  7355. OthDesc: oth_desc,
  7356. CashPay: cash_pay,
  7357. WechatPay: wechat_pay,
  7358. AliPay: ali_pay,
  7359. JifenPay: jifen_pay,
  7360. BandCardPay: band_card_pay,
  7361. Creator: adminUser.AdminUser.Id,
  7362. }
  7363. err = service.CreateOrderTX(order, tx)
  7364. if err != nil {
  7365. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7366. return
  7367. }
  7368. var customs []*Custom
  7369. for _, item := range prescriptions {
  7370. if item.Type == 1 { //药品a
  7371. for _, subItem := range item.HisDoctorAdviceInfo {
  7372. cus := &Custom{
  7373. AdviceId: subItem.ID,
  7374. ProjectId: 0,
  7375. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  7376. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  7377. FeedetlSn: subItem.FeedetlSn,
  7378. Price: fmt.Sprintf("%.4f", subItem.Price),
  7379. MedListCodg: subItem.MedListCodg,
  7380. Type: 1,
  7381. }
  7382. customs = append(customs, cus)
  7383. }
  7384. }
  7385. if item.Type == 2 { //项目
  7386. for _, subItem := range item.HisPrescriptionProject {
  7387. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7388. cus := &Custom{
  7389. AdviceId: 0,
  7390. ProjectId: subItem.ID,
  7391. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  7392. Cut: fmt.Sprintf("%.4f", cnt),
  7393. FeedetlSn: subItem.FeedetlSn,
  7394. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  7395. MedListCodg: subItem.MedListCodg,
  7396. Type: 2,
  7397. }
  7398. customs = append(customs, cus)
  7399. }
  7400. }
  7401. for _, item := range item.HisAdditionalCharge {
  7402. cus := &Custom{
  7403. ItemId: item.ID,
  7404. AdviceId: 0,
  7405. ProjectId: 0,
  7406. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  7407. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  7408. FeedetlSn: item.FeedetlSn,
  7409. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  7410. MedListCodg: item.XtHisAddtionConfig.Code,
  7411. Type: 3,
  7412. }
  7413. customs = append(customs, cus)
  7414. }
  7415. }
  7416. for _, item := range customs {
  7417. var advice_id int64 = 0
  7418. var project_id int64 = 0
  7419. var item_id int64 = 0
  7420. var types int64 = 0
  7421. if item.Type == 1 {
  7422. advice_id = item.AdviceId
  7423. project_id = 0
  7424. item_id = 0
  7425. } else if item.Type == 2 {
  7426. advice_id = 0
  7427. item_id = 0
  7428. project_id = item.ProjectId
  7429. } else if item.Type == 3 {
  7430. advice_id = 0
  7431. item_id = item.ItemId
  7432. project_id = 0
  7433. }
  7434. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  7435. cut, _ := strconv.ParseFloat(item.Cut, 32)
  7436. pric, _ := strconv.ParseFloat(item.Price, 32)
  7437. info := &models.HisOrderInfo{
  7438. OrderNumber: order.Number,
  7439. UploadDate: time.Now().Unix(),
  7440. AdviceId: advice_id,
  7441. DetItemFeeSumamt: detItemFeeSumamt,
  7442. Cnt: cut,
  7443. Pric: pric,
  7444. PatientId: id,
  7445. Status: 1,
  7446. Mtime: time.Now().Unix(),
  7447. Ctime: time.Now().Unix(),
  7448. UserOrgId: adminUser.CurrentOrgId,
  7449. HisPatientId: his.ID,
  7450. OrderId: order.ID,
  7451. ProjectId: project_id,
  7452. Type: types,
  7453. ItemId: item_id,
  7454. }
  7455. service.CreateOrderInfoTX(info, tx)
  7456. }
  7457. his.Diagnosis = diagnosis_id
  7458. his.SickType = sick_type
  7459. his.RegisterType = reg_type
  7460. his.MedicalTreatmentType = reg_type
  7461. service.UpdataHisPateintTX(&his, tx)
  7462. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  7463. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  7464. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  7465. //判断是否使用了押金
  7466. if dec_way == "true" {
  7467. tmpstring := strconv.FormatInt(order.ID, 10)
  7468. //扣押金
  7469. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  7470. order.Decimal = decimal
  7471. service.UpDateOrderTwo(order, tx)
  7472. if errmsg != nil {
  7473. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  7474. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7475. return
  7476. }
  7477. }
  7478. if err == nil {
  7479. for _, info := range prescriptions {
  7480. if info.Type == 1 {
  7481. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  7482. }
  7483. if info.Type == 2 {
  7484. for _, sumItem := range info.HisPrescriptionProject {
  7485. if sumItem.Type == 3 {
  7486. var good models.DialysisBeforePrepareGoods
  7487. var newGood models.NewDialysisBeforePrepareGoods
  7488. var oldGood models.OldDialysisBeforePrepareGoods
  7489. good.GoodId = sumItem.GoodInfo.ID
  7490. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7491. count, _ := strconv.Atoi(sumItem.Count)
  7492. good.Count = int64(count)
  7493. good.StorehouseId = houseConfig.StorehouseOutInfo
  7494. good.ProjectId = sumItem.ID
  7495. good.PatientId = sumItem.PatientId
  7496. goods = append(goods, &good)
  7497. newGood.GoodId = sumItem.GoodInfo.ID
  7498. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7499. count2, _ := strconv.Atoi(sumItem.Count)
  7500. newGood.Count = int64(count2)
  7501. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7502. newGood.ProjectId = sumItem.ID
  7503. newGood.PatientId = sumItem.HisPatientId
  7504. newGoods = append(newGoods, &newGood)
  7505. oldGood.GoodId = sumItem.GoodInfo.ID
  7506. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7507. count3, _ := strconv.Atoi(sumItem.Count)
  7508. oldGood.Count = int64(count3)
  7509. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  7510. oldGood.ProjectId = sumItem.ID
  7511. oldGood.RecordDate = sumItem.RecordDate
  7512. oldGood.PatientId = sumItem.HisPatientId
  7513. oldGoods = append(oldGoods, &oldGood)
  7514. }
  7515. }
  7516. }
  7517. }
  7518. if settConfig.IsOpen == 1 {
  7519. for _, item := range infoList {
  7520. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7521. if medical.IsUse == 2 {
  7522. //药品出库
  7523. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  7524. //查询默认仓库
  7525. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  7526. //查询默认仓库剩余多少库存
  7527. var sum_count int64
  7528. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  7529. for _, its := range stockInfo {
  7530. if its.MaxUnit == medical.MaxUnit {
  7531. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  7532. }
  7533. sum_count += its.StockMaxNumber + its.StockMinNumber
  7534. }
  7535. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  7536. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  7537. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  7538. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  7539. }
  7540. }
  7541. orgId := c.GetAdminUserInfo().CurrentOrgId
  7542. if len(oldGoods) > 0 {
  7543. timeStr := time.Now().Format("2006-01-02")
  7544. timeArr := strings.Split(timeStr, "-")
  7545. total, _ := service.FindAllWarehouseOut(orgId)
  7546. total = total + 1
  7547. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7548. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7549. number = number + total
  7550. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7551. operation_time := time.Now().Unix()
  7552. creater := c.GetAdminUserInfo().AdminUser.Id
  7553. //查询默认出库仓库库存
  7554. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  7555. recordDateStr := time.Now().Format("2006-01-02")
  7556. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  7557. nowtime := recordDate.Unix()
  7558. warehouseOut := models.WarehouseOut{
  7559. WarehouseOutOrderNumber: warehousing_out_order,
  7560. OperationTime: operation_time,
  7561. OrgId: orgId,
  7562. Creater: creater,
  7563. Ctime: time.Now().Unix(),
  7564. Status: 1,
  7565. WarehouseOutTime: nowtime,
  7566. Type: 1,
  7567. StorehouseId: storeConfig.StorehouseOutInfo,
  7568. IsCheck: 1,
  7569. OrderId: order.ID,
  7570. IsSys: 5,
  7571. }
  7572. //查询是否生成出库单
  7573. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  7574. if out.ID == 0 {
  7575. service.AddSigleWarehouseOut(&warehouseOut)
  7576. }
  7577. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  7578. for _, item := range oldGoods {
  7579. dialyPrepareOne := models.DialysisBeforePrepare{
  7580. GoodTypeId: item.GoodTypeId,
  7581. GoodId: item.GoodId,
  7582. PatientId: his.PatientId,
  7583. RecordDate: item.RecordDate,
  7584. UserOrgId: adminUser.CurrentOrgId,
  7585. Count: item.Count,
  7586. Ctime: time.Now().Unix(),
  7587. Creater: adminUser.AdminUser.Id,
  7588. CommdityCode: item.CommdityCode,
  7589. Status: 1,
  7590. StorehouseId: houseConfig.StorehouseOutInfo,
  7591. }
  7592. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  7593. //非零用
  7594. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  7595. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  7596. //查询剩余库存
  7597. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7598. var sum_count int64
  7599. for _, item := range goodList {
  7600. sum_count += item.StockCount
  7601. }
  7602. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  7603. //耗材
  7604. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  7605. }
  7606. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  7607. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  7608. //查询剩余库存
  7609. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7610. var sum_count int64
  7611. for _, item := range goodList {
  7612. sum_count += item.StockCount
  7613. }
  7614. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  7615. //耗材
  7616. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  7617. }
  7618. }
  7619. }
  7620. }
  7621. c.ServeSuccessJSON(map[string]interface{}{
  7622. "msg": "结算成功",
  7623. })
  7624. }
  7625. }
  7626. }
  7627. // 退款
  7628. func (c *HisApiController) Refund() {
  7629. order_id, _ := c.GetInt64("order_id")
  7630. order, _ := service.GetHisOrderByID(order_id)
  7631. adminUser := c.GetAdminUserInfo()
  7632. orgid := c.GetAdminUserInfo().CurrentOrgId
  7633. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  7634. if err != nil {
  7635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7636. return
  7637. }
  7638. tmp := strconv.FormatInt(order.ID, 10)
  7639. //当押金不为零时产生退费记录
  7640. if order.Decimal != 0 {
  7641. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  7642. if err != nil {
  7643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7644. return
  7645. }
  7646. }
  7647. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  7648. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  7649. var goods []*models.DialysisBeforePrepareGoods
  7650. var newGoods []*models.NewDialysisBeforePrepareGoods
  7651. var infos []*models.HisDoctorAdviceInfo
  7652. for _, info := range orders {
  7653. if info.AdviceId > 0 && info.ProjectId == 0 {
  7654. infos = append(infos, &info.HisDoctorAdviceInfo)
  7655. }
  7656. if info.ProjectId > 0 && info.AdviceId == 0 {
  7657. if info.HisPrescriptionProject.Type == 3 {
  7658. var good models.DialysisBeforePrepareGoods
  7659. var newGood models.NewDialysisBeforePrepareGoods
  7660. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  7661. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  7662. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  7663. good.Count = int64(count)
  7664. good.StorehouseId = houseConfig.StorehouseOutInfo
  7665. good.ProjectId = info.HisPrescriptionProject.ID
  7666. good.PatientId = info.PatientId
  7667. good.OrderId = order_id
  7668. goods = append(goods, &good)
  7669. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  7670. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  7671. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  7672. newGood.Count = int64(count2)
  7673. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7674. newGood.ProjectId = info.HisPrescriptionProject.ID
  7675. newGood.RecordDate = order.SettleAccountsDate
  7676. newGood.UserOrgId = order.UserOrgId
  7677. newGood.PatientId = info.PatientId
  7678. newGood.OrderId = order_id
  7679. newGoods = append(newGoods, &newGood)
  7680. }
  7681. }
  7682. }
  7683. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7684. if settConfig.IsOpen == 1 {
  7685. for _, item := range infos {
  7686. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  7687. }
  7688. for _, item := range newGoods {
  7689. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  7690. }
  7691. }
  7692. c.ServeSuccessJSON(map[string]interface{}{
  7693. "msg": "退费成功",
  7694. })
  7695. }
  7696. func (c *HisApiController) RefundNumber() {
  7697. his_patient_id, _ := c.GetInt64("id")
  7698. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7699. info.Status = 0
  7700. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  7701. if count > 0 {
  7702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  7703. return
  7704. }
  7705. err := service.SaveHisPatient(info)
  7706. if err == nil {
  7707. c.ServeSuccessJSON(map[string]interface{}{
  7708. "msg": "退号成功",
  7709. })
  7710. } else {
  7711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7712. return
  7713. }
  7714. }
  7715. func (this *HisApiController) AdditionalCharge() {
  7716. dataBody := make(map[string]interface{}, 0)
  7717. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  7718. fmt.Println(err)
  7719. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  7720. patient_id := int64(dataBody["patient_id"].(float64))
  7721. medicineData, _ := dataBody["medicineData"].([]interface{})
  7722. adminUserInfo := this.GetAdminUserInfo()
  7723. orgId := adminUserInfo.CurrentOrgId
  7724. admin_user_id := adminUserInfo.AdminUser.Id
  7725. timeStr := time.Now().Format("2006-01-02")
  7726. timeLayout := "2006-01-02 15:04:05"
  7727. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  7728. timenow := timeStringToTime.Unix()
  7729. var additionalCharges []*models.HisAdditionalCharge
  7730. for _, item := range medicineData {
  7731. var randNum int
  7732. randNum = rand.Intn(10000) + 1000
  7733. timestamp := time.Now().Unix()
  7734. tempTime := time.Unix(timestamp, 0)
  7735. timeFormat := tempTime.Format("20060102150405")
  7736. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  7737. items := item.(map[string]interface{})
  7738. money := items["price"].(string)
  7739. item_id_str := items["item_id"].(string)
  7740. name := items["name"].(string)
  7741. id_str := items["id"].(string)
  7742. moneys, _ := strconv.ParseInt(money, 10, 64)
  7743. monStr := strconv.FormatInt(moneys, 10)
  7744. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  7745. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  7746. id, _ := strconv.ParseInt(id_str, 10, 64)
  7747. additionalCharge := &models.HisAdditionalCharge{
  7748. ID: id,
  7749. HisPatientId: his_patient_id,
  7750. UserOrgId: orgId,
  7751. PatientId: patient_id,
  7752. RecordDate: timenow,
  7753. Price: monneyStr,
  7754. Status: 1,
  7755. ItemName: name,
  7756. ItemId: item_id,
  7757. AdminUserId: admin_user_id,
  7758. CreatedTime: time.Now().Unix(),
  7759. OrderStatus: 0,
  7760. PrescriptionNumber: "",
  7761. BatchNumber: "",
  7762. FeedetlSn: p_number,
  7763. }
  7764. service.CreateAdditionalCharge(additionalCharge)
  7765. additionalCharges = append(additionalCharges, additionalCharge)
  7766. }
  7767. this.ServeSuccessJSON(map[string]interface{}{
  7768. "msg": "添加成功",
  7769. "additional_charges": additionalCharges,
  7770. })
  7771. }
  7772. func (this *HisApiController) DeleteAddition() {
  7773. id, _ := this.GetInt64("id")
  7774. //TODO 需要判断是否已经结算
  7775. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  7776. if err == nil {
  7777. this.ServeSuccessJSON(map[string]interface{}{
  7778. "msg": "删除成功",
  7779. })
  7780. return
  7781. } else {
  7782. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7783. return
  7784. }
  7785. }
  7786. func (this *HisApiController) GetAdminUsers() {
  7787. adminUser := this.GetAdminUserInfo()
  7788. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  7789. this.ServeSuccessJSON(map[string]interface{}{
  7790. "doctors": doctors,
  7791. })
  7792. }
  7793. func (this *HisApiController) GetLastOrNextHisPrescription() {
  7794. change_type, _ := this.GetInt64("type", 0)
  7795. record_date := this.GetString("record_time")
  7796. patient_id, _ := this.GetInt64("patient_id", 0)
  7797. p_type, _ := this.GetInt64("p_type", 0)
  7798. timeLayout := "2006-01-02"
  7799. loc, _ := time.LoadLocation("Local")
  7800. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7801. record_time := theAdviceRecordTime.Unix()
  7802. adminUserInfo := this.GetAdminUserInfo()
  7803. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  7804. if err == nil {
  7805. if len(prescriptions) == 0 {
  7806. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  7807. return
  7808. } else {
  7809. this.ServeSuccessJSON(map[string]interface{}{
  7810. "prescriptions": prescriptions,
  7811. })
  7812. return
  7813. }
  7814. } else {
  7815. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7816. return
  7817. }
  7818. }
  7819. func (this *HisApiController) GetCallHisPrescription() {
  7820. patient_id, _ := this.GetInt64("patient_id", 0)
  7821. timeLayout := "2006-01-02"
  7822. loc, _ := time.LoadLocation("Local")
  7823. start_time := this.GetString("start_time")
  7824. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7825. end_time := this.GetString("end_time")
  7826. p_type, _ := this.GetInt64("p_type")
  7827. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7828. adminUserInfo := this.GetAdminUserInfo()
  7829. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  7830. if err == nil {
  7831. this.ServeSuccessJSON(map[string]interface{}{
  7832. "prescriptions": prescriptions,
  7833. })
  7834. return
  7835. } else {
  7836. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7837. return
  7838. }
  7839. }
  7840. func (this *HisApiController) GetHisDayPrescription() {
  7841. timeLayout := "2006-01-02"
  7842. loc, _ := time.LoadLocation("Local")
  7843. start_time := this.GetString("start_time")
  7844. patient_id, _ := this.GetInt64("patient_id", 0)
  7845. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7846. end_time := this.GetString("end_time")
  7847. p_type, _ := this.GetInt64("p_type")
  7848. order_status, _ := this.GetInt64("type")
  7849. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7850. adminUserInfo := this.GetAdminUserInfo()
  7851. var dayHisPrescription []*models.HisPrescription
  7852. var err error
  7853. if order_status == 1 || order_status == 0 {
  7854. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7855. } else if order_status == 2 {
  7856. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7857. }
  7858. var settle_total float64
  7859. for _, item := range dayHisPrescription {
  7860. if len(item.HisPrescriptionProject) > 0 {
  7861. for _, subItem := range item.HisPrescriptionProject {
  7862. count, _ := strconv.ParseFloat(subItem.Count, 64)
  7863. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  7864. settle_total = settle_total + total
  7865. }
  7866. }
  7867. if len(item.HisDoctorAdviceInfo) > 0 {
  7868. for _, subItem := range item.HisDoctorAdviceInfo {
  7869. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  7870. settle_total = settle_total + total
  7871. }
  7872. }
  7873. }
  7874. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  7875. if err == nil {
  7876. this.ServeSuccessJSON(map[string]interface{}{
  7877. "day_prescription": dayHisPrescription,
  7878. "settle_total": settle_total,
  7879. })
  7880. return
  7881. } else {
  7882. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7883. return
  7884. }
  7885. }
  7886. func (c *HisApiController) GetHisChargePatientList() {
  7887. record_date := c.GetString("record_date")
  7888. order_status, _ := c.GetInt64("type")
  7889. sch_type, _ := c.GetInt64("sch_type")
  7890. timeLayout := "2006-01-02"
  7891. loc, _ := time.LoadLocation("Local")
  7892. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7893. if err != nil {
  7894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7895. return
  7896. }
  7897. recordDateTime := theTime.Unix()
  7898. adminInfo := c.GetAdminUserInfo()
  7899. var tempPatients []*service.NewTempPatients
  7900. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  7901. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7902. if order_status != 2 {
  7903. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7904. } else {
  7905. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7906. }
  7907. } else {
  7908. if order_status != 2 {
  7909. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7910. } else {
  7911. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7912. }
  7913. }
  7914. var patients []*service.NewTempPatients
  7915. var patients_two []*service.NewTempPatients
  7916. for _, item := range tempPatients {
  7917. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7918. //过滤掉没挂号的和没开处方的
  7919. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7920. patients = append(patients, item)
  7921. }
  7922. //过滤掉没挂号的
  7923. if len(item.HisPatient) > 0 {
  7924. patients_two = append(patients_two, item)
  7925. }
  7926. } else {
  7927. if len(item.HisPrescription) > 0 {
  7928. patients = append(patients, item)
  7929. }
  7930. }
  7931. }
  7932. c.ServeSuccessJSON(map[string]interface{}{
  7933. "list": patients,
  7934. "list_two": patients_two,
  7935. })
  7936. }
  7937. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7938. record_date := c.GetString("record_date")
  7939. timeLayout := "2006-01-02"
  7940. loc, _ := time.LoadLocation("Local")
  7941. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7942. if err != nil {
  7943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7944. return
  7945. }
  7946. recordDateTime := theTime.Unix()
  7947. adminUser := c.GetAdminUserInfo()
  7948. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7949. var patients []*service.Patients
  7950. for _, item := range tempPatients {
  7951. if item.HisPatient.ID == 0 {
  7952. patients = append(patients, item)
  7953. }
  7954. }
  7955. c.ServeSuccessJSON(map[string]interface{}{
  7956. "list": patients,
  7957. //"list_two": patients_two,
  7958. })
  7959. }
  7960. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7961. newArr = make([]*service.Patients, 0)
  7962. for i := 0; i < len(patient); i++ {
  7963. repeat := false
  7964. for j := i + 1; j < len(patient); j++ {
  7965. if patient[i].ID == patient[j].ID {
  7966. repeat = true
  7967. break
  7968. }
  7969. }
  7970. if !repeat {
  7971. newArr = append(newArr, patient[i])
  7972. }
  7973. }
  7974. return
  7975. }
  7976. func (c *HisApiController) GetHisChargePatientInfo() {
  7977. patient_id, _ := c.GetInt64("patient_id")
  7978. his_patient_id, _ := c.GetInt64("his_patient_id")
  7979. record_date := c.GetString("record_date")
  7980. //start_time := c.GetString("start_time")
  7981. //end_time := c.GetString("end_time")
  7982. order_status, _ := c.GetInt64("type", 0)
  7983. p_type, _ := c.GetInt64("p_type", 0)
  7984. order_id, _ := c.GetInt64("order_id", 0)
  7985. timeLayout := "2006-01-02"
  7986. loc, _ := time.LoadLocation("Local")
  7987. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7988. if err != nil {
  7989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7990. return
  7991. }
  7992. recordDateTime := theTime.Unix()
  7993. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7994. //if err != nil {
  7995. //
  7996. //}
  7997. //startRecordDateTime := startTime.Unix()
  7998. //
  7999. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8000. //if err != nil {
  8001. //
  8002. //}
  8003. //endRecordDateTime := endTime.Unix()
  8004. admin := c.GetAdminUserInfo()
  8005. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8006. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8007. var prescriptions []*models.HisPrescription
  8008. //var unChargeMonthPrescriptions []*models.HisPrescription
  8009. order, _ := service.GetHisOrderByID(order_id)
  8010. if order_status == 1 || order_status == 0 {
  8011. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8012. } else if order_status == 2 {
  8013. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8014. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8015. }
  8016. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8017. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8018. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8019. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8020. //获取所有科室信息
  8021. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8022. c.ServeSuccessJSON(map[string]interface{}{
  8023. "his_info": his_patient_info,
  8024. "xt_info": xt_patient_info,
  8025. "prescription": prescriptions,
  8026. "case_history": case_history,
  8027. "info": patientPrescriptionInfo,
  8028. "last_info": lastPatientPrescriptionInfo,
  8029. "order": order,
  8030. "doctors": doctors,
  8031. "department": department,
  8032. })
  8033. return
  8034. }
  8035. func (c *HisApiController) GetAllOrderDetail() {
  8036. order_id, _ := c.GetInt64("id", 0)
  8037. order, _ := service.GetHisOrderByID(order_id)
  8038. if order.ID == 0 {
  8039. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8040. return
  8041. }
  8042. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8043. org_id := c.GetAdminUserInfo().CurrentOrgId
  8044. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8045. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8046. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8047. c.ServeSuccessJSON(map[string]interface{}{
  8048. "order": order,
  8049. "order_info": order_info,
  8050. "patient": patient,
  8051. "admin_info": adminInfo,
  8052. "hospital_record": record,
  8053. })
  8054. return
  8055. }
  8056. func (c *HisApiController) GetAllOrderDetailCollect() {
  8057. order_id, _ := c.GetInt64("id", 0)
  8058. order, _ := service.GetHisOrderByID(order_id)
  8059. if order.ID == 0 {
  8060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8061. return
  8062. }
  8063. org_id := c.GetAdminUserInfo().CurrentOrgId
  8064. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8065. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8066. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8067. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8068. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8069. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8070. var bedCostTotal float64 = 0 //床位总费
  8071. //var bedCostSelfTotal float64 = 0 //床位自费
  8072. var operationCostTotal float64 = 0 //手术费
  8073. //var operationCostSelfTotal float64 = 0 //手术费
  8074. var otherCostTotal float64 = 0 //其他费用
  8075. //var otherCostSelfTotal float64 = 0 //其他费用
  8076. var materialCostTotal float64 = 0 //材料费
  8077. //var materialCostSelfTotal float64 = 0 //材料费
  8078. var westernMedicineCostTotal float64 = 0 //西药费
  8079. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8080. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8081. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8082. var checkCostTotal float64 = 0 //检查费
  8083. //var checkCostSelfTotal float64 = 0 //检查费
  8084. var laboratoryCostTotal float64 = 0 //化验费
  8085. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8086. var treatCostTotal float64 = 0 //治疗费用
  8087. //var treatCostSelfTotal float64 = 0 //治疗费用
  8088. var zhenChaCostTotal float64 = 0 //其他费用
  8089. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8090. decimal.DivisionPrecision = 2
  8091. var BalanceAccountsType int64
  8092. if his.ID > 0 {
  8093. BalanceAccountsType = his.BalanceAccountsType
  8094. } else {
  8095. BalanceAccountsType = record.BalanceAccountsType
  8096. }
  8097. if BalanceAccountsType != 2 {
  8098. for _, item := range order_info {
  8099. if org_id == 10215 {
  8100. if item.MedChrgitmType == "01" { //床位费
  8101. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8102. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8103. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8104. }
  8105. if item.MedChrgitmType == "02" { //诊察费
  8106. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8107. //zhenChaCostSelfTotal = zhenChaCostTotal
  8108. }
  8109. if item.MedChrgitmType == "03" { //检查费
  8110. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8111. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8112. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8113. }
  8114. //if item.MedChrgitmType == "02" { //检查费
  8115. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8116. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8117. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8118. //}
  8119. if item.MedChrgitmType == "04" { //化验费
  8120. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8121. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8122. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8123. }
  8124. if item.MedChrgitmType == "05" { //治疗费
  8125. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8126. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8127. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8128. }
  8129. if item.MedChrgitmType == "06" { //手术费
  8130. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8131. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8132. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8133. }
  8134. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8135. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8136. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8137. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8138. }
  8139. if item.MedChrgitmType == "09" { //西药费
  8140. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8141. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8142. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8143. }
  8144. if item.MedChrgitmType == "11" { //中成费
  8145. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8146. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8147. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8148. }
  8149. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8150. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8151. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8152. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8153. }
  8154. } else if org_id == 10188 || org_id == 10217 {
  8155. if item.MedChrgitmType == "01" { //床位费
  8156. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8157. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8158. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8159. }
  8160. if item.MedChrgitmType == "02" { //诊察费
  8161. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8162. //zhenChaCostSelfTotal = zhenChaCostTotal
  8163. }
  8164. if item.MedChrgitmType == "03" { //检查费
  8165. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8166. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8167. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8168. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8169. }
  8170. //if item.MedChrgitmType == "02" { //检查费
  8171. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8172. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8173. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8174. //}
  8175. if item.MedChrgitmType == "04" { //化验费
  8176. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8177. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8178. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8179. }
  8180. if item.MedChrgitmType == "05" { //治疗费
  8181. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8182. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8183. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8184. }
  8185. if item.MedChrgitmType == "06" { //手术费
  8186. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8187. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8188. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8189. }
  8190. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8191. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8192. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8193. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8194. }
  8195. if item.MedChrgitmType == "09" { //西药费
  8196. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8197. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8198. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8199. }
  8200. if item.MedChrgitmType == "11" { //中成费
  8201. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8202. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8203. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8204. }
  8205. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8206. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8207. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8208. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8209. }
  8210. } else {
  8211. if item.MedChrgitmType == "01" { //床位费
  8212. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8213. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8214. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8215. }
  8216. //if item.MedChrgitmType == "02" { //诊察费
  8217. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8218. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8219. //}
  8220. if item.MedChrgitmType == "03" { //检查费
  8221. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8222. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8223. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8224. }
  8225. //if item.MedChrgitmType == "02" { //检查费
  8226. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8227. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8228. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8229. //}
  8230. if item.MedChrgitmType == "04" { //化验费
  8231. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8232. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8233. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8234. }
  8235. if item.MedChrgitmType == "05" { //治疗费
  8236. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8237. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8238. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8239. }
  8240. if item.MedChrgitmType == "06" { //手术费
  8241. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8242. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8243. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8244. }
  8245. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8246. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8247. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8248. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8249. }
  8250. if item.MedChrgitmType == "09" { //西药费
  8251. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8252. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8253. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8254. }
  8255. if item.MedChrgitmType == "11" { //中成费
  8256. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8257. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8258. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8259. }
  8260. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8261. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8262. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8263. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8264. }
  8265. }
  8266. }
  8267. c.ServeSuccessJSON(map[string]interface{}{
  8268. "order": order,
  8269. "order_info": order_info,
  8270. "patient": patient,
  8271. "admin_info": adminInfo,
  8272. "his_hospital": record,
  8273. "bedCostTotal": bedCostTotal,
  8274. "operationCostTotal": operationCostTotal,
  8275. "otherCostTotal": otherCostTotal,
  8276. "materialCostTotal": materialCostTotal,
  8277. "westernMedicineCostTotal": westernMedicineCostTotal,
  8278. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8279. "checkCostTotal": checkCostTotal,
  8280. "zhenChaCostTotal": zhenChaCostTotal,
  8281. "laboratoryCostTotal": laboratoryCostTotal,
  8282. "treatCostTotal": treatCostTotal,
  8283. })
  8284. } else {
  8285. for _, item := range order_info {
  8286. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8287. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8288. item.MedChrgitmType = "09"
  8289. }
  8290. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8291. if item.HisPrescriptionProject.Type == 2 {
  8292. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8293. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8294. case 0:
  8295. item.MedChrgitmType = "0"
  8296. break
  8297. case 1:
  8298. item.MedChrgitmType = "14"
  8299. break
  8300. case 2:
  8301. item.MedChrgitmType = "05"
  8302. break
  8303. case 3:
  8304. item.MedChrgitmType = "03"
  8305. break
  8306. case 4:
  8307. item.MedChrgitmType = "03"
  8308. break
  8309. case 5:
  8310. item.MedChrgitmType = "08"
  8311. break
  8312. case 6:
  8313. item.MedChrgitmType = "14"
  8314. break
  8315. case 7:
  8316. item.MedChrgitmType = "14"
  8317. break
  8318. case 8:
  8319. item.MedChrgitmType = "03"
  8320. break
  8321. case 9:
  8322. item.MedChrgitmType = "14"
  8323. break
  8324. case 10:
  8325. item.MedChrgitmType = "14"
  8326. break
  8327. case 11:
  8328. item.MedChrgitmType = "06"
  8329. break
  8330. case 12:
  8331. item.MedChrgitmType = "12"
  8332. break
  8333. case 13:
  8334. item.MedChrgitmType = "01"
  8335. break
  8336. case 14:
  8337. item.MedChrgitmType = "04"
  8338. break
  8339. case 15:
  8340. item.MedChrgitmType = "14"
  8341. break
  8342. }
  8343. } else {
  8344. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8345. case 1:
  8346. item.MedChrgitmType = "14"
  8347. break
  8348. case 2:
  8349. item.MedChrgitmType = "05"
  8350. break
  8351. case 3:
  8352. item.MedChrgitmType = "04"
  8353. break
  8354. case 4:
  8355. item.MedChrgitmType = "14"
  8356. break
  8357. case 5:
  8358. item.MedChrgitmType = "08"
  8359. break
  8360. case 6:
  8361. item.MedChrgitmType = "14"
  8362. break
  8363. case 7:
  8364. item.MedChrgitmType = "14"
  8365. break
  8366. case 8:
  8367. item.MedChrgitmType = "03"
  8368. break
  8369. case 9:
  8370. item.MedChrgitmType = "14"
  8371. break
  8372. }
  8373. }
  8374. } else if item.HisPrescriptionProject.Type == 3 {
  8375. item.MedChrgitmType = "08"
  8376. }
  8377. }
  8378. }
  8379. for _, item := range order_info {
  8380. if org_id == 10215 {
  8381. if item.MedChrgitmType == "01" { //床位费
  8382. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8383. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8384. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8385. }
  8386. if item.MedChrgitmType == "02" { //诊察费
  8387. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8388. //zhenChaCostSelfTotal = zhenChaCostTotal
  8389. }
  8390. if item.MedChrgitmType == "03" { //检查费
  8391. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8392. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8393. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8394. }
  8395. //if item.MedChrgitmType == "02" { //检查费
  8396. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8397. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8398. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8399. //}
  8400. if item.MedChrgitmType == "04" { //化验费
  8401. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8402. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8403. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8404. }
  8405. if item.MedChrgitmType == "05" { //治疗费
  8406. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8407. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8408. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8409. }
  8410. if item.MedChrgitmType == "06" { //手术费
  8411. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8412. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8413. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8414. }
  8415. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8416. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8417. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8418. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8419. }
  8420. if item.MedChrgitmType == "09" { //西药费
  8421. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8422. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8423. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8424. }
  8425. if item.MedChrgitmType == "11" { //中成费
  8426. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8427. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8428. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8429. }
  8430. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8431. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8432. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8433. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8434. }
  8435. } else {
  8436. if item.MedChrgitmType == "01" { //床位费
  8437. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8438. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8439. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8440. }
  8441. //if item.MedChrgitmType == "02" { //诊察费
  8442. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8443. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8444. //}
  8445. if item.MedChrgitmType == "03" { //检查费
  8446. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8447. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8448. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8449. }
  8450. //if item.MedChrgitmType == "02" { //检查费
  8451. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8452. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8453. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8454. //}
  8455. if item.MedChrgitmType == "04" { //化验费
  8456. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8457. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8458. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8459. }
  8460. if item.MedChrgitmType == "05" { //治疗费
  8461. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8462. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8463. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8464. }
  8465. if item.MedChrgitmType == "06" { //手术费
  8466. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8467. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8468. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8469. }
  8470. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8471. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8472. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8473. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8474. }
  8475. if item.MedChrgitmType == "09" { //西药费
  8476. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8477. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8478. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8479. }
  8480. if item.MedChrgitmType == "11" { //中成费
  8481. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8482. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8483. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8484. }
  8485. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8486. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8487. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8488. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8489. }
  8490. }
  8491. }
  8492. c.ServeSuccessJSON(map[string]interface{}{
  8493. "order": order,
  8494. "order_info": order_info,
  8495. "patient": patient,
  8496. "admin_info": adminInfo,
  8497. "his_hospital": record,
  8498. "bedCostTotal": bedCostTotal,
  8499. "operationCostTotal": operationCostTotal,
  8500. "otherCostTotal": otherCostTotal,
  8501. "materialCostTotal": materialCostTotal,
  8502. "westernMedicineCostTotal": westernMedicineCostTotal,
  8503. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8504. "checkCostTotal": checkCostTotal,
  8505. "zhenChaCostTotal": zhenChaCostTotal,
  8506. "laboratoryCostTotal": laboratoryCostTotal,
  8507. "treatCostTotal": treatCostTotal,
  8508. })
  8509. }
  8510. }
  8511. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  8512. page, _ := c.GetInt64("page")
  8513. limit, _ := c.GetInt64("limit")
  8514. keywords := c.GetString("keywords")
  8515. start_time := c.GetString("start_time")
  8516. end_time := c.GetString("end_time")
  8517. //clr_type := c.GetString("clr_type")
  8518. insutype := c.GetString("insutype")
  8519. timeLayout := "2006-01-02"
  8520. loc, _ := time.LoadLocation("Local")
  8521. var theStartTIme int64
  8522. if len(start_time) > 0 {
  8523. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8524. theStartTIme = theTime.Unix()
  8525. }
  8526. var theEndtTIme int64
  8527. if len(end_time) > 0 {
  8528. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8529. theEndtTIme = theTime.Unix()
  8530. }
  8531. if page <= 0 {
  8532. page = 1
  8533. }
  8534. if limit <= 0 {
  8535. limit = 10
  8536. }
  8537. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  8538. c.ServeSuccessJSON(map[string]interface{}{
  8539. "total": total,
  8540. "list": list,
  8541. })
  8542. return
  8543. }
  8544. func (c *HisApiController) GetPutOnRecordList() {
  8545. page, _ := c.GetInt64("page")
  8546. limit, _ := c.GetInt64("limit")
  8547. keywords := c.GetString("keywords")
  8548. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  8549. if page <= 0 {
  8550. page = 1
  8551. }
  8552. if limit <= 0 {
  8553. limit = 10
  8554. }
  8555. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  8556. c.ServeSuccessJSON(map[string]interface{}{
  8557. "total": total,
  8558. "list": list,
  8559. })
  8560. return
  8561. }
  8562. func (c *HisApiController) GetCompareData() {
  8563. start_time := c.GetString("start_time")
  8564. end_time := c.GetString("end_time")
  8565. insutype := c.GetString("insutype")
  8566. clr_type := c.GetString("clr_type")
  8567. timeLayout := "2006-01-02"
  8568. loc, _ := time.LoadLocation("Local")
  8569. var theStartTIme int64
  8570. if len(start_time) > 0 {
  8571. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8572. if err != nil {
  8573. theStartTIme = 0
  8574. }
  8575. theStartTIme = theTime.Unix()
  8576. }
  8577. var theEndtTIme int64
  8578. if len(end_time) > 0 {
  8579. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8580. if err != nil {
  8581. theEndtTIme = 0
  8582. }
  8583. theEndtTIme = theTime.Unix()
  8584. }
  8585. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  8586. fmt.Println(err)
  8587. if err == nil {
  8588. c.ServeSuccessJSON(map[string]interface{}{
  8589. "list": formData,
  8590. })
  8591. } else {
  8592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8593. return
  8594. }
  8595. }
  8596. func (c *HisApiController) GetFaPiaoData() {
  8597. order_id, _ := c.GetInt64("order_id")
  8598. patient_id, _ := c.GetInt64("patient_id")
  8599. //number := c.GetString("number")
  8600. adminUser := c.GetAdminUserInfo()
  8601. order, _ := service.GetHisOrderByID(order_id)
  8602. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8603. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8604. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8605. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8606. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  8607. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  8608. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8609. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8610. var bedCostTotal float64 = 0 //床位总费
  8611. var bedCostSelfTotal float64 = 0 //床位自费
  8612. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8613. var operationCostTotal float64 = 0 //手术费
  8614. var operationCostSelfTotal float64 = 0 //手术费
  8615. var operationCostPartSelfTotal float64 = 0 //手术费
  8616. var otherCostTotal float64 = 0 //其他费用
  8617. var otherCostSelfTotal float64 = 0 //其他费用
  8618. var otherCostPartSelfTotal float64 = 0 //其他费用
  8619. var materialCostTotal float64 = 0 //材料费
  8620. var materialCostSelfTotal float64 = 0 //材料费
  8621. var materialCostPartSelfTotal float64 = 0 //材料费
  8622. var westernMedicineCostTotal float64 = 0 //西药费
  8623. var westernMedicineCostSelfTotal float64 = 0 //西药费
  8624. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8625. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8626. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8627. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8628. var checkCostTotal float64 = 0 //检查费
  8629. var checkCostSelfTotal float64 = 0 //检查费
  8630. var checkCostPartSelfTotal float64 = 0 //检查费
  8631. var hiliCostTotal float64 = 0 //护理费
  8632. var hiliCostSelfTotal float64 = 0 //护理费
  8633. var hiliCostPartSelfTotal float64 = 0 //护理费
  8634. var laboratoryCostTotal float64 = 0 //化验费
  8635. var laboratoryCostSelfTotal float64 = 0 //化验费
  8636. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8637. var treatCostTotal float64 = 0 //治疗费用
  8638. var treatCostSelfTotal float64 = 0 //治疗费用
  8639. var treatCostPartSelfTotal float64 = 0 //治疗费用
  8640. var zhenChaCostTotal float64 = 0 //其他费用
  8641. var zhenChaCostSelfTotal float64 = 0 //其他费用
  8642. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8643. decimal.DivisionPrecision = 2
  8644. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8645. var balanceAccountsType int64
  8646. if his.ID > 0 {
  8647. balanceAccountsType = his.BalanceAccountsType
  8648. } else {
  8649. balanceAccountsType = his_hospital_record.BalanceAccountsType
  8650. }
  8651. if balanceAccountsType == 2 {
  8652. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8653. for _, item := range orderInfos_two {
  8654. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8655. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8656. item.MedChrgitmType = "09"
  8657. }
  8658. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8659. if item.HisPrescriptionProject.Type == 2 {
  8660. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8661. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8662. case 0:
  8663. item.MedChrgitmType = "0"
  8664. break
  8665. case 1:
  8666. item.MedChrgitmType = "14"
  8667. break
  8668. case 2:
  8669. item.MedChrgitmType = "05"
  8670. break
  8671. case 3:
  8672. item.MedChrgitmType = "03"
  8673. break
  8674. case 4:
  8675. item.MedChrgitmType = "03"
  8676. break
  8677. case 5:
  8678. item.MedChrgitmType = "08"
  8679. break
  8680. case 6:
  8681. item.MedChrgitmType = "14"
  8682. break
  8683. case 7:
  8684. item.MedChrgitmType = "14"
  8685. break
  8686. case 8:
  8687. item.MedChrgitmType = "03"
  8688. break
  8689. case 9:
  8690. item.MedChrgitmType = "14"
  8691. break
  8692. case 10:
  8693. item.MedChrgitmType = "14"
  8694. break
  8695. case 11:
  8696. item.MedChrgitmType = "06"
  8697. break
  8698. case 12:
  8699. item.MedChrgitmType = "12"
  8700. break
  8701. case 13:
  8702. item.MedChrgitmType = "01"
  8703. break
  8704. case 14:
  8705. item.MedChrgitmType = "04"
  8706. break
  8707. case 15:
  8708. item.MedChrgitmType = "02"
  8709. break
  8710. }
  8711. } else {
  8712. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8713. case 1:
  8714. item.MedChrgitmType = "14"
  8715. break
  8716. case 2:
  8717. item.MedChrgitmType = "05"
  8718. break
  8719. case 3:
  8720. item.MedChrgitmType = "03"
  8721. break
  8722. case 4:
  8723. item.MedChrgitmType = "03"
  8724. break
  8725. case 5:
  8726. item.MedChrgitmType = "08"
  8727. break
  8728. case 6:
  8729. item.MedChrgitmType = "14"
  8730. break
  8731. case 7:
  8732. item.MedChrgitmType = "14"
  8733. break
  8734. case 8:
  8735. item.MedChrgitmType = "03"
  8736. break
  8737. case 9:
  8738. item.MedChrgitmType = "14"
  8739. break
  8740. }
  8741. }
  8742. } else if item.HisPrescriptionProject.Type == 3 {
  8743. item.MedChrgitmType = "08"
  8744. }
  8745. }
  8746. }
  8747. for _, item := range orderInfos_two {
  8748. fmt.Println(item.MedChrgitmType)
  8749. if item.MedChrgitmType == "07" { //床位费
  8750. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8751. hiliCostSelfTotal = hiliCostTotal
  8752. }
  8753. if item.MedChrgitmType == "01" { //床位费
  8754. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8755. bedCostSelfTotal = bedCostTotal
  8756. }
  8757. if item.MedChrgitmType == "02" { //诊察费
  8758. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8759. zhenChaCostSelfTotal = zhenChaCostTotal
  8760. }
  8761. if item.MedChrgitmType == "03" { //检查费
  8762. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8763. checkCostSelfTotal = checkCostTotal
  8764. }
  8765. if item.MedChrgitmType == "04" { //化验费
  8766. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8767. laboratoryCostSelfTotal = laboratoryCostTotal
  8768. }
  8769. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8770. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8771. treatCostSelfTotal = treatCostTotal
  8772. }
  8773. if item.MedChrgitmType == "06" { //手术费
  8774. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8775. operationCostSelfTotal = treatCostTotal
  8776. }
  8777. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8778. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8779. materialCostSelfTotal = materialCostTotal
  8780. }
  8781. if item.MedChrgitmType == "09" { //西药费
  8782. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8783. westernMedicineCostSelfTotal = westernMedicineCostTotal
  8784. }
  8785. if item.MedChrgitmType == "11" { //中成费
  8786. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8787. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8788. }
  8789. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8790. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8791. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8792. otherCostSelfTotal = otherCostTotal
  8793. }
  8794. } else {
  8795. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8796. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8797. otherCostSelfTotal = otherCostTotal
  8798. }
  8799. }
  8800. }
  8801. } else {
  8802. for _, item := range orderInfos {
  8803. if item.MedChrgitmType == "01" { //床位费
  8804. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8805. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8806. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8807. }
  8808. if item.MedChrgitmType == "02" { //诊察费
  8809. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8810. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8811. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8812. }
  8813. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8814. if item.MedChrgitmType == "03" { //检查费
  8815. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8816. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8817. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8818. }
  8819. } else {
  8820. if item.MedChrgitmType == "03" { //检查费
  8821. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8822. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8823. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8824. }
  8825. }
  8826. if item.MedChrgitmType == "04" { //化验费
  8827. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8828. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8829. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8830. }
  8831. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8832. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8833. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8834. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8835. }
  8836. if item.MedChrgitmType == "06" { //手术费
  8837. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8838. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8839. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8840. }
  8841. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  8842. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8843. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8844. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8845. }
  8846. if item.MedChrgitmType == "07" { //西药费
  8847. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8848. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8849. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8850. }
  8851. if item.MedChrgitmType == "09" { //西药费
  8852. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8853. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8854. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8855. }
  8856. if item.MedChrgitmType == "11" { //中成费
  8857. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8858. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8859. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8860. }
  8861. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8862. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8863. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8864. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8865. }
  8866. }
  8867. }
  8868. timeLayout := "2006-01-02"
  8869. loc, _ := time.LoadLocation("Local")
  8870. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8871. if err != nil {
  8872. }
  8873. startRecordDateTime := startTime.Unix()
  8874. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8875. if err != nil {
  8876. }
  8877. endRecordDateTime := endTime.Unix()
  8878. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8879. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8880. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8881. c.ServeSuccessJSON(map[string]interface{}{
  8882. "order_number": order.Number, //业务流水号
  8883. "id_card_no": his.IdCardNo, //社会保障号
  8884. "patient": patient,
  8885. "department_name": department.Name, //科室
  8886. "number": his.Number, //门诊号
  8887. "date": order.SettleAccountsDate, //结算日期
  8888. "name": order.PsnName, //姓名
  8889. "gender": patient.Gender, //性别
  8890. "psn_cash_money": order.PsnCashPay, //个人支付
  8891. "pay_way": "门诊", //结算方式
  8892. "medfee_sumamt": order.MedfeeSumamt, //总费用
  8893. "admin_user_name": admin.UserName, //收款员
  8894. "order": order,
  8895. "order_info": orderInfos_two,
  8896. "his": his,
  8897. "bedCostTotal": bedCostTotal,
  8898. "bedCostSelfTotal": bedCostSelfTotal,
  8899. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8900. "operationCostTotal": operationCostTotal,
  8901. "operationCostSelfTotal": operationCostSelfTotal,
  8902. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8903. "otherCostTotal": otherCostTotal,
  8904. "otherCostSelfTotal": otherCostSelfTotal,
  8905. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8906. "materialCostTotal": materialCostTotal,
  8907. "materialCostSelfTotal": materialCostSelfTotal,
  8908. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8909. "westernMedicineCostTotal": westernMedicineCostTotal,
  8910. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8911. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8912. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8913. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8914. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8915. "checkCostTotal": checkCostTotal,
  8916. "checkCostSelfTotal": checkCostSelfTotal,
  8917. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8918. "laboratoryCostTotal": laboratoryCostTotal,
  8919. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8920. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8921. "treatCostTotal": treatCostTotal,
  8922. "treatCostSelfTotal": treatCostSelfTotal,
  8923. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8924. "zhenChaCostTotal": zhenChaCostTotal,
  8925. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8926. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8927. "his_hospital_record": his_hospital_record,
  8928. "pre_pay_money": pre_pay_money,
  8929. "refund_sum": sum,
  8930. "doctor_info": doctor_info,
  8931. "hiliCostTotal": hiliCostTotal,
  8932. "hiliCostSelfTotal": hiliCostSelfTotal,
  8933. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8934. })
  8935. }
  8936. //func (c *HisApiController) GetFaPiaoDatas() {
  8937. // order_ids := c.GetString("order_ids")
  8938. // patient_id, _ := c.GetInt64("patient_id")
  8939. // adminUser := c.GetAdminUserInfo()
  8940. //
  8941. // orders := strings.Split(order_ids, ",")
  8942. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8943. //
  8944. // for _, item := range orders {
  8945. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8946. // order, _ := service.GetHisOrderByID(order_id)
  8947. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8948. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8949. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8950. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8951. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8952. //
  8953. // }
  8954. //
  8955. // var bedCostTotal float64 = 0 //床位总费
  8956. // var bedCostSelfTotal float64 = 0 //床位自费
  8957. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8958. //
  8959. // var operationCostTotal float64 = 0 //手术费
  8960. // var operationCostSelfTotal float64 = 0 //手术费
  8961. // var operationCostPartSelfTotal float64 = 0 //手术费
  8962. //
  8963. // var otherCostTotal float64 = 0 //其他费用
  8964. // var otherCostSelfTotal float64 = 0 //其他费用
  8965. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8966. //
  8967. // var materialCostTotal float64 = 0 //材料费
  8968. // var materialCostSelfTotal float64 = 0 //材料费
  8969. // var materialCostPartSelfTotal float64 = 0 //材料费
  8970. //
  8971. // var westernMedicineCostTotal float64 = 0 //西药费
  8972. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8973. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8974. //
  8975. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8976. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8977. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8978. //
  8979. // var checkCostTotal float64 = 0 //检查费
  8980. // var checkCostSelfTotal float64 = 0 //检查费
  8981. // var checkCostPartSelfTotal float64 = 0 //检查费
  8982. //
  8983. // var laboratoryCostTotal float64 = 0 //化验费
  8984. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8985. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8986. //
  8987. // var treatCostTotal float64 = 0 //治疗费用
  8988. // var treatCostSelfTotal float64 = 0 //治疗费用
  8989. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8990. //
  8991. // var zhenChaCostTotal float64 = 0 //其他费用
  8992. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8993. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8994. //
  8995. // decimal.DivisionPrecision = 2
  8996. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8997. //
  8998. // var balanceAccountsType int64
  8999. // if his.ID > 0 {
  9000. // balanceAccountsType = his.BalanceAccountsType
  9001. // } else {
  9002. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9003. // }
  9004. // if balanceAccountsType == 2 {
  9005. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9006. // for _, item := range orderInfos_two {
  9007. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9008. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9009. // item.MedChrgitmType = "09"
  9010. // }
  9011. //
  9012. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9013. // if item.HisPrescriptionProject.Type == 2 {
  9014. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9015. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9016. // case 0:
  9017. // item.MedChrgitmType = "0"
  9018. // break
  9019. // case 1:
  9020. // item.MedChrgitmType = "14"
  9021. // break
  9022. // case 2:
  9023. // item.MedChrgitmType = "05"
  9024. //
  9025. // break
  9026. // case 3:
  9027. // item.MedChrgitmType = "03"
  9028. //
  9029. // break
  9030. // case 4:
  9031. // item.MedChrgitmType = "03"
  9032. //
  9033. // break
  9034. // case 5:
  9035. // item.MedChrgitmType = "08"
  9036. //
  9037. // break
  9038. // case 6:
  9039. // item.MedChrgitmType = "14"
  9040. //
  9041. // break
  9042. // case 7:
  9043. // item.MedChrgitmType = "14"
  9044. //
  9045. // break
  9046. // case 8:
  9047. // item.MedChrgitmType = "03"
  9048. // break
  9049. // case 9:
  9050. // item.MedChrgitmType = "14"
  9051. // break
  9052. // case 10:
  9053. // item.MedChrgitmType = "14"
  9054. // break
  9055. // case 11:
  9056. // item.MedChrgitmType = "06"
  9057. // break
  9058. // case 12:
  9059. // item.MedChrgitmType = "12"
  9060. // break
  9061. // case 13:
  9062. // item.MedChrgitmType = "01"
  9063. // break
  9064. // case 14:
  9065. // item.MedChrgitmType = "04"
  9066. // break
  9067. // case 15:
  9068. // item.MedChrgitmType = "02"
  9069. // break
  9070. //
  9071. // }
  9072. //
  9073. // } else {
  9074. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9075. //
  9076. // case 1:
  9077. // item.MedChrgitmType = "14"
  9078. // break
  9079. // case 2:
  9080. // item.MedChrgitmType = "05"
  9081. //
  9082. // break
  9083. // case 3:
  9084. // item.MedChrgitmType = "03"
  9085. //
  9086. // break
  9087. // case 4:
  9088. // item.MedChrgitmType = "03"
  9089. //
  9090. // break
  9091. // case 5:
  9092. // item.MedChrgitmType = "08"
  9093. //
  9094. // break
  9095. // case 6:
  9096. // item.MedChrgitmType = "14"
  9097. //
  9098. // break
  9099. // case 7:
  9100. // item.MedChrgitmType = "14"
  9101. //
  9102. // break
  9103. // case 8:
  9104. // item.MedChrgitmType = "03"
  9105. // break
  9106. // case 9:
  9107. // item.MedChrgitmType = "14"
  9108. // break
  9109. //
  9110. // }
  9111. //
  9112. // }
  9113. //
  9114. // } else if item.HisPrescriptionProject.Type == 3 {
  9115. // item.MedChrgitmType = "08"
  9116. // }
  9117. // }
  9118. // }
  9119. //
  9120. // for _, item := range orderInfos_two {
  9121. // fmt.Println(item.MedChrgitmType)
  9122. // if item.MedChrgitmType == "01" { //床位费
  9123. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9124. // bedCostSelfTotal = bedCostTotal
  9125. // }
  9126. //
  9127. // if item.MedChrgitmType == "02" { //诊察费
  9128. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9129. // zhenChaCostSelfTotal = zhenChaCostTotal
  9130. // }
  9131. //
  9132. // if item.MedChrgitmType == "03" { //检查费
  9133. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9134. // checkCostSelfTotal = checkCostTotal
  9135. // }
  9136. //
  9137. // if item.MedChrgitmType == "04" { //化验费
  9138. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9139. // laboratoryCostSelfTotal = laboratoryCostTotal
  9140. // }
  9141. //
  9142. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9143. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9144. // treatCostSelfTotal = treatCostTotal
  9145. // }
  9146. //
  9147. // if item.MedChrgitmType == "06" { //手术费
  9148. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9149. // operationCostSelfTotal = treatCostTotal
  9150. // }
  9151. //
  9152. // if item.MedChrgitmType == "08" { //材料费
  9153. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9154. // materialCostSelfTotal = materialCostTotal
  9155. // }
  9156. //
  9157. // if item.MedChrgitmType == "09" { //西药费
  9158. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9159. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9160. // }
  9161. //
  9162. // if item.MedChrgitmType == "11" { //中成费
  9163. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9164. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9165. // }
  9166. //
  9167. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9168. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9169. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9170. // otherCostSelfTotal = otherCostTotal
  9171. // }
  9172. // } else {
  9173. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9174. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9175. // otherCostSelfTotal = otherCostTotal
  9176. // }
  9177. //
  9178. // }
  9179. //
  9180. // }
  9181. //
  9182. // } else {
  9183. // for _, item := range orderInfos {
  9184. // if item.MedChrgitmType == "01" { //床位费
  9185. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9186. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9187. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9188. // }
  9189. //
  9190. // if item.MedChrgitmType == "02" { //诊察费
  9191. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9192. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9193. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9194. // }
  9195. //
  9196. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9197. // if item.MedChrgitmType == "03" { //检查费
  9198. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9199. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9200. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9201. //
  9202. // }
  9203. // } else {
  9204. // if item.MedChrgitmType == "03" { //检查费
  9205. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9206. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9207. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9208. // }
  9209. //
  9210. // }
  9211. //
  9212. // if item.MedChrgitmType == "04" { //化验费
  9213. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9214. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9215. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9216. //
  9217. // }
  9218. //
  9219. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  9220. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9221. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9222. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9223. //
  9224. // }
  9225. //
  9226. // if item.MedChrgitmType == "06" { //手术费
  9227. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9228. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9229. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9230. // }
  9231. //
  9232. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9233. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9234. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9235. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9236. // }
  9237. //
  9238. // if item.MedChrgitmType == "09" { //西药费
  9239. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9240. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9241. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9242. // }
  9243. //
  9244. // if item.MedChrgitmType == "11" { //中成费
  9245. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9246. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9247. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9248. // }
  9249. //
  9250. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9251. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9252. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9253. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9254. // }
  9255. //
  9256. // }
  9257. // }
  9258. // timeLayout := "2006-01-02"
  9259. // loc, _ := time.LoadLocation("Local")
  9260. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9261. // if err != nil {
  9262. // }
  9263. // startRecordDateTime := startTime.Unix()
  9264. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9265. // if err != nil {
  9266. // }
  9267. // endRecordDateTime := endTime.Unix()
  9268. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9269. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9270. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9271. //
  9272. // c.ServeSuccessJSON(map[string]interface{}{
  9273. // "order_number": order.Number, //业务流水号
  9274. // "id_card_no": his.IdCardNo, //社会保障号
  9275. // "department_name": department.Name, //科室
  9276. // "number": his.Number, //门诊号
  9277. // "date": order.SettleAccountsDate, //结算日期
  9278. // "name": order.PsnName, //姓名
  9279. // "gender": patient.Gender, //性别
  9280. // "psn_cash_money": order.PsnCashPay, //个人支付
  9281. // "pay_way": "门诊", //结算方式
  9282. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  9283. // "admin_user_name": admin.UserName, //收款员
  9284. // "order": order,
  9285. // "order_info": orderInfos_two,
  9286. // "his": his,
  9287. // "bedCostTotal": bedCostTotal,
  9288. // "bedCostSelfTotal": bedCostSelfTotal,
  9289. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9290. // "operationCostTotal": operationCostTotal,
  9291. // "operationCostSelfTotal": operationCostSelfTotal,
  9292. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9293. // "otherCostTotal": otherCostTotal,
  9294. // "otherCostSelfTotal": otherCostSelfTotal,
  9295. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9296. // "materialCostTotal": materialCostTotal,
  9297. // "materialCostSelfTotal": materialCostSelfTotal,
  9298. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9299. // "westernMedicineCostTotal": westernMedicineCostTotal,
  9300. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9301. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9302. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9303. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9304. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9305. // "checkCostTotal": checkCostTotal,
  9306. // "checkCostSelfTotal": checkCostSelfTotal,
  9307. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9308. // "laboratoryCostTotal": laboratoryCostTotal,
  9309. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9310. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9311. // "treatCostTotal": treatCostTotal,
  9312. // "treatCostSelfTotal": treatCostSelfTotal,
  9313. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9314. // "zhenChaCostTotal": zhenChaCostTotal,
  9315. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9316. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9317. // "his_hospital_record": his_hospital_record,
  9318. // "pre_pay_money": pre_pay_money,
  9319. // "refund_sum": sum,
  9320. // })
  9321. //
  9322. //}
  9323. func (this *HisApiController) GetIncomeStatisticsData() {
  9324. start_time := this.GetString("start_time")
  9325. end_time := this.GetString("end_time")
  9326. key_words := this.GetString("key_words")
  9327. limit, _ := this.GetInt64("limit")
  9328. page, _ := this.GetInt64("page")
  9329. if page <= 0 {
  9330. page = 1
  9331. }
  9332. if limit <= 0 {
  9333. limit = 10
  9334. }
  9335. statistics_type, _ := this.GetInt64("statistics_type")
  9336. admin := this.GetAdminUserInfo()
  9337. timeLayout := "2006-01-02"
  9338. loc, _ := time.LoadLocation("Local")
  9339. var theStartTIme int64
  9340. if len(start_time) > 0 {
  9341. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9342. if err != nil {
  9343. theStartTIme = 0
  9344. }
  9345. theStartTIme = theTime.Unix()
  9346. }
  9347. var theEndtTIme int64
  9348. if len(end_time) > 0 {
  9349. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9350. if err != nil {
  9351. theEndtTIme = 0
  9352. }
  9353. theEndtTIme = theTime.Unix()
  9354. }
  9355. if statistics_type == 1 {
  9356. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9357. this.ServeSuccessJSON(map[string]interface{}{
  9358. "list": list,
  9359. "total": total,
  9360. })
  9361. } else {
  9362. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9363. this.ServeSuccessJSON(map[string]interface{}{
  9364. "list": list,
  9365. "total": total,
  9366. })
  9367. }
  9368. }
  9369. func (c *HisApiController) PostProjectInformation() {
  9370. adminUser := c.GetAdminUserInfo()
  9371. orgId := adminUser.CurrentOrgId
  9372. dataBody := make(map[string]interface{}, 0)
  9373. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9374. if err != nil {
  9375. utils.ErrorLog(err.Error())
  9376. return
  9377. }
  9378. utils.ErrorLog("%v", dataBody)
  9379. var projectList []*models.HisProject
  9380. var total_goods []interface{}
  9381. tempProjects := dataBody["projects"].([]interface{})
  9382. total_goods = tempProjects
  9383. for index, projectMap := range tempProjects {
  9384. projectM := projectMap.(map[string]interface{})
  9385. var project models.HisProject
  9386. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  9387. utils.ErrorLog("project_name")
  9388. return
  9389. }
  9390. project_name, _ := projectM["project_name"].(string)
  9391. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  9392. err_log := models.ExportErrLog{
  9393. LogType: 6,
  9394. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9395. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  9396. Status: 1,
  9397. CreateTime: time.Now().Unix(),
  9398. UpdateTime: time.Now().Unix(),
  9399. ExportTime: time.Now().Unix(),
  9400. }
  9401. service.CreateExportErrLog(&err_log)
  9402. continue
  9403. }
  9404. project.ProjectName = project_name
  9405. prices := projectM["price"].(string)
  9406. price, _ := strconv.ParseFloat(prices, 64)
  9407. if price <= 0 { //名字为空则生成一条导入错误日志
  9408. err_log := models.ExportErrLog{
  9409. LogType: 6,
  9410. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9411. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  9412. Status: 1,
  9413. CreateTime: time.Now().Unix(),
  9414. UpdateTime: time.Now().Unix(),
  9415. ExportTime: time.Now().Unix(),
  9416. }
  9417. service.CreateExportErrLog(&err_log)
  9418. continue
  9419. }
  9420. project.Price = price
  9421. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  9422. utils.ErrorLog("unit_id")
  9423. return
  9424. }
  9425. unit := projectM["unit"].(string)
  9426. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  9427. err_log := models.ExportErrLog{
  9428. LogType: 6,
  9429. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9430. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  9431. Status: 1,
  9432. CreateTime: time.Now().Unix(),
  9433. UpdateTime: time.Now().Unix(),
  9434. ExportTime: time.Now().Unix(),
  9435. }
  9436. service.CreateExportErrLog(&err_log)
  9437. continue
  9438. }
  9439. project.Unit = unit
  9440. cost_classify := projectM["cost_classify"].(string)
  9441. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  9442. err_log := models.ExportErrLog{
  9443. LogType: 6,
  9444. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9445. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  9446. Status: 1,
  9447. CreateTime: time.Now().Unix(),
  9448. UpdateTime: time.Now().Unix(),
  9449. ExportTime: time.Now().Unix(),
  9450. }
  9451. service.CreateExportErrLog(&err_log)
  9452. continue
  9453. }
  9454. var costClassify = "费用类别"
  9455. var cost_classify_id int64
  9456. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  9457. if len(cost_classify) != 0 {
  9458. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  9459. if errcode == gorm.ErrRecordNotFound {
  9460. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  9461. dataconfig := models.DictDataconfig{
  9462. ParentId: costClassifyConfig.ID,
  9463. Module: "system",
  9464. OrgId: orgId,
  9465. Name: cost_classify,
  9466. FieldName: "",
  9467. Value: costConfig.Value + 1,
  9468. CreatedTime: "",
  9469. UpdatedTime: "",
  9470. CreateUserId: adminUser.AdminUser.Id,
  9471. Status: 1,
  9472. Remark: "",
  9473. DeleteIdSystem: 0,
  9474. Title: "",
  9475. Content: "",
  9476. Order: 0,
  9477. Code: "",
  9478. }
  9479. service.CreatedDicConfig(&dataconfig)
  9480. }
  9481. }
  9482. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  9483. for _, it := range costClassList {
  9484. if cost_classify == it.Name {
  9485. cost_classify_id = int64(it.Value)
  9486. }
  9487. }
  9488. project.CostClassify = cost_classify_id
  9489. executive_section := projectM["executive_section"].(string)
  9490. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  9491. err_log := models.ExportErrLog{
  9492. LogType: 6,
  9493. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9494. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  9495. Status: 1,
  9496. CreateTime: time.Now().Unix(),
  9497. UpdateTime: time.Now().Unix(),
  9498. ExportTime: time.Now().Unix(),
  9499. }
  9500. service.CreateExportErrLog(&err_log)
  9501. continue
  9502. }
  9503. if len(executive_section) != 0 {
  9504. //查找科室是否有内容
  9505. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  9506. if errcodedepart == gorm.ErrRecordNotFound {
  9507. department := models.XtHisDepartment{
  9508. Name: executive_section,
  9509. Status: 1,
  9510. UserOrgId: adminUser.CurrentOrgId,
  9511. CreatedTime: time.Now().Unix(),
  9512. }
  9513. service.CreateDePartment(&department)
  9514. }
  9515. }
  9516. var executive_section_id int64
  9517. departMentList, _ := service.GetAllDepartMent(orgId)
  9518. for _, it := range departMentList {
  9519. if executive_section == it.Name {
  9520. executive_section_id = it.ID
  9521. }
  9522. }
  9523. project.ExecutiveSection = executive_section_id
  9524. medical_coverage := projectM["medical_coverage"].(string)
  9525. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  9526. err_log := models.ExportErrLog{
  9527. LogType: 6,
  9528. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9529. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  9530. Status: 1,
  9531. CreateTime: time.Now().Unix(),
  9532. UpdateTime: time.Now().Unix(),
  9533. ExportTime: time.Now().Unix(),
  9534. }
  9535. service.CreateExportErrLog(&err_log)
  9536. continue
  9537. }
  9538. var medicalCoverage = "医保等级"
  9539. var medical_coverage_id int64
  9540. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  9541. if len(medical_coverage) != 0 {
  9542. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  9543. if errormedicalcoverage == gorm.ErrRecordNotFound {
  9544. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  9545. dataconfig := models.DictDataconfig{
  9546. ParentId: medicalCoverageConfig.ID,
  9547. Module: "system",
  9548. OrgId: orgId,
  9549. Name: medical_coverage,
  9550. FieldName: "",
  9551. Value: medicalCoverageConfig.Value + 1,
  9552. CreatedTime: "",
  9553. UpdatedTime: "",
  9554. CreateUserId: adminUser.AdminUser.Id,
  9555. Status: 1,
  9556. Remark: "",
  9557. DeleteIdSystem: 0,
  9558. Title: "",
  9559. Content: "",
  9560. Order: 0,
  9561. Code: "",
  9562. }
  9563. service.CreatedDicConfig(&dataconfig)
  9564. }
  9565. }
  9566. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  9567. for _, it := range medicalCoverageList {
  9568. if medical_coverage == it.Name {
  9569. medical_coverage_id = int64(it.Value)
  9570. }
  9571. }
  9572. project.MedicalCoverage = medical_coverage_id
  9573. pinyin := projectM["pinyin"].(string)
  9574. project.Pinyin = pinyin
  9575. wubi := projectM["wubi"].(string)
  9576. project.Wubi = wubi
  9577. statistical_classification := projectM["statistical_classification"].(string)
  9578. var statisticalClassification = "统计分类"
  9579. var statistical_classification_id int64
  9580. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  9581. if len(statistical_classification) != 0 {
  9582. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  9583. if classificationerrcodes == gorm.ErrRecordNotFound {
  9584. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  9585. dataconfig := models.DictDataconfig{
  9586. ParentId: classiFication.ID,
  9587. Module: "system",
  9588. OrgId: orgId,
  9589. Name: statistical_classification,
  9590. FieldName: "",
  9591. Value: classiFicationConfig.Value + 1,
  9592. CreatedTime: "",
  9593. UpdatedTime: "",
  9594. CreateUserId: adminUser.AdminUser.Id,
  9595. Status: 1,
  9596. Remark: "",
  9597. DeleteIdSystem: 0,
  9598. Title: "",
  9599. Content: "",
  9600. Order: 0,
  9601. Code: "",
  9602. }
  9603. service.CreatedDicConfig(&dataconfig)
  9604. }
  9605. }
  9606. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  9607. for _, it := range classiFicationList {
  9608. if statistical_classification == it.Name {
  9609. statistical_classification_id = int64(it.Value)
  9610. }
  9611. }
  9612. project.StatisticalClassification = statistical_classification_id
  9613. disease_directory := int64(projectM["disease_directory"].(float64))
  9614. project.DiseaseDirectory = disease_directory
  9615. is_record := int64(projectM["is_record"].(float64))
  9616. project.IsRecord = is_record
  9617. medical_code := projectM["medical_code"].(string)
  9618. project.MedicalCode = medical_code
  9619. tube_color := projectM["tube_color"].(string)
  9620. var tubeColor = "试管颜色"
  9621. var tube_color_id int64
  9622. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  9623. if len(tube_color) != 0 {
  9624. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  9625. if errcodetube == gorm.ErrRecordNotFound {
  9626. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  9627. dataconfig := models.DictDataconfig{
  9628. ParentId: tubeColorConfig.ID,
  9629. Module: "system",
  9630. OrgId: orgId,
  9631. Name: tube_color,
  9632. FieldName: "",
  9633. Value: tubeConfig.Value + 1,
  9634. CreatedTime: "",
  9635. UpdatedTime: "",
  9636. CreateUserId: adminUser.AdminUser.Id,
  9637. Status: 1,
  9638. Remark: "",
  9639. DeleteIdSystem: 0,
  9640. Title: "",
  9641. Content: "",
  9642. Order: 0,
  9643. Code: "",
  9644. }
  9645. service.CreatedDicConfig(&dataconfig)
  9646. }
  9647. }
  9648. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  9649. for _, it := range tubeColorList {
  9650. if tube_color == it.Name {
  9651. tube_color_id = int64(it.Value)
  9652. }
  9653. }
  9654. project.TubeColor = tube_color_id
  9655. single_dose := projectM["single_dose"].(string)
  9656. project.SingleDose = single_dose
  9657. execution_frequency := projectM["execution_frequency"].(string)
  9658. project.ExecutionFrequency = execution_frequency
  9659. delivery_way := projectM["delivery_way"].(string)
  9660. project.DeliveryWay = delivery_way
  9661. number_days := projectM["number_days"].(string)
  9662. project.NumberDays = number_days
  9663. total := projectM["total"].(string)
  9664. project.Total = total
  9665. medical_status := int64(projectM["medical_status"].(float64))
  9666. project.MedicalStatus = medical_status
  9667. category := int64(projectM["category"].(float64))
  9668. project.Category = category
  9669. specail_project := int64(projectM["specail_project"].(float64))
  9670. project.SpecailProject = specail_project
  9671. social_security_directory_code := projectM["social_security_directory_code"].(string)
  9672. project.SocialSecurityDirectoryCode = social_security_directory_code
  9673. remark := projectM["remark"].(string)
  9674. project.Remark = remark
  9675. record_date := projectM["record_date"].(string)
  9676. timeLayout := "2006-01-02"
  9677. loc, _ := time.LoadLocation("Local")
  9678. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9679. project.RecordDate = theTime.Unix()
  9680. projectList = append(projectList, &project)
  9681. }
  9682. export_time := time.Now().Unix()
  9683. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  9684. if len(projectList) > 0 {
  9685. for _, item := range projectList {
  9686. project := models.HisProject{
  9687. ProjectName: item.ProjectName,
  9688. Price: item.Price,
  9689. Unit: item.Unit,
  9690. CostClassify: item.CostClassify,
  9691. ExecutiveSection: item.ExecutiveSection,
  9692. MedicalCoverage: item.MedicalCoverage,
  9693. UserOrgId: orgId,
  9694. Status: 1,
  9695. CreatedTime: time.Now().Unix(),
  9696. Pinyin: item.Pinyin,
  9697. Wubi: item.Wubi,
  9698. StatisticalClassification: item.StatisticalClassification,
  9699. DiseaseDirectory: item.DiseaseDirectory,
  9700. IsRecord: item.IsRecord,
  9701. MedicalCode: item.MedicalCode,
  9702. TubeColor: item.TubeColor,
  9703. SingleDose: item.SingleDose,
  9704. DeliveryWay: item.DeliveryWay,
  9705. NumberDays: item.NumberDays,
  9706. Total: item.Total,
  9707. Category: item.Category,
  9708. MedicalStatus: item.MedicalStatus,
  9709. SpecailProject: item.SpecailProject,
  9710. RecordDate: item.RecordDate,
  9711. Remark: item.Remark,
  9712. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  9713. ExecutionFrequency: item.ExecutionFrequency,
  9714. }
  9715. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  9716. if errcodeproject == gorm.ErrRecordNotFound {
  9717. service.CreateProjectInfomation(&project)
  9718. } else if errcodeproject == nil {
  9719. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  9720. }
  9721. log := models.ExportLog{
  9722. LogType: 6,
  9723. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9724. TotalNum: int64(len(total_goods)),
  9725. FailNum: int64(len(errLogs)),
  9726. SuccessNum: int64(len(projectList)),
  9727. CreateTime: time.Now().Unix(),
  9728. UpdateTime: time.Now().Unix(),
  9729. ExportTime: export_time,
  9730. Status: 1,
  9731. }
  9732. service.CreateExportLog(&log)
  9733. c.ServeSuccessJSON(map[string]interface{}{
  9734. "msg": "导入成功",
  9735. "total_num": len(total_goods),
  9736. "success_num": len(projectList),
  9737. "fail_num": int64(len(errLogs)),
  9738. })
  9739. }
  9740. } else {
  9741. log := models.ExportLog{
  9742. LogType: 6,
  9743. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9744. TotalNum: int64(len(total_goods)),
  9745. FailNum: int64(len(errLogs)),
  9746. SuccessNum: int64(len(projectList)),
  9747. CreateTime: time.Now().Unix(),
  9748. UpdateTime: time.Now().Unix(),
  9749. ExportTime: export_time,
  9750. Status: 1,
  9751. }
  9752. service.CreateExportLog(&log)
  9753. c.ServeSuccessJSON(map[string]interface{}{
  9754. "msg": "导入成功",
  9755. "total_num": len(total_goods),
  9756. "success_num": len(projectList),
  9757. "fail_num": int64(len(errLogs)),
  9758. })
  9759. }
  9760. }
  9761. //func (this *HisApiController) EditProjectInformation(){
  9762. //
  9763. // id, _ := this.GetInt64("id")
  9764. // project_team := this.GetString("project_team")
  9765. // price := this.GetString("price")
  9766. // price_float, _ := strconv.ParseFloat(price, 64)
  9767. // pinyin := this.GetString("pinyin")
  9768. // wubi := this.GetString("wubi")
  9769. // tube_color, _ := this.GetInt64("tube_color")
  9770. // team_type, _ := this.GetInt64("team_type")
  9771. // remark := this.GetString("remark")
  9772. // ids := this.GetString("ids")
  9773. // item_id := this.GetString("item_id")
  9774. // projectTeam := models.XtHisProjectTeam{
  9775. // ProjectTeam: project_team,
  9776. // Price: price_float,
  9777. // Pinyin: pinyin,
  9778. // Wubi: wubi,
  9779. // TubeColor: tube_color,
  9780. // TeamType: team_type,
  9781. // Remark: remark,
  9782. // ProjectId: ids,
  9783. // ItemId: item_id,
  9784. // }
  9785. //
  9786. //
  9787. // dataBody := make(map[string]interface{}, 0)
  9788. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9789. // if err != nil {
  9790. // utils.ErrorLog(err.Error())
  9791. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9792. // return
  9793. // }
  9794. //
  9795. // err = service.UpdatedProjectTeam(id, &projectTeam)
  9796. //
  9797. //
  9798. // if err != nil {
  9799. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  9800. // return
  9801. // }
  9802. //
  9803. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  9804. // infos, _ := dataBody["info"].([]interface{})
  9805. // if len(infos) > 0 {
  9806. // var ids []string
  9807. //
  9808. // for _, item := range infos {
  9809. // items := item.(map[string]interface{})
  9810. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  9811. // utils.ErrorLog("id")
  9812. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9813. // return
  9814. // }
  9815. // id := int64(items["id"].(float64))
  9816. //
  9817. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9818. // utils.ErrorLog("type")
  9819. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9820. // return
  9821. // }
  9822. // types := int64(items["type"].(float64))
  9823. //
  9824. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  9825. // utils.ErrorLog("number")
  9826. // }
  9827. //
  9828. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  9829. //
  9830. // projectList := models.XtHisProjectList{
  9831. // Number: number,
  9832. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  9833. // ProjectId: id,
  9834. // Status: 1,
  9835. // CreatedTime: time.Now().Unix(),
  9836. // UpdatedTime: time.Now().Unix(),
  9837. // TeamId: projectTeam.ID,
  9838. // Type: types,
  9839. // }
  9840. // list := projectList
  9841. //
  9842. // service.CreateProjectList(&list)
  9843. //
  9844. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  9845. //
  9846. // }
  9847. // ids_str := strings.Join(ids, ",")
  9848. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  9849. // service.SaveProjectTeam(&projectTeam)
  9850. // this.ServeSuccessJSON(map[string]interface{}{
  9851. // "projectTeam": projectTeam,
  9852. // })
  9853. // }
  9854. // }
  9855. //}
  9856. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  9857. name := c.GetString("name")
  9858. mode_id, _ := c.GetInt64("mode", 0)
  9859. types, _ := c.GetInt64("type", 0)
  9860. patient_id, _ := c.GetInt64("patient_id", 0)
  9861. types = 1
  9862. adminInfo := c.GetAdminUserInfo()
  9863. template := &models.HisPrescriptionTemplate{
  9864. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9865. PatientId: patient_id,
  9866. Type: types,
  9867. Status: 1,
  9868. Ctime: time.Now().Unix(),
  9869. Mtime: time.Now().Unix(),
  9870. Name: name,
  9871. Mode: mode_id,
  9872. }
  9873. dataBody := make(map[string]interface{}, 0)
  9874. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9875. if err != nil {
  9876. utils.ErrorLog(err.Error())
  9877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9878. return
  9879. }
  9880. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  9881. //如果已经存在记录则删除处方
  9882. if template_one.ID > 0 {
  9883. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  9884. var ids []int64
  9885. var org_id int64
  9886. for _, item := range ps {
  9887. org_id = c.GetAdminUserInfo().CurrentOrgId
  9888. ids = append(ids, item.ID)
  9889. }
  9890. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  9891. if err2 == nil {
  9892. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9893. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9894. if len(prescriptions) > 0 {
  9895. for _, item := range prescriptions {
  9896. items := item.(map[string]interface{})
  9897. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9898. utils.ErrorLog("type")
  9899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9900. return
  9901. }
  9902. types := int64(items["type"].(float64))
  9903. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9904. utils.ErrorLog("med_type")
  9905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9906. return
  9907. }
  9908. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9909. ctime := time.Now().Unix()
  9910. prescription := &models.HisPrescriptionInfoTemplate{
  9911. PatientId: patient_id,
  9912. UserOrgId: adminInfo.CurrentOrgId,
  9913. Ctime: ctime,
  9914. Mtime: ctime,
  9915. Type: types,
  9916. Modifier: adminInfo.AdminUser.Id,
  9917. Creator: adminInfo.AdminUser.Id,
  9918. Status: 1,
  9919. PTemplateId: template_one.ID,
  9920. MedType: med_type,
  9921. }
  9922. service.CreateHisPrescriptionInfoTemplate(prescription)
  9923. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9924. advices := items["advices"].([]interface{})
  9925. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9926. ctime := time.Now().Unix()
  9927. mtime := ctime
  9928. if len(advices) > 0 {
  9929. for _, advice := range advices {
  9930. var s models.HisPrescriptionAdviceTemplate
  9931. s.PrescriptionId = prescription.ID
  9932. s.AdviceType = 2
  9933. s.StopState = 2
  9934. s.ExecutionState = 2
  9935. s.Status = 1
  9936. s.UserOrgId = adminInfo.CurrentOrgId
  9937. s.CreatedTime = ctime
  9938. s.UpdatedTime = mtime
  9939. s.PatientId = patient_id
  9940. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9941. if errcode > 0 {
  9942. c.ServeFailJSONWithSGJErrorCode(errcode)
  9943. return
  9944. }
  9945. service.CreateHisPrescriptionAdviceTemplate(&s)
  9946. }
  9947. }
  9948. }
  9949. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9950. projects := items["project"].([]interface{})
  9951. if len(projects) > 0 {
  9952. for _, project := range projects {
  9953. var p models.HisPrescriptionProjectTemplate
  9954. p.PrescriptionId = prescription.ID
  9955. p.Ctime = time.Now().Unix()
  9956. p.Mtime = time.Now().Unix()
  9957. p.PatientId = patient_id
  9958. p.UserOrgId = adminInfo.CurrentOrgId
  9959. p.Status = 1
  9960. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9961. if errcode > 0 {
  9962. c.ServeFailJSONWithSGJErrorCode(errcode)
  9963. return
  9964. }
  9965. service.CreateHisPrescriptionProjectTemplate(&p)
  9966. }
  9967. }
  9968. }
  9969. }
  9970. c.ServeSuccessJSON(map[string]interface{}{
  9971. "msg": "创建成功",
  9972. })
  9973. }
  9974. }
  9975. } else {
  9976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9977. return
  9978. }
  9979. } else {
  9980. err3 := service.CreateHisPrescriptionTemplate(template)
  9981. if err3 == nil {
  9982. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9983. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9984. if len(prescriptions) > 0 {
  9985. for _, item := range prescriptions {
  9986. items := item.(map[string]interface{})
  9987. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9988. utils.ErrorLog("type")
  9989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9990. return
  9991. }
  9992. types := int64(items["type"].(float64))
  9993. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9994. utils.ErrorLog("med_type")
  9995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9996. return
  9997. }
  9998. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9999. ctime := time.Now().Unix()
  10000. prescription := &models.HisPrescriptionInfoTemplate{
  10001. PatientId: patient_id,
  10002. UserOrgId: adminInfo.CurrentOrgId,
  10003. Ctime: ctime,
  10004. Mtime: ctime,
  10005. Type: types,
  10006. Modifier: adminInfo.AdminUser.Id,
  10007. Creator: adminInfo.AdminUser.Id,
  10008. Status: 1,
  10009. PTemplateId: template.ID,
  10010. MedType: med_type,
  10011. }
  10012. service.CreateHisPrescriptionInfoTemplate(prescription)
  10013. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10014. advices := items["advices"].([]interface{})
  10015. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10016. ctime := time.Now().Unix()
  10017. mtime := ctime
  10018. if len(advices) > 0 {
  10019. for _, advice := range advices {
  10020. var s models.HisPrescriptionAdviceTemplate
  10021. s.PrescriptionId = prescription.ID
  10022. s.AdviceType = 2
  10023. s.StopState = 2
  10024. s.ExecutionState = 2
  10025. s.Status = 1
  10026. s.UserOrgId = adminInfo.CurrentOrgId
  10027. s.CreatedTime = ctime
  10028. s.UpdatedTime = mtime
  10029. s.PatientId = patient_id
  10030. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10031. if errcode > 0 {
  10032. c.ServeFailJSONWithSGJErrorCode(errcode)
  10033. return
  10034. }
  10035. service.CreateHisPrescriptionAdviceTemplate(&s)
  10036. }
  10037. }
  10038. }
  10039. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10040. projects := items["project"].([]interface{})
  10041. if len(projects) > 0 {
  10042. for _, project := range projects {
  10043. var p models.HisPrescriptionProjectTemplate
  10044. p.PrescriptionId = prescription.ID
  10045. p.Ctime = time.Now().Unix()
  10046. p.Mtime = time.Now().Unix()
  10047. p.PatientId = patient_id
  10048. p.UserOrgId = adminInfo.CurrentOrgId
  10049. p.Status = 1
  10050. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10051. if errcode > 0 {
  10052. c.ServeFailJSONWithSGJErrorCode(errcode)
  10053. return
  10054. }
  10055. service.CreateHisPrescriptionProjectTemplate(&p)
  10056. }
  10057. }
  10058. }
  10059. }
  10060. c.ServeSuccessJSON(map[string]interface{}{
  10061. "msg": "创建成功",
  10062. })
  10063. }
  10064. }
  10065. } else {
  10066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10067. return
  10068. }
  10069. }
  10070. }
  10071. func (c *HisApiController) PreSettle() {
  10072. id, _ := c.GetInt64("id")
  10073. record_time := c.GetString("record_time")
  10074. his_patient_id, _ := c.GetInt64("his_patient_id")
  10075. timeLayout := "2006-01-02"
  10076. loc, _ := time.LoadLocation("Local")
  10077. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10078. diagnosis_id := c.GetString("diagnosis")
  10079. sick_type, _ := c.GetInt64("sick_type")
  10080. reg_type, _ := c.GetInt64("p_type")
  10081. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10082. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10083. if err != nil {
  10084. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10085. return
  10086. }
  10087. recordDateTime := theTime.Unix()
  10088. adminUser := c.GetAdminUserInfo()
  10089. var prescriptions []*models.HisPrescription
  10090. var start_time int64
  10091. var end_time int64
  10092. ids_str := c.GetString("ids")
  10093. ids_arr := strings.Split(ids_str, ",")
  10094. fmt.Println(reg_type)
  10095. if settle_accounts_type == 1 { //日结
  10096. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10097. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10098. } else {
  10099. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10100. }
  10101. fmt.Println(prescriptions)
  10102. } else { //月结
  10103. start_time_str := c.GetString("start_time")
  10104. end_time_str := c.GetString("end_time")
  10105. timeLayout := "2006-01-02"
  10106. loc, _ := time.LoadLocation("Local")
  10107. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10108. if err != nil {
  10109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10110. return
  10111. }
  10112. recordStartTime := theStartTime.Unix()
  10113. start_time = recordStartTime
  10114. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10115. if err != nil {
  10116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10117. return
  10118. }
  10119. recordEndTime := theEndTime.Unix()
  10120. end_time = recordEndTime
  10121. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10122. }
  10123. if reg_type == 1111 || reg_type == 1112 {
  10124. reg_type = 11
  10125. }
  10126. timestamp := time.Now().Unix()
  10127. tempTime := time.Unix(timestamp, 0)
  10128. timeFormat := tempTime.Format("20060102150405")
  10129. chrgBchno := rand.Intn(100000) + 10000
  10130. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10131. strconv.FormatInt(his.PatientId, 10)
  10132. var ids []int64
  10133. for _, item := range prescriptions {
  10134. ids = append(ids, item.ID)
  10135. }
  10136. fmt.Println(ids)
  10137. var total float64
  10138. for _, item := range prescriptions {
  10139. fmt.Println(item)
  10140. if item.Type == 1 { //药品
  10141. for _, subItem := range item.HisDoctorAdviceInfo {
  10142. total = total + (subItem.Price * subItem.PrescribingNumber)
  10143. }
  10144. }
  10145. if item.Type == 2 { //项目
  10146. for _, subItem := range item.HisPrescriptionProject {
  10147. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10148. total = total + (subItem.Price * cnt)
  10149. }
  10150. }
  10151. for _, subItem := range item.HisAdditionalCharge {
  10152. total = total + (subItem.Price * float64(subItem.Count))
  10153. }
  10154. }
  10155. allTotal := fmt.Sprintf("%.2f", total)
  10156. totals, _ := strconv.ParseFloat(allTotal, 64)
  10157. order := &models.HisOrder{
  10158. UserOrgId: adminUser.CurrentOrgId,
  10159. HisPatientId: his.ID,
  10160. PatientId: id,
  10161. SettleAccountsDate: recordDateTime,
  10162. Ctime: time.Now().Unix(),
  10163. Mtime: time.Now().Unix(),
  10164. Status: 1,
  10165. OrderStatus: 1,
  10166. MdtrtId: his.Number,
  10167. Number: chrg_bchno,
  10168. MedfeeSumamt: totals,
  10169. SettleEndTime: end_time,
  10170. SettleStartTime: start_time,
  10171. SettleType: settle_accounts_type,
  10172. PsnPartAmt: totals,
  10173. PsnCashPay: totals,
  10174. PType: 2,
  10175. IsPre: 1,
  10176. MedType: strconv.Itoa(int(reg_type)),
  10177. Diagnosis: diagnosis_id,
  10178. }
  10179. err = service.CreateOrder(order)
  10180. if err != nil {
  10181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10182. return
  10183. }
  10184. var customs []*Custom
  10185. for _, item := range prescriptions {
  10186. fmt.Println(item.Type)
  10187. if item.Type == 1 { //药品
  10188. for _, subItem := range item.HisDoctorAdviceInfo {
  10189. cus := &Custom{
  10190. AdviceId: subItem.ID,
  10191. ProjectId: 0,
  10192. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10193. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10194. FeedetlSn: subItem.FeedetlSn,
  10195. Price: fmt.Sprintf("%.2f", subItem.Price),
  10196. MedListCodg: subItem.MedListCodg,
  10197. Type: 1,
  10198. }
  10199. customs = append(customs, cus)
  10200. }
  10201. }
  10202. if item.Type == 2 { //项目
  10203. for _, subItem := range item.HisPrescriptionProject {
  10204. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10205. cus := &Custom{
  10206. AdviceId: 0,
  10207. ProjectId: subItem.ID,
  10208. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10209. Cut: fmt.Sprintf("%.2f", cnt),
  10210. FeedetlSn: subItem.FeedetlSn,
  10211. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10212. MedListCodg: subItem.MedListCodg,
  10213. Type: 2,
  10214. }
  10215. customs = append(customs, cus)
  10216. }
  10217. }
  10218. for _, item := range item.HisAdditionalCharge {
  10219. cus := &Custom{
  10220. ItemId: item.ID,
  10221. AdviceId: 0,
  10222. ProjectId: 0,
  10223. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10224. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10225. FeedetlSn: item.FeedetlSn,
  10226. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10227. MedListCodg: item.XtHisAddtionConfig.Code,
  10228. Type: 3,
  10229. }
  10230. customs = append(customs, cus)
  10231. }
  10232. }
  10233. fmt.Println(customs)
  10234. for _, item := range customs {
  10235. var advice_id int64 = 0
  10236. var project_id int64 = 0
  10237. var item_id int64 = 0
  10238. var types int64 = 0
  10239. if item.Type == 1 {
  10240. advice_id = item.AdviceId
  10241. project_id = 0
  10242. item_id = 0
  10243. } else if item.Type == 2 {
  10244. advice_id = 0
  10245. item_id = 0
  10246. project_id = item.ProjectId
  10247. } else if item.Type == 3 {
  10248. advice_id = 0
  10249. item_id = item.ItemId
  10250. project_id = 0
  10251. }
  10252. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10253. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10254. pric, _ := strconv.ParseFloat(item.Price, 32)
  10255. info := &models.HisOrderInfo{
  10256. OrderNumber: order.Number,
  10257. UploadDate: time.Now().Unix(),
  10258. AdviceId: advice_id,
  10259. DetItemFeeSumamt: detItemFeeSumamt,
  10260. Cnt: cut,
  10261. Pric: pric,
  10262. PatientId: id,
  10263. Status: 1,
  10264. Mtime: time.Now().Unix(),
  10265. Ctime: time.Now().Unix(),
  10266. UserOrgId: adminUser.CurrentOrgId,
  10267. HisPatientId: his.ID,
  10268. OrderId: order.ID,
  10269. ProjectId: project_id,
  10270. Type: types,
  10271. ItemId: item_id,
  10272. }
  10273. service.CreateOrderInfo(info)
  10274. }
  10275. his.SickType = sick_type
  10276. service.UpdataHisPateint(&his)
  10277. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  10278. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  10279. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  10280. if err == nil {
  10281. c.ServeSuccessJSON(map[string]interface{}{
  10282. "msg": "结算成功",
  10283. })
  10284. }
  10285. }
  10286. type CustomOrderInfo struct {
  10287. Name string
  10288. Spec string
  10289. Unit string
  10290. Count float64
  10291. Price float64
  10292. Total float64
  10293. }
  10294. func (c *HisApiController) GetPrivateExpensesInfo() {
  10295. order_id, _ := c.GetInt64("id", 0)
  10296. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  10297. order, _ := service.GetHisOrderByID(order_id)
  10298. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  10299. if order.ID == 0 {
  10300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10301. return
  10302. }
  10303. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  10304. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10305. org_id := c.GetAdminUserInfo().CurrentOrgId
  10306. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10307. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10308. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  10309. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  10310. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  10311. //var orderInfos_four []*models.HisOrderInfoTwo
  10312. //for _, item := range orderInfos_three {
  10313. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  10314. // item.HisPrescriptionProject.IsCheckTeam = 1
  10315. // orderInfos_four = append(orderInfos_four, item)
  10316. //
  10317. // }
  10318. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  10319. // item.HisPrescriptionProject.IsCheckTeam = 2
  10320. // orderInfos_two = append(orderInfos_two, item)
  10321. // }
  10322. //}
  10323. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  10324. //var cus_slice []CustomOrderInfo
  10325. //for _, item := range new_order_info {
  10326. // var cus CustomOrderInfo
  10327. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  10328. // cus.Unit = ""
  10329. // cus.Spec = ""
  10330. // var total float64
  10331. // for _, subItem := range orderInfos_four {
  10332. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  10333. // total = total + subItem.DetItemFeeSumamt
  10334. // fmt.Println(subItem.DetItemFeeSumamt)
  10335. // }
  10336. // }
  10337. // cus.Count = 1
  10338. // cus.Total = total
  10339. // cus_slice = append(cus_slice, cus)
  10340. //}
  10341. orderInfos = append(orderInfos, orderInfos_two...)
  10342. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  10343. //orderInfos = append(orderInfos, orderInfos_three...)
  10344. //}/**/
  10345. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10346. c.ServeSuccessJSON(map[string]interface{}{
  10347. "order": order,
  10348. "order_info": orderInfos,
  10349. "patient": patient,
  10350. "admin_info": adminInfo,
  10351. "his": his,
  10352. "current_admin": role,
  10353. "org_config": miConfig,
  10354. //"new_order_info": cus_slice,
  10355. })
  10356. }
  10357. func (this *HisApiController) ChangeMedType() {
  10358. med_type := this.GetString("med_type")
  10359. old_med_type := this.GetString("old_med_type")
  10360. ids := this.GetString("ids")
  10361. settle_type, _ := this.GetInt64("settle_type")
  10362. start_time := this.GetString("start_time")
  10363. end_time := this.GetString("end_time")
  10364. ids_arr := strings.Split(ids, ",")
  10365. if settle_type == 1 { //日结
  10366. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  10367. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  10368. prescription.MedType = med_type
  10369. err := service.SaveHisPrescriptionTwo(&prescription)
  10370. if err == nil {
  10371. this.ServeSuccessJSON(map[string]interface{}{
  10372. "msg": "修改成功",
  10373. })
  10374. } else {
  10375. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10376. return
  10377. }
  10378. } else if settle_type == 2 {
  10379. timeLayout := "2006-01-02"
  10380. loc, _ := time.LoadLocation("Local")
  10381. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10382. if err != nil {
  10383. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10384. return
  10385. }
  10386. recordStartTime := theStartTime.Unix()
  10387. start_time_timestamp := recordStartTime
  10388. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  10389. if err != nil {
  10390. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10391. return
  10392. }
  10393. recordEndTime := theEndTime.Unix()
  10394. end_time_timestamp := recordEndTime
  10395. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  10396. if updateErr == nil {
  10397. this.ServeSuccessJSON(map[string]interface{}{
  10398. "msg": "修改成功",
  10399. })
  10400. } else {
  10401. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10402. return
  10403. }
  10404. }
  10405. }
  10406. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  10407. patient_id, _ := c.GetInt64("patient_id")
  10408. his_patient_id, _ := c.GetInt64("his_patient_id")
  10409. record_date := c.GetString("record_date")
  10410. start_time := c.GetString("start_time")
  10411. end_time := c.GetString("end_time")
  10412. order_status, _ := c.GetInt64("type", 0)
  10413. p_type, _ := c.GetInt64("p_type", 0)
  10414. order_id, _ := c.GetInt64("order_id", 0)
  10415. timeLayout := "2006-01-02"
  10416. loc, _ := time.LoadLocation("Local")
  10417. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10418. if err != nil {
  10419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10420. return
  10421. }
  10422. recordDateTime := theTime.Unix()
  10423. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10424. if err != nil {
  10425. }
  10426. startRecordDateTime := startTime.Unix()
  10427. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10428. if err != nil {
  10429. }
  10430. endRecordDateTime := endTime.Unix()
  10431. admin := c.GetAdminUserInfo()
  10432. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10433. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10434. order, _ := service.GetHisOrderByID(order_id)
  10435. var monthPrescriptions []*models.HisPrescription
  10436. if order_status == 1 || order_status == 0 {
  10437. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10438. } else if order_status == 2 {
  10439. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10440. }
  10441. var settle_total float64
  10442. for _, item := range monthPrescriptions {
  10443. if len(item.HisPrescriptionProject) > 0 {
  10444. for _, subItem := range item.HisPrescriptionProject {
  10445. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10446. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10447. settle_total = settle_total + total
  10448. }
  10449. }
  10450. if len(item.HisDoctorAdviceInfo) > 0 {
  10451. for _, subItem := range item.HisDoctorAdviceInfo {
  10452. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10453. settle_total = settle_total + total
  10454. }
  10455. }
  10456. }
  10457. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10458. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10459. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10460. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10461. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10462. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10463. //获取所有科室信息
  10464. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10465. var dia string
  10466. for _, item := range month_p_info {
  10467. if len(dia) == 0 {
  10468. dia = item.Diagnosis
  10469. } else {
  10470. dia = dia + "," + item.Diagnosis
  10471. }
  10472. }
  10473. dia_arr := removeDuplicates(strings.Split(dia, ","))
  10474. dia_arr = removeEmptyStrings(dia_arr)
  10475. c.ServeSuccessJSON(map[string]interface{}{
  10476. "his_info": his_patient_info,
  10477. "xt_info": xt_patient_info,
  10478. "case_history": case_history,
  10479. "info": patientPrescriptionInfo,
  10480. "last_info": lastPatientPrescriptionInfo,
  10481. "month_prescriptions": monthPrescriptions,
  10482. "order": order,
  10483. "doctors": doctors,
  10484. "department": department,
  10485. "settle_total": settle_total,
  10486. "dia_arr": dia_arr,
  10487. })
  10488. return
  10489. }
  10490. func removeEmptyStrings(input []string) []string {
  10491. var output []string
  10492. for _, s := range input {
  10493. if s != "" {
  10494. output = append(output, s)
  10495. }
  10496. }
  10497. return output
  10498. }
  10499. func removeDuplicates(input []string) []string {
  10500. seen := make(map[string]bool)
  10501. output := []string{}
  10502. for _, s := range input {
  10503. if _, exists := seen[s]; !exists {
  10504. seen[s] = true
  10505. output = append(output, s)
  10506. }
  10507. }
  10508. return output
  10509. }
  10510. func (c *HisApiController) GetHisMonthPatientInfo() {
  10511. patient_id, _ := c.GetInt64("patient_id")
  10512. his_patient_id, _ := c.GetInt64("his_patient_id")
  10513. record_date := c.GetString("record_date")
  10514. number := c.GetString("number")
  10515. start_time := c.GetString("start_time")
  10516. end_time := c.GetString("end_time")
  10517. p_type, _ := c.GetInt64("p_type")
  10518. timeLayout := "2006-01-02"
  10519. loc, _ := time.LoadLocation("Local")
  10520. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10521. if err != nil {
  10522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10523. return
  10524. }
  10525. recordDateTime := theTime.Unix()
  10526. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10527. if err != nil {
  10528. }
  10529. startRecordDateTime := startTime.Unix()
  10530. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10531. if err != nil {
  10532. }
  10533. endRecordDateTime := endTime.Unix()
  10534. admin := c.GetAdminUserInfo()
  10535. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  10536. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10537. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  10538. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10539. var settle_total float64
  10540. for _, item := range monthPrescriptions {
  10541. if len(item.HisPrescriptionProject) > 0 {
  10542. for _, subItem := range item.HisPrescriptionProject {
  10543. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10544. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10545. settle_total = settle_total + total
  10546. }
  10547. }
  10548. if len(item.HisDoctorAdviceInfo) > 0 {
  10549. for _, subItem := range item.HisDoctorAdviceInfo {
  10550. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10551. settle_total = settle_total + total
  10552. }
  10553. }
  10554. }
  10555. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10556. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10557. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10558. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10559. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  10560. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10561. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  10562. //获取所有科室信息
  10563. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10564. c.ServeSuccessJSON(map[string]interface{}{
  10565. "his_info": his_patient_info,
  10566. "xt_info": xt_patient_info,
  10567. "case_history": case_history,
  10568. "info": patientPrescriptionInfo,
  10569. "month_prescriptions": monthPrescriptions,
  10570. "order": order,
  10571. "doctors": doctors,
  10572. "department": department,
  10573. "count": count,
  10574. "drugStockConfig": drugStockConfig,
  10575. "last_info": lastPatientPrescriptionInfo,
  10576. "settle_total": settle_total,
  10577. })
  10578. return
  10579. }
  10580. func (c *HisApiController) GetAllOrder() {
  10581. org_id := c.GetAdminUserInfo().CurrentOrgId
  10582. orders, _ := service.GetNewHisOrderList(org_id)
  10583. c.ServeSuccessJSON(map[string]interface{}{
  10584. "order": orders,
  10585. })
  10586. return
  10587. }
  10588. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  10589. newArr = make([]*models.HisOrderInfoTwo, 0)
  10590. for i := 0; i < len(arr); i++ {
  10591. repeat := false
  10592. for j := i + 1; j < len(arr); j++ {
  10593. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  10594. repeat = true
  10595. break
  10596. }
  10597. }
  10598. if !repeat {
  10599. newArr = append(newArr, arr[i])
  10600. }
  10601. }
  10602. return
  10603. }
  10604. // 修改处方退库操作 参数传修改之前的处方数据
  10605. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  10606. if advice.ExecutionState == 1 {
  10607. //查询该病人该药品是否有库存记录
  10608. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  10609. if errcode == gorm.ErrRecordNotFound {
  10610. } else {
  10611. //退库
  10612. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  10613. if advice.PrescribingNumberUnit == drug.MinUnit {
  10614. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  10615. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  10616. //退库
  10617. warehouseInfo := models.DrugWarehouseInfo{
  10618. StockMinNumber: prescribingNumber,
  10619. }
  10620. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  10621. operation_time := time.Now().Unix()
  10622. creater := advice.AdviceDoctor
  10623. ctime := time.Now().Unix()
  10624. timeStr := time.Now().Format("2006-01-02")
  10625. timeArr := strings.Split(timeStr, "-")
  10626. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  10627. total = total + 1
  10628. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  10629. cancelStock := models.DrugCancelStock{
  10630. OrderNumber: orderNumber,
  10631. OperaTime: operation_time,
  10632. OrgId: advice.UserOrgId,
  10633. Creater: creater,
  10634. Ctime: ctime,
  10635. Status: 1,
  10636. ReturnTime: advice.AdviceDate,
  10637. Dealer: info.Dealer,
  10638. Manufacturer: info.Manufacturer,
  10639. Type: 1,
  10640. }
  10641. service.AddSigleDrugCancelStock(&cancelStock)
  10642. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  10643. dealer, _ := service.GetDealerById(info.Dealer)
  10644. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  10645. cancelStockInfo := models.DrugCancelStockInfo{
  10646. OrderNumber: cancelInfo.OrderNumber,
  10647. CancelStockId: cancelInfo.ID,
  10648. DrugId: info.DrugId,
  10649. Count: info.Count,
  10650. Status: 1,
  10651. Ctime: ctime,
  10652. OrgId: advice.UserOrgId,
  10653. Type: 1,
  10654. Manufacturer: manufactureName.ManufacturerName,
  10655. Dealer: dealer.DealerName,
  10656. Total: 0,
  10657. RetailPrice: info.RetailPrice,
  10658. RetailTotalPrice: info.RetailTotalPrice,
  10659. Price: info.Price,
  10660. RegisterAccount: "",
  10661. Remark: info.Remark,
  10662. BatchNumber: info.BatchNumber,
  10663. MaxUnit: info.CountUnit,
  10664. ProductDate: info.ProductDate,
  10665. ExpiryDate: info.ExpiryDate,
  10666. BatchNumberId: info.WarehouseInfoId,
  10667. }
  10668. flow := models.DrugFlow{
  10669. WarehousingId: 0,
  10670. DrugId: info.DrugId,
  10671. Number: "",
  10672. BatchNumber: info.BatchNumber,
  10673. Count: info.Count,
  10674. UserOrgId: advice.UserOrgId,
  10675. PatientId: 0,
  10676. SystemTime: ctime,
  10677. ConsumableType: 4,
  10678. IsSys: 0,
  10679. WarehousingOrder: "",
  10680. WarehouseOutId: 0,
  10681. WarehouseOutOrderNumber: "",
  10682. IsEdit: 0,
  10683. CancelStockId: cancelStock.ID,
  10684. CancelOrderNumber: cancelStock.OrderNumber,
  10685. Manufacturer: info.Manufacturer,
  10686. Dealer: info.Dealer,
  10687. Creator: advice.UserOrgId,
  10688. UpdateCreator: 0,
  10689. Status: 1,
  10690. Ctime: time.Now().Unix(),
  10691. Mtime: 0,
  10692. Price: info.Price,
  10693. WarehousingDetailId: 0,
  10694. WarehouseOutDetailId: 0,
  10695. CancelOutDetailId: 0,
  10696. ExpireDate: info.ExpiryDate,
  10697. ProductDate: info.ProductDate,
  10698. MaxUnit: info.CountUnit,
  10699. MinUnit: "",
  10700. }
  10701. service.CreatedCancelStock(cancelStockInfo)
  10702. service.CreateDrugFlowOne(flow)
  10703. } else {
  10704. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  10705. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  10706. if advice.PrescribingNumberUnit == drug.MaxUnit {
  10707. warehouseInfo := models.DrugWarehouseInfo{
  10708. StockMinNumber: prescribingNumber,
  10709. }
  10710. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  10711. }
  10712. operation_time := time.Now().Unix()
  10713. creater := advice.AdviceDoctor
  10714. ctime := time.Now().Unix()
  10715. timeStr := time.Now().Format("2006-01-02")
  10716. timeArr := strings.Split(timeStr, "-")
  10717. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  10718. total = total + 1
  10719. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  10720. cancelStock := models.DrugCancelStock{
  10721. OrderNumber: orderNumber,
  10722. OperaTime: operation_time,
  10723. OrgId: advice.UserOrgId,
  10724. Creater: creater,
  10725. Ctime: ctime,
  10726. Status: 1,
  10727. ReturnTime: advice.AdviceDate,
  10728. Dealer: info.Dealer,
  10729. Manufacturer: info.Manufacturer,
  10730. Type: 1,
  10731. }
  10732. service.AddSigleDrugCancelStock(&cancelStock)
  10733. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  10734. dealer, _ := service.GetDealerById(info.Dealer)
  10735. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  10736. cancelStockInfo := models.DrugCancelStockInfo{
  10737. OrderNumber: cancelInfo.OrderNumber,
  10738. CancelStockId: cancelInfo.ID,
  10739. DrugId: info.DrugId,
  10740. Count: info.Count,
  10741. Status: 1,
  10742. Ctime: ctime,
  10743. OrgId: advice.UserOrgId,
  10744. Type: 1,
  10745. Manufacturer: manufactureName.ManufacturerName,
  10746. Dealer: dealer.DealerName,
  10747. Total: 0,
  10748. RetailPrice: info.RetailPrice,
  10749. RetailTotalPrice: info.RetailTotalPrice,
  10750. Price: info.Price,
  10751. RegisterAccount: "",
  10752. Remark: info.Remark,
  10753. BatchNumber: info.BatchNumber,
  10754. MaxUnit: info.CountUnit,
  10755. ProductDate: info.ProductDate,
  10756. ExpiryDate: info.ExpiryDate,
  10757. BatchNumberId: info.WarehouseInfoId,
  10758. }
  10759. flow := models.DrugFlow{
  10760. WarehousingId: 0,
  10761. DrugId: info.DrugId,
  10762. Number: "",
  10763. BatchNumber: info.BatchNumber,
  10764. Count: info.Count,
  10765. UserOrgId: advice.UserOrgId,
  10766. PatientId: 0,
  10767. SystemTime: ctime,
  10768. ConsumableType: 4,
  10769. IsSys: 0,
  10770. WarehousingOrder: "",
  10771. WarehouseOutId: 0,
  10772. WarehouseOutOrderNumber: "",
  10773. IsEdit: 0,
  10774. CancelStockId: cancelStock.ID,
  10775. CancelOrderNumber: cancelStock.OrderNumber,
  10776. Manufacturer: info.Manufacturer,
  10777. Dealer: info.Dealer,
  10778. Creator: advice.AdviceDoctor,
  10779. UpdateCreator: 0,
  10780. Status: 1,
  10781. Ctime: time.Now().Unix(),
  10782. Mtime: 0,
  10783. Price: info.Price,
  10784. WarehousingDetailId: 0,
  10785. WarehouseOutDetailId: 0,
  10786. CancelOutDetailId: 0,
  10787. ExpireDate: info.ExpiryDate,
  10788. ProductDate: info.ProductDate,
  10789. MaxUnit: info.CountUnit,
  10790. MinUnit: "",
  10791. }
  10792. service.CreatedCancelStock(cancelStockInfo)
  10793. service.CreateDrugFlowOne(flow)
  10794. }
  10795. }
  10796. }
  10797. return err
  10798. }
  10799. func (this *HisApiController) DeleteNCDS() {
  10800. id, _ := this.GetInt64("id", 0)
  10801. if id > 0 {
  10802. service.DeletePsnNCDSRecordById(id)
  10803. this.ServeSuccessJSON(map[string]interface{}{
  10804. "msg": "删除成功",
  10805. })
  10806. } else {
  10807. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  10808. return
  10809. }
  10810. }
  10811. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  10812. id, _ := c.GetInt64("id")
  10813. advice, _ := service.GetHisDoctorAdviceInfo(id)
  10814. c.ServeSuccessJSON(map[string]interface{}{
  10815. "advice": advice,
  10816. })
  10817. return
  10818. }
  10819. func (c *HisApiController) GetHisMonthChargePatientList() {
  10820. record_date := c.GetString("record_date")
  10821. start_time := c.GetString("start_time")
  10822. end_time := c.GetString("end_time")
  10823. timeLayout := "2006-01-02"
  10824. loc, _ := time.LoadLocation("Local")
  10825. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10826. if err != nil {
  10827. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10828. return
  10829. }
  10830. if err != nil {
  10831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10832. return
  10833. }
  10834. recordDateTime := theTime.Unix()
  10835. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10836. if err != nil {
  10837. }
  10838. startRecordDateTime := startTime.Unix()
  10839. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10840. if err != nil {
  10841. }
  10842. endRecordDateTime := endTime.Unix()
  10843. adminInfo := c.GetAdminUserInfo()
  10844. var tempMonthChargePatients []*service.MonthChargePatients
  10845. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  10846. for _, item := range tempPatients {
  10847. //过滤没有处方的
  10848. if len(item.HisPrescription) == 0 {
  10849. tempMonthChargePatients = append(tempMonthChargePatients, item)
  10850. }
  10851. }
  10852. c.ServeSuccessJSON(map[string]interface{}{
  10853. "list": tempMonthChargePatients,
  10854. })
  10855. }
  10856. // PrescriptionDifference 医嘱数量差值结构体
  10857. type PrescriptionDrugDifference struct {
  10858. DrugID int64 //基础库药品id
  10859. ID int64 //医嘱id
  10860. Difference float64 //差值
  10861. Unit string //单位
  10862. }
  10863. type PrescriptionGoodDifference struct {
  10864. GoodID int64 //基础库项目耗材id
  10865. ID int64 //医嘱id
  10866. Difference int64 //差值
  10867. Unit string //单位
  10868. Type int64 //类型
  10869. }
  10870. type EditCustomData struct {
  10871. adviceList []*models.HisDoctorAdviceInfo
  10872. projectList []*models.HisPrescriptionProject
  10873. }
  10874. type SrcCustomData struct {
  10875. adviceList []*models.HisDoctorAdviceInfo
  10876. projectList []*models.HisPrescriptionProject
  10877. }
  10878. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  10879. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  10880. differences := make([]*PrescriptionDrugDifference, 0)
  10881. // 创建一个 map 来存储第一个切片中的药品信息
  10882. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  10883. for _, advice := range firstPrescription {
  10884. firstMap[advice.DrugId] = advice
  10885. }
  10886. // 遍历第二个切片中的药品信息,并比较数量差值
  10887. for _, advice := range secondPrescription {
  10888. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  10889. diff := &PrescriptionDrugDifference{
  10890. DrugID: advice.DrugId,
  10891. ID: firstAdvice.ID,
  10892. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  10893. Unit: firstAdvice.PrescribingNumberUnit,
  10894. }
  10895. differences = append(differences, diff)
  10896. }
  10897. }
  10898. return differences
  10899. }
  10900. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  10901. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  10902. differences := make([]*PrescriptionGoodDifference, 0)
  10903. // 创建一个 map 来存储第一个切片中的耗材信息
  10904. firstMap := make(map[int64]*models.HisPrescriptionProject)
  10905. for _, good := range firstPrescription {
  10906. firstMap[good.ProjectId] = good
  10907. }
  10908. // 遍历第二个切片中的耗材信息,并比较数量差值
  10909. for _, good := range secondPrescription {
  10910. if firstGood, ok := firstMap[good.ProjectId]; ok {
  10911. count, _ := strconv.ParseInt(good.Count, 10, 64)
  10912. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  10913. diff := &PrescriptionGoodDifference{
  10914. GoodID: good.ProjectId,
  10915. ID: firstGood.ID,
  10916. Difference: count - firstCount,
  10917. Unit: firstGood.Unit,
  10918. Type: firstGood.Type,
  10919. }
  10920. differences = append(differences, diff)
  10921. }
  10922. }
  10923. return differences
  10924. }
  10925. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  10926. var adviceList []*models.HisDoctorAdviceInfo
  10927. var projectList []*models.HisPrescriptionProject
  10928. var advice_ids []int64
  10929. var project_ids []int64
  10930. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10931. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10932. //var tempPrescription *models.HisPrescriptionProjectscription
  10933. if len(prescriptions) > 0 {
  10934. for _, item := range prescriptions {
  10935. items := item.(map[string]interface{})
  10936. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10937. advices := items["advices"].([]interface{})
  10938. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10939. groupNo := int64(0)
  10940. ctime := time.Now().Unix()
  10941. mtime := ctime
  10942. if len(advices) > 0 {
  10943. for _, advice := range advices {
  10944. var s models.HisDoctorAdviceInfo
  10945. s.AdviceType = 2
  10946. s.StopState = 2
  10947. s.ExecutionState = 2
  10948. s.Status = 1
  10949. s.Groupno = groupNo
  10950. s.CreatedTime = ctime
  10951. s.UpdatedTime = mtime
  10952. s.IsSettle = 2
  10953. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  10954. //存储切片中
  10955. if s.ID > 0 {
  10956. advice_ids = append(advice_ids, s.ID)
  10957. adviceList = append(adviceList, &s)
  10958. }
  10959. }
  10960. }
  10961. }
  10962. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10963. projects := items["project"].([]interface{})
  10964. if len(projects) > 0 {
  10965. for _, project := range projects {
  10966. var p models.HisPrescriptionProject
  10967. p.Ctime = time.Now().Unix()
  10968. p.Mtime = time.Now().Unix()
  10969. p.Status = 1
  10970. SetProjectWithJSON(&p, project.(map[string]interface{}))
  10971. if p.ID > 0 {
  10972. project_ids = append(project_ids, p.ID)
  10973. projectList = append(projectList, &p)
  10974. }
  10975. }
  10976. }
  10977. }
  10978. }
  10979. }
  10980. }
  10981. editCustomData.projectList = projectList
  10982. editCustomData.adviceList = adviceList
  10983. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  10984. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  10985. srcCustomData.adviceList = list
  10986. srcCustomData.projectList = list2
  10987. return
  10988. }