his_api_controller.go 515KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. }
  92. func (c *HisApiController) CheckHisPatient() {
  93. record_date := c.GetString("record_date")
  94. patient_id, _ := c.GetInt64("patient_id")
  95. timeLayout := "2006-01-02"
  96. loc, _ := time.LoadLocation("Local")
  97. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  98. if err != nil {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. recordDateTime := theTime.Unix()
  103. adminInfo := c.GetAdminUserInfo()
  104. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  105. if len(patients) > 1 {
  106. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  107. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  108. c.ServeSuccessJSON(map[string]interface{}{
  109. "status": 1,
  110. "msg": "关联",
  111. "ps": ps,
  112. "his_patient_id": patients[len(patients)-1].ID,
  113. "patient_id": patients[len(patients)-1].PatientId,
  114. })
  115. } else {
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "status": 0,
  118. "msg": "无需关联",
  119. })
  120. }
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. return
  127. }
  128. }
  129. func (c *HisApiController) AssociationHisPrescription() {
  130. record_date := c.GetString("record_date")
  131. his_patient_id, _ := c.GetInt64("his_patient_id")
  132. patient_id, _ := c.GetInt64("patient_id")
  133. p_ids := c.GetString("p_ids")
  134. p_ids_arr := strings.Split(p_ids, ",")
  135. timeLayout := "2006-01-02"
  136. loc, _ := time.LoadLocation("Local")
  137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  138. if err != nil {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. recordDateTime := theTime.Unix()
  143. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  144. if his_patient_id == 0 || his_patient.ID == 0 {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  149. if err == nil {
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "msg": "关联处方成功",
  152. })
  153. return
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. return
  157. }
  158. }
  159. //func (c *HisApiController) AssociationHisPrescription() {
  160. // record_date, _ := c.GetInt64("record_date")
  161. // his_patient_id, _ := c.GetInt64("his_patient_id")
  162. // patient_id, _ := c.GetInt64("patient_id")
  163. // p_ids := c.GetString("p_ids")
  164. // p_ids_arr := strings.Split(p_ids, ",")
  165. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  166. // if his_patient_id == 0 || his_patient.ID == 0 {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. // return
  169. // }
  170. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  171. // if err == nil {
  172. // c.ServeSuccessJSON(map[string]interface{}{
  173. // "msg": "关联处方成功",
  174. // })
  175. // return
  176. // } else {
  177. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  178. // return
  179. // }
  180. //}
  181. func (c *HisApiController) GetFaPiaoNumber() {
  182. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  183. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  184. fmt.Println(count)
  185. var zero string
  186. number := count + 1
  187. //if number >= 1000 {
  188. // zero = "0000" + strconv.FormatInt(number, 10)
  189. //} else if number >= 10000 {
  190. // zero = "000" + strconv.FormatInt(number, 10)
  191. //} else if number >= 100000 {
  192. // zero = "00" + strconv.FormatInt(number, 10)
  193. //} else if number >= 1000000 {
  194. // zero = "0" + strconv.FormatInt(number, 10)
  195. //} else {
  196. zero = "0" + strconv.FormatInt(number, 10)
  197. //}
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "fapiao_number": zero,
  200. })
  201. return
  202. }
  203. func (c *HisApiController) ChangeOrderDesc() {
  204. id, _ := c.GetInt64("id")
  205. desc := c.GetString("desc")
  206. change_type := c.GetString("change_type")
  207. order, _ := service.GetHisOrderByID(id)
  208. if order.ID == 0 {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. switch change_type {
  213. case "oth_desc":
  214. order.OthDesc = desc
  215. break
  216. case "cash_pay":
  217. order.CashPay = desc
  218. break
  219. case "jifen_pay":
  220. order.JifenPay = desc
  221. break
  222. case "band_card_pay":
  223. order.BandCardPay = desc
  224. break
  225. case "ali_pay":
  226. order.AliPay = desc
  227. break
  228. case "wechat_pay":
  229. order.WechatPay = desc
  230. break
  231. case "fa_piao_number":
  232. order.FaPiaoNumber = desc
  233. break
  234. case "fa_piao_code":
  235. order.FaPiaoCode = desc
  236. break
  237. }
  238. err := service.SaveHisOrder(&order)
  239. if err == nil {
  240. c.ServeSuccessJSON(map[string]interface{}{
  241. "msg": "修改成功",
  242. })
  243. return
  244. } else {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  246. return
  247. }
  248. }
  249. func (c *HisApiController) GetMonthHisPatient() {
  250. record_date := c.GetString("record_date")
  251. //order_status, _ := c.GetInt64("type")
  252. timeLayout := "2006-01-02"
  253. loc, _ := time.LoadLocation("Local")
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  255. if err != nil {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. return
  258. }
  259. recordDateTime := theTime.Unix()
  260. adminInfo := c.GetAdminUserInfo()
  261. var tempPatients []service.NewTempPatients
  262. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  263. // 获取当前时间
  264. now := time.Now()
  265. // 获取本月的第一天
  266. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  267. // 获取下个月的第一天
  268. nextMonth := firstDay.AddDate(0, 1, 0)
  269. // 获取本月的最后一天
  270. lastDay := nextMonth.Add(-time.Nanosecond)
  271. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  272. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  273. var patients []service.NewTempPatients
  274. var patients_two []service.NewTempPatients
  275. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. patients_two = append(patients_two, item)
  281. }
  282. ////过滤掉没挂号的
  283. //if len(item.HisPatient) > 0 {
  284. //}
  285. }
  286. } else {
  287. for _, item := range tempPatients {
  288. //过滤掉没挂号的和没开处方的
  289. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  290. patients = append(patients, item)
  291. }
  292. ////过滤掉没挂号的
  293. //if len(item.HisPatient) > 0 {
  294. // patients_two = append(patients_two, item)
  295. //}
  296. }
  297. }
  298. c.ServeSuccessJSON(map[string]interface{}{
  299. "list": patients,
  300. "list_two": patients_two,
  301. "chargePatients": chargePatients,
  302. })
  303. }
  304. func (c *HisApiController) GetBatchSettleAccounts() {
  305. order_ids := c.GetString("order_ids")
  306. admin_user_id, _ := c.GetInt64("admin_user_id")
  307. adminUser := c.GetAdminUserInfo()
  308. orders := strings.Split(order_ids, ",")
  309. var newOrders []models.Orders
  310. for _, item := range orders {
  311. order, _ := service.GetHisOrderByIDTenOne(item)
  312. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  313. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  314. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  315. orderInfos = append(orderInfos, orderInfos_two...)
  316. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  317. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  318. var diagnosis_ids []string
  319. if his.ID > 0 {
  320. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  321. } else {
  322. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  323. }
  324. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  325. var dia_config []*models.HisXtDiagnoseConfig
  326. var name string
  327. for _, item := range diagnosis_ids {
  328. id, _ := strconv.ParseInt(item, 10, 64)
  329. diagnosisConfig, _ := service.FindDiagnoseById(id)
  330. dia_config = append(dia_config, diagnosisConfig)
  331. if len(name) == 0 {
  332. name = diagnosisConfig.ClassName
  333. } else {
  334. name = name + "," + diagnosisConfig.ClassName
  335. }
  336. }
  337. var bedCostTotal float64 = 0 //床位总费
  338. var bedCostSelfTotal float64 = 0 //床位自费
  339. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  340. var bedSelfTotal float64 = 0 //床位部分项目自费
  341. var bedInscpTotal float64 = 0 //床位部分项目自费
  342. var operationCostTotal float64 = 0 //手术费
  343. var operationCostSelfTotal float64 = 0 //手术费
  344. var operationCostPartSelfTotal float64 = 0 //手术费
  345. var operationSelfTotal float64 = 0 //床位部分项目自费
  346. var operationInscpTotal float64 = 0 //床位部分项目自费
  347. var otherCostTotal float64 = 0 //其他费用
  348. var otherCostSelfTotal float64 = 0 //其他费用
  349. var otherCostPartSelfTotal float64 = 0 //其他费用
  350. var otherSelfTotal float64 = 0 //床位部分项目自费
  351. var otherInscpTotal float64 = 0 //床位部分项目自费
  352. var materialCostTotal float64 = 0 //材料费
  353. var materialCostSelfTotal float64 = 0 //材料费
  354. var materialCostPartSelfTotal float64 = 0 //材料费
  355. var materialSelfTotal float64 = 0 //床位部分项目自费
  356. var materialInscpTotal float64 = 0 //床位部分项目自费
  357. var westernMedicineCostTotal float64 = 0 //西药费
  358. var westernMedicineCostSelfTotal float64 = 0 //西药费
  359. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  360. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  361. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  362. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  365. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  366. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  367. var checkCostTotal float64 = 0 //检查费
  368. var checkCostSelfTotal float64 = 0 //检查费
  369. var checkCostPartSelfTotal float64 = 0 //检查费
  370. var checkSelfTotal float64 = 0 //床位部分项目自费
  371. var checkInscpTotal float64 = 0 //床位部分项目自费
  372. var laboratoryCostTotal float64 = 0 //化验费
  373. var laboratoryCostSelfTotal float64 = 0 //化验费
  374. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  375. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  376. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  377. var treatCostTotal float64 = 0 //治疗费用
  378. var treatCostSelfTotal float64 = 0 //治疗费用
  379. var treatCostPartSelfTotal float64 = 0 //治疗费用
  380. var treatSelfTotal float64 = 0 //床位部分项目自费
  381. var treatInscpTotal float64 = 0 //床位部分项目自费
  382. decimal.DivisionPrecision = 2
  383. for _, item := range orderInfos {
  384. if item.MedChrgitmType == "01" { //床位费
  385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  386. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  387. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  388. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  389. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  390. }
  391. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  392. if item.MedChrgitmType == "03" { //检查费
  393. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  394. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  395. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  396. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  397. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  398. }
  399. } else {
  400. if item.MedChrgitmType == "03" { //检查费
  401. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  402. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  403. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  404. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  405. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  406. }
  407. }
  408. if item.MedChrgitmType == "04" { //化验费
  409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  410. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  411. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  412. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  413. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  414. }
  415. if item.MedChrgitmType == "05" { //治疗费
  416. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. if item.MedChrgitmType == "06" { //手术费
  423. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  424. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  425. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  426. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  427. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  428. }
  429. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  431. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  432. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  433. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  434. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  435. }
  436. if item.MedChrgitmType == "09" { //西药费
  437. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  438. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  439. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  440. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  441. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  442. }
  443. if item.MedChrgitmType == "11" { //中成费
  444. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  445. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  446. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  447. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  448. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  449. }
  450. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  454. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  455. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  456. }
  457. }
  458. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  459. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  460. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  461. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  462. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  463. var doctor_name string
  464. if roles.ID == 0 {
  465. doctor_name = "管理员"
  466. } else {
  467. doctor_name = roles.UserName
  468. }
  469. yiliao_leibie := ""
  470. switch order.MedType {
  471. case "11":
  472. yiliao_leibie = "普通门诊"
  473. break
  474. case "12":
  475. yiliao_leibie = "门诊挂号"
  476. break
  477. case "13":
  478. yiliao_leibie = "急诊"
  479. break
  480. case "14":
  481. yiliao_leibie = "门诊特殊病"
  482. break
  483. case "15":
  484. yiliao_leibie = "门诊统筹"
  485. break
  486. case "16":
  487. yiliao_leibie = "门诊慢性病"
  488. break
  489. case "21":
  490. yiliao_leibie = "普通住院"
  491. break
  492. }
  493. var newOrder models.Orders
  494. newOrder.Diagnosis = name
  495. newOrder.OrderInfos = orderInfos
  496. newOrder.Number = order.MdtrtId
  497. newOrder.Date = order.SettleAccountsDate
  498. newOrder.ChargeAdmin = charge_admin
  499. newOrder.PrintorAdmin = printor_admin
  500. newOrder.Order = order
  501. newOrder.BedCostTotal = bedCostTotal
  502. newOrder.BedCostSelfTotal = bedCostSelfTotal
  503. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  504. newOrder.BedSelfTotal = bedSelfTotal
  505. newOrder.BedInscpTotal = bedInscpTotal
  506. newOrder.OperationCostTotal = operationCostTotal
  507. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  508. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  509. newOrder.OperationSelfTotal = operationSelfTotal
  510. newOrder.OperationInscpTotal = operationInscpTotal
  511. newOrder.OtherCostTotal = otherCostTotal
  512. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  513. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  514. newOrder.OtherSelfTotal = otherSelfTotal
  515. newOrder.OtherInscpTotal = otherInscpTotal
  516. newOrder.MaterialCostTotal = materialCostTotal
  517. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  518. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  519. newOrder.MaterialSelfTotal = materialSelfTotal
  520. newOrder.MaterialInscpTotal = materialInscpTotal
  521. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  522. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  523. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  524. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  525. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  526. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  527. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  528. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  529. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  530. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  531. newOrder.CheckCostTotal = checkCostTotal
  532. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  533. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  534. newOrder.CheckSelfTotal = checkSelfTotal
  535. newOrder.CheckInscpTotal = checkInscpTotal
  536. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  537. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  538. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  539. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  540. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  541. newOrder.TreatCostTotal = treatCostTotal
  542. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  543. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  544. newOrder.TreatSelfTotal = treatSelfTotal
  545. newOrder.TreatInscpTotal = treatInscpTotal
  546. newOrder.DoctorInfo = doctor_info
  547. newOrder.DoctorName = doctor_name
  548. newOrder.HealthCardNo = order.PsnNo
  549. newOrder.YiliaoLeibie = yiliao_leibie
  550. newOrder.Patient = patient
  551. newOrder.OrgName = miConfig.OrgName
  552. newOrder.OrgCode = miConfig.Code
  553. newOrder.OrderNumber = order.Number
  554. newOrder.HisPatient = his
  555. newOrder.DiaConfig = dia_config
  556. newOrders = append(newOrders, newOrder)
  557. }
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "orders": newOrders,
  560. })
  561. }
  562. func (c *HisApiController) GetTestOrder() {
  563. order_id, _ := c.GetInt64("order_id")
  564. admin_user_id, _ := c.GetInt64("admin_user_id")
  565. adminUser := c.GetAdminUserInfo()
  566. order, _ := service.GetHisOrderByID(order_id)
  567. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  568. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  569. orderInfos = append(orderInfos, orderInfos_two...)
  570. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  571. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  572. var dia_config []*models.HisXtDiagnoseConfig
  573. var name string
  574. var bedCostTotal float64 = 0 //床位总费
  575. var bedCostSelfTotal float64 = 0 //床位自费
  576. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  577. var bedSelfTotal float64 = 0 //床位部分项目自费
  578. var bedInscpTotal float64 = 0 //床位部分项目自费
  579. var operationCostTotal float64 = 0 //手术费
  580. var operationCostSelfTotal float64 = 0 //手术费
  581. var operationCostPartSelfTotal float64 = 0 //手术费
  582. var operationSelfTotal float64 = 0 //床位部分项目自费
  583. var operationInscpTotal float64 = 0 //床位部分项目自费
  584. var otherCostTotal float64 = 0 //其他费用
  585. var otherCostSelfTotal float64 = 0 //其他费用
  586. var otherCostPartSelfTotal float64 = 0 //其他费用
  587. var otherSelfTotal float64 = 0 //床位部分项目自费
  588. var otherInscpTotal float64 = 0 //床位部分项目自费
  589. var materialCostTotal float64 = 0 //材料费
  590. var materialCostSelfTotal float64 = 0 //材料费
  591. var materialCostPartSelfTotal float64 = 0 //材料费
  592. var materialSelfTotal float64 = 0 //床位部分项目自费
  593. var materialInscpTotal float64 = 0 //床位部分项目自费
  594. var westernMedicineCostTotal float64 = 0 //西药费
  595. var westernMedicineCostSelfTotal float64 = 0 //西药费
  596. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  597. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  598. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  602. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  603. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  604. var checkCostTotal float64 = 0 //检查费
  605. var checkCostSelfTotal float64 = 0 //检查费
  606. var checkCostPartSelfTotal float64 = 0 //检查费
  607. var checkSelfTotal float64 = 0 //床位部分项目自费
  608. var checkInscpTotal float64 = 0 //床位部分项目自费
  609. var laboratoryCostTotal float64 = 0 //化验费
  610. var laboratoryCostSelfTotal float64 = 0 //化验费
  611. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  612. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  613. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  614. var treatCostTotal float64 = 0 //治疗费用
  615. var treatCostSelfTotal float64 = 0 //治疗费用
  616. var treatCostPartSelfTotal float64 = 0 //治疗费用
  617. var treatSelfTotal float64 = 0 //床位部分项目自费
  618. var treatInscpTotal float64 = 0 //床位部分项目自费
  619. decimal.DivisionPrecision = 2
  620. for _, item := range orderInfos {
  621. if item.MedChrgitmType == "01" { //床位费
  622. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  623. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  624. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  625. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  626. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  627. }
  628. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  629. if item.MedChrgitmType == "03" { //检查费
  630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  631. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  632. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  633. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  634. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  635. }
  636. } else {
  637. if item.MedChrgitmType == "03" { //检查费
  638. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  639. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  640. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  641. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  642. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  643. }
  644. }
  645. if item.MedChrgitmType == "04" { //化验费
  646. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  647. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  648. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  649. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  650. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  651. }
  652. if item.MedChrgitmType == "05" { //治疗费
  653. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. if item.MedChrgitmType == "06" { //手术费
  660. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  661. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  662. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  663. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  664. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  665. }
  666. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  668. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  669. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  670. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  671. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  672. }
  673. if item.MedChrgitmType == "09" { //西药费
  674. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  675. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  676. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  677. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  678. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  679. }
  680. if item.MedChrgitmType == "11" { //中成费
  681. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  682. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  683. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  684. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  685. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  686. }
  687. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  688. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  689. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  690. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  691. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  692. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  693. }
  694. }
  695. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  696. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  697. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  698. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  699. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  700. var doctor_name string
  701. if roles.ID == 0 {
  702. doctor_name = "管理员"
  703. } else {
  704. doctor_name = roles.UserName
  705. }
  706. yiliao_leibie := ""
  707. switch order.MedType {
  708. case "11":
  709. yiliao_leibie = "普通门诊"
  710. break
  711. case "12":
  712. yiliao_leibie = "门诊挂号"
  713. break
  714. case "13":
  715. yiliao_leibie = "急诊"
  716. break
  717. case "14":
  718. yiliao_leibie = "门诊特殊病"
  719. break
  720. case "15":
  721. yiliao_leibie = "门诊统筹"
  722. break
  723. case "16":
  724. yiliao_leibie = "门诊慢性病"
  725. break
  726. case "21":
  727. yiliao_leibie = "普通住院"
  728. break
  729. }
  730. c.ServeSuccessJSON(map[string]interface{}{
  731. "diagnosis": name,
  732. "order_infos": orderInfos,
  733. "number": order.MdtrtId,
  734. "date": order.SettleAccountsDate,
  735. "charge_admin": charge_admin,
  736. "printor_admin": printor_admin,
  737. "info": order,
  738. "order": order,
  739. "bedCostTotal": bedCostTotal,
  740. "bedCostSelfTotal": bedCostSelfTotal,
  741. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  742. "bedSelfTotal": bedSelfTotal,
  743. "bedInscpTotal": bedInscpTotal,
  744. "operationCostTotal": operationCostTotal,
  745. "operationCostSelfTotal": operationCostSelfTotal,
  746. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  747. "operationSelfTotal": operationSelfTotal,
  748. "operationInscpTotal": operationInscpTotal,
  749. "otherCostTotal": otherCostTotal,
  750. "otherCostSelfTotal": otherCostSelfTotal,
  751. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  752. "otherSelfTotal": otherSelfTotal,
  753. "otherInscpTotal": otherInscpTotal,
  754. "materialCostTotal": materialCostTotal,
  755. "materialCostSelfTotal": materialCostSelfTotal,
  756. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  757. "materialSelfTotal": materialSelfTotal,
  758. "materialInscpTotal": materialInscpTotal,
  759. "westernMedicineCostTotal": westernMedicineCostTotal,
  760. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  761. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  762. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  763. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  764. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  765. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  766. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  767. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  768. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  769. "checkCostTotal": checkCostTotal,
  770. "checkCostSelfTotal": checkCostSelfTotal,
  771. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  772. "checkSelfTotal": checkSelfTotal,
  773. "checkInscpTotal": checkInscpTotal,
  774. "laboratoryCostTotal": laboratoryCostTotal,
  775. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  776. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  777. "laboratorySelfTotal": laboratorySelfTotal,
  778. "laboratoryInscpTotal": laboratoryInscpTotal,
  779. "treatCostTotal": treatCostTotal,
  780. "treatCostSelfTotal": treatCostSelfTotal,
  781. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  782. "treatSelfTotal": treatSelfTotal,
  783. "treatInscpTotal": treatInscpTotal,
  784. "doctor_info": doctor_info,
  785. "doctor_name": doctor_name,
  786. "health_card_no": order.PsnNo,
  787. "yiliao_leibie": yiliao_leibie,
  788. "patient": patient,
  789. "org_name": miConfig.OrgName,
  790. "org_code": miConfig.Code,
  791. "order_number": order.Number,
  792. "his_hospital": his_hospital,
  793. "dia_config": dia_config,
  794. })
  795. }
  796. type CustomFundPay struct {
  797. FundPayType string `json:"fund_pay_type"`
  798. FundPayamt float64 `json:"fund_payamt"`
  799. InscpScpAmt float64 `json:"inscp_scp_amt"`
  800. }
  801. func (c *PublicApiController) GetBaiLinExportData() {
  802. data := service.GetBaiLinOrderData()
  803. fmt.Println(len(data))
  804. var new_data []*models.NewCustomHisOrder
  805. for _, item := range data {
  806. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  807. new_data = append(new_data, item)
  808. }
  809. }
  810. fmt.Println(len(new_data))
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "list": new_data,
  813. })
  814. }
  815. func (c *HisApiController) GetHisUnChargePatientList() {
  816. record_date := c.GetString("record_date")
  817. sch_type, _ := c.GetInt64("sch_type")
  818. timeLayout := "2006-01-02"
  819. loc, _ := time.LoadLocation("Local")
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. recordDateTime := theTime.Unix()
  826. adminInfo := c.GetAdminUserInfo()
  827. var tempPatients []*service.NewTempPatients
  828. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  829. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  830. var patients []*service.NewTempPatients
  831. var patients_two []*service.NewTempPatients
  832. for _, item := range tempPatients {
  833. //过滤掉没挂号的和没开处方的
  834. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  835. patients = append(patients, item)
  836. }
  837. //过滤掉没挂号的
  838. if len(item.HisPatient) > 0 {
  839. patients_two = append(patients_two, item)
  840. }
  841. }
  842. c.ServeSuccessJSON(map[string]interface{}{
  843. "list": patients,
  844. "list_two": patients_two,
  845. })
  846. }
  847. func (c *HisApiController) GetPrivateExpensesOrder() {
  848. //id, _ := c.GetInt64("id")
  849. //record_time := c.GetString("record_time")
  850. order_id, _ := c.GetInt64("order_id")
  851. admin_user_id, _ := c.GetInt64("admin_user_id")
  852. //timeLayout := "2006-01-02"
  853. //loc, _ := time.LoadLocation("Local")
  854. //
  855. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  856. //if err != nil {
  857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. // return
  859. //}
  860. //recordDateTime := theTime.Unix()
  861. adminUser := c.GetAdminUserInfo()
  862. order, _ := service.GetHisOrderByID(order_id)
  863. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  864. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  865. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  866. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  867. //var config []*models.HisXtDiagnoseConfig
  868. var name string
  869. if order.PType == 1 {
  870. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  871. for _, item := range diagnosis_ids {
  872. id, _ := strconv.ParseInt(item, 10, 64)
  873. diagnosisConfig, _ := service.FindDiagnoseById(id)
  874. if len(name) == 0 {
  875. name = diagnosisConfig.ClassName
  876. } else {
  877. name = name + "," + diagnosisConfig.ClassName
  878. }
  879. }
  880. } else {
  881. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  882. for _, item := range diagnosis_ids {
  883. id, _ := strconv.ParseInt(item, 10, 64)
  884. diagnosisConfig, _ := service.FindDiagnoseById(id)
  885. if len(name) == 0 {
  886. name = diagnosisConfig.ClassName
  887. } else {
  888. name = name + "," + diagnosisConfig.ClassName
  889. }
  890. }
  891. }
  892. var bedCostTotal float64 = 0 //床位总费
  893. //var bedCostSelfTotal float64 = 0 //床位自费
  894. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  895. var operationCostTotal float64 = 0 //手术费
  896. //var operationCostSelfTotal float64 = 0 //手术费
  897. var operationCostPartSelfTotal float64 = 0 //手术费
  898. var otherCostTotal float64 = 0 //其他费用
  899. //var otherCostSelfTotal float64 = 0 //其他费用
  900. var otherCostPartSelfTotal float64 = 0 //其他费用
  901. var materialCostTotal float64 = 0 //材料费
  902. //var materialCostSelfTotal float64 = 0 //材料费
  903. var materialCostPartSelfTotal float64 = 0 //材料费
  904. var westernMedicineCostTotal float64 = 0 //西药费
  905. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  906. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  907. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  908. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  909. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  910. var checkCostTotal float64 = 0 //检查费
  911. //var checkCostSelfTotal float64 = 0 //检查费
  912. var checkCostPartSelfTotal float64 = 0 //检查费
  913. var laboratoryCostTotal float64 = 0 //化验费
  914. //var laboratoryCostSelfTotal float64 = 0 //化验费
  915. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  916. var treatCostTotal float64 = 0 //治疗费用
  917. //var treatCostSelfTotal float64 = 0 //治疗费用
  918. var treatCostPartSelfTotal float64 = 0 //治疗费用
  919. var zhenChaCostTotal float64 = 0 //其他费用
  920. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  921. decimal.DivisionPrecision = 2
  922. for _, item := range orderInfos {
  923. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  924. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  925. item.MedChrgitmType = "09"
  926. }
  927. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  928. if item.HisPrescriptionProject.Type == 2 {
  929. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  930. fmt.Println("CostClassify")
  931. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  932. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  933. case 0:
  934. item.MedChrgitmType = "0"
  935. break
  936. case 1:
  937. item.MedChrgitmType = "14"
  938. break
  939. case 2:
  940. item.MedChrgitmType = "05"
  941. break
  942. case 3:
  943. item.MedChrgitmType = "03"
  944. break
  945. case 4:
  946. item.MedChrgitmType = "03"
  947. break
  948. case 5:
  949. item.MedChrgitmType = "08"
  950. break
  951. case 6:
  952. item.MedChrgitmType = "14"
  953. break
  954. case 7:
  955. item.MedChrgitmType = "14"
  956. break
  957. case 8:
  958. item.MedChrgitmType = "03"
  959. break
  960. case 9:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 10:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 11:
  967. item.MedChrgitmType = "06"
  968. break
  969. case 12:
  970. item.MedChrgitmType = "12"
  971. break
  972. case 13:
  973. item.MedChrgitmType = "01"
  974. break
  975. case 14:
  976. item.MedChrgitmType = "04"
  977. break
  978. case 15:
  979. item.MedChrgitmType = "14"
  980. break
  981. }
  982. } else {
  983. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  984. case 1:
  985. item.MedChrgitmType = "14"
  986. break
  987. case 2:
  988. item.MedChrgitmType = "05"
  989. break
  990. case 3:
  991. item.MedChrgitmType = "04"
  992. break
  993. case 4:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 5:
  997. item.MedChrgitmType = "08"
  998. break
  999. case 6:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 7:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 8:
  1006. item.MedChrgitmType = "03"
  1007. break
  1008. case 9:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. default:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. }
  1015. }
  1016. } else if item.HisPrescriptionProject.Type == 3 {
  1017. item.MedChrgitmType = "08"
  1018. }
  1019. }
  1020. }
  1021. if order.IsMedicineInsurance != 1 {
  1022. order.PsnCashPay = order.MedfeeSumamt
  1023. }
  1024. for _, item := range orderInfos {
  1025. if item.MedChrgitmType == "01" { //床位费
  1026. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1027. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1028. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1029. }
  1030. if item.MedChrgitmType == "02" { //诊察费
  1031. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1032. //zhenChaCostSelfTotal = zhenChaCostTotal
  1033. }
  1034. if item.MedChrgitmType == "03" { //检查费
  1035. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1036. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1037. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1038. }
  1039. if item.MedChrgitmType == "02" { //检查费
  1040. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1041. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1042. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1043. }
  1044. if item.MedChrgitmType == "04" { //化验费
  1045. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1046. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1047. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1048. }
  1049. if item.MedChrgitmType == "05" { //治疗费
  1050. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1051. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1052. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1053. }
  1054. if item.MedChrgitmType == "06" { //手术费
  1055. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. }
  1059. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1060. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1061. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1062. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1063. }
  1064. if item.MedChrgitmType == "09" { //西药费
  1065. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1066. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1067. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1068. }
  1069. if item.MedChrgitmType == "11" { //中成费
  1070. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1071. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1072. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1073. }
  1074. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1075. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1076. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1077. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1078. }
  1079. }
  1080. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1081. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1082. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1083. var dia_config []*models.HisXtDiagnoseConfig
  1084. var diagnosis_ids []string
  1085. if his.ID > 0 {
  1086. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1087. } else {
  1088. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1089. }
  1090. for _, item := range diagnosis_ids {
  1091. id, _ := strconv.ParseInt(item, 10, 64)
  1092. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1093. dia_config = append(dia_config, diagnosisConfig)
  1094. }
  1095. var rf []CustomFundPay
  1096. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1097. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1098. c.ServeSuccessJSON(map[string]interface{}{
  1099. "patient": patient,
  1100. "order_infos": orderInfos,
  1101. "diagnosis": name,
  1102. "bedCostTotal": bedCostTotal,
  1103. "bedCostSelfTotal": bedCostTotal,
  1104. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1105. "operationCostTotal": operationCostTotal,
  1106. "operationCostSelfTotal": operationCostTotal,
  1107. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1108. "otherCostTotal": otherCostTotal,
  1109. "otherCostSelfTotal": otherCostTotal,
  1110. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1111. "materialCostTotal": materialCostTotal,
  1112. "materialCostSelfTotal": materialCostTotal,
  1113. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1114. "westernMedicineCostTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1116. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1117. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1119. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1120. "checkCostTotal": checkCostTotal,
  1121. "checkCostSelfTotal": checkCostTotal,
  1122. "zhenChaCostTotal": zhenChaCostTotal,
  1123. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1124. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1125. "laboratoryCostTotal": laboratoryCostTotal,
  1126. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1127. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1128. "treatCostTotal": treatCostTotal,
  1129. "treatCostSelfTotal": treatCostTotal,
  1130. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1131. "charge_admin": charge_admin,
  1132. "printor_admin": printor_admin,
  1133. "org_name": org.OrgName,
  1134. "org_code": miConfig.Code,
  1135. "name": patient.Name,
  1136. "number": order.MdtrtId,
  1137. "date": order.SettleAccountsDate,
  1138. "info": order,
  1139. "new_order": order,
  1140. "his_hospital": his_hospital,
  1141. "his": his,
  1142. "funds": rf,
  1143. "dia_config": dia_config,
  1144. })
  1145. }
  1146. func (c *HisApiController) RefudDetail() {
  1147. order_id, _ := c.GetInt64("order_id")
  1148. order, _ := service.GetHisOrderByID(order_id)
  1149. adminUser := c.GetAdminUserInfo()
  1150. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1151. c.ServeSuccessJSON(map[string]interface{}{
  1152. "msg": "撤销成功",
  1153. })
  1154. }
  1155. func (c *HisApiController) Sscard() {
  1156. //r := CardInit()
  1157. //if r == 0 {
  1158. // GetBaseInfo()
  1159. //}
  1160. //c.ServeSuccessJSON(map[string]interface{}{
  1161. // "list": "11",
  1162. //})
  1163. }
  1164. func GetBaseInfo() error {
  1165. //handle := syscall.MustLoadDLL("SSCard.dll")
  1166. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1167. //
  1168. //str := make([]byte, 256)
  1169. //str1 := make([]byte, 256)
  1170. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1171. //if ferr != nil {
  1172. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1173. // return ferr
  1174. //}
  1175. //
  1176. //fmt.Println(string(str))
  1177. //
  1178. //fmt.Println(r)
  1179. return nil
  1180. }
  1181. func CardInit() int {
  1182. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1183. //add := DllTestDef.MustFindProc("Init")
  1184. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1185. //if err != nil {
  1186. // fmt.Println("SSCard的运算结果为:", ret)
  1187. //}
  1188. //result := int(ret)
  1189. return 0
  1190. }
  1191. func IntPtr(n int) uintptr {
  1192. return uintptr(n)
  1193. }
  1194. func StrPtr(s string) uintptr {
  1195. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1196. }
  1197. func (c *HisApiController) GetHisPatientList() {
  1198. //types, _ := c.GetInt64("type", 0)
  1199. record_date := c.GetString("record_date")
  1200. sch_type, _ := c.GetInt64("sch_type")
  1201. timeLayout := "2006-01-02"
  1202. loc, _ := time.LoadLocation("Local")
  1203. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1204. if err != nil {
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. recordDateTime := theTime.Unix()
  1209. adminInfo := c.GetAdminUserInfo()
  1210. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1211. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1212. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1213. //获取当前用户的信息
  1214. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1215. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1216. //获取所有科室信息
  1217. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1218. c.ServeSuccessJSON(map[string]interface{}{
  1219. "list": patients,
  1220. "list_two": patients_two,
  1221. "info": adminUserInfo,
  1222. "doctors": doctors,
  1223. "department": department,
  1224. })
  1225. }
  1226. type CustomTemplate struct {
  1227. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1228. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1229. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1230. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1231. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1232. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1233. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1234. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1235. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1236. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1237. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1238. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1239. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1240. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1241. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1242. }
  1243. func (c *HisApiController) GetHisPatientInfo() {
  1244. patient_id, _ := c.GetInt64("patient_id")
  1245. his_patient_id, _ := c.GetInt64("his_patient_id")
  1246. record_date := c.GetString("record_date")
  1247. number := c.GetString("number")
  1248. //start_time := c.GetString("start_time")
  1249. //end_time := c.GetString("end_time")
  1250. p_type, _ := c.GetInt64("p_type")
  1251. timeLayout := "2006-01-02"
  1252. loc, _ := time.LoadLocation("Local")
  1253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1254. if err != nil {
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1256. return
  1257. }
  1258. recordDateTime := theTime.Unix()
  1259. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1260. //if err != nil {
  1261. //
  1262. //}
  1263. //startRecordDateTime := startTime.Unix()
  1264. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1265. //if err != nil {
  1266. //
  1267. //}
  1268. //endRecordDateTime := endTime.Unix()
  1269. admin := c.GetAdminUserInfo()
  1270. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1271. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1272. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1273. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1274. var prescriptions []*models.HisPrescription
  1275. var last_prescriptions []*models.HisPrescription
  1276. var sch_prescriptions []CustomTemplate
  1277. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1278. if p_type == 1 { //住院
  1279. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1280. for _, item := range prescriptions {
  1281. for _, subItem := range item.HisDoctorAdviceInfo {
  1282. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1283. if info.RetailPrice > 0 {
  1284. subItem.Drug.MinPrice = info.RetailPrice
  1285. }
  1286. }
  1287. }
  1288. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1289. } else { //门诊
  1290. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1291. for _, item := range prescriptions {
  1292. for _, subItem := range item.HisDoctorAdviceInfo {
  1293. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1294. if info.RetailPrice > 0 {
  1295. subItem.Drug.MinPrice = info.RetailPrice
  1296. }
  1297. }
  1298. }
  1299. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1300. }
  1301. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1302. if sch.ID > 0 {
  1303. var week string
  1304. t := time.Now()
  1305. switch t.Weekday().String() {
  1306. case "Monday":
  1307. week = "周一"
  1308. break
  1309. case "Tuesday":
  1310. week = "周二"
  1311. break
  1312. case "Wednesday":
  1313. week = "周三"
  1314. break
  1315. case "Thursday":
  1316. week = "周四"
  1317. break
  1318. case "Friday":
  1319. week = "周五"
  1320. break
  1321. case "Saturday":
  1322. week = "周六"
  1323. break
  1324. case "Sunday":
  1325. week = "周日"
  1326. break
  1327. }
  1328. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1329. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1330. //根据推送频率组装新的数组
  1331. for _, item := range temp_sch_prescriptions {
  1332. var cus CustomTemplate
  1333. cus.ID = item.ID
  1334. cus.UserOrgId = item.UserOrgId
  1335. cus.PatientId = item.PatientId
  1336. cus.MedType = item.MedType
  1337. cus.RecordDate = item.RecordDate
  1338. cus.Type = item.Type
  1339. cus.PType = item.PType
  1340. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1341. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1342. if subItem.FrequencyType == 1 { //每次必推
  1343. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1346. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1347. }
  1348. if subItem.FrequencyType == 2 { //按照天数频率
  1349. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1350. now := p.Unix()
  1351. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1352. dayStr2 := "-" + dayStr
  1353. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1354. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1355. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1356. if len(advices) == 0 {
  1357. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1358. }
  1359. }
  1360. }
  1361. }
  1362. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1363. if subItem.Type == 2 {
  1364. if subItem.XtHisProject.MedicalStatus != 1 {
  1365. if subItem.FrequencyType == 1 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1369. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1370. }
  1371. if subItem.FrequencyType == 2 {
  1372. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1373. now := p.Unix()
  1374. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1375. dayStr2 := "-" + dayStr
  1376. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1377. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1378. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1379. if len(projects) == 0 {
  1380. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1381. }
  1382. }
  1383. }
  1384. } else if subItem.Type == 3 {
  1385. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1386. if subItem.FrequencyType == 1 {
  1387. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1388. }
  1389. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1390. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1391. }
  1392. if subItem.FrequencyType == 2 {
  1393. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1394. now := p.Unix()
  1395. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1396. dayStr2 := "-" + dayStr
  1397. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1398. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1399. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1400. if len(projects) == 0 {
  1401. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1402. }
  1403. }
  1404. }
  1405. }
  1406. }
  1407. sch_prescriptions = append(sch_prescriptions, cus)
  1408. }
  1409. for _, item := range sch_prescriptions {
  1410. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1411. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1412. }
  1413. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1414. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1415. }
  1416. }
  1417. }
  1418. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1419. if config.ID > 0 && config.IsOpen == 1 {
  1420. for _, item := range sch_prescriptions {
  1421. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1422. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1423. if info.RetailPrice > 0 {
  1424. subItem.Drug.MinPrice = info.RetailPrice
  1425. if admin.CurrentOrgId != 10598 {
  1426. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1427. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. if config.ID > 0 && config.IsOpen == 1 {
  1434. for _, item := range sch_prescriptions {
  1435. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1436. if subItem.Type == 3 {
  1437. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1438. if info.Price > 0 {
  1439. subItem.GoodInfo.PackingPrice = info.Price
  1440. if admin.CurrentOrgId != 10598 {
  1441. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1442. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1443. }
  1444. }
  1445. }
  1446. }
  1447. }
  1448. }
  1449. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1450. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1451. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1452. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1453. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1454. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1455. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1456. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1457. //获取所有科室信息
  1458. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1459. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1460. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1461. c.ServeSuccessJSON(map[string]interface{}{
  1462. "his_info": his_patient_info,
  1463. "xt_info": xt_patient_info,
  1464. "prescription": prescriptions,
  1465. "case_history": case_history,
  1466. "info": patientPrescriptionInfo,
  1467. //"month_prescriptions": monthPrescriptions,
  1468. "order": order,
  1469. "doctors": doctors,
  1470. "department": department,
  1471. "sch_prescriptions": sch_prescriptions,
  1472. "last_prescriptions": last_prescriptions,
  1473. "schedule": sch,
  1474. "count": count,
  1475. "drugStockConfig": drugStockConfig,
  1476. "last_info": lastPatientPrescriptionInfo,
  1477. "befor": beforThrity,
  1478. "LastCaseHistory": LastCaseHistory,
  1479. })
  1480. return
  1481. }
  1482. func (c *HisApiController) GetHisPrescriptionConfig() {
  1483. adminInfo := c.GetAdminUserInfo()
  1484. //获取医嘱模版
  1485. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1486. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1487. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1488. //获取所有基础药
  1489. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1490. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1491. if config.ID > 0 && config.IsOpen == 1 {
  1492. for _, item := range drugs {
  1493. var index = 0
  1494. for _, subItem := range item.OtherDrugWarehouseInfo {
  1495. if index == 0 {
  1496. index = index + 1
  1497. if subItem.RetailPrice > 0 {
  1498. item.MinPrice = subItem.RetailPrice
  1499. }
  1500. }
  1501. }
  1502. }
  1503. }
  1504. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1505. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1506. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1507. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1508. //获取所有科室信息
  1509. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1510. //获取诊断信息
  1511. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1512. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1513. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1514. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1515. //获取是否开启保存耗材出库的开关
  1516. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1517. c.ServeSuccessJSON(map[string]interface{}{
  1518. "drugs": drugs,
  1519. "advices_template": advices,
  1520. "drugways": drugways,
  1521. "efs": efs,
  1522. "doctors": doctors,
  1523. "department": department,
  1524. "sick": sick,
  1525. "additions": additions,
  1526. "diagnose": diagnose,
  1527. "manufacturers": manufacturers,
  1528. "goodOutOpen": goodOutOpen,
  1529. "patientDiagnose": patientDiagnose,
  1530. })
  1531. }
  1532. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1533. //获取所有基础药
  1534. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1535. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1536. if config.ID > 0 && config.IsOpen == 1 {
  1537. for _, item := range drugs {
  1538. var index = 0
  1539. for _, subItem := range item.OtherDrugWarehouseInfo {
  1540. if index == 0 {
  1541. index = index + 1
  1542. if subItem.RetailPrice > 0 {
  1543. item.MinPrice = subItem.RetailPrice
  1544. }
  1545. }
  1546. }
  1547. }
  1548. }
  1549. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1550. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1551. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1552. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1553. //获取所有科室信息
  1554. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1555. //获取诊断信息
  1556. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1557. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1558. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1559. //获取是否开启保存耗材出库的开关
  1560. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1561. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1562. c.ServeSuccessJSON(map[string]interface{}{
  1563. "drugs": drugs,
  1564. "advices_template": advices,
  1565. "drugways": drugways,
  1566. "efs": efs,
  1567. "doctors": doctors,
  1568. "department": department,
  1569. "sick": sick,
  1570. "additions": additions,
  1571. "diagnose": diagnose,
  1572. "manufacturers": manufacturers,
  1573. "goodOutOpen": goodOutOpen,
  1574. "patientDiagnose": patientDiagnose,
  1575. })
  1576. }
  1577. }
  1578. func (c *HisApiController) CreateHisPrescription() {
  1579. record_date := c.GetString("record_date")
  1580. patient_id, _ := c.GetInt64("patient_id")
  1581. reg_type, _ := c.GetInt64("reg_type")
  1582. diagnose := c.GetString("diagnose")
  1583. sick_type, _ := c.GetInt64("sick_type")
  1584. sick_history := c.GetString("sick_history")
  1585. doctor_id, _ := c.GetInt64("doctor", 0)
  1586. department, _ := c.GetInt64("department", 0)
  1587. his_patient_id, _ := c.GetInt64("his_patient_id")
  1588. p_type, _ := c.GetInt64("p_type")
  1589. patient_diagnose := c.GetString("patient_diagnose")
  1590. dataBody := make(map[string]interface{}, 0)
  1591. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1592. if err != nil {
  1593. utils.ErrorLog(err.Error())
  1594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1595. return
  1596. }
  1597. //edit, src := GetCompareData(dataBody)
  1598. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1599. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1600. //fmt.Println(drugResult)
  1601. //fmt.Println(goodResult)
  1602. timeLayout := "2006-01-02"
  1603. loc, _ := time.LoadLocation("Local")
  1604. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1605. if err != nil {
  1606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1607. return
  1608. }
  1609. adminInfo := c.GetAdminUserInfo()
  1610. recordDateTime := theTime.Unix()
  1611. //查询默认出库仓库库存
  1612. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1613. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1614. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1615. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1616. if len(lists) == 1 {
  1617. his_patient_id = lists[0].ID
  1618. }
  1619. }
  1620. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1621. //自动出库的开关开启
  1622. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1623. //自动出库
  1624. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1625. //耗材保存处方出库
  1626. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1627. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1628. //已发药和已收费限制逻辑
  1629. isMidicine := false
  1630. isCharge := false
  1631. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1632. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1633. if len(prescriptions) > 0 {
  1634. for _, item := range prescriptions {
  1635. items := item.(map[string]interface{})
  1636. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1637. utils.ErrorLog("id")
  1638. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1639. return
  1640. }
  1641. id := int64(items["id"].(float64))
  1642. if id > 0 {
  1643. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1644. if err != nil {
  1645. if new_prescription.OrderStatus == 4 {
  1646. isCharge = true
  1647. }
  1648. }
  1649. }
  1650. }
  1651. }
  1652. }
  1653. if isMidicine == true {
  1654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1655. return
  1656. }
  1657. if isCharge == true {
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1659. return
  1660. }
  1661. // 开始主事务
  1662. db := service.XTWriteDB()
  1663. tx := db.Begin()
  1664. // 在函数结束时处理事务回滚
  1665. defer func() {
  1666. if r := recover(); r != nil {
  1667. tx.Rollback()
  1668. }
  1669. }()
  1670. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1671. //药品发药出库
  1672. if pharmacyConfig.IsOpen == 1 {
  1673. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1674. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1675. if len(prescriptions) > 0 {
  1676. for _, item := range prescriptions {
  1677. items := item.(map[string]interface{})
  1678. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1679. advices := items["advices"].([]interface{})
  1680. if len(advices) > 0 {
  1681. for _, advice := range advices {
  1682. var drug_id int64
  1683. var prescribing_number float64
  1684. var prescribingNumberUnit string
  1685. var adviceId int64
  1686. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1687. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1688. }
  1689. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1690. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1691. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1692. }
  1693. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1694. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1695. }
  1696. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1697. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1698. }
  1699. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1700. if drug.ID == 0 {
  1701. tx.Rollback()
  1702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1703. return
  1704. }
  1705. //查询药品的所有库存
  1706. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1707. var total_count int64
  1708. for _, it := range list {
  1709. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1710. }
  1711. totals := strconv.FormatInt(total_count, 10)
  1712. //查询该药品是否存在开药记录
  1713. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1714. //新增处方盘点库存是否充足
  1715. if advicelist.ID == 0 {
  1716. all_count, _ := strconv.ParseFloat(totals, 64)
  1717. if prescribingNumberUnit == drug.MinUnit {
  1718. if drug.IsUse != 1 {
  1719. if drug.IsProject == 0 || drug.IsProject == 2 {
  1720. if all_count == 0 {
  1721. tx.Rollback()
  1722. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1723. return
  1724. }
  1725. if prescribing_number > all_count {
  1726. tx.Rollback()
  1727. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1728. return
  1729. }
  1730. }
  1731. }
  1732. }
  1733. if prescribingNumberUnit == drug.MaxUnit {
  1734. num := prescribing_number * float64(drug.MinNumber)
  1735. if drug.IsUse != 1 {
  1736. if drug.IsProject == 0 || drug.IsProject == 2 {
  1737. if all_count == 0 {
  1738. tx.Rollback()
  1739. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1740. return
  1741. }
  1742. if num > all_count {
  1743. tx.Rollback()
  1744. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1745. return
  1746. }
  1747. }
  1748. }
  1749. }
  1750. }
  1751. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1752. //不使用保存处方出库
  1753. if drugOutConfig.IsOpen != 1 {
  1754. //修改处方
  1755. for _, advice := range advices {
  1756. var drug_id int64
  1757. var prescribing_number float64
  1758. var prescribingNumberUnit string
  1759. var prescribingNumber string
  1760. var adviceId int64
  1761. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1762. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1763. }
  1764. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1765. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1766. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1767. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1768. }
  1769. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1770. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1771. }
  1772. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1773. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1774. }
  1775. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1776. if drug.ID == 0 {
  1777. tx.Rollback()
  1778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1779. return
  1780. }
  1781. //查询药品的所有库存
  1782. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1783. var total_count int64
  1784. for _, it := range list {
  1785. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1786. }
  1787. totals := strconv.FormatInt(total_count, 10)
  1788. //查询该药品是否存在开药记录
  1789. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1790. //新增处方
  1791. if advicelist.ID == 0 {
  1792. all_count, _ := strconv.ParseFloat(totals, 64)
  1793. if prescribingNumberUnit == drug.MinUnit {
  1794. if drug.IsUse != 1 {
  1795. if drug.IsProject == 0 || drug.IsProject == 2 {
  1796. if all_count == 0 {
  1797. tx.Rollback()
  1798. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1799. return
  1800. }
  1801. if prescribing_number > all_count {
  1802. tx.Rollback()
  1803. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1804. return
  1805. }
  1806. }
  1807. }
  1808. } else {
  1809. if prescribingNumberUnit == drug.MaxUnit {
  1810. num := prescribing_number * float64(drug.MinNumber)
  1811. if drug.IsUse != 1 {
  1812. if drug.IsProject == 0 || drug.IsProject == 2 {
  1813. if all_count == 0 {
  1814. tx.Rollback()
  1815. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1816. return
  1817. }
  1818. if num > all_count {
  1819. tx.Rollback()
  1820. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1821. return
  1822. }
  1823. }
  1824. }
  1825. }
  1826. }
  1827. }
  1828. //修改处方
  1829. if advicelist.ID > 0 {
  1830. var device_number int64
  1831. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1832. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1833. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1834. device_number = prescribingNumberInt * drug.MinNumber
  1835. }
  1836. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1837. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1838. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1839. device_number = prescribingNumberInt
  1840. }
  1841. var number_count int64
  1842. if prescribingNumberUnit == drug.MaxUnit {
  1843. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1844. number_count = prescribingNumberInt * drug.MinNumber
  1845. }
  1846. if prescribingNumberUnit == drug.MinUnit {
  1847. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1848. number_count = prescribingNumberInt
  1849. }
  1850. //如果修改的数量大于之前修改的数量
  1851. if (number_count - device_number) > 0 {
  1852. //如果修改的差数量 大于库存数量
  1853. if drug.IsUse != 1 {
  1854. if (number_count - device_number) > total_count {
  1855. tx.Rollback()
  1856. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1857. return
  1858. }
  1859. }
  1860. }
  1861. }
  1862. }
  1863. }
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. //已发药和已收费限制逻辑
  1872. //执行出库的逻辑
  1873. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1874. //校验库存总量
  1875. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1876. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1877. if len(prescriptions) > 0 {
  1878. for _, item := range prescriptions {
  1879. items := item.(map[string]interface{})
  1880. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1881. advices := items["advices"].([]interface{})
  1882. if len(advices) > 0 {
  1883. for _, advice := range advices {
  1884. var drug_id int64
  1885. var prescribing_number float64
  1886. var prescribingNumberUnit string
  1887. var adviceId int64
  1888. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1889. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1890. }
  1891. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1892. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1893. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1894. }
  1895. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1896. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1897. }
  1898. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1899. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1900. }
  1901. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1902. if drug.ID == 0 {
  1903. tx.Rollback()
  1904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1905. return
  1906. }
  1907. //查询药品的所有库存
  1908. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1909. var total_count int64
  1910. for _, it := range list {
  1911. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1912. }
  1913. totals := strconv.FormatInt(total_count, 10)
  1914. //查询该药品是否存在开药记录
  1915. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1916. //查询最新批次库存
  1917. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1918. var batch_number_count int64
  1919. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1920. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1921. //新增处方
  1922. if advicelist.ID == 0 {
  1923. all_count, _ := strconv.ParseFloat(totals, 64)
  1924. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1925. if prescribingNumberUnit == drug.MinUnit {
  1926. if drug.IsUse != 1 {
  1927. if drug.IsProject == 0 || drug.IsProject == 2 {
  1928. if all_count == 0 {
  1929. tx.Rollback()
  1930. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1931. return
  1932. }
  1933. if prescribing_number > all_count {
  1934. tx.Rollback()
  1935. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1936. return
  1937. }
  1938. }
  1939. if adminInfo.CurrentOrgId == 10215 {
  1940. if prescribing_number > batch_number_all_count {
  1941. tx.Rollback()
  1942. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1943. return
  1944. }
  1945. }
  1946. }
  1947. }
  1948. if prescribingNumberUnit == drug.MaxUnit {
  1949. num := prescribing_number * float64(drug.MinNumber)
  1950. if drug.IsUse != 1 {
  1951. if drug.IsProject == 0 || drug.IsProject == 2 {
  1952. if all_count == 0 {
  1953. tx.Rollback()
  1954. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1955. return
  1956. }
  1957. if num > all_count {
  1958. tx.Rollback()
  1959. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1960. return
  1961. }
  1962. }
  1963. if adminInfo.CurrentOrgId == 10215 {
  1964. if num > batch_number_all_count {
  1965. tx.Rollback()
  1966. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1967. return
  1968. }
  1969. }
  1970. }
  1971. }
  1972. }
  1973. //不是保存处方出库
  1974. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1975. if drugOutConfig.IsOpen != 1 {
  1976. //修改处方
  1977. for _, advice := range advices {
  1978. var drug_id int64
  1979. var prescribing_number float64
  1980. var prescribingNumberUnit string
  1981. var prescribingNumber string
  1982. var adviceId int64
  1983. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1984. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1985. }
  1986. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1987. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1988. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1989. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1990. }
  1991. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1992. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1993. }
  1994. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1995. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1996. }
  1997. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1998. if drug.ID == 0 {
  1999. tx.Rollback()
  2000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2001. return
  2002. }
  2003. //查询药品的所有库存
  2004. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2005. var total_count int64
  2006. for _, it := range list {
  2007. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2008. }
  2009. totals := strconv.FormatInt(total_count, 10)
  2010. //查询该药品是否存在开药记录
  2011. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2012. //新增处方
  2013. if advicelist.ID == 0 {
  2014. //查询最新批次库存
  2015. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2016. var batch_number_count int64
  2017. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2018. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2019. all_count, _ := strconv.ParseFloat(totals, 64)
  2020. if all_count == 0 {
  2021. tx.Rollback()
  2022. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2023. return
  2024. }
  2025. if prescribingNumberUnit == drug.MinUnit {
  2026. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2027. if drug.IsUse != 1 {
  2028. if drug.IsProject == 0 || drug.IsProject == 2 {
  2029. if all_count == 0 {
  2030. tx.Rollback()
  2031. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2032. return
  2033. }
  2034. if prescribing_number > all_count {
  2035. tx.Rollback()
  2036. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2037. return
  2038. }
  2039. }
  2040. if adminInfo.CurrentOrgId == 10215 {
  2041. if prescribing_number > batch_number_all_count {
  2042. tx.Rollback()
  2043. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2044. return
  2045. }
  2046. }
  2047. }
  2048. } else {
  2049. if prescribingNumberUnit == drug.MaxUnit {
  2050. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2051. num := prescribing_number * float64(drug.MinNumber)
  2052. if drug.IsUse != 1 {
  2053. if drug.IsProject == 0 || drug.IsProject == 2 {
  2054. if all_count == 0 {
  2055. tx.Rollback()
  2056. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2057. return
  2058. }
  2059. if num > all_count {
  2060. tx.Rollback()
  2061. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2062. return
  2063. }
  2064. }
  2065. if adminInfo.CurrentOrgId == 10215 {
  2066. if prescribing_number > batch_number_all_count {
  2067. tx.Rollback()
  2068. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2069. return
  2070. }
  2071. }
  2072. }
  2073. }
  2074. }
  2075. }
  2076. //修改处方
  2077. if advicelist.ID > 0 {
  2078. //查询最新批次库存
  2079. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2080. var batch_number_count int64
  2081. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2082. var device_number int64
  2083. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2084. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2085. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2086. device_number = prescribingNumberInt * drug.MinNumber
  2087. }
  2088. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2089. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2090. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2091. device_number = prescribingNumberInt
  2092. //回退库存
  2093. }
  2094. var number_count int64
  2095. if prescribingNumberUnit == drug.MaxUnit {
  2096. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2097. number_count = prescribingNumberInt * drug.MinNumber
  2098. //回退库存
  2099. }
  2100. if prescribingNumberUnit == drug.MinUnit {
  2101. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2102. number_count = prescribingNumberInt
  2103. //回退库存
  2104. }
  2105. //如果修改的数量大于之前修改的数量
  2106. if (number_count - device_number) > 0 {
  2107. //如果修改的差数量 大于库存数量
  2108. if drug.IsUse != 1 {
  2109. if drug.IsProject == 0 || drug.IsProject == 2 {
  2110. if total_count == 0 {
  2111. tx.Rollback()
  2112. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2113. return
  2114. }
  2115. if (number_count - device_number) > total_count {
  2116. tx.Rollback()
  2117. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2118. return
  2119. }
  2120. if (number_count - device_number) > batch_number_count {
  2121. tx.Rollback()
  2122. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2123. return
  2124. }
  2125. }
  2126. if adminInfo.CurrentOrgId == 10215 {
  2127. // 查询该药品最后一次出库记录
  2128. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2129. var out_count int64
  2130. var in_count int64
  2131. var stock_max_number int64
  2132. var stock_min_number int64
  2133. for _, it := range outInfo {
  2134. if it.CountUnit == drug.MaxUnit {
  2135. it.Count = it.Count * drug.MinNumber
  2136. }
  2137. out_count += it.Count
  2138. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2139. stock_max_number = warehouseInfoList.StockMaxNumber
  2140. stock_min_number = warehouseInfoList.StockMinNumber
  2141. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2142. }
  2143. if out_count > 0 {
  2144. if (number_count - device_number) > in_count {
  2145. tx.Rollback()
  2146. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2147. return
  2148. }
  2149. }
  2150. // 未出库
  2151. if out_count == 0 {
  2152. var sum_in_count int64
  2153. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2154. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2155. //如果修改的数量大于有库存的第一个批次
  2156. if number_count > sum_in_count {
  2157. tx.Rollback()
  2158. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2159. return
  2160. }
  2161. }
  2162. }
  2163. }
  2164. }
  2165. //药品发药
  2166. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2167. //不使用药品发药的功能
  2168. //if pharmacyConfig.IsOpen != 1 {
  2169. // if device_number != number_count {
  2170. //
  2171. // //查询该药品的出库记录
  2172. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2173. // if len(outListExport) > 0 {
  2174. // //
  2175. // for _, item := range outListExport {
  2176. // //回退库存
  2177. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2178. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2179. // }
  2180. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2181. // var stock_max_number int64
  2182. // var stock_min_number int64
  2183. //
  2184. // if number_count >= drug.MinNumber {
  2185. //
  2186. // stock_max_number = device_number / drug.MinNumber
  2187. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2188. //
  2189. // stock_min_number = device_number % drug.MinNumber
  2190. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2191. //
  2192. // } else {
  2193. //
  2194. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2195. //
  2196. // }
  2197. // }
  2198. //
  2199. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2200. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2201. // }
  2202. // }
  2203. // }
  2204. //
  2205. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2206. // var sum_count int64
  2207. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2208. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2209. // for _, its := range stockInfo {
  2210. // if its.MaxUnit == drug.MaxUnit {
  2211. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2212. // }
  2213. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2214. // }
  2215. // //更新字典里面的库存
  2216. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2217. //
  2218. // //剩余库存
  2219. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2220. //
  2221. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2222. // //减少出库数量
  2223. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2224. //
  2225. // }
  2226. //}
  2227. }
  2228. }
  2229. }
  2230. //保存处方开药
  2231. if drugOutConfig.IsOpen == 1 {
  2232. //修改处方
  2233. for _, advice := range advices {
  2234. var drug_id int64
  2235. var prescribing_number float64
  2236. var prescribingNumberUnit string
  2237. var prescribingNumber string
  2238. var adviceId int64
  2239. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2240. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2241. }
  2242. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2243. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2244. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2245. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2246. }
  2247. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2248. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2249. }
  2250. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2251. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2252. }
  2253. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2254. if drug.ID == 0 {
  2255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2256. return
  2257. }
  2258. //查询药品的所有库存
  2259. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2260. var total_count int64
  2261. for _, it := range list {
  2262. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2263. }
  2264. totals := strconv.FormatInt(total_count, 10)
  2265. //查询该药品是否存在开药记录
  2266. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2267. //新增处方
  2268. if advicelist.ID == 0 {
  2269. //查询最新批次库存
  2270. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2271. var batch_number_count int64
  2272. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2273. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2274. all_count, _ := strconv.ParseFloat(totals, 64)
  2275. if prescribingNumberUnit == drug.MinUnit {
  2276. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2277. if drug.IsUse != 1 {
  2278. if drug.IsProject == 0 || drug.IsProject == 2 {
  2279. if all_count == 0 {
  2280. tx.Rollback()
  2281. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2282. return
  2283. }
  2284. if prescribing_number > all_count {
  2285. tx.Rollback()
  2286. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2287. return
  2288. }
  2289. }
  2290. if adminInfo.CurrentOrgId == 10215 {
  2291. if prescribing_number > batch_number_all_count {
  2292. tx.Rollback()
  2293. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2294. return
  2295. }
  2296. }
  2297. }
  2298. } else {
  2299. if prescribingNumberUnit == drug.MaxUnit {
  2300. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2301. num := prescribing_number * float64(drug.MinNumber)
  2302. if drug.IsUse != 1 {
  2303. if drug.IsProject == 0 || drug.IsProject == 2 {
  2304. if all_count == 0 {
  2305. tx.Rollback()
  2306. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2307. return
  2308. }
  2309. if num > all_count {
  2310. tx.Rollback()
  2311. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2312. return
  2313. }
  2314. }
  2315. if adminInfo.CurrentOrgId == 10215 {
  2316. if prescribing_number > batch_number_all_count {
  2317. tx.Rollback()
  2318. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2319. return
  2320. }
  2321. }
  2322. }
  2323. }
  2324. }
  2325. }
  2326. //修改处方
  2327. if advicelist.ID > 0 {
  2328. //查询最新批次库存
  2329. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2330. var batch_number_count int64
  2331. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2332. var device_number int64
  2333. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2334. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2335. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2336. device_number = prescribingNumberInt * drug.MinNumber
  2337. }
  2338. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2339. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2340. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2341. device_number = prescribingNumberInt
  2342. }
  2343. var number_count int64
  2344. if prescribingNumberUnit == drug.MaxUnit {
  2345. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2346. number_count = prescribingNumberInt * drug.MinNumber
  2347. }
  2348. if prescribingNumberUnit == drug.MinUnit {
  2349. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2350. number_count = prescribingNumberInt
  2351. }
  2352. //如果修改的数量大于之前修改的数量
  2353. if (number_count - device_number) > 0 {
  2354. //如果修改的差数量 大于库存数量
  2355. if drug.IsUse != 1 {
  2356. if drug.IsProject == 0 || drug.IsProject == 2 {
  2357. if total_count == 0 {
  2358. tx.Rollback()
  2359. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2360. return
  2361. }
  2362. if (number_count - device_number) > total_count {
  2363. tx.Rollback()
  2364. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2365. return
  2366. }
  2367. }
  2368. if adminInfo.CurrentOrgId == 10215 {
  2369. if (number_count - device_number) > batch_number_count {
  2370. tx.Rollback()
  2371. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2372. return
  2373. }
  2374. }
  2375. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2376. //查询历史出库数据总批次
  2377. // 查询该药品最后一次出库记录
  2378. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2379. var out_count int64
  2380. var in_count int64
  2381. var stock_max_number int64
  2382. var stock_min_number int64
  2383. for _, it := range outInfo {
  2384. if it.CountUnit == drug.MaxUnit {
  2385. it.Count = it.Count * drug.MinNumber
  2386. }
  2387. out_count += it.Count
  2388. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2389. stock_max_number = warehouseInfoList.StockMaxNumber
  2390. stock_min_number = warehouseInfoList.StockMinNumber
  2391. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2392. }
  2393. if out_count > 0 {
  2394. if (number_count - device_number) > in_count {
  2395. tx.Rollback()
  2396. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2397. return
  2398. }
  2399. }
  2400. // 未出库
  2401. if out_count == 0 {
  2402. var sum_in_count int64
  2403. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2404. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2405. if sum_in_count == 0 {
  2406. tx.Rollback()
  2407. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2408. return
  2409. }
  2410. //如果修改的数量大于有库存的第一个批次
  2411. if number_count > sum_in_count {
  2412. tx.Rollback()
  2413. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2414. return
  2415. }
  2416. }
  2417. }
  2418. }
  2419. }
  2420. }
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. //校验耗材库存
  2431. if goodOutConfig.IsOpen == 1 {
  2432. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2433. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2434. if len(prescriptions) > 0 {
  2435. for _, item := range prescriptions {
  2436. items := item.(map[string]interface{})
  2437. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2438. projects := items["project"].([]interface{})
  2439. if len(projects) > 0 {
  2440. for _, project := range projects {
  2441. var project_id int64
  2442. var project_type int64
  2443. var totals float64
  2444. var project_name string
  2445. var parsetotal int64
  2446. var id int64
  2447. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2448. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2449. }
  2450. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2451. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2452. }
  2453. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2454. total, _ := project.(map[string]interface{})["total"].(string)
  2455. totals, _ = strconv.ParseFloat(total, 64)
  2456. }
  2457. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2458. project_name = project.(map[string]interface{})["project_name"].(string)
  2459. }
  2460. if project_type == 3 {
  2461. //查找该耗材的出库记录
  2462. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2463. if len(goodWarehouseInfo) == 0 {
  2464. //查询耗材库存
  2465. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2466. var stock_count int64
  2467. for _, it := range list {
  2468. stock_count += it.StockCount
  2469. }
  2470. stock_counts := strconv.FormatInt(stock_count, 10)
  2471. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2472. if stock_total_count == 0 {
  2473. tx.Rollback()
  2474. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2475. return
  2476. }
  2477. if totals > stock_total_count {
  2478. tx.Rollback()
  2479. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2480. return
  2481. }
  2482. }
  2483. if len(goodWarehouseInfo) > 0 {
  2484. //查询该患者耗材的历史数据
  2485. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2486. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2487. //数量发生改变
  2488. if parsetotal != count {
  2489. //如果现在的数量大于历史数量,就要看库存是否足够
  2490. if parsetotal > count {
  2491. //查询耗材所有库存
  2492. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2493. var stock_count int64
  2494. for _, it := range list {
  2495. stock_count += it.StockCount
  2496. }
  2497. //库存不足
  2498. if stock_count == 0 {
  2499. tx.Rollback()
  2500. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2501. return
  2502. }
  2503. if (parsetotal - count) > stock_count {
  2504. tx.Rollback()
  2505. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2506. return
  2507. }
  2508. }
  2509. }
  2510. }
  2511. }
  2512. }
  2513. }
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. //不使用耗材保存处方出库
  2520. if goodOutConfig.IsOpen != 1 {
  2521. if stockConfig.IsOpen == 1 {
  2522. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2523. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2524. if len(prescriptions) > 0 {
  2525. for _, item := range prescriptions {
  2526. items := item.(map[string]interface{})
  2527. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2528. projects := items["project"].([]interface{})
  2529. if len(projects) > 0 {
  2530. for _, project := range projects {
  2531. var project_id int64
  2532. var project_type int64
  2533. var totals float64
  2534. var project_name string
  2535. var parsetotal int64
  2536. var id int64
  2537. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2538. id = int64(project.(map[string]interface{})["id"].(float64))
  2539. }
  2540. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2541. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2542. }
  2543. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2544. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2545. }
  2546. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2547. total, _ := project.(map[string]interface{})["total"].(string)
  2548. totals, _ = strconv.ParseFloat(total, 64)
  2549. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2550. }
  2551. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2552. project_name = project.(map[string]interface{})["project_name"].(string)
  2553. }
  2554. if project_type == 3 {
  2555. //查找该耗材的出库记录
  2556. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2557. //没有出库记录
  2558. if len(goodWarehouseInfo) == 0 {
  2559. //查询耗材库存
  2560. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2561. var stock_count int64
  2562. for _, it := range list {
  2563. stock_count += it.StockCount
  2564. }
  2565. stock_counts := strconv.FormatInt(stock_count, 10)
  2566. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2567. if stock_total_count == 0 {
  2568. tx.Rollback()
  2569. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2570. return
  2571. }
  2572. if totals > stock_total_count {
  2573. tx.Rollback()
  2574. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2575. return
  2576. }
  2577. //查找今日该患者已经出库的所有耗材
  2578. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2579. for _, item := range goodList {
  2580. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2581. var flush_count int64
  2582. for _, it := range goodListSix {
  2583. flush_count += it.StockCount
  2584. }
  2585. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2586. creater := adminInfo.AdminUser.Id
  2587. if errs != nil {
  2588. goodErrcode := models.XtGoodErrcode{
  2589. UserOrgId: item.OrgId,
  2590. Errcode: "手动出库更新剩余出库失败",
  2591. GoodId: item.GoodId,
  2592. Status: 1,
  2593. Ctime: time.Now().Unix(),
  2594. Mtime: 0,
  2595. Count: 0,
  2596. StockCount: 0,
  2597. Creater: creater,
  2598. BatchNumberId: 0,
  2599. WarehouseOutId: 0,
  2600. }
  2601. service.CreateGoodErrcode(goodErrcode)
  2602. }
  2603. }
  2604. //service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2605. }
  2606. //有出库记录
  2607. if len(goodWarehouseInfo) > 0 {
  2608. //查询该患者耗材的历史数据
  2609. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2610. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2611. //数量发生改变
  2612. if parsetotal != count {
  2613. //查找今日该患者已经出库的所有耗材
  2614. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2615. for _, item := range goodList {
  2616. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2617. var flush_count int64
  2618. for _, it := range goodListSix {
  2619. flush_count += it.StockCount
  2620. }
  2621. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2622. //减少出库数量
  2623. creater := adminInfo.AdminUser.Id
  2624. if errs != nil {
  2625. goodErrcode := models.XtGoodErrcode{
  2626. UserOrgId: item.OrgId,
  2627. Errcode: "手动出库更新剩余出库失败",
  2628. GoodId: item.GoodId,
  2629. Status: 1,
  2630. Ctime: time.Now().Unix(),
  2631. Mtime: 0,
  2632. Count: 0,
  2633. StockCount: 0,
  2634. Creater: creater,
  2635. BatchNumberId: 0,
  2636. WarehouseOutId: 0,
  2637. }
  2638. service.CreateGoodErrcode(goodErrcode)
  2639. }
  2640. //查询默认仓库
  2641. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2642. var total_count int64
  2643. for _, it := range stockList {
  2644. total_count += it.StockCount
  2645. }
  2646. //基础库插入数据
  2647. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2648. }
  2649. //service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2650. }
  2651. }
  2652. }
  2653. }
  2654. }
  2655. }
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2662. var hpInfo models.HisPrescriptionInfo
  2663. if info.ID == 0 {
  2664. var randNum int
  2665. randNum = rand.Intn(10000) + 1000
  2666. timestamp := time.Now().Unix()
  2667. tempTime := time.Unix(timestamp, 0)
  2668. timeFormat := tempTime.Format("20060102150405")
  2669. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2670. hpInfo = models.HisPrescriptionInfo{
  2671. HisPatientId: his_patient_id,
  2672. UserOrgId: adminInfo.CurrentOrgId,
  2673. RecordDate: theTime.Unix(),
  2674. PatientId: patient_id,
  2675. Status: 1,
  2676. Ctime: time.Now().Unix(),
  2677. Mtime: time.Now().Unix(),
  2678. Creator: adminInfo.AdminUser.Id,
  2679. Modifier: adminInfo.AdminUser.Id,
  2680. Diagnosis: diagnose,
  2681. SickHistory: sick_history,
  2682. Departments: department,
  2683. RegisterType: reg_type,
  2684. PrescriptionNumber: p_number,
  2685. PrescriptionStatus: 1,
  2686. Doctor: role.UserName,
  2687. DoctorId: doctor_id,
  2688. SickType: sick_type,
  2689. PType: p_type,
  2690. PatientDiagnosis: patient_diagnose,
  2691. }
  2692. service.SavePatientPrescriptionInfo(hpInfo)
  2693. //创建步骤表
  2694. finish := models.XtDialysisFinish{
  2695. IsFinish: 1,
  2696. UserOrgId: adminInfo.CurrentOrgId,
  2697. Status: 1,
  2698. Ctime: time.Now().Unix(),
  2699. Mtime: 0,
  2700. Module: 4,
  2701. RecordDate: theTime.Unix(),
  2702. Sourse: 1,
  2703. PatientId: patient_id,
  2704. }
  2705. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2706. if dialysisFinish.ID == 0 {
  2707. service.CreateDialysisFinish(finish)
  2708. }
  2709. redis := service.RedisClient()
  2710. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2711. redis.Set(key, "", time.Second)
  2712. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2713. redis.Set(keyOne, "", time.Second)
  2714. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2715. redis.Set(keySeven, "", time.Second)
  2716. defer redis.Close()
  2717. } else {
  2718. hpInfo = models.HisPrescriptionInfo{
  2719. ID: info.ID,
  2720. UserOrgId: adminInfo.CurrentOrgId,
  2721. RecordDate: info.RecordDate,
  2722. PatientId: info.PatientId,
  2723. Status: 1,
  2724. Ctime: info.Ctime,
  2725. Mtime: time.Now().Unix(),
  2726. Creator: info.Creator,
  2727. Modifier: adminInfo.AdminUser.Id,
  2728. Diagnosis: diagnose,
  2729. SickHistory: sick_history,
  2730. Departments: department,
  2731. RegisterType: reg_type,
  2732. PrescriptionNumber: info.PrescriptionNumber,
  2733. Doctor: role.UserName,
  2734. PrescriptionStatus: info.PrescriptionStatus,
  2735. DoctorId: doctor_id,
  2736. SickType: sick_type,
  2737. PType: info.PType,
  2738. HisPatientId: info.HisPatientId,
  2739. PatientDiagnosis: patient_diagnose,
  2740. }
  2741. service.SavePatientPrescriptionInfo(hpInfo)
  2742. //创建步骤表
  2743. finish := models.XtDialysisFinish{
  2744. IsFinish: 1,
  2745. UserOrgId: adminInfo.CurrentOrgId,
  2746. Status: 1,
  2747. Ctime: time.Now().Unix(),
  2748. Mtime: 0,
  2749. Module: 4,
  2750. RecordDate: info.RecordDate,
  2751. Sourse: 1,
  2752. PatientId: info.PatientId,
  2753. }
  2754. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2755. if dialysisFinish.ID == 0 {
  2756. service.CreateDialysisFinish(finish)
  2757. }
  2758. redis := service.RedisClient()
  2759. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2760. redis.Set(key, "", time.Second)
  2761. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2762. redis.Set(keyOne, "", time.Second)
  2763. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2764. redis.Set(keySeven, "", time.Second)
  2765. defer redis.Close()
  2766. }
  2767. //定义切片
  2768. var adviceList []models.HisDoctorAdviceInfo
  2769. var projectList []models.HisPrescriptionProject
  2770. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 || adminInfo.CurrentOrgId == 10633 || adminInfo.CurrentOrgId == 10610 || adminInfo.CurrentOrgId == 10402 || adminInfo.CurrentOrgId == 10138 || adminInfo.CurrentOrgId == 10278 || adminInfo.CurrentOrgId == 10666 {
  2771. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2772. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2773. var tempPrescription *models.HisPrescription
  2774. if len(prescriptions) > 0 {
  2775. for _, item := range prescriptions {
  2776. // 开始外部循环的事务
  2777. tx := db.Begin()
  2778. // 在函数结束时处理事务回滚
  2779. defer func() {
  2780. if r := recover(); r != nil {
  2781. tx.Rollback()
  2782. }
  2783. }()
  2784. items := item.(map[string]interface{})
  2785. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2786. utils.ErrorLog("id")
  2787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2788. return
  2789. }
  2790. id := int64(items["id"].(float64))
  2791. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2792. tempPrescription = &new_prescription
  2793. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2794. utils.ErrorLog("type")
  2795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2796. return
  2797. }
  2798. types := int64(items["type"].(float64))
  2799. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2800. utils.ErrorLog("med_type")
  2801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2802. return
  2803. }
  2804. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2805. if med_type == "0" {
  2806. med_type = "14"
  2807. }
  2808. //if order_status == 0 {
  2809. // order_status = 1
  2810. //}
  2811. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2812. utils.ErrorLog("pre_time")
  2813. }
  2814. preTime, _ := items["pre_time"].(string)
  2815. fmt.Println("preTime", preTime)
  2816. timeLayout := "2006-01-02"
  2817. loc, _ := time.LoadLocation("Local")
  2818. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2819. result := strings.Split(preTime, " ")
  2820. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2821. if err != nil {
  2822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2823. return
  2824. }
  2825. pTime := theTime2.Unix()
  2826. ctime := time.Now().Unix()
  2827. if tempPrescription.ID == 0 {
  2828. prescription := &models.HisPrescription{
  2829. ID: 0,
  2830. PatientId: patient_id,
  2831. UserOrgId: adminInfo.CurrentOrgId,
  2832. RecordDate: recordDateTime,
  2833. Ctime: ctime,
  2834. Mtime: ctime,
  2835. Type: types,
  2836. Modifier: adminInfo.AdminUser.Id,
  2837. Creator: adminInfo.AdminUser.Id,
  2838. Status: 1,
  2839. Doctor: role.UserName,
  2840. HisPatientId: his_patient_id,
  2841. OrderStatus: 1,
  2842. BatchNumber: "",
  2843. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2844. PreTime: pTime,
  2845. PType: p_type,
  2846. MedType: med_type,
  2847. }
  2848. tempPrescription = prescription
  2849. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2850. redis := service.RedisClient()
  2851. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2852. redis.Set(key, "", time.Second)
  2853. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2854. redis.Set(keyOne, "", time.Second)
  2855. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2856. redis.Set(keySeven, "", time.Second)
  2857. defer redis.Close()
  2858. } else {
  2859. tempPrescription.ID = id
  2860. tempPrescription.Type = types
  2861. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2862. tempPrescription.Mtime = time.Now().Unix()
  2863. tempPrescription.Doctor = role.UserName
  2864. //tempPrescription.OrderStatus = order_status
  2865. tempPrescription.PreTime = pTime
  2866. tempPrescription.MedType = med_type
  2867. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2868. redis := service.RedisClient()
  2869. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2870. redis.Set(key, "", time.Second)
  2871. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2872. redis.Set(keyOne, "", time.Second)
  2873. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2874. redis.Set(keySeven, "", time.Second)
  2875. defer redis.Close()
  2876. }
  2877. //service.SaveHisPrescription(prescription)
  2878. //更改患者挂号状态
  2879. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2880. fmt.Println("更改失败", err2)
  2881. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2882. advices := items["advices"].([]interface{})
  2883. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2884. groupNo := int64(0)
  2885. if len(advices) > 0 {
  2886. for _, advice := range advices {
  2887. tx := db.Begin()
  2888. // 在函数结束时处理事务回滚
  2889. defer func() {
  2890. if r := recover(); r != nil {
  2891. tx.Rollback()
  2892. }
  2893. }()
  2894. var s models.HisDoctorAdviceInfo
  2895. s.PrescriptionId = tempPrescription.ID
  2896. s.AdviceType = 2
  2897. s.AdviceDoctor = doctor_id
  2898. s.StopState = 2
  2899. s.ExecutionState = 2
  2900. s.AdviceDate = theTime3.Unix()
  2901. s.Status = 1
  2902. s.UserOrgId = adminInfo.CurrentOrgId
  2903. s.RecordDate = theTime3.Unix()
  2904. s.StartTime = tempPrescription.PreTime
  2905. s.Groupno = groupNo
  2906. s.PatientId = patient_id
  2907. s.HisPatientId = his_patient_id
  2908. s.StartTime = pTime
  2909. s.IsSettle = 2
  2910. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2911. if errcode > 0 {
  2912. c.ServeFailJSONWithSGJErrorCode(errcode)
  2913. return
  2914. }
  2915. s.StartTime = pTime
  2916. var total_count int64 //处方总库存
  2917. //查询改药品信息
  2918. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2919. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2920. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2921. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2922. total_count += prescribingNumberSeven * medical.MinNumber
  2923. }
  2924. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2925. total_count += prescribingNumberSeven
  2926. }
  2927. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2928. total_count += prescribingNumberSeven
  2929. }
  2930. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2931. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2932. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2933. if s.Price != lastWarehouse.RetailPrice {
  2934. s.Price = lastWarehouse.RetailPrice
  2935. }
  2936. if s.Price == 0 {
  2937. if lastWarehouse.ID == 0 {
  2938. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2939. s.Price = lastWarehouseTwo.RetailPrice
  2940. }
  2941. }
  2942. }
  2943. //查询保存处方出库开关是否打开
  2944. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2945. if s.PatientId != 30038 {
  2946. if drugOutConfig.IsOpen == 1 {
  2947. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2948. // 查询该药品最后一次出库记录
  2949. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2950. var is_user_total int64
  2951. var no_user_total int64
  2952. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2953. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2954. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2955. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2956. }
  2957. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2958. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2959. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2960. no_user_total += prescribingNumberSevenTy
  2961. }
  2962. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2963. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2964. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2965. no_user_total += prescribingNumberSevenTy
  2966. }
  2967. if len(druginfo) > 0 {
  2968. for _, it := range druginfo {
  2969. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2970. it.Count = it.Count * drug.MinNumber
  2971. is_user_total += it.Count
  2972. }
  2973. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2974. is_user_total += it.Count
  2975. }
  2976. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2977. is_user_total += it.Count
  2978. }
  2979. }
  2980. }
  2981. //fmt.Println("药品名称----------------------", drug.DrugName)
  2982. //fmt.Println("药品名称----------------------", drug.IsUse)
  2983. //fmt.Println("is_user_total-------------------------", is_user_total)
  2984. //fmt.Println("no_user_total-------------------------", no_user_total)
  2985. if is_user_total != no_user_total {
  2986. //出库
  2987. if drug.IsUse == 2 {
  2988. creater := adminInfo.AdminUser.Id
  2989. newadviceInfo := &models.HisDoctorAdviceInfo{
  2990. ID: s.ID,
  2991. UserOrgId: s.UserOrgId,
  2992. PatientId: s.PatientId,
  2993. HisPatientId: s.HisPatientId,
  2994. AdviceType: s.AdviceType,
  2995. AdviceDate: s.AdviceDate,
  2996. StartTime: s.StartTime,
  2997. AdviceName: s.AdviceName,
  2998. AdviceDesc: s.AdviceDesc,
  2999. ReminderDate: s.ReminderDate,
  3000. SingleDose: s.SingleDose,
  3001. SingleDoseUnit: s.SingleDoseUnit,
  3002. PrescribingNumber: s.PrescribingNumber,
  3003. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3004. DeliveryWay: s.DeliveryWay,
  3005. ExecutionFrequency: s.ExecutionFrequency,
  3006. AdviceDoctor: s.AdviceDoctor,
  3007. Status: s.Status,
  3008. CreatedTime: s.CreatedTime,
  3009. UpdatedTime: s.UpdatedTime,
  3010. AdviceAffirm: s.AdviceAffirm,
  3011. Remark: s.Remark,
  3012. StopTime: s.StopTime,
  3013. StopReason: s.StopReason,
  3014. StopDoctor: s.StopDoctor,
  3015. StopState: s.StopState,
  3016. ParentId: s.ParentId,
  3017. ExecutionTime: s.ExecutionTime,
  3018. ExecutionStaff: s.ExecutionStaff,
  3019. ExecutionState: s.ExecutionState,
  3020. Checker: s.Checker,
  3021. RecordDate: s.RecordDate,
  3022. DialysisOrderId: s.DialysisOrderId,
  3023. CheckTime: s.CheckTime,
  3024. CheckState: s.CheckState,
  3025. DrugSpec: s.DrugSpec,
  3026. DrugSpecUnit: s.DrugSpecUnit,
  3027. Groupno: s.Groupno,
  3028. RemindType: s.RemindType,
  3029. FrequencyType: s.FrequencyType,
  3030. DayCount: s.DayCount,
  3031. WeekDay: s.WeekDay,
  3032. TemplateId: s.TemplateId,
  3033. Modifier: s.Modifier,
  3034. DrugId: s.DrugId,
  3035. Price: s.Price,
  3036. PrescriptionId: s.PrescriptionId,
  3037. MedListCodg: s.MedListCodg,
  3038. FeedetlSn: s.FeedetlSn,
  3039. Day: s.DayCount,
  3040. ChildDoctorAdvice: nil,
  3041. Drug: models.Drug{},
  3042. Diagnosis: s.Diagnosis,
  3043. Way: s.Way,
  3044. HospApprFlag: s.HospApprFlag,
  3045. LmtUsedFlag: s.LmtUsedFlag,
  3046. HisOrderInfo: models.HisOrderInfo{},
  3047. IsMedicine: s.IsMedicine,
  3048. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3049. Child: nil,
  3050. IsSettle: s.IsSettle,
  3051. IsMobile: s.IsMobile,
  3052. IsSelfDrug: s.IsSelfDrug,
  3053. DrugWayCount: s.DrugWayCount,
  3054. }
  3055. var history_count int64
  3056. var local_count int64
  3057. //查找已经开过的医嘱信息
  3058. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3059. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3060. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3061. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3062. local_count += prescribingNumberSevenTy * drug.MinNumber
  3063. }
  3064. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3065. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3066. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3067. local_count += prescribingNumberSevenTy
  3068. }
  3069. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3070. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3071. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3072. local_count += prescribingNumberSevenTy
  3073. }
  3074. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3075. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3076. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3077. history_count += prescribingNumberSevenTy * drug.MinNumber
  3078. }
  3079. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3080. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3081. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3082. history_count += prescribingNumberSevenTy
  3083. }
  3084. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3085. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3086. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3087. history_count += prescribingNumberSevenTy
  3088. }
  3089. //如果当前出库数量大于历史出库数量则需要出库
  3090. if local_count > history_count {
  3091. //按最小单位出库
  3092. var cha_count = local_count - history_count
  3093. newadviceInfo.PrescribingNumber = float64(cha_count)
  3094. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3095. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3096. }
  3097. //如果当前出库数量小于历史出库数量则需要退库
  3098. if local_count < history_count {
  3099. var cha_count = history_count - local_count
  3100. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3101. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3102. }
  3103. if local_count == history_count {
  3104. if is_user_total == 0 {
  3105. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3106. }
  3107. }
  3108. }
  3109. //更新字典里面的库存
  3110. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3111. var sum_count int64
  3112. for _, its := range stockInfo {
  3113. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3114. if its.MaxUnit == baseDrug.MaxUnit {
  3115. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3116. }
  3117. sum_count += its.StockMaxNumber + its.StockMinNumber
  3118. }
  3119. //更新基础库存
  3120. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3121. //剩余库存
  3122. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3123. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3124. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3125. //创建医嘱
  3126. service.CreateHisDoctorAdviceOne(&s, tx)
  3127. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3128. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3129. if len(outInfoTwo) > 0 {
  3130. for _, item := range outInfoTwo {
  3131. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3132. }
  3133. }
  3134. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3135. if len(drugAutoDetail) > 0 {
  3136. for _, item := range drugAutoDetail {
  3137. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3138. }
  3139. }
  3140. }
  3141. }
  3142. }
  3143. //记录日志
  3144. byterequest, _ := json.Marshal(s)
  3145. adviceLog := models.XtDoctorAdviceLog{
  3146. UserOrgId: s.UserOrgId,
  3147. PatientId: s.PatientId,
  3148. AdminUserId: adminInfo.AdminUser.Id,
  3149. Module: 1,
  3150. ErrLog: string(byterequest),
  3151. Status: 1,
  3152. Ctime: time.Now().Unix(),
  3153. Mtime: 0,
  3154. Source: "电脑端新建his医嘱",
  3155. RecordDate: s.AdviceDate,
  3156. }
  3157. service.CreateDoctorAdviceLog(adviceLog)
  3158. //存储切片中
  3159. adviceList = append(adviceList, s)
  3160. redis := service.RedisClient()
  3161. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3162. redis.Set(key, "", time.Second)
  3163. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3164. redis.Set(keyOne, "", time.Second)
  3165. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3166. redis.Set(keySeven, "", time.Second)
  3167. var randNum int
  3168. randNum = rand.Intn(10000) + 1000
  3169. timestamp := time.Now().Unix()
  3170. tempTime := time.Unix(timestamp, 0)
  3171. timeFormat := tempTime.Format("20060102150405")
  3172. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3173. //查询改药品是否已经停用
  3174. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3175. if base.ID > 0 {
  3176. tx.Rollback()
  3177. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3178. return
  3179. }
  3180. service.CreateHisDoctorAdviceOne(&s, tx)
  3181. tx.Commit()
  3182. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3183. redis.Set(keySix, "", time.Second)
  3184. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3185. redis.Set(keyFive, "", time.Second)
  3186. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3187. redis.Set(keyEight, "", time.Second)
  3188. defer redis.Close()
  3189. }
  3190. }
  3191. }
  3192. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3193. projects := items["project"].([]interface{})
  3194. if len(projects) > 0 {
  3195. for _, project := range projects {
  3196. tx := db.Begin()
  3197. // 在函数结束时处理事务回滚
  3198. defer func() {
  3199. if r := recover(); r != nil {
  3200. tx.Rollback()
  3201. }
  3202. }()
  3203. var p models.HisPrescriptionProject
  3204. p.PrescriptionId = tempPrescription.ID
  3205. p.PatientId = patient_id
  3206. p.RecordDate = theTime3.Unix()
  3207. p.Doctor = doctor_id
  3208. p.UserOrgId = adminInfo.CurrentOrgId
  3209. p.HisPatientId = his_patient_id
  3210. p.Status = 1
  3211. p.StartTime = pTime
  3212. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3213. if errcode > 0 {
  3214. c.ServeFailJSONWithSGJErrorCode(errcode)
  3215. return
  3216. }
  3217. if p.ID == 0 {
  3218. p.IsOut = 2
  3219. }
  3220. if p.ID > 0 {
  3221. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3222. p.IsOut = projectDetail.IsOut
  3223. }
  3224. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3225. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3226. if p.Type == 3 {
  3227. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3228. if p.Price != lastWarehouse.PackingPrice {
  3229. p.Price = lastWarehouse.PackingPrice
  3230. }
  3231. if p.Price == 0 {
  3232. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3233. p.Price = lastWarehouseTwo.PackingPrice
  3234. }
  3235. if p.Unit == "" {
  3236. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3237. p.Unit = goodInfoOne.PackingUnit
  3238. }
  3239. }
  3240. }
  3241. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3242. //
  3243. // if p.Type == 3 {
  3244. // //查询该耗材是否停用
  3245. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3246. // //表示该耗材已经停用,不能保存
  3247. // if goodInfoSeven.ID == 0 {
  3248. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3249. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3250. // return
  3251. // }
  3252. // }
  3253. //
  3254. //}
  3255. //查询保存耗材出库开关是否打开
  3256. if p.PatientId != 30038 {
  3257. if goodOutConfig.IsOpen == 1 {
  3258. //耗材出库
  3259. if p.Type == 3 {
  3260. //对比当前数据和历史出库数据
  3261. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3262. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3263. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3264. //如果当前处方数量大于历史数据,则需要出库
  3265. if nowCount > historyCount {
  3266. var cha_count int64
  3267. cha_count = nowCount - historyCount
  3268. timeStr := time.Now().Format("2006-01-02")
  3269. timeArr := strings.Split(timeStr, "-")
  3270. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3271. total = total + 1
  3272. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3273. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3274. number = number + total
  3275. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3276. operation_time := time.Now().Unix()
  3277. creater := c.GetAdminUserInfo().AdminUser.Id
  3278. recordDateStr := time.Now().Format("2006-01-02")
  3279. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3280. nowtime := recordDate.Unix()
  3281. warehouseOut := models.WarehouseOut{
  3282. WarehouseOutOrderNumber: warehousing_out_order,
  3283. OperationTime: operation_time,
  3284. OrgId: adminInfo.CurrentOrgId,
  3285. Creater: creater,
  3286. Ctime: time.Now().Unix(),
  3287. Status: 1,
  3288. WarehouseOutTime: nowtime,
  3289. Type: 1,
  3290. StorehouseId: storeConfig.StorehouseOutInfo,
  3291. IsCheck: 1,
  3292. IsSys: 1,
  3293. }
  3294. //查询是否生成出库单
  3295. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3296. if out.ID == 0 {
  3297. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3298. }
  3299. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3300. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3301. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3302. dialyPrepareOne := models.DialysisBeforePrepare{
  3303. GoodTypeId: goodObj.GoodTypeId,
  3304. GoodId: p.ProjectId,
  3305. PatientId: p.PatientId,
  3306. RecordDate: p.RecordDate,
  3307. UserOrgId: adminInfo.CurrentOrgId,
  3308. Count: cha_count,
  3309. Ctime: time.Now().Unix(),
  3310. Creater: creater,
  3311. Status: 1,
  3312. StorehouseId: houseConfig.StorehouseOutInfo,
  3313. ProjectId: p.ID,
  3314. }
  3315. //出库
  3316. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3317. }
  3318. //如果当前处方数量小于历史数据,怎需要退库
  3319. if nowCount < historyCount {
  3320. var cha_count int64
  3321. cha_count = historyCount - nowCount
  3322. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3323. creater := c.GetAdminUserInfo().AdminUser.Id
  3324. newPrescriptionProject := &models.HisPrescriptionProject{
  3325. ID: p.ID,
  3326. ProjectId: p.ProjectId,
  3327. Price: p.Price,
  3328. UserOrgId: p.UserOrgId,
  3329. Status: 1,
  3330. Ctime: time.Now().Unix(),
  3331. Mtime: time.Now().Unix(),
  3332. PatientId: p.PatientId,
  3333. HisPatientId: p.HisPatientId,
  3334. RecordDate: p.RecordDate,
  3335. PrescriptionId: p.PrescriptionId,
  3336. Count: p.Count,
  3337. FeedetlSn: p.FeedetlSn,
  3338. MedListCodg: p.MedListCodg,
  3339. SingleDose: p.SingleDose,
  3340. DeliveryWay: p.DeliveryWay,
  3341. ExecutionFrequency: p.ExecutionFrequency,
  3342. Day: p.Day,
  3343. HisProject: models.HisProject{},
  3344. GoodInfo: models.GoodInfo{},
  3345. Remark: p.Remark,
  3346. Unit: p.Unit,
  3347. Type: p.Type,
  3348. Doctor: p.Doctor,
  3349. ExecutionTime: p.ExecutionTime,
  3350. ExecutionStaff: p.ExecutionStaff,
  3351. ExecutionState: p.ExecutionState,
  3352. CheckTime: p.CheckTime,
  3353. CheckState: p.CheckState,
  3354. Checker: p.Checker,
  3355. StartTime: p.StartTime,
  3356. TeamId: p.TeamId,
  3357. XtHisProjectTeam: models.XtHisProjectTeam{},
  3358. FrequencyType: p.FrequencyType,
  3359. DayCount: p.DayCount,
  3360. WeekDay: p.WeekDay,
  3361. IsCheckTeam: p.IsCheckTeam,
  3362. HisOrderInfo: models.HisOrderInfo{},
  3363. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3364. IsOut: p.IsOut,
  3365. YbSyncStatus: p.YbSyncStatus,
  3366. }
  3367. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3368. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3369. }
  3370. if nowCount == historyCount {
  3371. if historyCount == 0 {
  3372. recordDateStr := time.Now().Format("2006-01-02")
  3373. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3374. nowtime := recordDate.Unix()
  3375. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3376. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3377. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3378. creater := c.GetAdminUserInfo().AdminUser.Id
  3379. dialyPrepareOne := models.DialysisBeforePrepare{
  3380. GoodTypeId: goodObj.GoodTypeId,
  3381. GoodId: p.ProjectId,
  3382. PatientId: p.PatientId,
  3383. RecordDate: p.RecordDate,
  3384. UserOrgId: adminInfo.CurrentOrgId,
  3385. Count: nowCount,
  3386. Ctime: time.Now().Unix(),
  3387. Creater: creater,
  3388. Status: 1,
  3389. StorehouseId: houseConfig.StorehouseOutInfo,
  3390. ProjectId: p.ID,
  3391. }
  3392. //出库
  3393. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3394. }
  3395. }
  3396. //lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3397. ////查询历史出库数据
  3398. //flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3399. //
  3400. //var out_count_five int64
  3401. //for _, item := range flowGood {
  3402. // out_count_five += item.Count
  3403. //}
  3404. //parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3405. //
  3406. ////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3407. //if out_count_five != parseIntCount {
  3408. // //查询耗材最后一次出库记录
  3409. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3410. // //查询默认出库仓库库存
  3411. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3412. // if len(wareOut) > 0 {
  3413. //
  3414. // for _, it := range wareOut {
  3415. // //回退库存
  3416. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3417. //
  3418. // //删除出库记录
  3419. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3420. //
  3421. // }
  3422. // }
  3423. //
  3424. // timeStr := time.Now().Format("2006-01-02")
  3425. // timeArr := strings.Split(timeStr, "-")
  3426. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3427. //
  3428. // total = total + 1
  3429. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3430. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3431. // number = number + total
  3432. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3433. //
  3434. // operation_time := time.Now().Unix()
  3435. // creater := c.GetAdminUserInfo().AdminUser.Id
  3436. //
  3437. // recordDateStr := time.Now().Format("2006-01-02")
  3438. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3439. // nowtime := recordDate.Unix()
  3440. // warehouseOut := models.WarehouseOut{
  3441. // WarehouseOutOrderNumber: warehousing_out_order,
  3442. // OperationTime: operation_time,
  3443. // OrgId: adminInfo.CurrentOrgId,
  3444. // Creater: creater,
  3445. // Ctime: time.Now().Unix(),
  3446. // Status: 1,
  3447. // WarehouseOutTime: nowtime,
  3448. // Type: 1,
  3449. // StorehouseId: storeConfig.StorehouseOutInfo,
  3450. // IsCheck: 1,
  3451. // IsSys: 1,
  3452. // }
  3453. // //查询是否生成出库单
  3454. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3455. // if out.ID == 0 {
  3456. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3457. // }
  3458. //
  3459. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3460. //
  3461. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3462. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3463. //
  3464. // dialyPrepareOne := models.DialysisBeforePrepare{
  3465. // GoodTypeId: goodObj.GoodTypeId,
  3466. // GoodId: p.ProjectId,
  3467. // PatientId: p.PatientId,
  3468. // RecordDate: p.RecordDate,
  3469. // UserOrgId: adminInfo.CurrentOrgId,
  3470. // Count: parseIntCount,
  3471. // Ctime: time.Now().Unix(),
  3472. // Creater: creater,
  3473. // Status: 1,
  3474. // StorehouseId: houseConfig.StorehouseOutInfo,
  3475. // ProjectId: lastHisProject.ID,
  3476. // }
  3477. // //判断是否是零用耗材(非零用)
  3478. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3479. //
  3480. // //查询历史出库数据
  3481. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3482. // var out_count int64
  3483. // for _, item := range flowGood {
  3484. // out_count += item.Count
  3485. // }
  3486. // //如果历史数和当前数据不想等才进行退库出库
  3487. // if out_count != parseIntCount {
  3488. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3489. //
  3490. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3491. // detail := models.AutomaticReduceDetail{
  3492. // WarehouseOutId: 0,
  3493. // WarehouseOutOrderNumber: "",
  3494. // PatientId: p.PatientId,
  3495. // Ctime: time.Now().Unix(),
  3496. // Mtime: 0,
  3497. // Status: 1,
  3498. // RecordTime: p.RecordDate,
  3499. // OrgId: p.UserOrgId,
  3500. // GoodId: p.ProjectId,
  3501. // GoodTypeId: 0,
  3502. // Count: parseIntCount,
  3503. // Type: 0,
  3504. // ProjectId: lastHisProject.ID,
  3505. // StorehouseId: 0,
  3506. // }
  3507. //
  3508. // service.CreateNewAutoDetail(detail, tx)
  3509. //
  3510. // //查询剩余库存
  3511. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3512. // var sum_count int64
  3513. // for _, item := range goodList {
  3514. // sum_count += item.StockCount
  3515. // }
  3516. //
  3517. // //更新剩余库存
  3518. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3519. //
  3520. // //耗材
  3521. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3522. //
  3523. // }
  3524. // //判断是否是零用耗材(零用但是是出库耗材)
  3525. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3526. //
  3527. // //查询历史出库数据
  3528. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3529. // var out_count int64
  3530. // for _, item := range flowGood {
  3531. // out_count += item.Count
  3532. // }
  3533. // //如果历史数和当前数据不想等才进行退库出库
  3534. // if out_count != parseIntCount {
  3535. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3536. //
  3537. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3538. // detail := models.AutomaticReduceDetail{
  3539. // WarehouseOutId: 0,
  3540. // WarehouseOutOrderNumber: "",
  3541. // PatientId: p.PatientId,
  3542. // Ctime: time.Now().Unix(),
  3543. // Mtime: 0,
  3544. // Status: 1,
  3545. // RecordTime: p.RecordDate,
  3546. // OrgId: p.UserOrgId,
  3547. // GoodId: p.ProjectId,
  3548. // GoodTypeId: 0,
  3549. // Count: parseIntCount,
  3550. // Type: 0,
  3551. // ProjectId: p.ID,
  3552. // StorehouseId: 0,
  3553. // }
  3554. //
  3555. // service.CreateNewAutoDetail(detail, tx)
  3556. //
  3557. // //查询剩余库存
  3558. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3559. // var sum_count int64
  3560. // for _, item := range goodList {
  3561. // sum_count += item.StockCount
  3562. // }
  3563. //
  3564. // //更新剩余库存
  3565. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3566. //
  3567. // //耗材
  3568. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3569. // }
  3570. //
  3571. // }
  3572. //
  3573. // }
  3574. //
  3575. //}
  3576. //记录日志
  3577. byterequest, _ := json.Marshal(p)
  3578. adviceLog := models.XtDoctorAdviceLog{
  3579. UserOrgId: p.UserOrgId,
  3580. PatientId: p.PatientId,
  3581. AdminUserId: adminInfo.AdminUser.Id,
  3582. Module: 1,
  3583. ErrLog: string(byterequest),
  3584. Status: 1,
  3585. Ctime: time.Now().Unix(),
  3586. Mtime: 0,
  3587. Source: "电脑端新建his项目",
  3588. RecordDate: p.RecordDate,
  3589. }
  3590. service.CreateDoctorAdviceLog(adviceLog)
  3591. projectList = append(projectList, p)
  3592. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3593. //新增或者编辑项目,修改对应的标签数据
  3594. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3595. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3596. var label models.HisLabelPrintInfo
  3597. project, _ := service.GetProjectDetail(p.ProjectId)
  3598. if project.CostClassify == 3 { //类别为检验检查
  3599. if p.TeamId > 0 { //检验检查组套
  3600. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3601. if tempLabel.ID == 0 {
  3602. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3603. label.Number = tempPrescription.PrescriptionNumber
  3604. label.ProjectId = project.ID
  3605. label.Status = 1
  3606. label.IsPrint = 2
  3607. label.DoctorId = info.DoctorId
  3608. label.UserOrgId = p.UserOrgId
  3609. label.PatientId = patient_id
  3610. label.RecordDate = recordDateTime
  3611. label.Ctime = time.Now().Unix()
  3612. label.Mtime = time.Now().Unix()
  3613. label.ItemId = p.TeamId
  3614. label.FeedetlSn = p.FeedetlSn
  3615. label.PProjectId = p.ID
  3616. label.ProjectName = team.ProjectTeam
  3617. label.PatientName = patient.Name
  3618. service.CreateNewHisLabelRecord(&label, tx)
  3619. }
  3620. } else { //单条检验检查项目
  3621. label.Number = tempPrescription.PrescriptionNumber
  3622. label.ProjectId = project.ID
  3623. label.Status = 1
  3624. label.DoctorId = info.DoctorId
  3625. label.UserOrgId = p.UserOrgId
  3626. label.PatientId = patient_id
  3627. label.RecordDate = recordDateTime
  3628. label.IsPrint = 2
  3629. label.Ctime = time.Now().Unix()
  3630. label.Mtime = time.Now().Unix()
  3631. label.FeedetlSn = p.FeedetlSn
  3632. label.PProjectId = p.ID
  3633. label.ItemId = p.TeamId
  3634. label.ProjectName = project.ProjectName
  3635. label.PatientName = patient.Name
  3636. service.CreateNewHisLabelRecord(&label, tx)
  3637. }
  3638. }
  3639. }
  3640. }
  3641. }
  3642. }
  3643. }
  3644. service.CreateNewHisProjectTwo(&p, tx)
  3645. var randNum int
  3646. randNum = rand.Intn(10000) + 1000
  3647. timestamp := time.Now().Unix()
  3648. tempTime := time.Unix(timestamp, 0)
  3649. timeFormat := tempTime.Format("20060102150405")
  3650. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3651. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3652. if goodBase.ID > 0 {
  3653. tx.Rollback()
  3654. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3655. return
  3656. }
  3657. service.CreateNewHisProjectTwo(&p, tx)
  3658. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3659. //查询剩余库存
  3660. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3661. var sum_count int64
  3662. for _, item := range goodList {
  3663. sum_count += item.StockCount
  3664. }
  3665. //更新剩余库存
  3666. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3667. //耗材
  3668. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3669. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3670. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3671. if len(outInfoTwo) > 0 {
  3672. for _, item := range outInfoTwo {
  3673. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3674. }
  3675. }
  3676. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3677. if len(drugAutoDetail) > 0 {
  3678. for _, item := range drugAutoDetail {
  3679. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3680. }
  3681. }
  3682. tx.Commit()
  3683. }
  3684. }
  3685. }
  3686. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3687. // addition := items["addition"].([]interface{})
  3688. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3689. // ctime := time.Now().Unix()
  3690. // mtime := ctime
  3691. // if len(addition) > 0 {
  3692. // for _, item := range addition {
  3693. // var s models.HisAdditionalCharge
  3694. // s.PrescriptionId = tempPrescription.ID
  3695. // s.Status = 1
  3696. // s.UserOrgId = adminInfo.CurrentOrgId
  3697. // s.RecordDate = recordDateTime
  3698. // s.CreatedTime = ctime
  3699. // s.UpdatedTime = mtime
  3700. // s.PatientId = patient_id
  3701. // s.HisPatientId = his_patient_id
  3702. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3703. // if errcode > 0 {
  3704. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3705. // return
  3706. // }
  3707. // service.CreateAdditionalCharge(&s)
  3708. // var randNum int
  3709. // randNum = rand.Intn(10000) + 1000
  3710. // timestamp := time.Now().Unix()
  3711. // tempTime := time.Unix(timestamp, 0)
  3712. // timeFormat := tempTime.Format("20060102150405")
  3713. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3714. // service.CreateAdditionalCharge(&s)
  3715. //
  3716. // }
  3717. // }
  3718. //}
  3719. }
  3720. }
  3721. }
  3722. tx.Commit()
  3723. if err == nil {
  3724. c.ServeSuccessJSON(map[string]interface{}{
  3725. "msg": "保存成功",
  3726. })
  3727. return
  3728. } else {
  3729. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3730. return
  3731. }
  3732. } else {
  3733. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3734. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3735. var tempPrescription *models.HisPrescription
  3736. if len(prescriptions) > 0 {
  3737. for _, item := range prescriptions {
  3738. items := item.(map[string]interface{})
  3739. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3740. utils.ErrorLog("id")
  3741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3742. return
  3743. }
  3744. id := int64(items["id"].(float64))
  3745. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3746. tempPrescription = &new_prescription
  3747. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3748. utils.ErrorLog("type")
  3749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3750. return
  3751. }
  3752. types := int64(items["type"].(float64))
  3753. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3754. utils.ErrorLog("med_type")
  3755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3756. return
  3757. }
  3758. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3759. if med_type == "0" {
  3760. med_type = "14"
  3761. }
  3762. //if order_status == 0 {
  3763. // order_status = 1
  3764. //}
  3765. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3766. utils.ErrorLog("pre_time")
  3767. }
  3768. preTime, _ := items["pre_time"].(string)
  3769. timeLayout := "2006-01-02"
  3770. loc, _ := time.LoadLocation("Local")
  3771. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3772. result := strings.Split(preTime, " ")
  3773. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3774. if err != nil {
  3775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3776. return
  3777. }
  3778. pTime := theTime2.Unix()
  3779. ctime := time.Now().Unix()
  3780. if tempPrescription.ID == 0 {
  3781. prescription := &models.HisPrescription{
  3782. ID: 0,
  3783. PatientId: patient_id,
  3784. UserOrgId: adminInfo.CurrentOrgId,
  3785. RecordDate: recordDateTime,
  3786. Ctime: ctime,
  3787. Mtime: ctime,
  3788. Type: types,
  3789. Modifier: adminInfo.AdminUser.Id,
  3790. Creator: adminInfo.AdminUser.Id,
  3791. Status: 1,
  3792. Doctor: role.UserName,
  3793. HisPatientId: his_patient_id,
  3794. OrderStatus: 1,
  3795. BatchNumber: "",
  3796. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3797. PreTime: pTime,
  3798. PType: p_type,
  3799. MedType: med_type,
  3800. }
  3801. tempPrescription = prescription
  3802. service.SaveHisPrescription(tempPrescription)
  3803. redis := service.RedisClient()
  3804. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3805. redis.Set(key, "", time.Second)
  3806. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3807. redis.Set(keyOne, "", time.Second)
  3808. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3809. redis.Set(keySeven, "", time.Second)
  3810. defer redis.Close()
  3811. } else {
  3812. tempPrescription.ID = id
  3813. tempPrescription.Type = types
  3814. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3815. tempPrescription.Mtime = time.Now().Unix()
  3816. tempPrescription.Doctor = role.UserName
  3817. //tempPrescription.OrderStatus = order_status
  3818. tempPrescription.PreTime = pTime
  3819. tempPrescription.MedType = med_type
  3820. service.SaveHisPrescription(tempPrescription)
  3821. redis := service.RedisClient()
  3822. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3823. redis.Set(key, "", time.Second)
  3824. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3825. redis.Set(keyOne, "", time.Second)
  3826. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3827. redis.Set(keySeven, "", time.Second)
  3828. defer redis.Close()
  3829. }
  3830. //service.SaveHisPrescription(prescription)
  3831. //更改患者挂号状态
  3832. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3833. fmt.Println("更改失败", err2)
  3834. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3835. advices := items["advices"].([]interface{})
  3836. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3837. groupNo := int64(0)
  3838. if len(advices) > 0 {
  3839. for _, advice := range advices {
  3840. var s models.HisDoctorAdviceInfo
  3841. s.PrescriptionId = tempPrescription.ID
  3842. s.AdviceType = 2
  3843. s.AdviceDoctor = doctor_id
  3844. s.StopState = 2
  3845. s.ExecutionState = 2
  3846. s.AdviceDate = theTime3.Unix()
  3847. s.Status = 1
  3848. s.UserOrgId = adminInfo.CurrentOrgId
  3849. s.RecordDate = theTime3.Unix()
  3850. s.StartTime = tempPrescription.PreTime
  3851. s.Groupno = groupNo
  3852. s.PatientId = patient_id
  3853. s.HisPatientId = his_patient_id
  3854. s.StartTime = pTime
  3855. s.IsSettle = 2
  3856. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3857. if errcode > 0 {
  3858. c.ServeFailJSONWithSGJErrorCode(errcode)
  3859. return
  3860. }
  3861. s.StartTime = pTime
  3862. var total_count int64 //处方总库存
  3863. //查询改药品信息
  3864. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3865. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3866. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3867. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3868. total_count += prescribingNumberSeven * medical.MinNumber
  3869. }
  3870. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3871. total_count += prescribingNumberSeven
  3872. }
  3873. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3874. total_count += prescribingNumberSeven
  3875. }
  3876. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3877. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3878. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3879. if s.Price != lastWarehouse.RetailPrice {
  3880. s.Price = lastWarehouse.RetailPrice
  3881. }
  3882. if s.Price == 0 {
  3883. s.Price = lastWarehouse.RetailPrice
  3884. }
  3885. }
  3886. service.CreateHisDoctorAdvice(&s)
  3887. //记录日志
  3888. byterequest, _ := json.Marshal(s)
  3889. adviceLog := models.XtDoctorAdviceLog{
  3890. UserOrgId: s.UserOrgId,
  3891. PatientId: s.PatientId,
  3892. AdminUserId: adminInfo.AdminUser.Id,
  3893. Module: 1,
  3894. ErrLog: string(byterequest),
  3895. Status: 1,
  3896. Ctime: time.Now().Unix(),
  3897. Mtime: 0,
  3898. Source: "电脑端新建his医嘱",
  3899. RecordDate: s.AdviceDate,
  3900. }
  3901. service.CreateDoctorAdviceLog(adviceLog)
  3902. //存储切片中
  3903. adviceList = append(adviceList, s)
  3904. redis := service.RedisClient()
  3905. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3906. redis.Set(key, "", time.Second)
  3907. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3908. redis.Set(keyOne, "", time.Second)
  3909. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3910. redis.Set(keySeven, "", time.Second)
  3911. var randNum int
  3912. randNum = rand.Intn(10000) + 1000
  3913. timestamp := time.Now().Unix()
  3914. tempTime := time.Unix(timestamp, 0)
  3915. timeFormat := tempTime.Format("20060102150405")
  3916. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3917. service.CreateHisDoctorAdvice(&s)
  3918. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3919. redis.Set(keySix, "", time.Second)
  3920. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3921. redis.Set(keyFive, "", time.Second)
  3922. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3923. redis.Set(keyEight, "", time.Second)
  3924. defer redis.Close()
  3925. }
  3926. }
  3927. }
  3928. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3929. projects := items["project"].([]interface{})
  3930. if len(projects) > 0 {
  3931. for _, project := range projects {
  3932. var p models.HisPrescriptionProject
  3933. p.PrescriptionId = tempPrescription.ID
  3934. p.PatientId = patient_id
  3935. p.RecordDate = theTime3.Unix()
  3936. p.Doctor = doctor_id
  3937. p.UserOrgId = adminInfo.CurrentOrgId
  3938. p.HisPatientId = his_patient_id
  3939. p.Status = 1
  3940. p.StartTime = pTime
  3941. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3942. if errcode > 0 {
  3943. c.ServeFailJSONWithSGJErrorCode(errcode)
  3944. return
  3945. }
  3946. if p.ID == 0 {
  3947. p.IsOut = 2
  3948. }
  3949. if p.ID > 0 {
  3950. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3951. p.IsOut = projectDetail.IsOut
  3952. }
  3953. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3954. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3955. if p.Type == 3 {
  3956. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3957. if p.Price != lastWarehouse.PackingPrice {
  3958. p.Price = lastWarehouse.PackingPrice
  3959. }
  3960. if p.Unit == "" {
  3961. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3962. p.Unit = goodInfoOne.PackingUnit
  3963. }
  3964. }
  3965. }
  3966. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3967. //
  3968. // if p.Type == 3 {
  3969. // //查询该耗材是否停用
  3970. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3971. // //表示该耗材已经停用,不能保存
  3972. // if goodInfoSeven.ID == 0 {
  3973. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3974. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3975. // return
  3976. // }
  3977. // }
  3978. //
  3979. //}
  3980. service.CreateHisProjectTwo(&p)
  3981. //记录日志
  3982. byterequest, _ := json.Marshal(p)
  3983. adviceLog := models.XtDoctorAdviceLog{
  3984. UserOrgId: p.UserOrgId,
  3985. PatientId: p.PatientId,
  3986. AdminUserId: adminInfo.AdminUser.Id,
  3987. Module: 1,
  3988. ErrLog: string(byterequest),
  3989. Status: 1,
  3990. Ctime: time.Now().Unix(),
  3991. Mtime: 0,
  3992. Source: "电脑端新建his项目",
  3993. RecordDate: p.RecordDate,
  3994. }
  3995. service.CreateDoctorAdviceLog(adviceLog)
  3996. projectList = append(projectList, p)
  3997. var randNum int
  3998. randNum = rand.Intn(10000) + 1000
  3999. timestamp := time.Now().Unix()
  4000. tempTime := time.Unix(timestamp, 0)
  4001. timeFormat := tempTime.Format("20060102150405")
  4002. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4003. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4004. //新增或者编辑项目,修改对应的标签数据
  4005. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4006. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4007. var label models.HisLabelPrintInfo
  4008. project, _ := service.GetProjectDetail(p.ProjectId)
  4009. if project.CostClassify == 3 { //类别为检验检查
  4010. if p.TeamId > 0 { //检验检查组套
  4011. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4012. if tempLabel.ID == 0 {
  4013. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4014. label.Number = tempPrescription.PrescriptionNumber
  4015. label.ProjectId = project.ID
  4016. label.Status = 1
  4017. label.IsPrint = 2
  4018. label.DoctorId = info.DoctorId
  4019. label.UserOrgId = p.UserOrgId
  4020. label.PatientId = patient_id
  4021. label.RecordDate = recordDateTime
  4022. label.Ctime = time.Now().Unix()
  4023. label.Mtime = time.Now().Unix()
  4024. label.ItemId = p.TeamId
  4025. label.FeedetlSn = p.FeedetlSn
  4026. label.PProjectId = p.ID
  4027. label.ProjectName = team.ProjectTeam
  4028. label.PatientName = patient.Name
  4029. service.CreateHisLabelRecord(&label)
  4030. }
  4031. } else { //单条检验检查项目
  4032. label.Number = tempPrescription.PrescriptionNumber
  4033. label.ProjectId = project.ID
  4034. label.Status = 1
  4035. label.DoctorId = info.DoctorId
  4036. label.UserOrgId = p.UserOrgId
  4037. label.PatientId = patient_id
  4038. label.RecordDate = recordDateTime
  4039. label.IsPrint = 2
  4040. label.Ctime = time.Now().Unix()
  4041. label.Mtime = time.Now().Unix()
  4042. label.FeedetlSn = p.FeedetlSn
  4043. label.PProjectId = p.ID
  4044. label.ItemId = p.TeamId
  4045. label.ProjectName = project.ProjectName
  4046. label.PatientName = patient.Name
  4047. service.CreateHisLabelRecord(&label)
  4048. }
  4049. }
  4050. }
  4051. }
  4052. service.SaveHisProjectTwo(&p)
  4053. }
  4054. }
  4055. }
  4056. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4057. // addition := items["addition"].([]interface{})
  4058. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4059. // ctime := time.Now().Unix()
  4060. // mtime := ctime
  4061. // if len(addition) > 0 {
  4062. // for _, item := range addition {
  4063. // var s models.HisAdditionalCharge
  4064. // s.PrescriptionId = tempPrescription.ID
  4065. // s.Status = 1
  4066. // s.UserOrgId = adminInfo.CurrentOrgId
  4067. // s.RecordDate = recordDateTime
  4068. // s.CreatedTime = ctime
  4069. // s.UpdatedTime = mtime
  4070. // s.PatientId = patient_id
  4071. // s.HisPatientId = his_patient_id
  4072. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4073. // if errcode > 0 {
  4074. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4075. // return
  4076. // }
  4077. // service.CreateAdditionalCharge(&s)
  4078. // var randNum int
  4079. // randNum = rand.Intn(10000) + 1000
  4080. // timestamp := time.Now().Unix()
  4081. // tempTime := time.Unix(timestamp, 0)
  4082. // timeFormat := tempTime.Format("20060102150405")
  4083. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4084. // service.CreateAdditionalCharge(&s)
  4085. //
  4086. // }
  4087. // }
  4088. //}
  4089. }
  4090. }
  4091. //查询今日该患者开的药品处方
  4092. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4093. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4094. //药品出库
  4095. if drugOutConfig.IsOpen == 1 {
  4096. for _, item := range hisdoctorlist {
  4097. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4098. // 查询该药品最后一次出库记录
  4099. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4100. if len(druginfo) > 0 {
  4101. //回退库存
  4102. for _, it := range druginfo {
  4103. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4104. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4105. }
  4106. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4107. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4108. }
  4109. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4110. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4111. }
  4112. }
  4113. }
  4114. //删除记录
  4115. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4116. //查询最后一次数据
  4117. if drugOutConfig.IsOpen == 1 {
  4118. //出库
  4119. if drug.IsUse == 2 {
  4120. creater := adminInfo.AdminUser.Id
  4121. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4122. }
  4123. //更新字典里面的库存
  4124. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4125. var sum_count int64
  4126. for _, its := range stockInfo {
  4127. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4128. if its.MaxUnit == baseDrug.MaxUnit {
  4129. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4130. }
  4131. sum_count += its.StockMaxNumber + its.StockMinNumber
  4132. }
  4133. //更新基础库存
  4134. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4135. //剩余库存
  4136. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4137. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4138. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4139. }
  4140. }
  4141. }
  4142. //耗材保存处方出库
  4143. if goodOutConfig.IsOpen == 1 {
  4144. //查询今日耗材出库数量
  4145. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4146. for _, item := range hisgoodlist {
  4147. //查询历史出库数据
  4148. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4149. var out_count_five int64
  4150. for _, item := range flowGood {
  4151. out_count_five += item.Count
  4152. }
  4153. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4154. if out_count_five != parseIntCount {
  4155. //查询耗材最后一次出库记录
  4156. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4157. //查询默认出库仓库库存
  4158. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4159. if len(wareOut) > 0 {
  4160. for _, it := range wareOut {
  4161. //回退库存
  4162. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4163. //删除出库记录
  4164. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4165. }
  4166. }
  4167. timeStr := time.Now().Format("2006-01-02")
  4168. timeArr := strings.Split(timeStr, "-")
  4169. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4170. total = total + 1
  4171. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4172. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4173. number = number + total
  4174. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4175. operation_time := time.Now().Unix()
  4176. creater := c.GetAdminUserInfo().AdminUser.Id
  4177. recordDateStr := time.Now().Format("2006-01-02")
  4178. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4179. nowtime := recordDate.Unix()
  4180. warehouseOut := models.WarehouseOut{
  4181. WarehouseOutOrderNumber: warehousing_out_order,
  4182. OperationTime: operation_time,
  4183. OrgId: adminInfo.CurrentOrgId,
  4184. Creater: creater,
  4185. Ctime: time.Now().Unix(),
  4186. Status: 1,
  4187. WarehouseOutTime: nowtime,
  4188. Type: 1,
  4189. StorehouseId: storeConfig.StorehouseOutInfo,
  4190. IsCheck: 1,
  4191. IsSys: 1,
  4192. }
  4193. //查询是否生成出库单
  4194. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4195. if out.ID == 0 {
  4196. service.AddSigleWarehouseOut(&warehouseOut)
  4197. }
  4198. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4199. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4200. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4201. dialyPrepareOne := models.DialysisBeforePrepare{
  4202. GoodTypeId: goodObj.GoodTypeId,
  4203. GoodId: item.ProjectId,
  4204. PatientId: item.PatientId,
  4205. RecordDate: item.RecordDate,
  4206. UserOrgId: adminInfo.CurrentOrgId,
  4207. Count: parseIntCount,
  4208. Ctime: time.Now().Unix(),
  4209. Creater: creater,
  4210. Status: 1,
  4211. StorehouseId: houseConfig.StorehouseOutInfo,
  4212. ProjectId: item.ID,
  4213. }
  4214. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4215. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4216. //查询历史出库数据
  4217. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4218. var out_count int64
  4219. for _, item := range flowGood {
  4220. out_count += item.Count
  4221. }
  4222. //如果历史数和当前数据不想等才进行退库出库
  4223. if out_count != parseIntCount {
  4224. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4225. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4226. detail := models.AutomaticReduceDetail{
  4227. WarehouseOutId: 0,
  4228. WarehouseOutOrderNumber: "",
  4229. PatientId: item.PatientId,
  4230. Ctime: time.Now().Unix(),
  4231. Mtime: 0,
  4232. Status: 1,
  4233. RecordTime: item.RecordDate,
  4234. OrgId: item.UserOrgId,
  4235. GoodId: item.ProjectId,
  4236. GoodTypeId: 0,
  4237. Count: parseIntCount,
  4238. Type: 0,
  4239. ProjectId: item.ID,
  4240. StorehouseId: 0,
  4241. }
  4242. service.CreateAutoDetail(detail)
  4243. //查询剩余库存
  4244. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4245. var sum_count int64
  4246. for _, item := range goodList {
  4247. sum_count += item.StockCount
  4248. }
  4249. //更新剩余库存
  4250. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4251. //耗材
  4252. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4253. }
  4254. }
  4255. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4256. //查询历史出库数据
  4257. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4258. var out_count int64
  4259. for _, item := range flowGood {
  4260. out_count += item.Count
  4261. }
  4262. //如果历史数和当前数据不想等才进行退库出库
  4263. if out_count != parseIntCount {
  4264. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4265. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4266. detail := models.AutomaticReduceDetail{
  4267. WarehouseOutId: 0,
  4268. WarehouseOutOrderNumber: "",
  4269. PatientId: item.PatientId,
  4270. Ctime: time.Now().Unix(),
  4271. Mtime: 0,
  4272. Status: 1,
  4273. RecordTime: item.RecordDate,
  4274. OrgId: item.UserOrgId,
  4275. GoodId: item.ProjectId,
  4276. GoodTypeId: 0,
  4277. Count: parseIntCount,
  4278. Type: 0,
  4279. ProjectId: item.ID,
  4280. StorehouseId: 0,
  4281. }
  4282. service.CreateAutoDetail(detail)
  4283. //查询剩余库存
  4284. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4285. var sum_count int64
  4286. for _, item := range goodList {
  4287. sum_count += item.StockCount
  4288. }
  4289. //更新剩余库存
  4290. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4291. //耗材
  4292. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4293. }
  4294. }
  4295. }
  4296. }
  4297. }
  4298. }
  4299. tx.Commit()
  4300. if err == nil {
  4301. c.ServeSuccessJSON(map[string]interface{}{
  4302. "msg": "保存成功",
  4303. })
  4304. return
  4305. } else {
  4306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4307. return
  4308. }
  4309. }
  4310. }
  4311. //func (c *HisApiController) EditHisPrescription() {
  4312. // record_date := c.GetString("record_date")
  4313. // patient_id, _ := c.GetInt64("patient_id")
  4314. // reg_type, _ := c.GetInt64("reg_type")
  4315. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4316. // diagnose := c.GetString("diagnose")
  4317. // sick_type, _ := c.GetInt64("sick_type")
  4318. // sick_history := c.GetString("sick_history")
  4319. // doctor_id, _ := c.GetInt64("doctor", 0)
  4320. // department, _ := c.GetInt64("department", 0)
  4321. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4322. // p_type, _ := c.GetInt64("p_type")
  4323. //
  4324. // dataBody := make(map[string]interface{}, 0)
  4325. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4326. // if err != nil {
  4327. // utils.ErrorLog(err.Error())
  4328. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4329. // return
  4330. // }
  4331. //
  4332. // timeLayout := "2006-01-02"
  4333. // loc, _ := time.LoadLocation("Local")
  4334. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4335. // if err != nil {
  4336. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4337. // return
  4338. // }
  4339. // adminInfo := c.GetAdminUserInfo()
  4340. // recordDateTime := theTime.Unix()
  4341. //
  4342. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4343. //
  4344. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4345. // var hpInfo models.HisPrescriptionInfo
  4346. // if info.ID == 0 {
  4347. // var randNum int
  4348. // randNum = rand.Intn(10000) + 1000
  4349. // timestamp := time.Now().Unix()
  4350. // tempTime := time.Unix(timestamp, 0)
  4351. // timeFormat := tempTime.Format("20060102150405")
  4352. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4353. //
  4354. // hpInfo = models.HisPrescriptionInfo{
  4355. // UserOrgId: adminInfo.CurrentOrgId,
  4356. // RecordDate: theTime.Unix(),
  4357. // PatientId: patient_id,
  4358. // Status: 1,
  4359. // Ctime: time.Now().Unix(),
  4360. // Mtime: time.Now().Unix(),
  4361. // Creator: adminInfo.AdminUser.Id,
  4362. // Modifier: adminInfo.AdminUser.Id,
  4363. // Diagnosis: diagnose,
  4364. // SickHistory: sick_history,
  4365. // Departments: department,
  4366. // RegisterType: reg_type,
  4367. // PrescriptionNumber: p_number,
  4368. // PrescriptionStatus: 1,
  4369. // Doctor: role.UserName,
  4370. // DoctorId: doctor_id,
  4371. // SickType: sick_type,
  4372. // PType: p_type,
  4373. // }
  4374. // service.SavePatientPrescriptionInfo(hpInfo)
  4375. //
  4376. // } else {
  4377. // hpInfo = models.HisPrescriptionInfo{
  4378. // ID: info.ID,
  4379. // UserOrgId: adminInfo.CurrentOrgId,
  4380. // RecordDate: info.RecordDate,
  4381. // PatientId: info.PatientId,
  4382. // Status: 1,
  4383. // Ctime: info.Ctime,
  4384. // Mtime: time.Now().Unix(),
  4385. // Creator: info.Creator,
  4386. // Modifier: adminInfo.AdminUser.Id,
  4387. // Diagnosis: diagnose,
  4388. // SickHistory: sick_history,
  4389. // Departments: department,
  4390. // RegisterType: reg_type,
  4391. // PrescriptionNumber: info.PrescriptionNumber,
  4392. // Doctor: role.UserName,
  4393. // PrescriptionStatus: info.PrescriptionStatus,
  4394. // DoctorId: doctor_id,
  4395. // SickType: sick_type,
  4396. // PType: info.PType,
  4397. // }
  4398. // service.SavePatientPrescriptionInfo(hpInfo)
  4399. // }
  4400. //
  4401. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4402. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4403. //
  4404. // if len(prescriptions) > 0 {
  4405. // for _, item := range prescriptions {
  4406. // items := item.(map[string]interface{})
  4407. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4408. // utils.ErrorLog("id")
  4409. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4410. // return
  4411. // }
  4412. // id := int64(items["id"].(float64))
  4413. //
  4414. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4415. // utils.ErrorLog("type")
  4416. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4417. // return
  4418. // }
  4419. // types := int64(items["type"].(float64))
  4420. //
  4421. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4422. // utils.ErrorLog("med_type")
  4423. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4424. // return
  4425. // }
  4426. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4427. //
  4428. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4429. //
  4430. // ctime := time.Now().Unix()
  4431. //
  4432. // prescription := &models.HisPrescription{
  4433. // ID: id,
  4434. // PatientId: patient_id,
  4435. // UserOrgId: adminInfo.CurrentOrgId,
  4436. // RecordDate: recordDateTime,
  4437. // Ctime: ctime,
  4438. // Mtime: ctime,
  4439. // Type: types,
  4440. // Modifier: adminInfo.AdminUser.Id,
  4441. // Creator: adminInfo.AdminUser.Id,
  4442. // Status: 1,
  4443. // Doctor: role.UserName,
  4444. // HisPatientId: his_patient_id,
  4445. // OrderStatus: 1,
  4446. // BatchNumber: "",
  4447. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4448. // PType: hpInfo.PType,
  4449. // MedType: med_type,
  4450. // }
  4451. //
  4452. // if historyPrescription.ID > 0 {
  4453. // prescription.PreTime = historyPrescription.PreTime
  4454. //
  4455. // }
  4456. //
  4457. // service.SaveHisPrescription(prescription)
  4458. //
  4459. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4460. // advices := items["advices"].([]interface{})
  4461. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4462. // groupNo := int64(0)
  4463. // ctime := time.Now().Unix()
  4464. // mtime := ctime
  4465. // if len(advices) > 0 {
  4466. // for _, advice := range advices {
  4467. // var s models.HisDoctorAdviceInfo
  4468. // s.PrescriptionId = prescription.ID
  4469. // s.AdviceType = 2
  4470. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4471. // s.StopState = 2
  4472. // s.ExecutionState = 2
  4473. // s.AdviceDate = recordDateTime
  4474. // s.Status = 1
  4475. // s.UserOrgId = adminInfo.CurrentOrgId
  4476. // s.RecordDate = recordDateTime
  4477. // s.StartTime = prescription.PreTime
  4478. // s.Groupno = groupNo
  4479. // s.CreatedTime = ctime
  4480. // s.UpdatedTime = mtime
  4481. // s.PatientId = patient_id
  4482. // s.HisPatientId = his_patient_id
  4483. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4484. // if errcode > 0 {
  4485. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4486. // return
  4487. // }
  4488. //
  4489. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4490. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4491. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4492. // if s.Price == 0 {
  4493. // s.Price = lastWarehouse.RetailPrice
  4494. // }
  4495. // }
  4496. //
  4497. // service.CreateHisDoctorAdvice(&s)
  4498. // //记录日志
  4499. // byterequest, _ := json.Marshal(s)
  4500. // adviceLog := models.XtDoctorAdviceLog{
  4501. // UserOrgId: s.UserOrgId,
  4502. // PatientId: s.PatientId,
  4503. // AdminUserId: adminInfo.AdminUser.Id,
  4504. // Module: 1,
  4505. // ErrLog: string(byterequest),
  4506. // Status: 1,
  4507. // Ctime: time.Now().Unix(),
  4508. // Mtime: 0,
  4509. // Source: "电脑端his医嘱修改",
  4510. // RecordDate: s.AdviceDate,
  4511. // }
  4512. // service.CreateDoctorAdviceLog(adviceLog)
  4513. // redis := service.RedisClient()
  4514. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4515. // redis.Set(key, "", time.Second)
  4516. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4517. // fmt.Println("keyOne", keyOne)
  4518. // redis.Set(keyOne, "", time.Second)
  4519. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4520. // redis.Set(keySeven, "", time.Second)
  4521. // redis.Close()
  4522. //
  4523. // }
  4524. // }
  4525. // }
  4526. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4527. // projects := items["project"].([]interface{})
  4528. // if len(projects) > 0 {
  4529. // for _, project := range projects {
  4530. // var p models.HisPrescriptionProject
  4531. // p.PrescriptionId = prescription.ID
  4532. // p.Ctime = time.Now().Unix()
  4533. // p.Mtime = time.Now().Unix()
  4534. // p.PatientId = patient_id
  4535. // p.RecordDate = recordDateTime
  4536. // p.UserOrgId = adminInfo.CurrentOrgId
  4537. // p.HisPatientId = his_patient_id
  4538. // p.Status = 1
  4539. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4540. // if errcode > 0 {
  4541. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4542. // return
  4543. // }
  4544. // service.CreateHisProjectTwo(&p)
  4545. //
  4546. // //记录日志
  4547. // byterequest, _ := json.Marshal(p)
  4548. // adviceLog := models.XtDoctorAdviceLog{
  4549. // UserOrgId: p.UserOrgId,
  4550. // PatientId: p.PatientId,
  4551. // AdminUserId: adminInfo.AdminUser.Id,
  4552. // Module: 1,
  4553. // ErrLog: string(byterequest),
  4554. // Status: 1,
  4555. // Ctime: time.Now().Unix(),
  4556. // Mtime: 0,
  4557. // Source: "电脑端his项目修改",
  4558. // RecordDate: p.RecordDate,
  4559. // }
  4560. // service.CreateDoctorAdviceLog(adviceLog)
  4561. // }
  4562. // }
  4563. // }
  4564. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4565. // addition := items["addition"].([]interface{})
  4566. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4567. // ctime := time.Now().Unix()
  4568. // mtime := ctime
  4569. // if len(addition) > 0 {
  4570. // for _, item := range addition {
  4571. // var s models.HisAdditionalCharge
  4572. // s.PrescriptionId = prescription.ID
  4573. // s.Status = 1
  4574. // s.UserOrgId = adminInfo.CurrentOrgId
  4575. // s.RecordDate = recordDateTime
  4576. // s.CreatedTime = ctime
  4577. // s.UpdatedTime = mtime
  4578. // s.PatientId = patient_id
  4579. // s.HisPatientId = his_patient_id
  4580. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4581. // if errcode > 0 {
  4582. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4583. // return
  4584. // }
  4585. // service.CreateAdditionalCharge(&s)
  4586. // }
  4587. // }
  4588. // }
  4589. //
  4590. // }
  4591. // }
  4592. // }
  4593. // if err == nil {
  4594. // c.ServeSuccessJSON(map[string]interface{}{
  4595. // "msg": "保存成功",
  4596. // })
  4597. // return
  4598. //
  4599. // } else {
  4600. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4601. // return
  4602. // }
  4603. //}
  4604. func (c *HisApiController) DeletePrescription() {
  4605. prescription_id, _ := c.GetInt64("id")
  4606. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4607. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4608. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4609. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4610. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4611. //耗材保存处方出库
  4612. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4613. //已收费和已发药限制逻辑
  4614. isCharge := false
  4615. isMedicine := false
  4616. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4617. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4618. for _, item := range new_prescriptions {
  4619. if item.IsMedicine == 1 {
  4620. isMedicine = true
  4621. }
  4622. }
  4623. for _, item := range new_prescriptions {
  4624. if item.OrderStatus == 4 {
  4625. isCharge = true
  4626. }
  4627. }
  4628. if p_err != nil {
  4629. if new_prescription.ID > 0 {
  4630. if new_prescription.OrderStatus == 2 {
  4631. isCharge = true
  4632. }
  4633. }
  4634. }
  4635. for _, item := range advices {
  4636. if item.IsMedicine == 1 {
  4637. isMedicine = true
  4638. }
  4639. }
  4640. if isCharge {
  4641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4642. return
  4643. }
  4644. if isMedicine {
  4645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4646. return
  4647. }
  4648. //已收费和已发药限制逻辑
  4649. if len(projects) > 0 {
  4650. for _, item := range projects {
  4651. service.DeletePrintInfo(item.ID) //删除打印信息
  4652. if goodOutConfig.IsOpen != 1 {
  4653. if stockConfig.IsOpen == 1 {
  4654. if item.Type == 3 && item.IsOut == 1 {
  4655. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4656. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4657. good.Total = good.Total + f_count
  4658. service.UpdateGoodInfo(&good)
  4659. operation_time := time.Now().Unix()
  4660. creater := c.GetAdminUserInfo().AdminUser.Id
  4661. //创建退库单
  4662. timeStr := time.Now().Format("2006-01-02")
  4663. timeArr := strings.Split(timeStr, "-")
  4664. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4665. total = total + 1
  4666. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4667. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4668. cancelStock := models.CancelStock{
  4669. OrderNumber: orderNumber,
  4670. OperaTime: operation_time,
  4671. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4672. Creater: creater,
  4673. Ctime: time.Now().Unix(),
  4674. Status: 1,
  4675. ReturnTime: item.RecordDate,
  4676. Type: 1,
  4677. StorehouseId: houseConfig.StorehouseOutInfo,
  4678. IsCheck: 1,
  4679. }
  4680. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4681. if msgerrkonde == gorm.ErrRecordNotFound {
  4682. service.AddSigleCancelStock(&cancelStock)
  4683. }
  4684. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4685. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4686. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4687. //查询该耗材是否出库
  4688. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4689. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4690. deaerler, _ := service.GetDealerById(info.Dealer)
  4691. var total_count int64
  4692. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4693. total_count += count
  4694. if info.ID > 0 {
  4695. if info.Count >= total_count {
  4696. //回退库存
  4697. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4698. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4699. var flush_count int64
  4700. for _, it := range goodList {
  4701. flush_count += it.StockCount
  4702. }
  4703. cancelStockInfo := models.CancelStockInfo{
  4704. GoodId: item.ProjectId,
  4705. CancelStockId: cancel.ID,
  4706. GoodTypeId: good.GoodTypeId,
  4707. Count: prescribingNumber,
  4708. Price: info.Price,
  4709. Total: 0,
  4710. ProductDate: info.ProductDate,
  4711. ExpiryDate: info.ExpiryDate,
  4712. Ctime: time.Now().Unix(),
  4713. Status: 1,
  4714. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4715. OrderNumber: cancel.OrderNumber,
  4716. Type: 0,
  4717. Dealer: deaerler.DealerName,
  4718. Manufacturer: manufacturer.ManufacturerName,
  4719. Number: info.Number,
  4720. RegisterAccount: "",
  4721. Remark: "",
  4722. WarehouseInfoId: info.WarehouseInfotId,
  4723. PatientId: info.PatientId,
  4724. RecordDate: info.SysRecordTime,
  4725. StorehouseId: houseConfig.StorehouseOutInfo,
  4726. IsCheck: 1,
  4727. }
  4728. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4729. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4730. flow := models.VmStockFlow{
  4731. WarehousingId: info.WarehouseInfotId,
  4732. GoodId: item.ProjectId,
  4733. Number: info.Number,
  4734. LicenseNumber: info.LicenseNumber,
  4735. Count: prescribingNumber,
  4736. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4737. PatientId: item.PatientId,
  4738. SystemTime: info.SysRecordTime,
  4739. ConsumableType: 7,
  4740. IsSys: 0,
  4741. WarehousingOrder: "",
  4742. WarehouseOutId: info.WarehouseOutId,
  4743. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4744. IsEdit: 0,
  4745. CancelStockId: cancel.ID,
  4746. CancelOrderNumber: cancel.OrderNumber,
  4747. Manufacturer: manufacturer.ID,
  4748. Dealer: 0,
  4749. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4750. UpdateCreator: 0,
  4751. Status: 1,
  4752. Ctime: time.Now().Unix(),
  4753. Mtime: 0,
  4754. Price: info.Price,
  4755. WarehousingDetailId: info.WarehouseInfotId,
  4756. WarehouseOutDetailId: info.ID,
  4757. CancelOutDetailId: cancelInfo.ID,
  4758. ProductDate: info.ProductDate,
  4759. ExpireDate: info.ExpiryDate,
  4760. StorehouseId: houseConfig.StorehouseOutInfo,
  4761. OverCount: flush_count,
  4762. OperateTime: time.Now().Unix(),
  4763. }
  4764. service.CreateStockFlowOne(flow)
  4765. //退库数量增加
  4766. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4767. //出库数量减少
  4768. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4769. }
  4770. if info.Count < total_count {
  4771. //回退库存
  4772. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4773. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4774. var flush_count int64
  4775. for _, it := range goodList {
  4776. flush_count += it.StockCount
  4777. }
  4778. cancelStockInfo := models.CancelStockInfo{
  4779. GoodId: item.ProjectId,
  4780. CancelStockId: cancel.ID,
  4781. GoodTypeId: good.GoodTypeId,
  4782. Count: info.Count,
  4783. Price: info.Price,
  4784. Total: 0,
  4785. ProductDate: info.ProductDate,
  4786. ExpiryDate: info.ExpiryDate,
  4787. Ctime: time.Now().Unix(),
  4788. Status: 1,
  4789. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4790. OrderNumber: cancel.OrderNumber,
  4791. Type: 0,
  4792. Dealer: deaerler.DealerName,
  4793. Manufacturer: manufacturer.ManufacturerName,
  4794. Number: info.Number,
  4795. RegisterAccount: "",
  4796. Remark: "",
  4797. WarehouseInfoId: info.WarehouseInfotId,
  4798. PatientId: info.PatientId,
  4799. RecordDate: info.SysRecordTime,
  4800. StorehouseId: houseConfig.StorehouseOutInfo,
  4801. IsCheck: 1,
  4802. }
  4803. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4804. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4805. flow := models.VmStockFlow{
  4806. WarehousingId: info.WarehouseInfotId,
  4807. GoodId: item.ProjectId,
  4808. Number: info.Number,
  4809. LicenseNumber: info.LicenseNumber,
  4810. Count: info.Count,
  4811. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4812. PatientId: item.PatientId,
  4813. SystemTime: info.SysRecordTime,
  4814. ConsumableType: 7,
  4815. IsSys: 0,
  4816. WarehousingOrder: "",
  4817. WarehouseOutId: info.WarehouseOutId,
  4818. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4819. IsEdit: 0,
  4820. CancelStockId: cancel.ID,
  4821. CancelOrderNumber: cancel.OrderNumber,
  4822. Manufacturer: manufacturer.ID,
  4823. Dealer: 0,
  4824. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4825. UpdateCreator: 0,
  4826. Status: 1,
  4827. Ctime: time.Now().Unix(),
  4828. Mtime: 0,
  4829. Price: info.Price,
  4830. WarehousingDetailId: info.WarehouseInfotId,
  4831. WarehouseOutDetailId: info.ID,
  4832. CancelOutDetailId: cancelInfo.ID,
  4833. ProductDate: info.ProductDate,
  4834. ExpireDate: info.ExpiryDate,
  4835. StorehouseId: houseConfig.StorehouseOutInfo,
  4836. OverCount: flush_count,
  4837. OperateTime: time.Now().Unix(),
  4838. }
  4839. service.CreateStockFlowOne(flow)
  4840. //退库数量增加
  4841. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4842. //出库数量减少
  4843. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4844. }
  4845. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4846. var flush_count int64
  4847. for _, it := range goodList {
  4848. flush_count += it.StockCount
  4849. }
  4850. //查询已出库数量
  4851. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4852. if prescribingNumber < dialysisInfo.Count {
  4853. //改变数量
  4854. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4855. }
  4856. if prescribingNumber >= dialysisInfo.Count {
  4857. //删除出库表
  4858. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4859. }
  4860. //更新库存
  4861. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4862. //更新基础库库存
  4863. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4864. }
  4865. }
  4866. }
  4867. }
  4868. //保存耗材出库
  4869. if goodOutConfig.IsOpen == 1 {
  4870. if item.Type == 3 {
  4871. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4872. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4873. good.Total = good.Total + f_count
  4874. service.UpdateGoodInfo(&good)
  4875. operation_time := time.Now().Unix()
  4876. creater := c.GetAdminUserInfo().AdminUser.Id
  4877. //创建退库单
  4878. timeStr := time.Now().Format("2006-01-02")
  4879. timeArr := strings.Split(timeStr, "-")
  4880. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4881. total = total + 1
  4882. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4883. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4884. cancelStock := models.CancelStock{
  4885. OrderNumber: orderNumber,
  4886. OperaTime: operation_time,
  4887. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4888. Creater: creater,
  4889. Ctime: time.Now().Unix(),
  4890. Status: 1,
  4891. ReturnTime: item.RecordDate,
  4892. Type: 1,
  4893. StorehouseId: houseConfig.StorehouseOutInfo,
  4894. IsCheck: 1,
  4895. }
  4896. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4897. if msgerrkonde == gorm.ErrRecordNotFound {
  4898. service.AddSigleCancelStock(&cancelStock)
  4899. }
  4900. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4901. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4902. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4903. //查询该耗材是否出库
  4904. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4905. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4906. deaerler, _ := service.GetDealerById(info.Dealer)
  4907. var total_count int64
  4908. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4909. total_count += count
  4910. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4911. var flush_count int64
  4912. for _, it := range goodList {
  4913. flush_count += it.StockCount
  4914. }
  4915. fmt.Println("历史出库数据", info.Count)
  4916. fmt.Println("出库数量", total_count)
  4917. if info.ID > 0 {
  4918. cancelStockInfo := models.CancelStockInfo{
  4919. GoodId: item.ProjectId,
  4920. CancelStockId: cancel.ID,
  4921. GoodTypeId: good.GoodTypeId,
  4922. Count: prescribingNumber,
  4923. Price: info.Price,
  4924. Total: 0,
  4925. ProductDate: info.ProductDate,
  4926. ExpiryDate: info.ExpiryDate,
  4927. Ctime: time.Now().Unix(),
  4928. Status: 1,
  4929. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4930. OrderNumber: cancel.OrderNumber,
  4931. Type: 0,
  4932. Dealer: deaerler.DealerName,
  4933. Manufacturer: manufacturer.ManufacturerName,
  4934. Number: info.Number,
  4935. RegisterAccount: "",
  4936. Remark: "",
  4937. WarehouseInfoId: info.WarehouseInfotId,
  4938. PatientId: info.PatientId,
  4939. RecordDate: info.SysRecordTime,
  4940. StorehouseId: houseConfig.StorehouseOutInfo,
  4941. IsCheck: 1,
  4942. }
  4943. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4944. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4945. //查询出库数量
  4946. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4947. //出库数据 大于 退库数量
  4948. if len(list) > 0 {
  4949. for _, it := range list {
  4950. //回退库存
  4951. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4952. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4953. var flush_count_one int64
  4954. for _, it := range goodList {
  4955. flush_count_one += it.StockCount
  4956. }
  4957. //查询该批次是否有退库数据
  4958. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4959. creater := c.GetAdminUserInfo().AdminUser.Id
  4960. flow := models.VmStockFlow{
  4961. WarehousingId: it.WarehouseInfotId,
  4962. GoodId: it.GoodId,
  4963. Number: it.Number,
  4964. LicenseNumber: it.LicenseNumber,
  4965. Count: it.Count,
  4966. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4967. PatientId: it.PatientId,
  4968. SystemTime: it.SysRecordTime,
  4969. ConsumableType: 7,
  4970. IsSys: 0,
  4971. WarehousingOrder: "",
  4972. WarehouseOutId: it.WarehouseOutId,
  4973. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4974. IsEdit: 0,
  4975. CancelStockId: cancel.ID,
  4976. CancelOrderNumber: cancel.OrderNumber,
  4977. Manufacturer: manufacturer.ID,
  4978. Dealer: 0,
  4979. Creator: creater,
  4980. UpdateCreator: 0,
  4981. Status: 1,
  4982. Ctime: time.Now().Unix(),
  4983. Mtime: 0,
  4984. Price: it.Price,
  4985. WarehousingDetailId: it.WarehouseInfotId,
  4986. WarehouseOutDetailId: it.ID,
  4987. CancelOutDetailId: cancelInfo.ID,
  4988. ProductDate: it.ProductDate,
  4989. ExpireDate: it.ExpiryDate,
  4990. StorehouseId: houseConfig.StorehouseOutInfo,
  4991. OverCount: flush_count_one,
  4992. }
  4993. service.CreateStockFlowOne(flow)
  4994. //if flow.ID > 0 {
  4995. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  4996. //}
  4997. }
  4998. }
  4999. //flow := models.VmStockFlow{
  5000. // WarehousingId: info.WarehouseInfotId,
  5001. // GoodId: item.ProjectId,
  5002. // Number: info.Number,
  5003. // LicenseNumber: info.LicenseNumber,
  5004. // Count: prescribingNumber,
  5005. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5006. // PatientId: item.PatientId,
  5007. // SystemTime: info.SysRecordTime,
  5008. // ConsumableType: 7,
  5009. // IsSys: 0,
  5010. // WarehousingOrder: "",
  5011. // WarehouseOutId: info.WarehouseOutId,
  5012. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5013. // IsEdit: 0,
  5014. // CancelStockId: cancel.ID,
  5015. // CancelOrderNumber: cancel.OrderNumber,
  5016. // Manufacturer: manufacturer.ID,
  5017. // Dealer: 0,
  5018. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5019. // UpdateCreator: 0,
  5020. // Status: 1,
  5021. // Ctime: time.Now().Unix(),
  5022. // Mtime: 0,
  5023. // Price: info.Price,
  5024. // WarehousingDetailId: info.WarehouseInfotId,
  5025. // WarehouseOutDetailId: info.ID,
  5026. // CancelOutDetailId: cancelInfo.ID,
  5027. // ProductDate: info.ProductDate,
  5028. // ExpireDate: info.ExpiryDate,
  5029. // StorehouseId: houseConfig.StorehouseOutInfo,
  5030. // OverCount: flush_count,
  5031. //}
  5032. //service.CreateStockFlowOne(flow)
  5033. //退库数量增加
  5034. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5035. //出库数量减少
  5036. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5037. //查询已出库数量
  5038. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5039. if prescribingNumber < dialysisInfo.Count {
  5040. //改变数量
  5041. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5042. }
  5043. if prescribingNumber >= dialysisInfo.Count {
  5044. //删除出库表
  5045. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5046. }
  5047. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5048. var flush_count_one int64
  5049. for _, it := range goodList {
  5050. flush_count_one += it.StockCount
  5051. }
  5052. //更新库存
  5053. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5054. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5055. //更新基础库库存
  5056. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5057. }
  5058. }
  5059. }
  5060. }
  5061. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5062. fmt.Println(err)
  5063. }
  5064. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5065. fmt.Println(err)
  5066. if len(advices) > 0 {
  5067. for _, item := range advices {
  5068. redis := service.RedisClient()
  5069. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5070. redis.Set(keyFive, "", time.Second)
  5071. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5072. redis.Set(keyOne, "", time.Second)
  5073. redis.Close()
  5074. }
  5075. }
  5076. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5077. if len(advices) > 0 {
  5078. for _, item := range advices {
  5079. creater := c.GetAdminUserInfo().AdminUser.Id
  5080. service.DrugAutoAddCancelInfo(item, creater)
  5081. }
  5082. }
  5083. } else {
  5084. if drugOutConfig.IsOpen == 1 {
  5085. if len(advices) > 0 {
  5086. for _, item := range advices {
  5087. creater := c.GetAdminUserInfo().AdminUser.Id
  5088. service.DrugAutoAddCancelInfo(item, creater)
  5089. }
  5090. }
  5091. } else {
  5092. if len(advices) > 0 {
  5093. for _, item := range advices {
  5094. creater := c.GetAdminUserInfo().AdminUser.Id
  5095. service.DrugAutoAddCancelInfo(item, creater)
  5096. }
  5097. }
  5098. }
  5099. }
  5100. c.ServeSuccessJSON(map[string]interface{}{
  5101. "msg": "删除成功",
  5102. })
  5103. return
  5104. }
  5105. func (c *HisApiController) DeleteDoctorAdvice() {
  5106. id, _ := c.GetInt64("id")
  5107. advice, _ := service.GetHisDoctorAdvicesById(id)
  5108. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5109. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5110. //已收费和已发药的限制逻辑
  5111. isCharge := false
  5112. isMedicine := false
  5113. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5114. //获取今天该患者所有处方,判断是否发药或者收费
  5115. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5116. for _, item := range new_prescriptions {
  5117. if item.IsMedicine == 1 {
  5118. isMedicine = true
  5119. }
  5120. }
  5121. for _, item := range new_prescriptions {
  5122. if item.OrderStatus == 4 {
  5123. isCharge = true
  5124. }
  5125. }
  5126. if isMedicine {
  5127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5128. return
  5129. }
  5130. if isCharge {
  5131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5132. return
  5133. }
  5134. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5135. for _, item := range advices {
  5136. if item.IsMedicine == 1 {
  5137. isMedicine = true
  5138. }
  5139. }
  5140. if isMedicine {
  5141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5142. return
  5143. }
  5144. if new_prescription.ID > 0 {
  5145. if new_prescription.OrderStatus == 2 {
  5146. isCharge = true
  5147. }
  5148. }
  5149. if isCharge {
  5150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5151. return
  5152. }
  5153. //已收费和已发药的限制逻辑
  5154. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5155. redis := service.RedisClient()
  5156. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5157. redis.Set(keyFive, "", time.Second)
  5158. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5159. redis.Set(keyOne, "", time.Second)
  5160. defer redis.Close()
  5161. if err == nil {
  5162. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5163. //查询是否在处方中出库
  5164. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5165. if openConfig.IsOpen != 1 {
  5166. //判断该医嘱是否执行了
  5167. if advice.ExecutionState == 1 {
  5168. creater := c.GetAdminUserInfo().AdminUser.Id
  5169. service.DrugAutoAddCancelInfo(&advice, creater)
  5170. }
  5171. }
  5172. //开启保存处方扣减功能
  5173. if openConfig.IsOpen == 1 {
  5174. creater := c.GetAdminUserInfo().AdminUser.Id
  5175. service.DrugAutoAddCancelInfo(&advice, creater)
  5176. }
  5177. } else {
  5178. if drugOutConfig.IsOpen == 1 {
  5179. //查询是否在处方中出库
  5180. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5181. if openConfig.IsOpen != 1 {
  5182. //判断该医嘱是否执行了
  5183. if advice.ExecutionState == 1 {
  5184. creater := c.GetAdminUserInfo().AdminUser.Id
  5185. service.DrugAutoAddCancelInfo(&advice, creater)
  5186. }
  5187. }
  5188. //开启保存处方扣减功能
  5189. if openConfig.IsOpen == 1 {
  5190. creater := c.GetAdminUserInfo().AdminUser.Id
  5191. service.DrugAutoAddCancelInfo(&advice, creater)
  5192. }
  5193. } else {
  5194. //判断该医嘱是否执行了
  5195. if advice.ExecutionState == 1 {
  5196. creater := c.GetAdminUserInfo().AdminUser.Id
  5197. service.DrugAutoAddCancelInfo(&advice, creater)
  5198. }
  5199. }
  5200. }
  5201. c.ServeSuccessJSON(map[string]interface{}{
  5202. "msg": "删除成功",
  5203. })
  5204. return
  5205. } else {
  5206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5207. return
  5208. }
  5209. }
  5210. func (c *HisApiController) DeleteProject() {
  5211. id, _ := c.GetInt64("id")
  5212. adminInfo := c.GetAdminUserInfo()
  5213. project, _ := service.GetHisProjectByID(id)
  5214. // var consumable models.DialysisBeforePrepare
  5215. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5216. //耗材保存处方出库
  5217. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5218. isCharge := false
  5219. isMedicine := false
  5220. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5221. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5222. for _, item := range new_prescriptions {
  5223. if item.IsMedicine == 1 {
  5224. isMedicine = true
  5225. }
  5226. }
  5227. for _, item := range new_prescriptions {
  5228. if item.OrderStatus == 4 {
  5229. isCharge = true
  5230. }
  5231. }
  5232. if isMedicine {
  5233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5234. return
  5235. }
  5236. if isCharge {
  5237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5238. return
  5239. }
  5240. if new_prescription.ID > 0 {
  5241. if new_prescription.OrderStatus == 2 {
  5242. isCharge = true
  5243. }
  5244. }
  5245. if isCharge {
  5246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5247. return
  5248. }
  5249. service.DeletePrintInfo(id)
  5250. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5251. label.Status = 0
  5252. service.CreateHisLabelRecordTwo(&label)
  5253. fmt.Println(goodOutConfig.IsOpen)
  5254. if goodOutConfig.IsOpen != 1 {
  5255. if stockConfig.IsOpen == 1 {
  5256. if project.Type == 2 {
  5257. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5258. fmt.Println(err)
  5259. }
  5260. if project.Type == 3 && project.IsOut == 1 {
  5261. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5262. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5263. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5264. operation_time := time.Now().Unix()
  5265. creater := adminInfo.AdminUser.Id
  5266. //创建退库单
  5267. timeStr := time.Now().Format("2006-01-02")
  5268. timeArr := strings.Split(timeStr, "-")
  5269. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5270. total = total + 1
  5271. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5272. cancelStock := models.CancelStock{
  5273. OrderNumber: orderNumber,
  5274. OperaTime: operation_time,
  5275. OrgId: adminInfo.CurrentOrgId,
  5276. Creater: creater,
  5277. Ctime: time.Now().Unix(),
  5278. Status: 1,
  5279. ReturnTime: project.RecordDate,
  5280. Type: 1,
  5281. StorehouseId: houseConfig.StorehouseOutInfo,
  5282. IsCheck: 1,
  5283. }
  5284. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5285. if msgerrkonde == gorm.ErrRecordNotFound {
  5286. service.AddSigleCancelStock(&cancelStock)
  5287. }
  5288. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5289. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5290. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5291. //查询是否有出库
  5292. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5293. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5294. deaerler, _ := service.GetDealerById(info.Dealer)
  5295. if info.ID > 0 {
  5296. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5297. if info.Count >= prescribingNumber {
  5298. cancelStockInfo := models.CancelStockInfo{
  5299. GoodId: project.ProjectId,
  5300. CancelStockId: cancel.ID,
  5301. GoodTypeId: good.GoodTypeId,
  5302. Count: prescribingNumber,
  5303. Price: info.Price,
  5304. Total: 0,
  5305. ProductDate: info.ProductDate,
  5306. ExpiryDate: info.ExpiryDate,
  5307. Ctime: time.Now().Unix(),
  5308. Status: 1,
  5309. OrgId: adminInfo.CurrentOrgId,
  5310. OrderNumber: cancel.OrderNumber,
  5311. Type: 0,
  5312. Dealer: deaerler.DealerName,
  5313. Manufacturer: manufacturer.ManufacturerName,
  5314. Number: info.Number,
  5315. RegisterAccount: "",
  5316. Remark: "",
  5317. WarehouseInfoId: info.WarehouseInfotId,
  5318. PatientId: info.PatientId,
  5319. RecordDate: info.SysRecordTime,
  5320. StorehouseId: houseConfig.StorehouseOutInfo,
  5321. IsCheck: 1,
  5322. }
  5323. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5324. //回退库存
  5325. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5326. //退库数量增加
  5327. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5328. //出库数量减少
  5329. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5330. }
  5331. if info.Count < prescribingNumber {
  5332. cancelStockInfo := models.CancelStockInfo{
  5333. GoodId: project.ProjectId,
  5334. CancelStockId: cancel.ID,
  5335. GoodTypeId: good.GoodTypeId,
  5336. Count: info.Count,
  5337. Price: info.Price,
  5338. Total: 0,
  5339. ProductDate: info.ProductDate,
  5340. ExpiryDate: info.ExpiryDate,
  5341. Ctime: time.Now().Unix(),
  5342. Status: 1,
  5343. OrgId: adminInfo.CurrentOrgId,
  5344. OrderNumber: cancel.OrderNumber,
  5345. Type: 0,
  5346. Dealer: deaerler.DealerName,
  5347. Manufacturer: manufacturer.ManufacturerName,
  5348. Number: info.Number,
  5349. RegisterAccount: "",
  5350. Remark: "",
  5351. WarehouseInfoId: info.WarehouseInfotId,
  5352. PatientId: info.PatientId,
  5353. RecordDate: info.SysRecordTime,
  5354. StorehouseId: houseConfig.StorehouseOutInfo,
  5355. IsCheck: 1,
  5356. }
  5357. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5358. //回退库存
  5359. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5360. //退库数量增加
  5361. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5362. //出库数量减少
  5363. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5364. }
  5365. //查询剩余库存
  5366. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5367. var over_count int64
  5368. for _, it := range goodList {
  5369. over_count += it.StockCount
  5370. }
  5371. //出库数据 大于 退库数量
  5372. if info.Count >= prescribingNumber {
  5373. flow := models.VmStockFlow{
  5374. WarehousingId: info.WarehouseInfotId,
  5375. GoodId: project.ProjectId,
  5376. Number: info.Number,
  5377. LicenseNumber: info.LicenseNumber,
  5378. Count: prescribingNumber,
  5379. UserOrgId: adminInfo.CurrentOrgId,
  5380. PatientId: project.PatientId,
  5381. SystemTime: info.SysRecordTime,
  5382. ConsumableType: 7,
  5383. IsSys: 0,
  5384. WarehousingOrder: "",
  5385. WarehouseOutId: info.WarehouseOutId,
  5386. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5387. IsEdit: 0,
  5388. CancelStockId: cancel.ID,
  5389. CancelOrderNumber: cancel.OrderNumber,
  5390. Manufacturer: manufacturer.ID,
  5391. Dealer: 0,
  5392. Creator: adminInfo.AdminUser.Id,
  5393. UpdateCreator: 0,
  5394. Status: 1,
  5395. Ctime: time.Now().Unix(),
  5396. Mtime: 0,
  5397. Price: info.Price,
  5398. WarehousingDetailId: info.WarehouseInfotId,
  5399. WarehouseOutDetailId: info.ID,
  5400. CancelOutDetailId: cancelInfo.ID,
  5401. ProductDate: info.ProductDate,
  5402. ExpireDate: info.ExpiryDate,
  5403. StorehouseId: houseConfig.StorehouseOutInfo,
  5404. OverCount: over_count,
  5405. OperateTime: time.Now().Unix(),
  5406. }
  5407. service.CreateStockFlowOne(flow)
  5408. }
  5409. //出库数据小于退库数据
  5410. if info.Count < prescribingNumber {
  5411. flow := models.VmStockFlow{
  5412. WarehousingId: info.WarehouseInfotId,
  5413. GoodId: project.ProjectId,
  5414. Number: info.Number,
  5415. LicenseNumber: info.LicenseNumber,
  5416. Count: info.Count,
  5417. UserOrgId: adminInfo.CurrentOrgId,
  5418. PatientId: project.PatientId,
  5419. SystemTime: info.SysRecordTime,
  5420. ConsumableType: 7,
  5421. IsSys: 0,
  5422. WarehousingOrder: "",
  5423. WarehouseOutId: info.WarehouseOutId,
  5424. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5425. IsEdit: 0,
  5426. CancelStockId: cancel.ID,
  5427. CancelOrderNumber: cancel.OrderNumber,
  5428. Manufacturer: manufacturer.ID,
  5429. Dealer: 0,
  5430. Creator: adminInfo.AdminUser.Id,
  5431. UpdateCreator: 0,
  5432. Status: 1,
  5433. Ctime: time.Now().Unix(),
  5434. Mtime: 0,
  5435. Price: info.Price,
  5436. WarehousingDetailId: info.WarehouseInfotId,
  5437. WarehouseOutDetailId: info.ID,
  5438. CancelOutDetailId: cancelInfo.ID,
  5439. ProductDate: info.ProductDate,
  5440. ExpireDate: info.ExpiryDate,
  5441. StorehouseId: houseConfig.StorehouseOutInfo,
  5442. OverCount: over_count,
  5443. OperateTime: time.Now().Unix(),
  5444. }
  5445. service.CreateStockFlowOne(flow)
  5446. }
  5447. //查询已出库数量
  5448. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5449. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  5450. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  5451. if prescribingNumber < dialysisInfo.Count {
  5452. //改变数量
  5453. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5454. }
  5455. if prescribingNumber >= dialysisInfo.Count {
  5456. //删除出库表
  5457. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5458. }
  5459. //更新剩余库存
  5460. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5461. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5462. var total_count_one int64
  5463. for _, it := range stockList {
  5464. total_count_one += it.StockCount
  5465. }
  5466. //基础库插入数据
  5467. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5468. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5469. var flush_count int64
  5470. for _, it := range goodListOne {
  5471. flush_count += it.StockCount
  5472. }
  5473. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5474. if errs != nil {
  5475. goodErrcode := models.XtGoodErrcode{
  5476. UserOrgId: project.UserOrgId,
  5477. Errcode: "手动出库更新剩余出库失败",
  5478. GoodId: project.ProjectId,
  5479. Status: 1,
  5480. Ctime: time.Now().Unix(),
  5481. Mtime: 0,
  5482. Count: 0,
  5483. StockCount: 0,
  5484. Creater: creater,
  5485. BatchNumberId: 0,
  5486. WarehouseOutId: 0,
  5487. }
  5488. service.CreateGoodErrcode(goodErrcode)
  5489. }
  5490. }
  5491. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5492. fmt.Println(err)
  5493. } else {
  5494. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5495. fmt.Println(err)
  5496. }
  5497. } else {
  5498. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5499. fmt.Println(err)
  5500. }
  5501. }
  5502. //保存处方出库
  5503. if goodOutConfig.IsOpen == 1 {
  5504. if project.Type == 3 {
  5505. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5506. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5507. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5508. operation_time := time.Now().Unix()
  5509. creater := adminInfo.AdminUser.Id
  5510. //创建退库单
  5511. timeStr := time.Now().Format("2006-01-02")
  5512. timeArr := strings.Split(timeStr, "-")
  5513. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5514. total = total + 1
  5515. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5516. cancelStock := models.CancelStock{
  5517. OrderNumber: orderNumber,
  5518. OperaTime: operation_time,
  5519. OrgId: adminInfo.CurrentOrgId,
  5520. Creater: creater,
  5521. Ctime: time.Now().Unix(),
  5522. Status: 1,
  5523. ReturnTime: project.RecordDate,
  5524. Type: 1,
  5525. StorehouseId: houseConfig.StorehouseOutInfo,
  5526. IsCheck: 1,
  5527. }
  5528. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5529. if msgerrkonde == gorm.ErrRecordNotFound {
  5530. service.AddSigleCancelStock(&cancelStock)
  5531. }
  5532. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5533. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5534. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5535. //获取出库数据
  5536. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5537. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5538. deaerler, _ := service.GetDealerById(info.Dealer)
  5539. if info.ID > 0 {
  5540. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5541. if info.Count >= prescribingNumber {
  5542. cancelStockInfo := models.CancelStockInfo{
  5543. GoodId: project.ProjectId,
  5544. CancelStockId: cancel.ID,
  5545. GoodTypeId: good.GoodTypeId,
  5546. Count: prescribingNumber,
  5547. Price: info.Price,
  5548. Total: 0,
  5549. ProductDate: info.ProductDate,
  5550. ExpiryDate: info.ExpiryDate,
  5551. Ctime: time.Now().Unix(),
  5552. Status: 1,
  5553. OrgId: adminInfo.CurrentOrgId,
  5554. OrderNumber: cancel.OrderNumber,
  5555. Type: 0,
  5556. Dealer: deaerler.DealerName,
  5557. Manufacturer: manufacturer.ManufacturerName,
  5558. Number: info.Number,
  5559. RegisterAccount: "",
  5560. Remark: "",
  5561. WarehouseInfoId: info.WarehouseInfotId,
  5562. PatientId: info.PatientId,
  5563. RecordDate: info.SysRecordTime,
  5564. StorehouseId: houseConfig.StorehouseOutInfo,
  5565. IsCheck: 1,
  5566. }
  5567. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5568. //退库数量增加
  5569. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5570. //出库数量减少
  5571. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5572. }
  5573. if info.Count < prescribingNumber {
  5574. cancelStockInfo := models.CancelStockInfo{
  5575. GoodId: project.ProjectId,
  5576. CancelStockId: cancel.ID,
  5577. GoodTypeId: good.GoodTypeId,
  5578. Count: prescribingNumber,
  5579. Price: info.Price,
  5580. Total: 0,
  5581. ProductDate: info.ProductDate,
  5582. ExpiryDate: info.ExpiryDate,
  5583. Ctime: time.Now().Unix(),
  5584. Status: 1,
  5585. OrgId: adminInfo.CurrentOrgId,
  5586. OrderNumber: cancel.OrderNumber,
  5587. Type: 0,
  5588. Dealer: deaerler.DealerName,
  5589. Manufacturer: manufacturer.ManufacturerName,
  5590. Number: info.Number,
  5591. RegisterAccount: "",
  5592. Remark: "",
  5593. WarehouseInfoId: info.WarehouseInfotId,
  5594. PatientId: info.PatientId,
  5595. RecordDate: info.SysRecordTime,
  5596. StorehouseId: houseConfig.StorehouseOutInfo,
  5597. IsCheck: 1,
  5598. }
  5599. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5600. //回退库存
  5601. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5602. }
  5603. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5604. var over_count int64
  5605. for _, it := range goodList {
  5606. over_count += it.StockCount
  5607. }
  5608. //查询出库数量
  5609. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  5610. //出库数据 大于 退库数量
  5611. if len(list) > 0 {
  5612. for _, it := range list {
  5613. //回退库存
  5614. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5615. //退库数量增加
  5616. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  5617. //出库数量减少
  5618. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  5619. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5620. var over_count_one int64
  5621. for _, it := range goodList {
  5622. over_count_one += it.StockCount
  5623. }
  5624. //查询该批次是否有退库数据
  5625. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  5626. flow := models.VmStockFlow{
  5627. WarehousingId: it.WarehouseInfotId,
  5628. GoodId: it.GoodId,
  5629. Number: it.Number,
  5630. LicenseNumber: it.LicenseNumber,
  5631. Count: it.Count,
  5632. UserOrgId: adminInfo.CurrentOrgId,
  5633. PatientId: it.PatientId,
  5634. SystemTime: it.SysRecordTime,
  5635. ConsumableType: 7,
  5636. IsSys: 0,
  5637. WarehousingOrder: "",
  5638. WarehouseOutId: it.WarehouseOutId,
  5639. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5640. IsEdit: 0,
  5641. CancelStockId: cancel.ID,
  5642. CancelOrderNumber: cancel.OrderNumber,
  5643. Manufacturer: manufacturer.ID,
  5644. Dealer: 0,
  5645. Creator: adminInfo.AdminUser.Id,
  5646. UpdateCreator: 0,
  5647. Status: 1,
  5648. Ctime: time.Now().Unix(),
  5649. Mtime: 0,
  5650. Price: it.Price,
  5651. WarehousingDetailId: it.WarehouseInfotId,
  5652. WarehouseOutDetailId: it.ID,
  5653. CancelOutDetailId: cancelInfo.ID,
  5654. ProductDate: it.ProductDate,
  5655. ExpireDate: it.ExpiryDate,
  5656. StorehouseId: houseConfig.StorehouseOutInfo,
  5657. OverCount: over_count_one,
  5658. OperateTime: time.Now().Unix(),
  5659. }
  5660. service.CreateStockFlowOne(flow)
  5661. }
  5662. }
  5663. //查询已出库数量
  5664. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5665. if prescribingNumber < dialysisInfo.Count {
  5666. //改变数量
  5667. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5668. }
  5669. if prescribingNumber >= dialysisInfo.Count {
  5670. //删除出库表
  5671. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5672. }
  5673. //更新剩余库存
  5674. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5675. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5676. var total_count_one int64
  5677. for _, it := range stockList {
  5678. total_count_one += it.StockCount
  5679. }
  5680. //基础库插入数据
  5681. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5682. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5683. var flush_count int64
  5684. for _, it := range goodListOne {
  5685. flush_count += it.StockCount
  5686. }
  5687. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5688. if errs != nil {
  5689. goodErrcode := models.XtGoodErrcode{
  5690. UserOrgId: project.UserOrgId,
  5691. Errcode: "手动出库更新剩余出库失败",
  5692. GoodId: project.ProjectId,
  5693. Status: 1,
  5694. Ctime: time.Now().Unix(),
  5695. Mtime: 0,
  5696. Count: 0,
  5697. StockCount: 0,
  5698. Creater: creater,
  5699. BatchNumberId: 0,
  5700. WarehouseOutId: 0,
  5701. }
  5702. service.CreateGoodErrcode(goodErrcode)
  5703. }
  5704. }
  5705. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5706. fmt.Println(err)
  5707. } else {
  5708. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5709. fmt.Println(err)
  5710. }
  5711. }
  5712. c.ServeSuccessJSON(map[string]interface{}{
  5713. "msg": "删除成功",
  5714. })
  5715. return
  5716. }
  5717. func (c *HisApiController) CreateHisAdditionalCharge() {
  5718. his_patient_id, _ := c.GetInt64("his_patient_id")
  5719. patient_id, _ := c.GetInt64("patient_id")
  5720. record_date := c.GetString("record_date")
  5721. timeLayout := "2006-01-02"
  5722. loc, _ := time.LoadLocation("Local")
  5723. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5724. if err != nil {
  5725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5726. return
  5727. }
  5728. adminInfo := c.GetAdminUserInfo()
  5729. recordDateTime := theTime.Unix()
  5730. dataBody := make(map[string]interface{}, 0)
  5731. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5732. if err != nil {
  5733. utils.ErrorLog(err.Error())
  5734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5735. return
  5736. }
  5737. var additions []*models.HisAdditionalCharge
  5738. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5739. additions, _ := dataBody["addition"].([]interface{})
  5740. if len(additions) > 0 {
  5741. for _, item := range additions {
  5742. items := item.(map[string]interface{})
  5743. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5744. utils.ErrorLog("item_id")
  5745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5746. return
  5747. }
  5748. item_id := int64(items["item_id"].(float64))
  5749. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5750. utils.ErrorLog("item_name")
  5751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5752. return
  5753. }
  5754. item_name := items["item_name"].(string)
  5755. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5756. utils.ErrorLog("price")
  5757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5758. return
  5759. }
  5760. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5761. ctime := time.Now().Unix()
  5762. additional := &models.HisAdditionalCharge{
  5763. PatientId: patient_id,
  5764. HisPatientId: his_patient_id,
  5765. UserOrgId: adminInfo.CurrentOrgId,
  5766. RecordDate: recordDateTime,
  5767. CreatedTime: ctime,
  5768. UpdatedTime: ctime,
  5769. Modifier: adminInfo.AdminUser.Id,
  5770. Creator: adminInfo.AdminUser.Id,
  5771. Price: price,
  5772. ItemName: item_name,
  5773. ItemId: item_id,
  5774. Status: 1,
  5775. }
  5776. additions = append(additions, additional)
  5777. }
  5778. }
  5779. }
  5780. for _, item := range additions {
  5781. service.CreateAddtionalCharge(item)
  5782. }
  5783. c.ServeSuccessJSON(map[string]interface{}{
  5784. "msg": "创建成功",
  5785. })
  5786. }
  5787. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5788. blood_fat := c.GetString("blood_fat")
  5789. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5790. blood_sugar := c.GetString("blood_sugar")
  5791. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5792. chief_conplaint := c.GetString("chief_conplaint")
  5793. dbp := c.GetString("dbp")
  5794. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5795. delivery_way, _ := c.GetInt64("delivery_way")
  5796. diagnostic := c.GetString("diagnostic")
  5797. family_history := c.GetString("family_history")
  5798. height := c.GetString("height")
  5799. history_of_present_illness := c.GetString("history_of_present_illness")
  5800. is_infect, _ := c.GetInt64("is_infect")
  5801. past_history := c.GetString("past_history")
  5802. patient_id, _ := c.GetInt64("patient_id")
  5803. his_patient_id, _ := c.GetInt64("his_patient_id")
  5804. personal_history := c.GetString("personal_history")
  5805. pulse := c.GetString("pulse")
  5806. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5807. sbp := c.GetString("sbp")
  5808. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5809. heightfloat, _ := strconv.ParseFloat(height, 64)
  5810. sicktype := c.GetString("sick_type")
  5811. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5812. symptom := c.GetString("symptom")
  5813. sick_date := c.GetString("sick_date")
  5814. temperatures := c.GetString("temperature")
  5815. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5816. record_date := c.GetString("record_date")
  5817. breathing := c.GetString("breathing")
  5818. doctor_advice := c.GetString("doctor_advice")
  5819. remark := c.GetString("remark")
  5820. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5821. sick, _ := c.GetInt64("sick")
  5822. diagnose, _ := c.GetInt64("diagnose")
  5823. //id, _ := c.GetInt64("id")
  5824. timeLayout := "2006-01-02"
  5825. loc, _ := time.LoadLocation("Local")
  5826. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5827. allergic_history := c.GetString("allergic_history")
  5828. if err != nil {
  5829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5830. return
  5831. }
  5832. recordDateTime := theTime.Unix()
  5833. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5834. if err != nil {
  5835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5836. return
  5837. }
  5838. sickTimes := sickTime.Unix()
  5839. ctime := time.Now().Unix()
  5840. primary_disease := c.GetString("primary_disease")
  5841. confirm_failure_date := c.GetString("confirm_failure_date")
  5842. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5843. drug_allergy_history := c.GetString("drug_allergy_history")
  5844. physical_examination := c.GetString("physical_examination")
  5845. special_inspection := c.GetString("special_inspection")
  5846. lab_apparatus := c.GetString("lab_apparatus")
  5847. caseHistory := models.HisPatientCaseHistory{
  5848. HisPatientId: his_patient_id,
  5849. PatientId: patient_id,
  5850. Temperature: temperature,
  5851. BloodSugar: bloodsugarfloat,
  5852. Pulse: pulsefloat,
  5853. Sbp: sbpfloat,
  5854. Dbp: dbpfloat,
  5855. Height: heightfloat,
  5856. BloodFat: bloodfatfloat,
  5857. SickType: sick_type,
  5858. Symptom: symptom,
  5859. SickDate: sickTimes,
  5860. IsInfect: is_infect,
  5861. HistoryOfPresentIllness: history_of_present_illness,
  5862. PastHistory: past_history,
  5863. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5864. ChiefConplaint: chief_conplaint,
  5865. PersonalHistory: personal_history,
  5866. FamilyHistory: family_history,
  5867. Diagnostic: diagnostic,
  5868. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5869. Status: 1,
  5870. Ctime: ctime,
  5871. Mtime: ctime,
  5872. RecordDate: recordDateTime,
  5873. DeliveryWay: delivery_way,
  5874. Breathing: breathingfloat,
  5875. DoctorAdvice: doctor_advice,
  5876. Remark: remark,
  5877. Sick: sick,
  5878. Diagnose: diagnose,
  5879. AllergicHistory: allergic_history,
  5880. PrimaryDisease: primary_disease,
  5881. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5882. DrugAllergyHistory: drug_allergy_history,
  5883. PhysicalExamination: physical_examination,
  5884. SpecialInspection: special_inspection,
  5885. LabApparatus: lab_apparatus,
  5886. }
  5887. //查询该患者是否有病历
  5888. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5889. if errcodes == gorm.ErrRecordNotFound {
  5890. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5891. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5892. if err != nil {
  5893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5894. return
  5895. }
  5896. c.ServeSuccessJSON(map[string]interface{}{
  5897. "caseHistory": caseHistory,
  5898. "historyInfo": historyInfo,
  5899. })
  5900. return
  5901. } else if errcodes == nil {
  5902. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5903. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5904. if err != nil {
  5905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5906. return
  5907. }
  5908. c.ServeSuccessJSON(map[string]interface{}{
  5909. "caseHistory": caseHistory,
  5910. "historyInfo": historyInfo,
  5911. })
  5912. }
  5913. //查询该患者是否有病历
  5914. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5915. //if errcode == gorm.ErrRecordNotFound {
  5916. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5917. // if err != nil {
  5918. // c.ServeSuccessJSON(map[string]interface{}{
  5919. // "msg": "保存成功",
  5920. // })
  5921. // }
  5922. //} else if errcode == nil {
  5923. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5924. // return
  5925. //}
  5926. }
  5927. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5928. patient_id, _ := c.GetInt64("patient_id", 0)
  5929. adminUser := c.GetAdminUserInfo()
  5930. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5931. c.ServeSuccessJSON(map[string]interface{}{
  5932. "list": caseHistorys,
  5933. })
  5934. }
  5935. func (c *HisApiController) GetHisPatientCaseHistory() {
  5936. record_date, _ := c.GetInt64("record_date", 0)
  5937. patient_id, _ := c.GetInt64("patient_id", 0)
  5938. admin := c.GetAdminUserInfo()
  5939. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5940. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5941. c.ServeSuccessJSON(map[string]interface{}{
  5942. "info": info,
  5943. "case_history": case_history,
  5944. })
  5945. }
  5946. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5947. template_name := c.GetString("template_name")
  5948. template_remark := c.GetString("template_remark")
  5949. doctor := c.GetAdminUserInfo().AdminUser.Id
  5950. diagnostic := c.GetString("diagnostic")
  5951. chief_conplaint := c.GetString("chief_conplain")
  5952. history_of_present_illness := c.GetString("history_of_present_illness")
  5953. past_history := c.GetString("past_history")
  5954. personal_history := c.GetString("personal_history")
  5955. family_history := c.GetString("family_history")
  5956. user_name := c.GetString("user_name")
  5957. doctor_advice := c.GetString("doctor_advice")
  5958. remark := c.GetString("remark")
  5959. //record_date := c.GetString("record_date")
  5960. //fmt.Println("record_date--------",record_date)
  5961. //timeLayout := "2006-01-02"
  5962. //loc, _ := time.LoadLocation("Local")
  5963. //
  5964. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5965. //if err != nil {
  5966. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5967. // return
  5968. //}
  5969. //recordDateTime := theTime.Unix()
  5970. ctime := time.Now().Unix()
  5971. template := models.HisCaseHistoryTemplate{
  5972. HistoryOfPresentIllness: history_of_present_illness,
  5973. PastHistory: past_history,
  5974. ChiefConplaint: chief_conplaint,
  5975. PersonalHistory: personal_history,
  5976. FamilyHistory: family_history,
  5977. Diagnostic: diagnostic,
  5978. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5979. Status: 1,
  5980. Ctime: ctime,
  5981. Mtime: ctime,
  5982. RecordDate: time.Now().Unix(),
  5983. TemplateName: template_name,
  5984. TemplateRemark: template_remark,
  5985. Creator: doctor,
  5986. Modifier: doctor,
  5987. UserName: user_name,
  5988. DoctorAdvice: doctor_advice,
  5989. Remark: remark,
  5990. }
  5991. err := service.SaveHisPatientCaseHistoryTemplate(template)
  5992. if err == nil {
  5993. c.ServeSuccessJSON(map[string]interface{}{
  5994. "msg": "保存成功",
  5995. })
  5996. } else {
  5997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5998. return
  5999. }
  6000. }
  6001. func (c *HisApiController) GetCaseHistoryTemplate() {
  6002. timeLayout := "2006-01-02"
  6003. loc, _ := time.LoadLocation("Local")
  6004. keyword := c.GetString("keyword")
  6005. start_time := c.GetString("start_time")
  6006. end_time := c.GetString("end_time")
  6007. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6008. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6009. admin := c.GetAdminUserInfo()
  6010. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6011. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6012. c.ServeSuccessJSON(map[string]interface{}{
  6013. "template": template,
  6014. //"history": history,
  6015. })
  6016. }
  6017. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6018. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6019. utils.ErrorLog("drug_name")
  6020. return enums.ErrorCodeParamWrong
  6021. }
  6022. adviceName, _ := json["drug_name"].(string)
  6023. if len(adviceName) == 0 {
  6024. utils.ErrorLog("len(advice_name) == 0")
  6025. return enums.ErrorCodeParamWrong
  6026. }
  6027. advice.AdviceName = adviceName
  6028. adviceDesc, _ := json["advice_desc"].(string)
  6029. advice.AdviceDesc = adviceDesc
  6030. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6031. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6032. advice.DrugSpec = drugSpec
  6033. }
  6034. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6035. remark, _ := json["remark"].(string)
  6036. advice.Remark = remark
  6037. }
  6038. if json["id"] == nil {
  6039. advice.DrugId = 0
  6040. } else {
  6041. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6042. drug_id := int64(json["id"].(float64))
  6043. advice.DrugId = drug_id
  6044. }
  6045. }
  6046. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6047. advice_id := int64(json["advice_id"].(float64))
  6048. advice.ID = advice_id
  6049. if advice.ID > 0 {
  6050. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6051. if err == nil {
  6052. if hisAdvice.ID > 0 {
  6053. advice.ExecutionTime = hisAdvice.ExecutionTime
  6054. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6055. advice.ExecutionState = hisAdvice.ExecutionState
  6056. advice.CheckTime = hisAdvice.CheckTime
  6057. advice.Checker = hisAdvice.Checker
  6058. advice.CheckState = hisAdvice.CheckState
  6059. advice.StartTime = hisAdvice.StartTime
  6060. advice.FeedetlSn = hisAdvice.FeedetlSn
  6061. }
  6062. }
  6063. }
  6064. }
  6065. //
  6066. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6067. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6068. // advice.ExecutionTime = execution_time
  6069. //}
  6070. //
  6071. //
  6072. //
  6073. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6074. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6075. // advice.ExecutionStaff = execution_staff
  6076. //}
  6077. //
  6078. //
  6079. //
  6080. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6081. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6082. // advice.ExecutionState = execution_state
  6083. //}
  6084. //
  6085. //
  6086. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6087. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6088. // advice.CheckTime = check_time
  6089. //}
  6090. //
  6091. //
  6092. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6093. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6094. // advice.CheckState = check_state
  6095. //}
  6096. //
  6097. //
  6098. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6099. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6100. // advice.Checker = checker
  6101. //}
  6102. //
  6103. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6104. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6105. // advice.StartTime = start_time
  6106. //}
  6107. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6108. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6109. advice.IsSelfDrug = is_self_drug
  6110. }
  6111. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6112. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6113. drug_way_count, _ := json["drug_way_count"].(string)
  6114. advice.DrugWayCount = drug_way_count
  6115. }
  6116. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6117. drugSpecUnit, _ := json["min_unit"].(string)
  6118. advice.DrugSpecUnit = drugSpecUnit
  6119. }
  6120. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6121. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6122. advice.SingleDose = singleDose
  6123. }
  6124. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6125. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6126. advice.SingleDoseUnit = singleDoseUnit
  6127. }
  6128. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6129. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6130. advice.PrescribingNumber = prescribingNumber
  6131. }
  6132. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6133. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6134. advice.PrescribingNumberUnit = prescribingNumberUnit
  6135. }
  6136. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6137. deliveryWay, _ := json["delivery_way"].(string)
  6138. advice.DeliveryWay = deliveryWay
  6139. }
  6140. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6141. executionFrequency, _ := json["execution_frequency"].(string)
  6142. advice.ExecutionFrequency = executionFrequency
  6143. }
  6144. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6145. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6146. advice.Price = price
  6147. }
  6148. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6149. med_list_codg, _ := json["medical_insurance_number"].(string)
  6150. advice.MedListCodg = med_list_codg
  6151. }
  6152. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6153. day := int64(json["day"].(float64))
  6154. advice.Day = day
  6155. }
  6156. return 0
  6157. }
  6158. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6159. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6160. id := int64(json["id"].(float64))
  6161. project.ID = id
  6162. historyProject, _ := service.GetHisProjectByID(id)
  6163. project.FeedetlSn = historyProject.FeedetlSn
  6164. }
  6165. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6166. project_id := int64(json["project_id"].(float64))
  6167. project.ProjectId = project_id
  6168. }
  6169. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6170. // price := int64(json["price"].(float64))
  6171. // formatInt_price := strconv.FormatInt(price, 10)
  6172. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6173. // project.Price = float_price
  6174. // }
  6175. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6176. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6177. project.Price = price
  6178. }
  6179. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6180. total, _ := json["total"].(string)
  6181. project.Count = total
  6182. }
  6183. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6184. medical_code, _ := json["medical_code"].(string)
  6185. project.MedListCodg = medical_code
  6186. }
  6187. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6188. single_dose, _ := json["single_dose"].(string)
  6189. project.SingleDose = single_dose
  6190. }
  6191. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6192. delivery_way, _ := json["delivery_way"].(string)
  6193. project.DeliveryWay = delivery_way
  6194. }
  6195. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6196. execution_frequency, _ := json["execution_frequency"].(string)
  6197. project.ExecutionFrequency = execution_frequency
  6198. }
  6199. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6200. remark, _ := json["remark"].(string)
  6201. project.Remark = remark
  6202. }
  6203. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6204. day, _ := json["number_days"].(string)
  6205. project.Day = day
  6206. }
  6207. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6208. unit, _ := json["unit"].(string)
  6209. project.Unit = unit
  6210. }
  6211. return 0
  6212. }
  6213. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6214. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6215. id := int64(json["id"].(float64))
  6216. historyAddtions, _ := service.GetHisAdditionByID(id)
  6217. additionalCharge.ID = id
  6218. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6219. }
  6220. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6221. item_id := int64(json["item_id"].(float64))
  6222. additionalCharge.ItemId = item_id
  6223. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6224. if config.ID > 0 {
  6225. if len(config.Code) > 0 {
  6226. additionalCharge.MedListCodg = config.Code
  6227. }
  6228. }
  6229. }
  6230. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6231. // price := int64(json["price"].(float64))
  6232. // formatInt_price := strconv.FormatInt(price, 10)
  6233. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6234. // additionalCharge.Price = float_price
  6235. // }
  6236. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6237. // price := int64(json["price"].(float64))
  6238. // formatInt_price := strconv.FormatInt(price, 10)
  6239. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6240. // additionalCharge.Price = float_price
  6241. //}
  6242. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6243. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6244. additionalCharge.Price = price
  6245. }
  6246. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6247. count, _ := json["count"].(string)
  6248. counts, _ := strconv.ParseInt(count, 10, 64)
  6249. additionalCharge.Count = counts
  6250. }
  6251. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6252. item_name, _ := json["item_name"].(string)
  6253. additionalCharge.ItemName = item_name
  6254. }
  6255. return 0
  6256. }
  6257. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6258. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6259. utils.ErrorLog("drug_name")
  6260. return enums.ErrorCodeParamWrong
  6261. }
  6262. adviceName, _ := json["drug_name"].(string)
  6263. if len(adviceName) == 0 {
  6264. utils.ErrorLog("len(advice_name) == 0")
  6265. return enums.ErrorCodeParamWrong
  6266. }
  6267. advice.AdviceName = adviceName
  6268. adviceDesc, _ := json["advice_desc"].(string)
  6269. advice.AdviceDesc = adviceDesc
  6270. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6271. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6272. advice.DrugSpec = drugSpec
  6273. }
  6274. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6275. remark, _ := json["remark"].(string)
  6276. advice.Remark = remark
  6277. }
  6278. if json["id"] == nil {
  6279. advice.DrugId = 0
  6280. } else {
  6281. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6282. drug_id := int64(json["id"].(float64))
  6283. advice.DrugId = drug_id
  6284. }
  6285. }
  6286. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6287. groupno := int64(json["groupno"].(float64))
  6288. advice.Groupno = groupno
  6289. }
  6290. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6291. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6292. advice.IsSelfDrug = is_self_drug
  6293. }
  6294. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6295. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6296. drug_way_count, _ := json["drug_way_count"].(string)
  6297. advice.DrugWayCount = drug_way_count
  6298. }
  6299. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6300. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6301. advice.HospApprFlag = hosp_appr_flag
  6302. }
  6303. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6304. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6305. advice.PrescribingNumber = prescribingNumber
  6306. }
  6307. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6308. // frequency_type := int64(json["frequency_type"].(float64))
  6309. // advice.FrequencyType = frequency_type
  6310. //}
  6311. //
  6312. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6313. // day_count := int64(json["day_count"].(float64))
  6314. // advice.DayCount = day_count
  6315. //}
  6316. //
  6317. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6318. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6319. // week_day, _ := json["week_day"].(string)
  6320. // advice.WeekDay = week_day
  6321. //}
  6322. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6323. drugSpecUnit, _ := json["min_unit"].(string)
  6324. advice.DrugSpecUnit = drugSpecUnit
  6325. }
  6326. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6327. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6328. advice.SingleDose = singleDose
  6329. }
  6330. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6331. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6332. advice.SingleDoseUnit = singleDoseUnit
  6333. }
  6334. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6335. deliveryWay, _ := json["delivery_way"].(string)
  6336. advice.DeliveryWay = deliveryWay
  6337. }
  6338. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6339. executionFrequency, _ := json["execution_frequency"].(string)
  6340. advice.ExecutionFrequency = executionFrequency
  6341. }
  6342. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6343. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6344. advice.Price = price
  6345. }
  6346. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6347. med_list_codg, _ := json["medical_insurance_number"].(string)
  6348. advice.MedListCodg = med_list_codg
  6349. }
  6350. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6351. day := int64(json["day"].(float64))
  6352. advice.Day = day
  6353. }
  6354. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6355. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6356. advice.PrescribingNumberUnit = prescribingNumberUnit
  6357. }
  6358. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6359. advice_id := int64(json["advice_id"].(float64))
  6360. advice.ID = advice_id
  6361. if advice.ID > 0 {
  6362. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6363. if err == nil {
  6364. if hisAdvice.ID > 0 {
  6365. advice.ExecutionTime = hisAdvice.ExecutionTime
  6366. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6367. advice.ExecutionState = hisAdvice.ExecutionState
  6368. advice.CheckTime = hisAdvice.CheckTime
  6369. advice.Checker = hisAdvice.Checker
  6370. advice.CheckState = hisAdvice.CheckState
  6371. advice.StartTime = hisAdvice.StartTime
  6372. advice.HospApprFlag = hisAdvice.HospApprFlag
  6373. advice.IsMedicine = hisAdvice.IsMedicine
  6374. if hisAdvice.UserOrgId == 10028 {
  6375. 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 {
  6376. advice.ExecutionTime = 0
  6377. advice.ExecutionStaff = 0
  6378. advice.ExecutionState = 2
  6379. advice.CheckTime = 0
  6380. advice.Checker = 0
  6381. advice.CheckState = 2
  6382. }
  6383. } else {
  6384. 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 {
  6385. advice.ExecutionTime = 0
  6386. advice.ExecutionStaff = 0
  6387. advice.ExecutionState = 2
  6388. advice.CheckTime = 0
  6389. advice.Checker = 0
  6390. advice.CheckState = 2
  6391. advice.UpdatedTime = time.Now().Unix()
  6392. }
  6393. }
  6394. //advice.Groupno = hisAdvice.Groupno
  6395. }
  6396. }
  6397. }
  6398. }
  6399. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6400. //
  6401. //if drugStockConfig.IsOpen == 1 {
  6402. //
  6403. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6404. // if advice.ID == 0 { //医嘱不存在
  6405. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6406. // drug.Total = drug.Total - advice.PrescribingNumber
  6407. // service.UpdateBaseDrugLib(&drug)
  6408. //
  6409. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6410. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6411. // drug.Total = drug.Total - num
  6412. // service.UpdateBaseDrugLib(&drug)
  6413. // }
  6414. //
  6415. // } else if advice.ID > 0 { //医嘱存在
  6416. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6417. // var num float64
  6418. //
  6419. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6420. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6421. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6422. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6423. // drug.Total = drug.Total + num
  6424. // service.UpdateBaseDrugLib(&drug)
  6425. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6426. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6427. // drug.Total = drug.Total - num
  6428. // service.UpdateBaseDrugLib(&drug)
  6429. // }
  6430. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6431. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6432. // if num2 > advice.PrescribingNumber {
  6433. // num = num2 - advice.PrescribingNumber
  6434. // drug.Total = drug.Total + num
  6435. // service.UpdateBaseDrugLib(&drug)
  6436. // } else if num2 < advice.PrescribingNumber {
  6437. // num = advice.PrescribingNumber - num2
  6438. // drug.Total = drug.Total - num
  6439. // service.UpdateBaseDrugLib(&drug)
  6440. // }
  6441. //
  6442. // }
  6443. //
  6444. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6445. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6446. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6447. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6448. // if num1 > num2 {
  6449. // num = num1 - num2
  6450. // drug.Total = drug.Total + num
  6451. // service.UpdateBaseDrugLib(&drug)
  6452. // } else if num1 < num2 {
  6453. // num = num2 - num1
  6454. // drug.Total = drug.Total - num
  6455. // service.UpdateBaseDrugLib(&drug)
  6456. // }
  6457. //
  6458. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6459. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6460. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6461. // if hisAdvice.PrescribingNumber > num2 {
  6462. // num = hisAdvice.PrescribingNumber - num2
  6463. // drug.Total = drug.Total + num
  6464. // service.UpdateBaseDrugLib(&drug)
  6465. // } else if num2 < advice.PrescribingNumber {
  6466. // num = num2 - hisAdvice.PrescribingNumber
  6467. // drug.Total = drug.Total - num
  6468. // service.UpdateBaseDrugLib(&drug)
  6469. // }
  6470. //
  6471. // }
  6472. // }
  6473. // }
  6474. //}
  6475. //
  6476. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6477. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6478. // advice.ExecutionTime = execution_time
  6479. //}
  6480. //
  6481. //
  6482. //
  6483. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6484. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6485. // advice.ExecutionStaff = execution_staff
  6486. //}
  6487. //
  6488. //
  6489. //
  6490. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6491. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6492. // advice.ExecutionState = execution_state
  6493. //}
  6494. //
  6495. //
  6496. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6497. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6498. // advice.CheckTime = check_time
  6499. //}
  6500. //
  6501. //
  6502. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6503. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6504. // advice.CheckState = check_state
  6505. //}
  6506. //
  6507. //
  6508. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6509. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6510. // advice.Checker = checker
  6511. //}
  6512. //
  6513. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6514. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6515. // advice.StartTime = start_time
  6516. //}
  6517. return 0
  6518. }
  6519. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6520. project.ExecutionStaff = 0
  6521. project.ExecutionState = 2
  6522. project.ExecutionTime = 0
  6523. project.Checker = 0
  6524. project.CheckState = 2
  6525. project.CheckTime = 0
  6526. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6527. id := int64(json["id"].(float64))
  6528. project.ID = id
  6529. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6530. project.ExecutionStaff = temp_project.ExecutionStaff
  6531. project.ExecutionState = temp_project.ExecutionState
  6532. project.ExecutionTime = temp_project.ExecutionTime
  6533. project.Checker = temp_project.Checker
  6534. project.CheckState = temp_project.CheckState
  6535. project.CheckTime = temp_project.CheckTime
  6536. project.TeamId = temp_project.TeamId
  6537. }
  6538. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6539. types := int64(json["type"].(float64))
  6540. project.Type = types
  6541. }
  6542. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6543. project_id := int64(json["project_id"].(float64))
  6544. project.ProjectId = project_id
  6545. }
  6546. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6547. team_id := int64(json["team_id"].(float64))
  6548. project.TeamId = team_id
  6549. }
  6550. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6551. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6552. project.Price = price
  6553. }
  6554. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6555. total, _ := json["total"].(string)
  6556. //totals, _ := strconv.ParseInt(total, 10, 64)
  6557. project.Count = total
  6558. }
  6559. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6560. medical_code, _ := json["medical_code"].(string)
  6561. project.MedListCodg = medical_code
  6562. }
  6563. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6564. single_dose, _ := json["single_dose"].(string)
  6565. project.SingleDose = single_dose
  6566. }
  6567. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6568. delivery_way, _ := json["delivery_way"].(string)
  6569. project.DeliveryWay = delivery_way
  6570. }
  6571. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6572. execution_frequency, _ := json["execution_frequency"].(string)
  6573. project.ExecutionFrequency = execution_frequency
  6574. }
  6575. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6576. remark, _ := json["remark"].(string)
  6577. project.Remark = remark
  6578. }
  6579. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6580. day, _ := json["number_days"].(string)
  6581. project.Day = day
  6582. }
  6583. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6584. unit, _ := json["unit"].(string)
  6585. project.Unit = unit
  6586. }
  6587. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6588. // frequency_type := int64(json["frequency_type"].(float64))
  6589. // project.FrequencyType = frequency_type
  6590. //}
  6591. //
  6592. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6593. // day_count := int64(json["day_count"].(float64))
  6594. // project.DayCount = day_count
  6595. //}
  6596. //
  6597. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6598. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6599. // week_day, _ := json["week_day"].(string)
  6600. // project.WeekDay = week_day
  6601. //}
  6602. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6603. //
  6604. //if project.ID == 0 {
  6605. // if stockConfig.IsOpen == 1 {
  6606. // if project.Type == 3 {
  6607. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6608. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6609. // good.Total = good.Total - f_count
  6610. // service.UpdateGoodInfo(&good)
  6611. // }
  6612. // }
  6613. //
  6614. //} else {
  6615. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6616. //
  6617. // if stockConfig.IsOpen == 1 {
  6618. // if project.Type == 3 {
  6619. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6620. // if project.Count < temp_project.Count {
  6621. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6622. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6623. //
  6624. // other_count := f_count_two - f_count_one
  6625. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6626. // good.Total = good.Total + other_count_two
  6627. // service.UpdateGoodInfo(&good)
  6628. // } else if project.Count > temp_project.Count {
  6629. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6630. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6631. //
  6632. // other_count := f_count_one - f_count_two
  6633. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6634. // good.Total = good.Total - other_count_two
  6635. // service.UpdateGoodInfo(&good)
  6636. // }
  6637. //
  6638. // }
  6639. // }
  6640. //
  6641. //}
  6642. return 0
  6643. }
  6644. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6645. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6646. utils.ErrorLog("drug_name")
  6647. return enums.ErrorCodeParamWrong
  6648. }
  6649. adviceName, _ := json["drug_name"].(string)
  6650. if len(adviceName) == 0 {
  6651. utils.ErrorLog("len(advice_name) == 0")
  6652. return enums.ErrorCodeParamWrong
  6653. }
  6654. advice.AdviceName = adviceName
  6655. adviceDesc, _ := json["advice_desc"].(string)
  6656. advice.AdviceDesc = adviceDesc
  6657. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6658. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6659. advice.DrugSpec = drugSpec
  6660. }
  6661. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6662. remark, _ := json["remark"].(string)
  6663. advice.Remark = remark
  6664. }
  6665. if json["id"] == nil {
  6666. advice.DrugId = 0
  6667. } else {
  6668. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6669. drug_id := int64(json["id"].(float64))
  6670. advice.DrugId = drug_id
  6671. }
  6672. }
  6673. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6674. groupno := int64(json["groupno"].(float64))
  6675. advice.Groupno = groupno
  6676. }
  6677. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6678. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6679. advice.IsSelfDrug = is_self_drug
  6680. }
  6681. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6682. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6683. drug_way_count, _ := json["drug_way_count"].(string)
  6684. advice.DrugWayCount = drug_way_count
  6685. }
  6686. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6687. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6688. advice.HospApprFlag = hosp_appr_flag
  6689. }
  6690. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6691. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6692. advice.PrescribingNumber = prescribingNumber
  6693. }
  6694. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6695. // frequency_type := int64(json["frequency_type"].(float64))
  6696. // advice.FrequencyType = frequency_type
  6697. //}
  6698. //
  6699. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6700. // day_count := int64(json["day_count"].(float64))
  6701. // advice.DayCount = day_count
  6702. //}
  6703. //
  6704. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6705. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6706. // week_day, _ := json["week_day"].(string)
  6707. // advice.WeekDay = week_day
  6708. //}
  6709. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6710. drugSpecUnit, _ := json["min_unit"].(string)
  6711. advice.DrugSpecUnit = drugSpecUnit
  6712. }
  6713. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6714. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6715. advice.SingleDose = singleDose
  6716. }
  6717. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6718. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6719. advice.SingleDoseUnit = singleDoseUnit
  6720. }
  6721. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6722. deliveryWay, _ := json["delivery_way"].(string)
  6723. advice.DeliveryWay = deliveryWay
  6724. }
  6725. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6726. executionFrequency, _ := json["execution_frequency"].(string)
  6727. advice.ExecutionFrequency = executionFrequency
  6728. }
  6729. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6730. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6731. advice.Price = price
  6732. }
  6733. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6734. med_list_codg, _ := json["medical_insurance_number"].(string)
  6735. advice.MedListCodg = med_list_codg
  6736. }
  6737. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6738. day := int64(json["day"].(float64))
  6739. advice.Day = day
  6740. }
  6741. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6742. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6743. advice.PrescribingNumberUnit = prescribingNumberUnit
  6744. }
  6745. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6746. advice_id := int64(json["advice_id"].(float64))
  6747. advice.ID = advice_id
  6748. if advice.ID > 0 {
  6749. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6750. if err == nil {
  6751. if hisAdvice.ID > 0 {
  6752. advice.ExecutionTime = hisAdvice.ExecutionTime
  6753. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6754. advice.ExecutionState = hisAdvice.ExecutionState
  6755. advice.CheckTime = hisAdvice.CheckTime
  6756. advice.Checker = hisAdvice.Checker
  6757. advice.CheckState = hisAdvice.CheckState
  6758. advice.StartTime = hisAdvice.StartTime
  6759. advice.HospApprFlag = hisAdvice.HospApprFlag
  6760. advice.IsMedicine = hisAdvice.IsMedicine
  6761. if hisAdvice.UserOrgId == 10028 {
  6762. 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 {
  6763. advice.ExecutionTime = 0
  6764. advice.ExecutionStaff = 0
  6765. advice.ExecutionState = 2
  6766. advice.CheckTime = 0
  6767. advice.Checker = 0
  6768. advice.CheckState = 2
  6769. }
  6770. } else {
  6771. if hisAdvice.SingleDoseUnit != advice.SingleDoseUnit || 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 {
  6772. advice.ExecutionTime = 0
  6773. advice.ExecutionStaff = 0
  6774. advice.ExecutionState = 2
  6775. advice.CheckTime = 0
  6776. advice.Checker = 0
  6777. advice.CheckState = 2
  6778. //advice.UpdatedTime = time.Now().Unix()
  6779. advice.CreatedTime = hisAdvice.CreatedTime
  6780. advice.UpdatedTime = time.Now().Unix()
  6781. } else {
  6782. advice.CreatedTime = hisAdvice.CreatedTime
  6783. advice.UpdatedTime = hisAdvice.UpdatedTime
  6784. }
  6785. }
  6786. //advice.Groupno = hisAdvice.Groupno
  6787. } else {
  6788. ctime := time.Now().Unix()
  6789. advice.CreatedTime = ctime
  6790. advice.UpdatedTime = ctime
  6791. }
  6792. }
  6793. } else {
  6794. ctime := time.Now().Unix()
  6795. advice.CreatedTime = ctime
  6796. advice.UpdatedTime = ctime
  6797. }
  6798. }
  6799. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6800. //
  6801. //if drugStockConfig.IsOpen == 1 {
  6802. //
  6803. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6804. // if advice.ID == 0 { //医嘱不存在
  6805. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6806. // drug.Total = drug.Total - advice.PrescribingNumber
  6807. // service.UpdateBaseDrugLib(&drug)
  6808. //
  6809. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6810. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6811. // drug.Total = drug.Total - num
  6812. // service.UpdateBaseDrugLib(&drug)
  6813. // }
  6814. //
  6815. // } else if advice.ID > 0 { //医嘱存在
  6816. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6817. // var num float64
  6818. //
  6819. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6820. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6821. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6822. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6823. // drug.Total = drug.Total + num
  6824. // service.UpdateBaseDrugLib(&drug)
  6825. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6826. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6827. // drug.Total = drug.Total - num
  6828. // service.UpdateBaseDrugLib(&drug)
  6829. // }
  6830. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6831. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6832. // if num2 > advice.PrescribingNumber {
  6833. // num = num2 - advice.PrescribingNumber
  6834. // drug.Total = drug.Total + num
  6835. // service.UpdateBaseDrugLib(&drug)
  6836. // } else if num2 < advice.PrescribingNumber {
  6837. // num = advice.PrescribingNumber - num2
  6838. // drug.Total = drug.Total - num
  6839. // service.UpdateBaseDrugLib(&drug)
  6840. // }
  6841. //
  6842. // }
  6843. //
  6844. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6845. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6846. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6847. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6848. // if num1 > num2 {
  6849. // num = num1 - num2
  6850. // drug.Total = drug.Total + num
  6851. // service.UpdateBaseDrugLib(&drug)
  6852. // } else if num1 < num2 {
  6853. // num = num2 - num1
  6854. // drug.Total = drug.Total - num
  6855. // service.UpdateBaseDrugLib(&drug)
  6856. // }
  6857. //
  6858. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6859. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6860. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6861. // if hisAdvice.PrescribingNumber > num2 {
  6862. // num = hisAdvice.PrescribingNumber - num2
  6863. // drug.Total = drug.Total + num
  6864. // service.UpdateBaseDrugLib(&drug)
  6865. // } else if num2 < advice.PrescribingNumber {
  6866. // num = num2 - hisAdvice.PrescribingNumber
  6867. // drug.Total = drug.Total - num
  6868. // service.UpdateBaseDrugLib(&drug)
  6869. // }
  6870. //
  6871. // }
  6872. // }
  6873. // }
  6874. //}
  6875. //
  6876. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6877. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6878. // advice.ExecutionTime = execution_time
  6879. //}
  6880. //
  6881. //
  6882. //
  6883. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6884. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6885. // advice.ExecutionStaff = execution_staff
  6886. //}
  6887. //
  6888. //
  6889. //
  6890. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6891. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6892. // advice.ExecutionState = execution_state
  6893. //}
  6894. //
  6895. //
  6896. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6897. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6898. // advice.CheckTime = check_time
  6899. //}
  6900. //
  6901. //
  6902. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6903. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6904. // advice.CheckState = check_state
  6905. //}
  6906. //
  6907. //
  6908. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6909. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6910. // advice.Checker = checker
  6911. //}
  6912. //
  6913. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6914. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6915. // advice.StartTime = start_time
  6916. //}
  6917. return 0
  6918. }
  6919. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6920. project.ExecutionStaff = 0
  6921. project.ExecutionState = 2
  6922. project.ExecutionTime = 0
  6923. project.Checker = 0
  6924. project.CheckState = 2
  6925. project.CheckTime = 0
  6926. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6927. id := int64(json["id"].(float64))
  6928. project.ID = id
  6929. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6930. project.ExecutionStaff = temp_project.ExecutionStaff
  6931. project.ExecutionState = temp_project.ExecutionState
  6932. project.ExecutionTime = temp_project.ExecutionTime
  6933. project.Checker = temp_project.Checker
  6934. project.CheckState = temp_project.CheckState
  6935. project.CheckTime = temp_project.CheckTime
  6936. project.TeamId = temp_project.TeamId
  6937. }
  6938. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6939. types := int64(json["type"].(float64))
  6940. project.Type = types
  6941. }
  6942. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6943. project_id := int64(json["project_id"].(float64))
  6944. project.ProjectId = project_id
  6945. }
  6946. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6947. team_id := int64(json["team_id"].(float64))
  6948. project.TeamId = team_id
  6949. }
  6950. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6951. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6952. project.Price = price
  6953. }
  6954. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6955. total, _ := json["total"].(string)
  6956. //totals, _ := strconv.ParseInt(total, 10, 64)
  6957. project.Count = total
  6958. }
  6959. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6960. medical_code, _ := json["medical_code"].(string)
  6961. project.MedListCodg = medical_code
  6962. }
  6963. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6964. single_dose, _ := json["single_dose"].(string)
  6965. project.SingleDose = single_dose
  6966. }
  6967. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6968. delivery_way, _ := json["delivery_way"].(string)
  6969. project.DeliveryWay = delivery_way
  6970. }
  6971. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6972. execution_frequency, _ := json["execution_frequency"].(string)
  6973. project.ExecutionFrequency = execution_frequency
  6974. }
  6975. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6976. remark, _ := json["remark"].(string)
  6977. project.Remark = remark
  6978. }
  6979. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6980. day, _ := json["number_days"].(string)
  6981. project.Day = day
  6982. }
  6983. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6984. unit, _ := json["unit"].(string)
  6985. project.Unit = unit
  6986. }
  6987. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6988. // frequency_type := int64(json["frequency_type"].(float64))
  6989. // project.FrequencyType = frequency_type
  6990. //}
  6991. //
  6992. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6993. // day_count := int64(json["day_count"].(float64))
  6994. // project.DayCount = day_count
  6995. //}
  6996. //
  6997. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6998. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6999. // week_day, _ := json["week_day"].(string)
  7000. // project.WeekDay = week_day
  7001. //}
  7002. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7003. //
  7004. //if project.ID == 0 {
  7005. // if stockConfig.IsOpen == 1 {
  7006. // if project.Type == 3 {
  7007. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7008. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7009. // good.Total = good.Total - f_count
  7010. // service.UpdateGoodInfo(&good)
  7011. // }
  7012. // }
  7013. //
  7014. //} else {
  7015. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7016. //
  7017. // if stockConfig.IsOpen == 1 {
  7018. // if project.Type == 3 {
  7019. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7020. // if project.Count < temp_project.Count {
  7021. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7022. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7023. //
  7024. // other_count := f_count_two - f_count_one
  7025. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7026. // good.Total = good.Total + other_count_two
  7027. // service.UpdateGoodInfo(&good)
  7028. // } else if project.Count > temp_project.Count {
  7029. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7030. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7031. //
  7032. // other_count := f_count_one - f_count_two
  7033. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7034. // good.Total = good.Total - other_count_two
  7035. // service.UpdateGoodInfo(&good)
  7036. // }
  7037. //
  7038. // }
  7039. // }
  7040. //
  7041. //}
  7042. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7043. id := int64(json["id"].(float64))
  7044. if id > 0 {
  7045. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7046. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7047. fmt.Println("666666")
  7048. project.Mtime = time.Now().Unix()
  7049. project.Ctime = temp_project.Ctime
  7050. } else {
  7051. project.Mtime = temp_project.Mtime
  7052. project.Ctime = temp_project.Ctime
  7053. }
  7054. } else {
  7055. ctime := time.Now().Unix()
  7056. project.Mtime = ctime
  7057. project.Ctime = ctime
  7058. }
  7059. }
  7060. return 0
  7061. }
  7062. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7063. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7064. id := int64(json["id"].(float64))
  7065. additionalCharge.ID = id
  7066. }
  7067. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7068. item_id := int64(json["item_id"].(float64))
  7069. additionalCharge.ItemId = item_id
  7070. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7071. if config.ID > 0 {
  7072. if len(config.Code) > 0 {
  7073. additionalCharge.MedListCodg = config.Code
  7074. }
  7075. }
  7076. }
  7077. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7078. // price := int64(json["price"].(float64))
  7079. // formatInt_price := strconv.FormatInt(price, 10)
  7080. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7081. // additionalCharge.Price = float_price
  7082. // }
  7083. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7084. // price := int64(json["price"].(float64))
  7085. // formatInt_price := strconv.FormatInt(price, 10)
  7086. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7087. // additionalCharge.Price = float_price
  7088. //}
  7089. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7090. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7091. additionalCharge.Price = price
  7092. }
  7093. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7094. count, _ := json["count"].(string)
  7095. counts, _ := strconv.ParseInt(count, 10, 64)
  7096. additionalCharge.Count = counts
  7097. }
  7098. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7099. item_name, _ := json["item_name"].(string)
  7100. additionalCharge.ItemName = item_name
  7101. }
  7102. return 0
  7103. }
  7104. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7105. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7106. utils.ErrorLog("drug_name")
  7107. return enums.ErrorCodeParamWrong
  7108. }
  7109. adviceName, _ := json["drug_name"].(string)
  7110. if len(adviceName) == 0 {
  7111. utils.ErrorLog("len(advice_name) == 0")
  7112. return enums.ErrorCodeParamWrong
  7113. }
  7114. advice.AdviceName = adviceName
  7115. adviceDesc, _ := json["advice_desc"].(string)
  7116. advice.AdviceDesc = adviceDesc
  7117. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7118. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7119. advice.DrugSpec = drugSpec
  7120. }
  7121. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7122. remark, _ := json["remark"].(string)
  7123. advice.Remark = remark
  7124. }
  7125. if json["id"] == nil {
  7126. advice.DrugId = 0
  7127. } else {
  7128. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7129. drug_id := int64(json["id"].(float64))
  7130. advice.DrugId = drug_id
  7131. }
  7132. }
  7133. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7134. groupno := int64(json["groupno"].(float64))
  7135. advice.Groupno = groupno
  7136. }
  7137. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7138. drugSpecUnit, _ := json["min_unit"].(string)
  7139. advice.DrugSpecUnit = drugSpecUnit
  7140. }
  7141. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7142. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7143. advice.SingleDose = singleDose
  7144. }
  7145. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7146. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7147. advice.SingleDoseUnit = singleDoseUnit
  7148. }
  7149. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7150. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7151. advice.PrescribingNumber = prescribingNumber
  7152. }
  7153. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7154. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7155. advice.PrescribingNumberUnit = prescribingNumberUnit
  7156. }
  7157. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7158. deliveryWay, _ := json["delivery_way"].(string)
  7159. advice.DeliveryWay = deliveryWay
  7160. }
  7161. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7162. executionFrequency, _ := json["execution_frequency"].(string)
  7163. advice.ExecutionFrequency = executionFrequency
  7164. }
  7165. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7166. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7167. advice.Price = price
  7168. }
  7169. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7170. med_list_codg, _ := json["medical_insurance_number"].(string)
  7171. advice.MedListCodg = med_list_codg
  7172. }
  7173. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7174. day := int64(json["day"].(float64))
  7175. advice.Day = day
  7176. }
  7177. advice.FrequencyType = 1
  7178. return 0
  7179. }
  7180. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7181. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7182. types := int64(json["type"].(float64))
  7183. project.Type = types
  7184. }
  7185. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7186. project_id := int64(json["project_id"].(float64))
  7187. project.ProjectId = project_id
  7188. }
  7189. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7190. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7191. project.Price = price
  7192. }
  7193. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7194. total, _ := json["total"].(string)
  7195. //totals, _ := strconv.ParseInt(total, 10, 64)
  7196. project.Count = total
  7197. }
  7198. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7199. medical_code, _ := json["medical_code"].(string)
  7200. project.MedListCodg = medical_code
  7201. }
  7202. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7203. single_dose, _ := json["single_dose"].(string)
  7204. project.SingleDose = single_dose
  7205. }
  7206. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7207. delivery_way, _ := json["delivery_way"].(string)
  7208. project.DeliveryWay = delivery_way
  7209. }
  7210. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7211. execution_frequency, _ := json["execution_frequency"].(string)
  7212. project.ExecutionFrequency = execution_frequency
  7213. }
  7214. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7215. remark, _ := json["remark"].(string)
  7216. project.Remark = remark
  7217. }
  7218. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7219. day, _ := json["number_days"].(string)
  7220. project.Day = day
  7221. }
  7222. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7223. unit, _ := json["unit"].(string)
  7224. project.Unit = unit
  7225. }
  7226. project.FrequencyType = 1
  7227. return 0
  7228. }
  7229. func (c *HisApiController) GetHisOrderListTwo() {
  7230. start_time := c.GetString("start_time")
  7231. end_time := c.GetString("end_time")
  7232. timeLayout := "2006-01-02"
  7233. loc, _ := time.LoadLocation("Local")
  7234. var startTime int64
  7235. if len(start_time) > 0 {
  7236. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7237. if err != nil {
  7238. //fmt.Println(err)
  7239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7240. return
  7241. }
  7242. startTime = theTime.Unix()
  7243. }
  7244. var endTime int64
  7245. if len(end_time) > 0 {
  7246. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7247. if err != nil {
  7248. utils.ErrorLog(err.Error())
  7249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7250. return
  7251. }
  7252. endTime = theTime.Unix()
  7253. }
  7254. adminUser := c.GetAdminUserInfo()
  7255. org_id := adminUser.CurrentOrgId
  7256. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7257. if err == nil {
  7258. c.ServeSuccessJSON(map[string]interface{}{
  7259. "order2": order,
  7260. })
  7261. } else {
  7262. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7263. return
  7264. }
  7265. }
  7266. func (c *HisApiController) GetHisOrderList() {
  7267. page, _ := c.GetInt64("page", -1)
  7268. limit, _ := c.GetInt64("limit", -1)
  7269. start_time := c.GetString("start_time")
  7270. end_time := c.GetString("end_time")
  7271. types, _ := c.GetInt64("type", 0)
  7272. keywords := c.GetString("keywords")
  7273. p_type, _ := c.GetInt64("p_type", 0)
  7274. sort_type, _ := c.GetInt64("sort_type", 0)
  7275. charge_type, _ := c.GetInt64("charge_type", 0)
  7276. sch_type, _ := c.GetInt64("sch_type", 0)
  7277. zone_type, _ := c.GetInt64("zone_type", 0)
  7278. med_type, _ := c.GetInt64("med_type", 0)
  7279. timeLayout := "2006-01-02"
  7280. loc, _ := time.LoadLocation("Local")
  7281. var startTime int64
  7282. if len(start_time) > 0 {
  7283. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7284. if err != nil {
  7285. //fmt.Println(err)
  7286. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7287. return
  7288. }
  7289. startTime = theTime.Unix()
  7290. }
  7291. var endTime int64
  7292. if len(end_time) > 0 {
  7293. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7294. if err != nil {
  7295. utils.ErrorLog(err.Error())
  7296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7297. return
  7298. }
  7299. endTime = theTime.Unix()
  7300. }
  7301. adminUser := c.GetAdminUserInfo()
  7302. org_id := adminUser.CurrentOrgId
  7303. 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)
  7304. for _, item := range order {
  7305. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7306. item.DoctorName = info.Doctor
  7307. item.DepartmentName = info.XtHisDepartment.Name
  7308. }
  7309. if err == nil {
  7310. c.ServeSuccessJSON(map[string]interface{}{
  7311. "order": order,
  7312. "total": total,
  7313. })
  7314. } else {
  7315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7316. return
  7317. }
  7318. }
  7319. func (c *HisApiController) GetHisOrder() {
  7320. patient_id, _ := c.GetInt64("patient_id", 0)
  7321. number := c.GetString("number")
  7322. adminInfo := c.GetAdminUserInfo()
  7323. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7324. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7325. if err == nil {
  7326. c.ServeSuccessJSON(map[string]interface{}{
  7327. "order": order,
  7328. "prescription": prescriptions,
  7329. })
  7330. } else {
  7331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7332. return
  7333. }
  7334. }
  7335. func (c *HisApiController) GetHisPrescriptionList() {
  7336. record_date := c.GetString("record_date")
  7337. keywords := c.GetString("keywords")
  7338. page, _ := c.GetInt64("page")
  7339. limit, _ := c.GetInt64("limit")
  7340. sch_type, _ := c.GetInt64("sch_type")
  7341. timeLayout := "2006-01-02"
  7342. loc, _ := time.LoadLocation("Local")
  7343. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7344. if err != nil {
  7345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7346. return
  7347. }
  7348. recordDateTime := theTime.Unix()
  7349. adminInfo := c.GetAdminUserInfo()
  7350. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7351. //adminInfo := c.GetAdminUserInfo()
  7352. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7353. //fmt.Println(prescriptionOrder)
  7354. if err == nil {
  7355. c.ServeSuccessJSON(map[string]interface{}{
  7356. "order": prescriptionOrder,
  7357. "total": total,
  7358. })
  7359. } else {
  7360. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7361. return
  7362. }
  7363. }
  7364. func (c *HisApiController) GetHisPrescriptionInfo() {
  7365. id, _ := c.GetInt64("id")
  7366. adminInfo := c.GetAdminUserInfo()
  7367. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7368. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7369. if err == nil {
  7370. c.ServeSuccessJSON(map[string]interface{}{
  7371. "order": prescriptionOrder,
  7372. "prescription": prescription,
  7373. })
  7374. } else {
  7375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7376. return
  7377. }
  7378. }
  7379. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7380. adminUser := c.GetAdminUserInfo()
  7381. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7382. c.ServeSuccessJSON(map[string]interface{}{
  7383. "config": config,
  7384. })
  7385. }
  7386. type ResultTwo struct {
  7387. ErrMsg interface{} `json:"err_msg"`
  7388. InfRefmsgid string `json:"inf_refmsgid"`
  7389. Infcode int64 `json:"infcode"`
  7390. Output struct {
  7391. Baseinfo struct {
  7392. Age float64 `json:"age"`
  7393. Brdy string `json:"brdy"`
  7394. Certno string `json:"certno"`
  7395. Gend string `json:"gend"`
  7396. Naty string `json:"naty"`
  7397. PsnCertType string `json:"psn_cert_type"`
  7398. PsnName string `json:"psn_name"`
  7399. PsnNo string `json:"psn_no"`
  7400. } `json:"baseinfo"`
  7401. Idetinfo []interface{} `json:"idetinfo"`
  7402. Iinfo []struct {
  7403. Balc float64 `json:"balc"`
  7404. CvlservFlag string `json:"cvlserv_flag"`
  7405. EmpName string `json:"emp_name"`
  7406. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7407. Insutype string `json:"insutype"`
  7408. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7409. PausInsuDate interface{} `json:"paus_insu_date"`
  7410. PsnInsuDate string `json:"psn_insu_date"`
  7411. PsnInsuStas string `json:"psn_insu_stas"`
  7412. PsnType string `json:"psn_type"`
  7413. } `json:"insuinfo"`
  7414. } `json:"output"`
  7415. RefmsgTime string `json:"refmsg_time"`
  7416. RespondTime string `json:"respond_time"`
  7417. Signtype interface{} `json:"signtype"`
  7418. WarnInfo interface{} `json:"warn_info"`
  7419. }
  7420. type ResultThree struct {
  7421. Cainfo interface{} `json:"cainfo"`
  7422. ErrMsg interface{} `json:"err_msg"`
  7423. InfRefmsgid string `json:"inf_refmsgid"`
  7424. Infcode int64 `json:"infcode"`
  7425. Output struct {
  7426. Data struct {
  7427. IptOtpNo string `json:"ipt_otp_no"`
  7428. MdtrtID string `json:"mdtrt_id"`
  7429. PsnNo string `json:"psn_no"`
  7430. } `json:"data"`
  7431. } `json:"output"`
  7432. RefmsgTime string `json:"refmsg_time"`
  7433. RespondTime string `json:"respond_time"`
  7434. Signtype interface{} `json:"signtype"`
  7435. WarnMsg interface{} `json:"warn_msg"`
  7436. }
  7437. type ResultFour struct {
  7438. Cainfo string `json:"cainfo"`
  7439. ErrMsg string `json:"err_msg"`
  7440. InfRefmsgid string `json:"inf_refmsgid"`
  7441. Infcode int64 `json:"infcode"`
  7442. Output struct {
  7443. Result []struct {
  7444. BasMednFlag string `json:"bas_medn_flag"`
  7445. ChldMedcFlag string `json:"chld_medc_flag"`
  7446. ChrgitmLv string `json:"chrgitm_lv"`
  7447. Cnt float64 `json:"cnt"`
  7448. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  7449. DrtReimFlag string `json:"drt_reim_flag"`
  7450. FeedetlSn string `json:"feedetl_sn"`
  7451. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7452. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  7453. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7454. ListSpItemFlag string `json:"list_sp_item_flag"`
  7455. LmtUsedFlag string `json:"lmt_used_flag"`
  7456. MedChrgitmType string `json:"med_chrgitm_type"`
  7457. Memo string `json:"memo"`
  7458. OverlmtAmt float64 `json:"overlmt_amt"`
  7459. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7460. Pric float64 `json:"pric"`
  7461. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  7462. SelfpayProp float64 `json:"selfpay_prop"`
  7463. } `json:"result"`
  7464. } `json:"output"`
  7465. RefmsgTime string `json:"refmsg_time"`
  7466. RespondTime string `json:"respond_time"`
  7467. Signtype string `json:"signtype"`
  7468. WarnMsg string `json:"warn_msg"`
  7469. }
  7470. type ResultFive struct {
  7471. Insutype string `json:"insutype"`
  7472. }
  7473. type ResultSix struct {
  7474. Cainfo interface{} `json:"cainfo"`
  7475. ErrMsg interface{} `json:"err_msg"`
  7476. InfRefmsgid string `json:"inf_refmsgid"`
  7477. Infcode int64 `json:"infcode"`
  7478. Output struct {
  7479. } `json:"output"`
  7480. RefmsgTime string `json:"refmsg_time"`
  7481. RespondTime string `json:"respond_time"`
  7482. Signtype interface{} `json:"signtype"`
  7483. WarnMsg interface{} `json:"warn_msg"`
  7484. }
  7485. type ResultSeven struct {
  7486. Cainfo string `json:"cainfo"`
  7487. ErrMsg string `json:"err_msg"`
  7488. InfRefmsgid string `json:"inf_refmsgid"`
  7489. Infcode int64 `json:"infcode"`
  7490. Output struct {
  7491. Setldetail []interface{} `json:"setldetail"`
  7492. Setlinfo struct {
  7493. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7494. AcctPay float64 `json:"acct_pay"`
  7495. ActPayDedc float64 `json:"act_pay_dedc"`
  7496. Age float64 `json:"age"`
  7497. Balc float64 `json:"balc"`
  7498. Brdy string `json:"brdy"`
  7499. Certno string `json:"certno"`
  7500. ClrOptins string `json:"clr_optins"`
  7501. ClrType string `json:"clr_type"`
  7502. ClrWay string `json:"clr_way"`
  7503. CvlservFlag string `json:"cvlserv_flag"`
  7504. CvlservPay float64 `json:"cvlserv_pay"`
  7505. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7506. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7507. Gend string `json:"gend"`
  7508. HifesPay float64 `json:"hifes_pay"`
  7509. HifmiPay float64 `json:"hifmi_pay"`
  7510. HifobPay float64 `json:"hifob_pay"`
  7511. HifpPay float64 `json:"hifp_pay"`
  7512. HospPartAmt float64 `json:"hosp_part_amt"`
  7513. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7514. Insutype string `json:"insutype"`
  7515. MafPay float64 `json:"maf_pay"`
  7516. MdtrtCertType string `json:"mdtrt_cert_type"`
  7517. MdtrtID string `json:"mdtrt_id"`
  7518. MedType string `json:"med_type"`
  7519. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7520. MedinsSetlID string `json:"medins_setl_id"`
  7521. Naty string `json:"naty"`
  7522. OthPay float64 `json:"oth_pay"`
  7523. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7524. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7525. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7526. PsnCashPay float64 `json:"psn_cash_pay"`
  7527. PsnCertType string `json:"psn_cert_type"`
  7528. PsnName string `json:"psn_name"`
  7529. PsnNo string `json:"psn_no"`
  7530. PsnPartAmt float64 `json:"psn_part_amt"`
  7531. PsnType string `json:"psn_type"`
  7532. SetlID string `json:"setl_id"`
  7533. SetlTime string `json:"setl_time"`
  7534. } `json:"setlinfo"`
  7535. } `json:"output"`
  7536. RefmsgTime string `json:"refmsg_time"`
  7537. RespondTime string `json:"respond_time"`
  7538. Signtype interface{} `json:"signtype"`
  7539. WarnMsg interface{} `json:"warn_msg"`
  7540. }
  7541. type ResultEight struct {
  7542. Cainfo string `json:"cainfo"`
  7543. ErrMsg string `json:"err_msg"`
  7544. InfRefmsgid string `json:"inf_refmsgid"`
  7545. Infcode int64 `json:"infcode"`
  7546. Output struct {
  7547. Stmtinfo struct {
  7548. SetlOptins string `json:"setl_optins"`
  7549. StmtRslt string `json:"stmt_rslt"`
  7550. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  7551. } `json:"stmtinfo"`
  7552. } `json:"output"`
  7553. RefmsgTime string `json:"refmsg_time"`
  7554. RespondTime string `json:"respond_time"`
  7555. Signtype interface{} `json:"signtype"`
  7556. WarnMsg interface{} `json:"warn_msg"`
  7557. }
  7558. type ResultNine struct {
  7559. Cainfo string `json:"cainfo"`
  7560. ErrMsg string `json:"err_msg"`
  7561. InfRefmsgid string `json:"inf_refmsgid"`
  7562. Infcode int64 `json:"infcode"`
  7563. Output struct {
  7564. FileQuryNo string `json:"file_qury_no"`
  7565. } `json:"output"`
  7566. RefmsgTime string `json:"refmsg_time"`
  7567. RespondTime string `json:"respond_time"`
  7568. Signtype interface{} `json:"signtype"`
  7569. WarnMsg interface{} `json:"warn_msg"`
  7570. }
  7571. type ResultTen struct {
  7572. Cainfo string `json:"cainfo"`
  7573. ErrMsg string `json:"err_msg"`
  7574. InfRefmsgid string `json:"inf_refmsgid"`
  7575. Infcode int64 `json:"infcode"`
  7576. Output struct {
  7577. DldEndtime string `json:"dld_endtime"`
  7578. FileQuryNo string `json:"file_qury_no"`
  7579. Filename string `json:"filename"`
  7580. } `json:"output"`
  7581. RefmsgTime string `json:"refmsg_time"`
  7582. RespondTime string `json:"respond_time"`
  7583. Signtype interface{} `json:"signtype"`
  7584. WarnMsg interface{} `json:"warn_msg"`
  7585. }
  7586. type ResultEleven struct {
  7587. Cainfo string `json:"cainfo"`
  7588. ErrMsg string `json:"err_msg"`
  7589. InfRefmsgid string `json:"inf_refmsgid"`
  7590. Infcode int64 `json:"infcode"`
  7591. Output struct {
  7592. Setlinfo struct {
  7593. FixmedinsName string `json:"fixmedins_name"`
  7594. FixmedinsCode string `json:"fixmedins_code"`
  7595. PsnNo string `json:"psn_no"`
  7596. PsnName string `json:"psn_name"`
  7597. HifobPay float64 `json:"hifob_pay"`
  7598. Gend string `json:"gend"`
  7599. Brdy string `json:"brdy"`
  7600. PsnCertType string `json:"psn_cert_type"`
  7601. PsnType string `json:"psn_type"`
  7602. EmpName string `json:"emp_name"`
  7603. Certno string `json:"certno"`
  7604. Insutype string `json:"insutype"`
  7605. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7606. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7607. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7608. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7609. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7610. ActPayDedc float64 `json:"act_pay_dedc"`
  7611. HifpPay float64 `json:"hifp_pay"`
  7612. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7613. CvlservPay float64 `json:"cvlserv_pay"`
  7614. HifesPay float64 `json:"hifes_pay"`
  7615. HifmiPay float64 `json:"hifmi_pay"`
  7616. MafPay float64 `json:"maf_pay"`
  7617. OthPay float64 `json:"oth_pay"`
  7618. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7619. PsnPay float64 `json:"psn_pay"`
  7620. AcctPay float64 `json:"acct_pay"`
  7621. CashPayamt float64 `json:"cash_payamt"`
  7622. Balc float64 `json:"balc"`
  7623. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7624. MedinsSetlId string `json:"medins_setl_id"`
  7625. RefdSetlFlag string `json:"refd_setl_flag"`
  7626. SetlTime string `json:"setl_time"`
  7627. MedType string `json:"med_type"`
  7628. } `json:"setlinfo"`
  7629. } `json:"output"`
  7630. RefmsgTime string `json:"refmsg_time"`
  7631. RespondTime string `json:"respond_time"`
  7632. Signtype interface{} `json:"signtype"`
  7633. WarnMsg interface{} `json:"warn_msg"`
  7634. }
  7635. type Custom struct {
  7636. DetItemFeeSumamt string
  7637. Cut string
  7638. FeedetlSn string
  7639. Price string
  7640. MedListCodg string
  7641. Type int64
  7642. AdviceId int64
  7643. ProjectId int64
  7644. ItemId int64
  7645. }
  7646. // 获取个人信息----挂号-----上传就诊信息
  7647. func (c *HisApiController) GetRegisterInfo() {
  7648. id, _ := c.GetInt64("id")
  7649. record_time := c.GetString("record_time")
  7650. settlementValue, _ := c.GetInt64("settlement_value")
  7651. medical_insurance_card := c.GetString("medical_insurance_card")
  7652. name := c.GetString("name")
  7653. id_card_type, _ := c.GetInt64("id_card_type")
  7654. certificates, _ := c.GetInt64("certificates")
  7655. medical_care, _ := c.GetInt64("medical_care")
  7656. birthday := c.GetString("birthday")
  7657. age, _ := c.GetInt64("age")
  7658. id_card := c.GetString("id_card")
  7659. register_type, _ := c.GetInt64("register")
  7660. doctor, _ := c.GetInt64("doctor")
  7661. department, _ := c.GetInt64("department")
  7662. gender, _ := c.GetInt64("sex")
  7663. phone := c.GetString("phone")
  7664. registration_fee, _ := c.GetFloat("registration_fee")
  7665. medical_expenses, _ := c.GetFloat("medical_expenses")
  7666. social_type, _ := c.GetInt64("social_type")
  7667. //diagnosis_id, _ := c.GetInt64("diagnosis")
  7668. diagnosis_ids := c.GetString("diagnosis")
  7669. sick_type, _ := c.GetInt64("sick_type")
  7670. reg_type := c.GetString("p_type")
  7671. timeLayout := "2006-01-02"
  7672. loc, _ := time.LoadLocation("Local")
  7673. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  7674. birthUnix := birthdays.Unix()
  7675. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7676. if err != nil {
  7677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7678. return
  7679. }
  7680. recordDateTime := theTime.Unix()
  7681. adminInfo := c.GetAdminUserInfo()
  7682. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  7683. if tempPatient.ID == 0 {
  7684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  7685. return
  7686. }
  7687. var patient service.Patients
  7688. if id == 0 {
  7689. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  7690. } else {
  7691. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  7692. }
  7693. if patient.ID == 0 {
  7694. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7695. return
  7696. }
  7697. if len(patient.IdCardNo) == 0 {
  7698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  7699. return
  7700. }
  7701. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7702. if len(his) >= 1 {
  7703. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  7704. if len(his) >= 1 && order.ID == 0 {
  7705. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  7706. return
  7707. }
  7708. }
  7709. timeStr := time.Now().Format("2006-01-02 15:04:05")
  7710. fmt.Println(timeStr)
  7711. timeArr := strings.Split(timeStr, " ")
  7712. fmt.Println(timeArr)
  7713. timeArrTwo := strings.Split(timeArr[0], "-")
  7714. timeArrThree := strings.Split(timeArr[1], ":")
  7715. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  7716. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7717. if len(lists) == 0 {
  7718. var hisPatient models.XtHisPatient
  7719. hisPatient = models.XtHisPatient{
  7720. Name: name,
  7721. Age: age,
  7722. Gender: gender,
  7723. Birthday: birthUnix,
  7724. Phone: phone,
  7725. MedicalTreatmentType: medical_care,
  7726. IdType: certificates,
  7727. IdCardNo: id_card,
  7728. BalanceAccountsType: settlementValue,
  7729. SocialType: social_type,
  7730. MedicalInsuranceNumber: medical_insurance_card,
  7731. RegisterType: register_type,
  7732. RegisterCost: registration_fee,
  7733. TreatmentCost: medical_expenses,
  7734. AdminUserId: adminInfo.AdminUser.Id,
  7735. UserOrgId: adminInfo.CurrentOrgId,
  7736. Status: 1,
  7737. RecordDate: recordDateTime,
  7738. IsReturn: 1,
  7739. PatientId: patient.ID,
  7740. Ctime: time.Now().Unix(),
  7741. Mtime: time.Now().Unix(),
  7742. Number: str,
  7743. IdCardType: id_card_type,
  7744. Departments: department,
  7745. Doctor: doctor,
  7746. PType: reg_type,
  7747. Diagnosis: diagnosis_ids,
  7748. SickType: sick_type,
  7749. }
  7750. service.CreateHisPatient(&hisPatient)
  7751. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7752. c.ServeSuccessJSON(map[string]interface{}{
  7753. "his_info": hisPatient,
  7754. })
  7755. } else {
  7756. //chrgBchno := rand.Intn(1000000) + 10000
  7757. var hisPatient models.XtHisPatient
  7758. hisPatient = models.XtHisPatient{
  7759. Name: name,
  7760. Age: age,
  7761. Gender: gender,
  7762. Birthday: birthUnix,
  7763. Phone: phone,
  7764. MedicalTreatmentType: medical_care,
  7765. IdType: certificates,
  7766. IdCardNo: id_card,
  7767. BalanceAccountsType: settlementValue,
  7768. SocialType: social_type,
  7769. MedicalInsuranceNumber: medical_insurance_card,
  7770. RegisterType: register_type,
  7771. RegisterCost: registration_fee,
  7772. TreatmentCost: medical_expenses,
  7773. AdminUserId: adminInfo.AdminUser.Id,
  7774. UserOrgId: adminInfo.CurrentOrgId,
  7775. Status: 1,
  7776. RecordDate: recordDateTime,
  7777. IsReturn: 1,
  7778. PatientId: patient.ID,
  7779. Ctime: time.Now().Unix(),
  7780. Mtime: time.Now().Unix(),
  7781. Number: str,
  7782. IdCardType: id_card_type,
  7783. Departments: department,
  7784. Doctor: doctor,
  7785. PType: reg_type,
  7786. Diagnosis: diagnosis_ids,
  7787. SickType: sick_type,
  7788. }
  7789. service.CreateHisPatient(&hisPatient)
  7790. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7791. c.ServeSuccessJSON(map[string]interface{}{
  7792. "his_info": hisPatient,
  7793. })
  7794. }
  7795. }
  7796. // 上传明细----结算
  7797. func (c *HisApiController) GetUploadInfo() {
  7798. id, _ := c.GetInt64("id")
  7799. record_time := c.GetString("record_time")
  7800. his_patient_id, _ := c.GetInt64("his_patient_id")
  7801. oth_desc := c.GetString("oth_desc")
  7802. pay_way, _ := c.GetInt64("pay_way")
  7803. pay_ways := c.GetString("pay_ways")
  7804. pay_price, _ := c.GetFloat("pay_price")
  7805. pay_card_no := c.GetString("pay_card_no")
  7806. discount_price, _ := c.GetFloat("discount_price")
  7807. preferential_price, _ := c.GetFloat("preferential_price")
  7808. reality_price, _ := c.GetFloat("reality_price")
  7809. found_price, _ := c.GetFloat("found_price")
  7810. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7811. private_price, _ := c.GetFloat("private_price")
  7812. timeLayout := "2006-01-02"
  7813. loc, _ := time.LoadLocation("Local")
  7814. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7815. fapiao_code := c.GetString("fapiao_code")
  7816. fapiao_number := c.GetString("fapiao_number")
  7817. diagnosis_id := c.GetString("diagnosis")
  7818. sick_type, _ := c.GetInt64("sick_type")
  7819. reg_type, _ := c.GetInt64("p_type")
  7820. order_id, _ := c.GetInt64("order_id")
  7821. cash_pay := c.GetString("cash_pay")
  7822. wechat_pay := c.GetString("wechat_pay")
  7823. ali_pay := c.GetString("ali_pay")
  7824. jifen_pay := c.GetString("jifen_pay")
  7825. band_card_pay := c.GetString("band_card_pay")
  7826. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7827. tmp_decimal := c.GetString("tmp_decimal")
  7828. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7829. var decimal float64 //本次使用的押金
  7830. var errmsg error
  7831. tx := service.XTWriteDB().Begin() //开了事务
  7832. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7833. defer func() {
  7834. if errmsg != nil {
  7835. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7836. tx.Rollback()
  7837. } else {
  7838. tx.Commit()
  7839. }
  7840. }()
  7841. fmt.Println("dec_way", dec_way)
  7842. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7843. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7844. return
  7845. }
  7846. if len(tmp_decimal) > 0 {
  7847. if tmp_decimal[0] == 45 {
  7848. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7849. return
  7850. }
  7851. }
  7852. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7853. fmt.Println(errs)
  7854. decimal = tt
  7855. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7856. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7857. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7858. if err != nil {
  7859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7860. return
  7861. }
  7862. recordDateTime := theTime.Unix()
  7863. adminUser := c.GetAdminUserInfo()
  7864. var prescriptions []*models.HisPrescription
  7865. var prescriptionsOne []*models.HisPrescription
  7866. var start_time int64
  7867. var end_time int64
  7868. ids_str := c.GetString("ids")
  7869. ids_arr := strings.Split(ids_str, ",")
  7870. if tempOrder.ID == 0 {
  7871. if settle_accounts_type == 1 { //日结
  7872. fmt.Println(reg_type)
  7873. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7874. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7875. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7876. } else {
  7877. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7878. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7879. }
  7880. } else { //月结
  7881. start_time_str := c.GetString("start_time")
  7882. end_time_str := c.GetString("end_time")
  7883. timeLayout := "2006-01-02"
  7884. loc, _ := time.LoadLocation("Local")
  7885. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7886. if err != nil {
  7887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7888. return
  7889. }
  7890. recordStartTime := theStartTime.Unix()
  7891. start_time = recordStartTime
  7892. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7893. if err != nil {
  7894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7895. return
  7896. }
  7897. recordEndTime := theEndTime.Unix()
  7898. end_time = recordEndTime
  7899. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7900. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7901. }
  7902. var goods []*models.DialysisBeforePrepareGoods
  7903. var newGoods []*models.NewDialysisBeforePrepareGoods
  7904. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7905. var infos []*models.HisDoctorAdviceInfo
  7906. var infoList []*models.HisDoctorAdviceInfo
  7907. var hisAdvice []*models.HisDoctorAdviceInfo
  7908. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7909. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7910. //判断库存不足
  7911. //结算出库开关
  7912. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7913. if settConfig.IsOpen == 1 {
  7914. //判断库存的地方
  7915. for _, info := range prescriptions {
  7916. if info.Type == 1 {
  7917. infos = append(infos, info.HisDoctorAdviceInfo...)
  7918. }
  7919. if info.Type == 2 {
  7920. for _, sumItem := range info.HisPrescriptionProject {
  7921. if sumItem.Type == 3 {
  7922. var good models.DialysisBeforePrepareGoods
  7923. var newGood models.NewDialysisBeforePrepareGoods
  7924. good.GoodId = sumItem.GoodInfo.ID
  7925. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7926. count, _ := strconv.Atoi(sumItem.Count)
  7927. good.Count = int64(count)
  7928. good.StorehouseId = houseConfig.StorehouseOutInfo
  7929. good.ProjectId = sumItem.ID
  7930. goods = append(goods, &good)
  7931. newGood.GoodId = sumItem.GoodInfo.ID
  7932. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7933. count2, _ := strconv.Atoi(sumItem.Count)
  7934. newGood.Count = int64(count2)
  7935. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7936. newGood.ProjectId = sumItem.ID
  7937. newGoods = append(newGoods, &newGood)
  7938. }
  7939. }
  7940. }
  7941. }
  7942. for _, info := range prescriptionsOne {
  7943. if info.Type == 1 {
  7944. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7945. }
  7946. if info.Type == 2 {
  7947. for _, sumItem := range info.HisPrescriptionProject {
  7948. if sumItem.Type == 3 {
  7949. var newGood models.NewDialysisBeforePrepareGoods
  7950. newGood.GoodId = sumItem.GoodInfo.ID
  7951. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7952. count2, _ := strconv.Atoi(sumItem.Count)
  7953. newGood.Count = int64(count2)
  7954. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7955. newGood.ProjectId = sumItem.ID
  7956. newGoodOne = append(newGoodOne, &newGood)
  7957. }
  7958. }
  7959. }
  7960. }
  7961. //判断
  7962. for _, itemOne := range infos {
  7963. for _, itemTwo := range hisAdvice {
  7964. if itemOne.DrugId == itemTwo.DrugId {
  7965. itemTwo.Child = append(itemTwo.Child, itemOne)
  7966. }
  7967. }
  7968. }
  7969. for _, itemTwo := range hisAdvice {
  7970. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7971. var sum_out_count int64
  7972. for _, itemThree := range itemTwo.Child {
  7973. var prescribing_number int64
  7974. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7975. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7976. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7977. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7978. }
  7979. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7980. prescribing_number = parseIntPrescribingNumber
  7981. }
  7982. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7983. prescribing_number = parseIntPrescribingNumber
  7984. }
  7985. sum_out_count += prescribing_number
  7986. }
  7987. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  7988. if sum_out_count > drugStockOut.FlushCount {
  7989. c.ServeSuccessJSON(map[string]interface{}{
  7990. "msg": "2",
  7991. "drug": medical,
  7992. })
  7993. return
  7994. }
  7995. }
  7996. for _, itemOne := range newGoods {
  7997. for _, item := range newGoodOne {
  7998. if itemOne.GoodId == item.GoodId {
  7999. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8000. }
  8001. }
  8002. }
  8003. for _, item := range newGoodOne {
  8004. var sum_out_count_one int64
  8005. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8006. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8007. sum_out_count_one += itemOne.Count
  8008. }
  8009. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8010. fmt.Println("sum_out_count_one", sum_out_count_one)
  8011. fmt.Println("list.FlushCount", list.FlushCount)
  8012. if sum_out_count_one > list.FlushCount {
  8013. c.ServeSuccessJSON(map[string]interface{}{
  8014. "msg": "3",
  8015. "good": good,
  8016. })
  8017. return
  8018. }
  8019. }
  8020. }
  8021. timestamp := time.Now().Unix()
  8022. tempTime := time.Unix(timestamp, 0)
  8023. timeFormat := tempTime.Format("20060102150405")
  8024. chrgBchno := rand.Intn(100000) + 10000
  8025. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8026. strconv.FormatInt(his.PatientId, 10)
  8027. var ids []int64
  8028. for _, item := range prescriptions {
  8029. ids = append(ids, item.ID)
  8030. }
  8031. var total float64
  8032. for _, item := range prescriptions {
  8033. fmt.Println(item)
  8034. if item.Type == 1 { //药品
  8035. for _, subItem := range item.HisDoctorAdviceInfo {
  8036. total = total + (subItem.Price * subItem.PrescribingNumber)
  8037. }
  8038. }
  8039. if item.Type == 2 { //项目
  8040. for _, subItem := range item.HisPrescriptionProject {
  8041. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8042. total = total + (subItem.Price * cnt)
  8043. }
  8044. }
  8045. for _, subItem := range item.HisAdditionalCharge {
  8046. total = total + (subItem.Price * float64(subItem.Count))
  8047. }
  8048. }
  8049. if reg_type == 1111 || reg_type == 1112 {
  8050. reg_type = 11
  8051. }
  8052. tm := time.Unix(time.Now().Unix(), 0)
  8053. allTotal := fmt.Sprintf("%.4f", total)
  8054. totals, _ := strconv.ParseFloat(allTotal, 64)
  8055. order := &models.HisOrder{
  8056. UserOrgId: adminUser.CurrentOrgId,
  8057. HisPatientId: his.ID,
  8058. PatientId: id,
  8059. SettleAccountsDate: recordDateTime,
  8060. Ctime: time.Now().Unix(),
  8061. Mtime: time.Now().Unix(),
  8062. Status: 1,
  8063. OrderStatus: 2,
  8064. MdtrtId: his.Number,
  8065. Number: chrg_bchno,
  8066. MedfeeSumamt: totals,
  8067. PayWay: pay_way,
  8068. PayWays: pay_ways,
  8069. PayPrice: pay_price,
  8070. MedType: strconv.Itoa(int(reg_type)),
  8071. PayCardNo: pay_card_no,
  8072. DiscountPrice: discount_price,
  8073. PreferentialPrice: preferential_price,
  8074. RealityPrice: reality_price,
  8075. FoundPrice: found_price,
  8076. MedicalInsurancePrice: medical_insurance_price,
  8077. PrivatePrice: private_price,
  8078. SettleEndTime: end_time,
  8079. SettleStartTime: start_time,
  8080. PsnPartAmt: totals,
  8081. PsnCashPay: totals,
  8082. SettleType: settle_accounts_type,
  8083. FaPiaoCode: fapiao_code,
  8084. FaPiaoNumber: fapiao_number,
  8085. Diagnosis: diagnosis_id,
  8086. PType: 2,
  8087. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8088. Decimal: decimal,
  8089. OthDesc: oth_desc,
  8090. CashPay: cash_pay,
  8091. WechatPay: wechat_pay,
  8092. AliPay: ali_pay,
  8093. JifenPay: jifen_pay,
  8094. BandCardPay: band_card_pay,
  8095. Creator: adminUser.AdminUser.Id,
  8096. }
  8097. err = service.CreateOrderTX(order, tx)
  8098. if err != nil {
  8099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8100. return
  8101. }
  8102. var customs []*Custom
  8103. for _, item := range prescriptions {
  8104. if item.Type == 1 { //药品a
  8105. for _, subItem := range item.HisDoctorAdviceInfo {
  8106. cus := &Custom{
  8107. AdviceId: subItem.ID,
  8108. ProjectId: 0,
  8109. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8110. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8111. FeedetlSn: subItem.FeedetlSn,
  8112. Price: fmt.Sprintf("%.4f", subItem.Price),
  8113. MedListCodg: subItem.MedListCodg,
  8114. Type: 1,
  8115. }
  8116. customs = append(customs, cus)
  8117. }
  8118. }
  8119. if item.Type == 2 { //项目
  8120. for _, subItem := range item.HisPrescriptionProject {
  8121. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8122. cus := &Custom{
  8123. AdviceId: 0,
  8124. ProjectId: subItem.ID,
  8125. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8126. Cut: fmt.Sprintf("%.4f", cnt),
  8127. FeedetlSn: subItem.FeedetlSn,
  8128. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8129. MedListCodg: subItem.MedListCodg,
  8130. Type: 2,
  8131. }
  8132. customs = append(customs, cus)
  8133. }
  8134. }
  8135. for _, item := range item.HisAdditionalCharge {
  8136. cus := &Custom{
  8137. ItemId: item.ID,
  8138. AdviceId: 0,
  8139. ProjectId: 0,
  8140. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8141. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8142. FeedetlSn: item.FeedetlSn,
  8143. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8144. MedListCodg: item.XtHisAddtionConfig.Code,
  8145. Type: 3,
  8146. }
  8147. customs = append(customs, cus)
  8148. }
  8149. }
  8150. for _, item := range customs {
  8151. var advice_id int64 = 0
  8152. var project_id int64 = 0
  8153. var item_id int64 = 0
  8154. var types int64 = 0
  8155. if item.Type == 1 {
  8156. advice_id = item.AdviceId
  8157. project_id = 0
  8158. item_id = 0
  8159. } else if item.Type == 2 {
  8160. advice_id = 0
  8161. item_id = 0
  8162. project_id = item.ProjectId
  8163. } else if item.Type == 3 {
  8164. advice_id = 0
  8165. item_id = item.ItemId
  8166. project_id = 0
  8167. }
  8168. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8169. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8170. pric, _ := strconv.ParseFloat(item.Price, 32)
  8171. info := &models.HisOrderInfo{
  8172. OrderNumber: order.Number,
  8173. UploadDate: time.Now().Unix(),
  8174. AdviceId: advice_id,
  8175. DetItemFeeSumamt: detItemFeeSumamt,
  8176. Cnt: cut,
  8177. Pric: pric,
  8178. PatientId: id,
  8179. Status: 1,
  8180. Mtime: time.Now().Unix(),
  8181. Ctime: time.Now().Unix(),
  8182. UserOrgId: adminUser.CurrentOrgId,
  8183. HisPatientId: his.ID,
  8184. OrderId: order.ID,
  8185. ProjectId: project_id,
  8186. Type: types,
  8187. ItemId: item_id,
  8188. }
  8189. service.CreateOrderInfoTX(info, tx)
  8190. }
  8191. his.Diagnosis = diagnosis_id
  8192. his.SickType = sick_type
  8193. his.RegisterType = reg_type
  8194. his.MedicalTreatmentType = reg_type
  8195. service.UpdataHisPateintTX(&his, tx)
  8196. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8197. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8198. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8199. //判断是否使用了押金
  8200. if dec_way == "true" {
  8201. tmpstring := strconv.FormatInt(order.ID, 10)
  8202. //扣押金
  8203. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8204. order.Decimal = decimal
  8205. service.UpDateOrderTwo(order, tx)
  8206. if errmsg != nil {
  8207. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8208. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8209. return
  8210. }
  8211. }
  8212. if err == nil {
  8213. for _, info := range prescriptions {
  8214. if info.Type == 1 {
  8215. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8216. }
  8217. if info.Type == 2 {
  8218. for _, sumItem := range info.HisPrescriptionProject {
  8219. if sumItem.Type == 3 {
  8220. var good models.DialysisBeforePrepareGoods
  8221. var newGood models.NewDialysisBeforePrepareGoods
  8222. var oldGood models.OldDialysisBeforePrepareGoods
  8223. good.GoodId = sumItem.GoodInfo.ID
  8224. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8225. count, _ := strconv.Atoi(sumItem.Count)
  8226. good.Count = int64(count)
  8227. good.StorehouseId = houseConfig.StorehouseOutInfo
  8228. good.ProjectId = sumItem.ID
  8229. good.PatientId = sumItem.PatientId
  8230. goods = append(goods, &good)
  8231. newGood.GoodId = sumItem.GoodInfo.ID
  8232. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8233. count2, _ := strconv.Atoi(sumItem.Count)
  8234. newGood.Count = int64(count2)
  8235. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8236. newGood.ProjectId = sumItem.ID
  8237. newGood.PatientId = sumItem.HisPatientId
  8238. newGoods = append(newGoods, &newGood)
  8239. oldGood.GoodId = sumItem.GoodInfo.ID
  8240. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8241. count3, _ := strconv.Atoi(sumItem.Count)
  8242. oldGood.Count = int64(count3)
  8243. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8244. oldGood.ProjectId = sumItem.ID
  8245. oldGood.RecordDate = sumItem.RecordDate
  8246. oldGood.PatientId = sumItem.HisPatientId
  8247. oldGoods = append(oldGoods, &oldGood)
  8248. }
  8249. }
  8250. }
  8251. }
  8252. if settConfig.IsOpen == 1 {
  8253. for _, item := range infoList {
  8254. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8255. if medical.IsUse == 2 {
  8256. //药品出库
  8257. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8258. //查询默认仓库
  8259. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8260. //查询默认仓库剩余多少库存
  8261. var sum_count int64
  8262. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8263. for _, its := range stockInfo {
  8264. if its.MaxUnit == medical.MaxUnit {
  8265. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8266. }
  8267. sum_count += its.StockMaxNumber + its.StockMinNumber
  8268. }
  8269. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8270. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8271. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8272. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8273. }
  8274. }
  8275. orgId := c.GetAdminUserInfo().CurrentOrgId
  8276. if len(oldGoods) > 0 {
  8277. timeStr := time.Now().Format("2006-01-02")
  8278. timeArr := strings.Split(timeStr, "-")
  8279. total, _ := service.FindAllWarehouseOut(orgId)
  8280. total = total + 1
  8281. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8282. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8283. number = number + total
  8284. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8285. operation_time := time.Now().Unix()
  8286. creater := c.GetAdminUserInfo().AdminUser.Id
  8287. //查询默认出库仓库库存
  8288. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8289. recordDateStr := time.Now().Format("2006-01-02")
  8290. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8291. nowtime := recordDate.Unix()
  8292. warehouseOut := models.WarehouseOut{
  8293. WarehouseOutOrderNumber: warehousing_out_order,
  8294. OperationTime: operation_time,
  8295. OrgId: orgId,
  8296. Creater: creater,
  8297. Ctime: time.Now().Unix(),
  8298. Status: 1,
  8299. WarehouseOutTime: nowtime,
  8300. Type: 1,
  8301. StorehouseId: storeConfig.StorehouseOutInfo,
  8302. IsCheck: 1,
  8303. OrderId: order.ID,
  8304. IsSys: 5,
  8305. }
  8306. //查询是否生成出库单
  8307. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8308. if out.ID == 0 {
  8309. service.AddSigleWarehouseOut(&warehouseOut)
  8310. }
  8311. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8312. for _, item := range oldGoods {
  8313. dialyPrepareOne := models.DialysisBeforePrepare{
  8314. GoodTypeId: item.GoodTypeId,
  8315. GoodId: item.GoodId,
  8316. PatientId: his.PatientId,
  8317. RecordDate: item.RecordDate,
  8318. UserOrgId: adminUser.CurrentOrgId,
  8319. Count: item.Count,
  8320. Ctime: time.Now().Unix(),
  8321. Creater: adminUser.AdminUser.Id,
  8322. CommdityCode: item.CommdityCode,
  8323. Status: 1,
  8324. StorehouseId: houseConfig.StorehouseOutInfo,
  8325. }
  8326. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8327. //非零用
  8328. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8329. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8330. //查询剩余库存
  8331. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8332. var sum_count int64
  8333. for _, item := range goodList {
  8334. sum_count += item.StockCount
  8335. }
  8336. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8337. //耗材
  8338. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8339. }
  8340. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8341. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8342. //查询剩余库存
  8343. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8344. var sum_count int64
  8345. for _, item := range goodList {
  8346. sum_count += item.StockCount
  8347. }
  8348. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8349. //耗材
  8350. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8351. }
  8352. }
  8353. }
  8354. }
  8355. c.ServeSuccessJSON(map[string]interface{}{
  8356. "msg": "结算成功",
  8357. })
  8358. }
  8359. }
  8360. }
  8361. // 退款
  8362. func (c *HisApiController) Refund() {
  8363. order_id, _ := c.GetInt64("order_id")
  8364. order, _ := service.GetHisOrderByID(order_id)
  8365. adminUser := c.GetAdminUserInfo()
  8366. orgid := c.GetAdminUserInfo().CurrentOrgId
  8367. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8368. if err != nil {
  8369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8370. return
  8371. }
  8372. tmp := strconv.FormatInt(order.ID, 10)
  8373. //当押金不为零时产生退费记录
  8374. if order.Decimal != 0 {
  8375. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8376. if err != nil {
  8377. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8378. return
  8379. }
  8380. }
  8381. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8382. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8383. var goods []*models.DialysisBeforePrepareGoods
  8384. var newGoods []*models.NewDialysisBeforePrepareGoods
  8385. var infos []*models.HisDoctorAdviceInfo
  8386. for _, info := range orders {
  8387. if info.AdviceId > 0 && info.ProjectId == 0 {
  8388. infos = append(infos, &info.HisDoctorAdviceInfo)
  8389. }
  8390. if info.ProjectId > 0 && info.AdviceId == 0 {
  8391. if info.HisPrescriptionProject.Type == 3 {
  8392. var good models.DialysisBeforePrepareGoods
  8393. var newGood models.NewDialysisBeforePrepareGoods
  8394. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8395. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8396. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8397. good.Count = int64(count)
  8398. good.StorehouseId = houseConfig.StorehouseOutInfo
  8399. good.ProjectId = info.HisPrescriptionProject.ID
  8400. good.PatientId = info.PatientId
  8401. good.OrderId = order_id
  8402. goods = append(goods, &good)
  8403. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8404. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8405. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8406. newGood.Count = int64(count2)
  8407. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8408. newGood.ProjectId = info.HisPrescriptionProject.ID
  8409. newGood.RecordDate = order.SettleAccountsDate
  8410. newGood.UserOrgId = order.UserOrgId
  8411. newGood.PatientId = info.PatientId
  8412. newGood.OrderId = order_id
  8413. newGoods = append(newGoods, &newGood)
  8414. }
  8415. }
  8416. }
  8417. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8418. if settConfig.IsOpen == 1 {
  8419. for _, item := range infos {
  8420. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8421. }
  8422. for _, item := range newGoods {
  8423. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8424. }
  8425. }
  8426. c.ServeSuccessJSON(map[string]interface{}{
  8427. "msg": "退费成功",
  8428. })
  8429. }
  8430. func (c *HisApiController) RefundNumber() {
  8431. his_patient_id, _ := c.GetInt64("id")
  8432. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8433. info.Status = 0
  8434. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  8435. if count > 0 {
  8436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  8437. return
  8438. }
  8439. err := service.SaveHisPatient(info)
  8440. if err == nil {
  8441. c.ServeSuccessJSON(map[string]interface{}{
  8442. "msg": "退号成功",
  8443. })
  8444. } else {
  8445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8446. return
  8447. }
  8448. }
  8449. func (this *HisApiController) AdditionalCharge() {
  8450. dataBody := make(map[string]interface{}, 0)
  8451. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8452. fmt.Println(err)
  8453. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  8454. patient_id := int64(dataBody["patient_id"].(float64))
  8455. medicineData, _ := dataBody["medicineData"].([]interface{})
  8456. adminUserInfo := this.GetAdminUserInfo()
  8457. orgId := adminUserInfo.CurrentOrgId
  8458. admin_user_id := adminUserInfo.AdminUser.Id
  8459. timeStr := time.Now().Format("2006-01-02")
  8460. timeLayout := "2006-01-02 15:04:05"
  8461. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8462. timenow := timeStringToTime.Unix()
  8463. var additionalCharges []*models.HisAdditionalCharge
  8464. for _, item := range medicineData {
  8465. var randNum int
  8466. randNum = rand.Intn(10000) + 1000
  8467. timestamp := time.Now().Unix()
  8468. tempTime := time.Unix(timestamp, 0)
  8469. timeFormat := tempTime.Format("20060102150405")
  8470. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  8471. items := item.(map[string]interface{})
  8472. money := items["price"].(string)
  8473. item_id_str := items["item_id"].(string)
  8474. name := items["name"].(string)
  8475. id_str := items["id"].(string)
  8476. moneys, _ := strconv.ParseInt(money, 10, 64)
  8477. monStr := strconv.FormatInt(moneys, 10)
  8478. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  8479. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  8480. id, _ := strconv.ParseInt(id_str, 10, 64)
  8481. additionalCharge := &models.HisAdditionalCharge{
  8482. ID: id,
  8483. HisPatientId: his_patient_id,
  8484. UserOrgId: orgId,
  8485. PatientId: patient_id,
  8486. RecordDate: timenow,
  8487. Price: monneyStr,
  8488. Status: 1,
  8489. ItemName: name,
  8490. ItemId: item_id,
  8491. AdminUserId: admin_user_id,
  8492. CreatedTime: time.Now().Unix(),
  8493. OrderStatus: 0,
  8494. PrescriptionNumber: "",
  8495. BatchNumber: "",
  8496. FeedetlSn: p_number,
  8497. }
  8498. service.CreateAdditionalCharge(additionalCharge)
  8499. additionalCharges = append(additionalCharges, additionalCharge)
  8500. }
  8501. this.ServeSuccessJSON(map[string]interface{}{
  8502. "msg": "添加成功",
  8503. "additional_charges": additionalCharges,
  8504. })
  8505. }
  8506. func (this *HisApiController) DeleteAddition() {
  8507. id, _ := this.GetInt64("id")
  8508. //TODO 需要判断是否已经结算
  8509. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  8510. if err == nil {
  8511. this.ServeSuccessJSON(map[string]interface{}{
  8512. "msg": "删除成功",
  8513. })
  8514. return
  8515. } else {
  8516. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8517. return
  8518. }
  8519. }
  8520. func (this *HisApiController) GetAdminUsers() {
  8521. adminUser := this.GetAdminUserInfo()
  8522. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  8523. this.ServeSuccessJSON(map[string]interface{}{
  8524. "doctors": doctors,
  8525. })
  8526. }
  8527. func (this *HisApiController) GetLastOrNextHisPrescription() {
  8528. change_type, _ := this.GetInt64("type", 0)
  8529. record_date := this.GetString("record_time")
  8530. patient_id, _ := this.GetInt64("patient_id", 0)
  8531. p_type, _ := this.GetInt64("p_type", 0)
  8532. timeLayout := "2006-01-02"
  8533. loc, _ := time.LoadLocation("Local")
  8534. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8535. record_time := theAdviceRecordTime.Unix()
  8536. adminUserInfo := this.GetAdminUserInfo()
  8537. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  8538. if err == nil {
  8539. if len(prescriptions) == 0 {
  8540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  8541. return
  8542. } else {
  8543. this.ServeSuccessJSON(map[string]interface{}{
  8544. "prescriptions": prescriptions,
  8545. })
  8546. return
  8547. }
  8548. } else {
  8549. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8550. return
  8551. }
  8552. }
  8553. func (this *HisApiController) GetCallHisPrescription() {
  8554. patient_id, _ := this.GetInt64("patient_id", 0)
  8555. timeLayout := "2006-01-02"
  8556. loc, _ := time.LoadLocation("Local")
  8557. start_time := this.GetString("start_time")
  8558. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8559. end_time := this.GetString("end_time")
  8560. p_type, _ := this.GetInt64("p_type")
  8561. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8562. adminUserInfo := this.GetAdminUserInfo()
  8563. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  8564. if err == nil {
  8565. this.ServeSuccessJSON(map[string]interface{}{
  8566. "prescriptions": prescriptions,
  8567. })
  8568. return
  8569. } else {
  8570. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8571. return
  8572. }
  8573. }
  8574. func (this *HisApiController) GetHisDayPrescription() {
  8575. timeLayout := "2006-01-02"
  8576. loc, _ := time.LoadLocation("Local")
  8577. start_time := this.GetString("start_time")
  8578. patient_id, _ := this.GetInt64("patient_id", 0)
  8579. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8580. end_time := this.GetString("end_time")
  8581. p_type, _ := this.GetInt64("p_type")
  8582. order_status, _ := this.GetInt64("type")
  8583. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8584. adminUserInfo := this.GetAdminUserInfo()
  8585. var dayHisPrescription []*models.HisPrescription
  8586. var err error
  8587. if order_status == 1 || order_status == 0 {
  8588. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8589. } else if order_status == 2 {
  8590. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8591. }
  8592. var settle_total float64
  8593. for _, item := range dayHisPrescription {
  8594. if len(item.HisPrescriptionProject) > 0 {
  8595. for _, subItem := range item.HisPrescriptionProject {
  8596. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8597. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8598. settle_total = settle_total + total
  8599. }
  8600. }
  8601. if len(item.HisDoctorAdviceInfo) > 0 {
  8602. for _, subItem := range item.HisDoctorAdviceInfo {
  8603. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8604. settle_total = settle_total + total
  8605. }
  8606. }
  8607. }
  8608. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8609. if err == nil {
  8610. this.ServeSuccessJSON(map[string]interface{}{
  8611. "day_prescription": dayHisPrescription,
  8612. "settle_total": settle_total,
  8613. })
  8614. return
  8615. } else {
  8616. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8617. return
  8618. }
  8619. }
  8620. func (c *HisApiController) GetHisChargePatientList() {
  8621. record_date := c.GetString("record_date")
  8622. order_status, _ := c.GetInt64("type")
  8623. sch_type, _ := c.GetInt64("sch_type")
  8624. timeLayout := "2006-01-02"
  8625. loc, _ := time.LoadLocation("Local")
  8626. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8627. if err != nil {
  8628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8629. return
  8630. }
  8631. recordDateTime := theTime.Unix()
  8632. adminInfo := c.GetAdminUserInfo()
  8633. var tempPatients []*service.NewTempPatients
  8634. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  8635. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  8636. if order_status != 2 {
  8637. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8638. } else {
  8639. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8640. }
  8641. } else {
  8642. if order_status != 2 {
  8643. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8644. } else {
  8645. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8646. }
  8647. }
  8648. var patients []*service.NewTempPatients
  8649. var patients_two []*service.NewTempPatients
  8650. for _, item := range tempPatients {
  8651. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  8652. //过滤掉没挂号的和没开处方的
  8653. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  8654. patients = append(patients, item)
  8655. }
  8656. //过滤掉没挂号的
  8657. if len(item.HisPatient) > 0 {
  8658. patients_two = append(patients_two, item)
  8659. }
  8660. } else {
  8661. if len(item.HisPrescription) > 0 {
  8662. patients = append(patients, item)
  8663. }
  8664. }
  8665. }
  8666. c.ServeSuccessJSON(map[string]interface{}{
  8667. "list": patients,
  8668. "list_two": patients_two,
  8669. })
  8670. }
  8671. func (c *HisApiController) GetHisUnRegisterPatientList() {
  8672. record_date := c.GetString("record_date")
  8673. timeLayout := "2006-01-02"
  8674. loc, _ := time.LoadLocation("Local")
  8675. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8676. if err != nil {
  8677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8678. return
  8679. }
  8680. recordDateTime := theTime.Unix()
  8681. adminUser := c.GetAdminUserInfo()
  8682. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  8683. var patients []*service.Patients
  8684. for _, item := range tempPatients {
  8685. if item.HisPatient.ID == 0 {
  8686. patients = append(patients, item)
  8687. }
  8688. }
  8689. c.ServeSuccessJSON(map[string]interface{}{
  8690. "list": patients,
  8691. //"list_two": patients_two,
  8692. })
  8693. }
  8694. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  8695. newArr = make([]*service.Patients, 0)
  8696. for i := 0; i < len(patient); i++ {
  8697. repeat := false
  8698. for j := i + 1; j < len(patient); j++ {
  8699. if patient[i].ID == patient[j].ID {
  8700. repeat = true
  8701. break
  8702. }
  8703. }
  8704. if !repeat {
  8705. newArr = append(newArr, patient[i])
  8706. }
  8707. }
  8708. return
  8709. }
  8710. func (c *HisApiController) GetHisChargePatientInfo() {
  8711. patient_id, _ := c.GetInt64("patient_id")
  8712. his_patient_id, _ := c.GetInt64("his_patient_id")
  8713. record_date := c.GetString("record_date")
  8714. //start_time := c.GetString("start_time")
  8715. //end_time := c.GetString("end_time")
  8716. order_status, _ := c.GetInt64("type", 0)
  8717. p_type, _ := c.GetInt64("p_type", 0)
  8718. order_id, _ := c.GetInt64("order_id", 0)
  8719. timeLayout := "2006-01-02"
  8720. loc, _ := time.LoadLocation("Local")
  8721. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8722. if err != nil {
  8723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8724. return
  8725. }
  8726. recordDateTime := theTime.Unix()
  8727. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8728. //if err != nil {
  8729. //
  8730. //}
  8731. //startRecordDateTime := startTime.Unix()
  8732. //
  8733. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8734. //if err != nil {
  8735. //
  8736. //}
  8737. //endRecordDateTime := endTime.Unix()
  8738. admin := c.GetAdminUserInfo()
  8739. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8740. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8741. var prescriptions []*models.HisPrescription
  8742. //var unChargeMonthPrescriptions []*models.HisPrescription
  8743. order, _ := service.GetHisOrderByID(order_id)
  8744. if order_status == 1 || order_status == 0 {
  8745. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8746. } else if order_status == 2 {
  8747. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8748. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8749. }
  8750. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8751. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8752. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8753. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8754. //获取所有科室信息
  8755. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8756. c.ServeSuccessJSON(map[string]interface{}{
  8757. "his_info": his_patient_info,
  8758. "xt_info": xt_patient_info,
  8759. "prescription": prescriptions,
  8760. "case_history": case_history,
  8761. "info": patientPrescriptionInfo,
  8762. "last_info": lastPatientPrescriptionInfo,
  8763. "order": order,
  8764. "doctors": doctors,
  8765. "department": department,
  8766. })
  8767. return
  8768. }
  8769. func (c *HisApiController) GetAllOrderDetail() {
  8770. order_id, _ := c.GetInt64("id", 0)
  8771. order, _ := service.GetHisOrderByID(order_id)
  8772. if order.ID == 0 {
  8773. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8774. return
  8775. }
  8776. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8777. org_id := c.GetAdminUserInfo().CurrentOrgId
  8778. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8779. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8780. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8781. c.ServeSuccessJSON(map[string]interface{}{
  8782. "order": order,
  8783. "order_info": order_info,
  8784. "patient": patient,
  8785. "admin_info": adminInfo,
  8786. "hospital_record": record,
  8787. })
  8788. return
  8789. }
  8790. func (c *HisApiController) GetAllOrderDetailCollect() {
  8791. order_id, _ := c.GetInt64("id", 0)
  8792. order, _ := service.GetHisOrderByID(order_id)
  8793. if order.ID == 0 {
  8794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8795. return
  8796. }
  8797. org_id := c.GetAdminUserInfo().CurrentOrgId
  8798. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8799. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8800. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8801. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8802. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8803. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8804. var bedCostTotal float64 = 0 //床位总费
  8805. //var bedCostSelfTotal float64 = 0 //床位自费
  8806. var operationCostTotal float64 = 0 //手术费
  8807. //var operationCostSelfTotal float64 = 0 //手术费
  8808. var otherCostTotal float64 = 0 //其他费用
  8809. //var otherCostSelfTotal float64 = 0 //其他费用
  8810. var materialCostTotal float64 = 0 //材料费
  8811. //var materialCostSelfTotal float64 = 0 //材料费
  8812. var westernMedicineCostTotal float64 = 0 //西药费
  8813. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8814. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8815. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8816. var checkCostTotal float64 = 0 //检查费
  8817. //var checkCostSelfTotal float64 = 0 //检查费
  8818. var laboratoryCostTotal float64 = 0 //化验费
  8819. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8820. var treatCostTotal float64 = 0 //治疗费用
  8821. //var treatCostSelfTotal float64 = 0 //治疗费用
  8822. var zhenChaCostTotal float64 = 0 //其他费用
  8823. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8824. decimal.DivisionPrecision = 2
  8825. var BalanceAccountsType int64
  8826. if his.ID > 0 {
  8827. BalanceAccountsType = his.BalanceAccountsType
  8828. } else {
  8829. BalanceAccountsType = record.BalanceAccountsType
  8830. }
  8831. if BalanceAccountsType != 2 {
  8832. for _, item := range order_info {
  8833. if org_id == 10215 {
  8834. if item.MedChrgitmType == "01" { //床位费
  8835. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8836. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8837. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8838. }
  8839. if item.MedChrgitmType == "02" { //诊察费
  8840. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8841. //zhenChaCostSelfTotal = zhenChaCostTotal
  8842. }
  8843. if item.MedChrgitmType == "03" { //检查费
  8844. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8845. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8846. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8847. }
  8848. //if item.MedChrgitmType == "02" { //检查费
  8849. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8850. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8851. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8852. //}
  8853. if item.MedChrgitmType == "04" { //化验费
  8854. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8855. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8856. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8857. }
  8858. if item.MedChrgitmType == "05" { //治疗费
  8859. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8860. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8861. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8862. }
  8863. if item.MedChrgitmType == "06" { //手术费
  8864. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8865. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8866. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8867. }
  8868. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8869. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8870. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8871. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8872. }
  8873. if item.MedChrgitmType == "09" { //西药费
  8874. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8875. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8876. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8877. }
  8878. if item.MedChrgitmType == "11" { //中成费
  8879. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8880. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8881. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8882. }
  8883. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8884. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8885. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8886. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8887. }
  8888. } else if org_id == 10188 || org_id == 10217 {
  8889. if item.MedChrgitmType == "01" { //床位费
  8890. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8891. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8892. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8893. }
  8894. if item.MedChrgitmType == "02" { //诊察费
  8895. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8896. //zhenChaCostSelfTotal = zhenChaCostTotal
  8897. }
  8898. if item.MedChrgitmType == "03" { //检查费
  8899. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8900. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8901. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8902. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8903. }
  8904. //if item.MedChrgitmType == "02" { //检查费
  8905. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8906. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8907. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8908. //}
  8909. if item.MedChrgitmType == "04" { //化验费
  8910. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8911. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8912. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8913. }
  8914. if item.MedChrgitmType == "05" { //治疗费
  8915. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8916. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8917. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8918. }
  8919. if item.MedChrgitmType == "06" { //手术费
  8920. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8921. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8922. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8923. }
  8924. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8925. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8926. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8927. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8928. }
  8929. if item.MedChrgitmType == "09" { //西药费
  8930. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8931. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8932. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8933. }
  8934. if item.MedChrgitmType == "11" { //中成费
  8935. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8936. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8937. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8938. }
  8939. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8940. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8941. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8942. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8943. }
  8944. } else {
  8945. if item.MedChrgitmType == "01" { //床位费
  8946. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8947. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8948. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8949. }
  8950. //if item.MedChrgitmType == "02" { //诊察费
  8951. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8952. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8953. //}
  8954. if item.MedChrgitmType == "03" { //检查费
  8955. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8956. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8957. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8958. }
  8959. //if item.MedChrgitmType == "02" { //检查费
  8960. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8961. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8962. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8963. //}
  8964. if item.MedChrgitmType == "04" { //化验费
  8965. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8966. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8967. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8968. }
  8969. if item.MedChrgitmType == "05" { //治疗费
  8970. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8971. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8972. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8973. }
  8974. if item.MedChrgitmType == "06" { //手术费
  8975. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8976. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8977. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8978. }
  8979. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8980. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8981. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8982. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8983. }
  8984. if item.MedChrgitmType == "09" { //西药费
  8985. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8986. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8987. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8988. }
  8989. if item.MedChrgitmType == "11" { //中成费
  8990. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8991. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8992. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8993. }
  8994. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8995. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8996. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8997. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8998. }
  8999. }
  9000. }
  9001. c.ServeSuccessJSON(map[string]interface{}{
  9002. "order": order,
  9003. "order_info": order_info,
  9004. "patient": patient,
  9005. "admin_info": adminInfo,
  9006. "his_hospital": record,
  9007. "bedCostTotal": bedCostTotal,
  9008. "operationCostTotal": operationCostTotal,
  9009. "otherCostTotal": otherCostTotal,
  9010. "materialCostTotal": materialCostTotal,
  9011. "westernMedicineCostTotal": westernMedicineCostTotal,
  9012. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9013. "checkCostTotal": checkCostTotal,
  9014. "zhenChaCostTotal": zhenChaCostTotal,
  9015. "laboratoryCostTotal": laboratoryCostTotal,
  9016. "treatCostTotal": treatCostTotal,
  9017. })
  9018. } else {
  9019. for _, item := range order_info {
  9020. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9021. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9022. item.MedChrgitmType = "09"
  9023. }
  9024. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9025. if item.HisPrescriptionProject.Type == 2 {
  9026. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9027. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9028. case 0:
  9029. item.MedChrgitmType = "0"
  9030. break
  9031. case 1:
  9032. item.MedChrgitmType = "14"
  9033. break
  9034. case 2:
  9035. item.MedChrgitmType = "05"
  9036. break
  9037. case 3:
  9038. item.MedChrgitmType = "03"
  9039. break
  9040. case 4:
  9041. item.MedChrgitmType = "03"
  9042. break
  9043. case 5:
  9044. item.MedChrgitmType = "08"
  9045. break
  9046. case 6:
  9047. item.MedChrgitmType = "14"
  9048. break
  9049. case 7:
  9050. item.MedChrgitmType = "14"
  9051. break
  9052. case 8:
  9053. item.MedChrgitmType = "03"
  9054. break
  9055. case 9:
  9056. item.MedChrgitmType = "14"
  9057. break
  9058. case 10:
  9059. item.MedChrgitmType = "14"
  9060. break
  9061. case 11:
  9062. item.MedChrgitmType = "06"
  9063. break
  9064. case 12:
  9065. item.MedChrgitmType = "12"
  9066. break
  9067. case 13:
  9068. item.MedChrgitmType = "01"
  9069. break
  9070. case 14:
  9071. item.MedChrgitmType = "04"
  9072. break
  9073. case 15:
  9074. item.MedChrgitmType = "14"
  9075. break
  9076. }
  9077. } else {
  9078. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9079. case 1:
  9080. item.MedChrgitmType = "14"
  9081. break
  9082. case 2:
  9083. item.MedChrgitmType = "05"
  9084. break
  9085. case 3:
  9086. item.MedChrgitmType = "04"
  9087. break
  9088. case 4:
  9089. item.MedChrgitmType = "14"
  9090. break
  9091. case 5:
  9092. item.MedChrgitmType = "08"
  9093. break
  9094. case 6:
  9095. item.MedChrgitmType = "14"
  9096. break
  9097. case 7:
  9098. item.MedChrgitmType = "14"
  9099. break
  9100. case 8:
  9101. item.MedChrgitmType = "03"
  9102. break
  9103. case 9:
  9104. item.MedChrgitmType = "14"
  9105. break
  9106. }
  9107. }
  9108. } else if item.HisPrescriptionProject.Type == 3 {
  9109. item.MedChrgitmType = "08"
  9110. }
  9111. }
  9112. }
  9113. for _, item := range order_info {
  9114. if org_id == 10215 {
  9115. if item.MedChrgitmType == "01" { //床位费
  9116. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9117. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9118. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9119. }
  9120. if item.MedChrgitmType == "02" { //诊察费
  9121. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9122. //zhenChaCostSelfTotal = zhenChaCostTotal
  9123. }
  9124. if item.MedChrgitmType == "03" { //检查费
  9125. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9126. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9127. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9128. }
  9129. //if item.MedChrgitmType == "02" { //检查费
  9130. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9131. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9132. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9133. //}
  9134. if item.MedChrgitmType == "04" { //化验费
  9135. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9136. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9137. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9138. }
  9139. if item.MedChrgitmType == "05" { //治疗费
  9140. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9141. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9142. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9143. }
  9144. if item.MedChrgitmType == "06" { //手术费
  9145. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9146. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9147. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9148. }
  9149. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9150. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9151. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9152. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9153. }
  9154. if item.MedChrgitmType == "09" { //西药费
  9155. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9156. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9157. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9158. }
  9159. if item.MedChrgitmType == "11" { //中成费
  9160. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9161. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9162. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9163. }
  9164. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9165. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9166. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9167. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9168. }
  9169. } else {
  9170. if item.MedChrgitmType == "01" { //床位费
  9171. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9172. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9173. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9174. }
  9175. //if item.MedChrgitmType == "02" { //诊察费
  9176. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9177. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9178. //}
  9179. if item.MedChrgitmType == "03" { //检查费
  9180. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9181. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9182. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9183. }
  9184. //if item.MedChrgitmType == "02" { //检查费
  9185. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9186. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9187. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9188. //}
  9189. if item.MedChrgitmType == "04" { //化验费
  9190. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9191. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9192. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9193. }
  9194. if item.MedChrgitmType == "05" { //治疗费
  9195. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9196. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9197. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9198. }
  9199. if item.MedChrgitmType == "06" { //手术费
  9200. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9201. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9202. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9203. }
  9204. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9205. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9206. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9207. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9208. }
  9209. if item.MedChrgitmType == "09" { //西药费
  9210. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9211. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9212. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9213. }
  9214. if item.MedChrgitmType == "11" { //中成费
  9215. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9216. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9217. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9218. }
  9219. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9220. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9221. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9222. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9223. }
  9224. }
  9225. }
  9226. c.ServeSuccessJSON(map[string]interface{}{
  9227. "order": order,
  9228. "order_info": order_info,
  9229. "patient": patient,
  9230. "admin_info": adminInfo,
  9231. "his_hospital": record,
  9232. "bedCostTotal": bedCostTotal,
  9233. "operationCostTotal": operationCostTotal,
  9234. "otherCostTotal": otherCostTotal,
  9235. "materialCostTotal": materialCostTotal,
  9236. "westernMedicineCostTotal": westernMedicineCostTotal,
  9237. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9238. "checkCostTotal": checkCostTotal,
  9239. "zhenChaCostTotal": zhenChaCostTotal,
  9240. "laboratoryCostTotal": laboratoryCostTotal,
  9241. "treatCostTotal": treatCostTotal,
  9242. })
  9243. }
  9244. }
  9245. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9246. page, _ := c.GetInt64("page")
  9247. limit, _ := c.GetInt64("limit")
  9248. keywords := c.GetString("keywords")
  9249. start_time := c.GetString("start_time")
  9250. end_time := c.GetString("end_time")
  9251. //clr_type := c.GetString("clr_type")
  9252. insutype := c.GetString("insutype")
  9253. timeLayout := "2006-01-02"
  9254. loc, _ := time.LoadLocation("Local")
  9255. var theStartTIme int64
  9256. if len(start_time) > 0 {
  9257. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9258. theStartTIme = theTime.Unix()
  9259. }
  9260. var theEndtTIme int64
  9261. if len(end_time) > 0 {
  9262. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9263. theEndtTIme = theTime.Unix()
  9264. }
  9265. if page <= 0 {
  9266. page = 1
  9267. }
  9268. if limit <= 0 {
  9269. limit = 10
  9270. }
  9271. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9272. c.ServeSuccessJSON(map[string]interface{}{
  9273. "total": total,
  9274. "list": list,
  9275. })
  9276. return
  9277. }
  9278. func (c *HisApiController) GetPutOnRecordList() {
  9279. page, _ := c.GetInt64("page")
  9280. limit, _ := c.GetInt64("limit")
  9281. keywords := c.GetString("keywords")
  9282. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9283. if page <= 0 {
  9284. page = 1
  9285. }
  9286. if limit <= 0 {
  9287. limit = 10
  9288. }
  9289. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9290. c.ServeSuccessJSON(map[string]interface{}{
  9291. "total": total,
  9292. "list": list,
  9293. })
  9294. return
  9295. }
  9296. func (c *HisApiController) GetCompareData() {
  9297. start_time := c.GetString("start_time")
  9298. end_time := c.GetString("end_time")
  9299. insutype := c.GetString("insutype")
  9300. clr_type := c.GetString("clr_type")
  9301. timeLayout := "2006-01-02"
  9302. loc, _ := time.LoadLocation("Local")
  9303. var theStartTIme int64
  9304. if len(start_time) > 0 {
  9305. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9306. if err != nil {
  9307. theStartTIme = 0
  9308. }
  9309. theStartTIme = theTime.Unix()
  9310. }
  9311. var theEndtTIme int64
  9312. if len(end_time) > 0 {
  9313. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9314. if err != nil {
  9315. theEndtTIme = 0
  9316. }
  9317. theEndtTIme = theTime.Unix()
  9318. }
  9319. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9320. fmt.Println(err)
  9321. if err == nil {
  9322. c.ServeSuccessJSON(map[string]interface{}{
  9323. "list": formData,
  9324. })
  9325. } else {
  9326. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9327. return
  9328. }
  9329. }
  9330. func (c *HisApiController) GetFaPiaoData() {
  9331. order_id, _ := c.GetInt64("order_id")
  9332. patient_id, _ := c.GetInt64("patient_id")
  9333. //number := c.GetString("number")
  9334. adminUser := c.GetAdminUserInfo()
  9335. order, _ := service.GetHisOrderByID(order_id)
  9336. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9337. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9338. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9339. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9340. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9341. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9342. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9343. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9344. var bedCostTotal float64 = 0 //床位总费
  9345. var bedCostSelfTotal float64 = 0 //床位自费
  9346. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9347. var operationCostTotal float64 = 0 //手术费
  9348. var operationCostSelfTotal float64 = 0 //手术费
  9349. var operationCostPartSelfTotal float64 = 0 //手术费
  9350. var otherCostTotal float64 = 0 //其他费用
  9351. var otherCostSelfTotal float64 = 0 //其他费用
  9352. var otherCostPartSelfTotal float64 = 0 //其他费用
  9353. var materialCostTotal float64 = 0 //材料费
  9354. var materialCostSelfTotal float64 = 0 //材料费
  9355. var materialCostPartSelfTotal float64 = 0 //材料费
  9356. var westernMedicineCostTotal float64 = 0 //西药费
  9357. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9358. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9359. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9360. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9361. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9362. var checkCostTotal float64 = 0 //检查费
  9363. var checkCostSelfTotal float64 = 0 //检查费
  9364. var checkCostPartSelfTotal float64 = 0 //检查费
  9365. var hiliCostTotal float64 = 0 //护理费
  9366. var hiliCostSelfTotal float64 = 0 //护理费
  9367. var hiliCostPartSelfTotal float64 = 0 //护理费
  9368. var laboratoryCostTotal float64 = 0 //化验费
  9369. var laboratoryCostSelfTotal float64 = 0 //化验费
  9370. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9371. var treatCostTotal float64 = 0 //治疗费用
  9372. var treatCostSelfTotal float64 = 0 //治疗费用
  9373. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9374. var zhenChaCostTotal float64 = 0 //其他费用
  9375. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9376. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9377. decimal.DivisionPrecision = 2
  9378. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9379. var balanceAccountsType int64
  9380. if his.ID > 0 {
  9381. balanceAccountsType = his.BalanceAccountsType
  9382. } else {
  9383. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9384. }
  9385. if balanceAccountsType == 2 {
  9386. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9387. for _, item := range orderInfos_two {
  9388. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9389. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9390. item.MedChrgitmType = "09"
  9391. }
  9392. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9393. if item.HisPrescriptionProject.Type == 2 {
  9394. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9395. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9396. case 0:
  9397. item.MedChrgitmType = "0"
  9398. break
  9399. case 1:
  9400. item.MedChrgitmType = "14"
  9401. break
  9402. case 2:
  9403. item.MedChrgitmType = "05"
  9404. break
  9405. case 3:
  9406. item.MedChrgitmType = "03"
  9407. break
  9408. case 4:
  9409. item.MedChrgitmType = "03"
  9410. break
  9411. case 5:
  9412. item.MedChrgitmType = "08"
  9413. break
  9414. case 6:
  9415. item.MedChrgitmType = "14"
  9416. break
  9417. case 7:
  9418. item.MedChrgitmType = "14"
  9419. break
  9420. case 8:
  9421. item.MedChrgitmType = "03"
  9422. break
  9423. case 9:
  9424. item.MedChrgitmType = "14"
  9425. break
  9426. case 10:
  9427. item.MedChrgitmType = "14"
  9428. break
  9429. case 11:
  9430. item.MedChrgitmType = "06"
  9431. break
  9432. case 12:
  9433. item.MedChrgitmType = "12"
  9434. break
  9435. case 13:
  9436. item.MedChrgitmType = "01"
  9437. break
  9438. case 14:
  9439. item.MedChrgitmType = "04"
  9440. break
  9441. case 15:
  9442. item.MedChrgitmType = "02"
  9443. break
  9444. }
  9445. } else {
  9446. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9447. case 1:
  9448. item.MedChrgitmType = "14"
  9449. break
  9450. case 2:
  9451. item.MedChrgitmType = "05"
  9452. break
  9453. case 3:
  9454. item.MedChrgitmType = "04"
  9455. break
  9456. case 4:
  9457. item.MedChrgitmType = "03"
  9458. break
  9459. case 5:
  9460. item.MedChrgitmType = "08"
  9461. break
  9462. case 6:
  9463. item.MedChrgitmType = "14"
  9464. break
  9465. case 7:
  9466. item.MedChrgitmType = "14"
  9467. break
  9468. case 8:
  9469. item.MedChrgitmType = "03"
  9470. break
  9471. case 9:
  9472. item.MedChrgitmType = "14"
  9473. break
  9474. }
  9475. }
  9476. } else if item.HisPrescriptionProject.Type == 3 {
  9477. item.MedChrgitmType = "08"
  9478. }
  9479. }
  9480. }
  9481. for _, item := range orderInfos_two {
  9482. fmt.Println(item.MedChrgitmType)
  9483. if item.MedChrgitmType == "07" { //床位费
  9484. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9485. hiliCostSelfTotal = hiliCostTotal
  9486. }
  9487. if item.MedChrgitmType == "01" { //床位费
  9488. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9489. bedCostSelfTotal = bedCostTotal
  9490. }
  9491. if item.MedChrgitmType == "02" { //诊察费
  9492. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9493. zhenChaCostSelfTotal = zhenChaCostTotal
  9494. }
  9495. if item.MedChrgitmType == "03" { //检查费
  9496. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9497. checkCostSelfTotal = checkCostTotal
  9498. }
  9499. if item.MedChrgitmType == "04" { //化验费
  9500. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9501. laboratoryCostSelfTotal = laboratoryCostTotal
  9502. }
  9503. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9504. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9505. treatCostSelfTotal = treatCostTotal
  9506. }
  9507. if item.MedChrgitmType == "06" { //手术费
  9508. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9509. operationCostSelfTotal = treatCostTotal
  9510. }
  9511. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  9512. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9513. materialCostSelfTotal = materialCostTotal
  9514. }
  9515. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9516. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9517. westernMedicineCostSelfTotal = westernMedicineCostTotal
  9518. }
  9519. if item.MedChrgitmType == "11" { //中成费
  9520. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9521. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9522. }
  9523. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9524. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9525. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9526. otherCostSelfTotal = otherCostTotal
  9527. }
  9528. } else {
  9529. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9530. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9531. otherCostSelfTotal = otherCostTotal
  9532. }
  9533. }
  9534. }
  9535. } else {
  9536. for _, item := range orderInfos {
  9537. if item.MedChrgitmType == "01" { //床位费
  9538. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9539. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9540. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9541. }
  9542. if item.MedChrgitmType == "02" { //诊察费
  9543. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9544. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9545. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9546. }
  9547. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9548. if item.MedChrgitmType == "03" { //检查费
  9549. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9550. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9551. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9552. }
  9553. } else {
  9554. if item.MedChrgitmType == "03" { //检查费
  9555. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9556. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9557. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9558. }
  9559. }
  9560. if item.MedChrgitmType == "04" { //化验费
  9561. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9562. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9563. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9564. }
  9565. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9566. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9567. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9568. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9569. }
  9570. if item.MedChrgitmType == "06" { //手术费
  9571. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9572. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9573. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9574. }
  9575. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  9576. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9577. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9578. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9579. }
  9580. if item.MedChrgitmType == "07" { //护理
  9581. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9582. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9583. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9584. }
  9585. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9586. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9587. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9588. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9589. }
  9590. if item.MedChrgitmType == "11" { //中成费
  9591. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9592. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9593. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9594. }
  9595. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9596. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9597. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9598. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9599. }
  9600. }
  9601. }
  9602. timeLayout := "2006-01-02"
  9603. loc, _ := time.LoadLocation("Local")
  9604. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9605. if err != nil {
  9606. }
  9607. startRecordDateTime := startTime.Unix()
  9608. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9609. if err != nil {
  9610. }
  9611. endRecordDateTime := endTime.Unix()
  9612. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9613. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9614. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9615. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  9616. c.ServeSuccessJSON(map[string]interface{}{
  9617. "charge_admin_name": charge_admin.UserName,
  9618. "order_number": order.Number, //业务流水号
  9619. "id_card_no": his.IdCardNo, //社会保障号
  9620. "patient": patient,
  9621. "department_name": department.Name, //科室
  9622. "number": his.Number, //门诊号
  9623. "date": order.SettleAccountsDate, //结算日期
  9624. "name": order.PsnName, //姓名
  9625. "gender": patient.Gender, //性别
  9626. "psn_cash_money": order.PsnCashPay, //个人支付
  9627. "pay_way": "门诊", //结算方式
  9628. "medfee_sumamt": order.MedfeeSumamt, //总费用
  9629. "admin_user_name": admin.UserName, //收款员
  9630. "order": order,
  9631. "order_info": orderInfos_two,
  9632. "his": his,
  9633. "bedCostTotal": bedCostTotal,
  9634. "bedCostSelfTotal": bedCostSelfTotal,
  9635. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9636. "operationCostTotal": operationCostTotal,
  9637. "operationCostSelfTotal": operationCostSelfTotal,
  9638. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9639. "otherCostTotal": otherCostTotal,
  9640. "otherCostSelfTotal": otherCostSelfTotal,
  9641. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9642. "materialCostTotal": materialCostTotal,
  9643. "materialCostSelfTotal": materialCostSelfTotal,
  9644. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9645. "westernMedicineCostTotal": westernMedicineCostTotal,
  9646. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9647. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9648. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9649. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9650. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9651. "checkCostTotal": checkCostTotal,
  9652. "checkCostSelfTotal": checkCostSelfTotal,
  9653. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9654. "laboratoryCostTotal": laboratoryCostTotal,
  9655. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9656. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9657. "treatCostTotal": treatCostTotal,
  9658. "treatCostSelfTotal": treatCostSelfTotal,
  9659. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9660. "zhenChaCostTotal": zhenChaCostTotal,
  9661. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9662. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9663. "his_hospital_record": his_hospital_record,
  9664. "pre_pay_money": pre_pay_money,
  9665. "refund_sum": sum,
  9666. "doctor_info": doctor_info,
  9667. "hiliCostTotal": hiliCostTotal,
  9668. "hiliCostSelfTotal": hiliCostSelfTotal,
  9669. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  9670. })
  9671. }
  9672. //func (c *HisApiController) GetFaPiaoDatas() {
  9673. // order_ids := c.GetString("order_ids")
  9674. // patient_id, _ := c.GetInt64("patient_id")
  9675. // adminUser := c.GetAdminUserInfo()
  9676. //
  9677. // orders := strings.Split(order_ids, ",")
  9678. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9679. //
  9680. // for _, item := range orders {
  9681. // order_id, _ := strconv.ParseInt(item, 10, 64)
  9682. // order, _ := service.GetHisOrderByID(order_id)
  9683. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9684. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9685. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9686. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9687. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9688. //
  9689. // }
  9690. //
  9691. // var bedCostTotal float64 = 0 //床位总费
  9692. // var bedCostSelfTotal float64 = 0 //床位自费
  9693. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9694. //
  9695. // var operationCostTotal float64 = 0 //手术费
  9696. // var operationCostSelfTotal float64 = 0 //手术费
  9697. // var operationCostPartSelfTotal float64 = 0 //手术费
  9698. //
  9699. // var otherCostTotal float64 = 0 //其他费用
  9700. // var otherCostSelfTotal float64 = 0 //其他费用
  9701. // var otherCostPartSelfTotal float64 = 0 //其他费用
  9702. //
  9703. // var materialCostTotal float64 = 0 //材料费
  9704. // var materialCostSelfTotal float64 = 0 //材料费
  9705. // var materialCostPartSelfTotal float64 = 0 //材料费
  9706. //
  9707. // var westernMedicineCostTotal float64 = 0 //西药费
  9708. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  9709. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9710. //
  9711. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9712. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9713. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9714. //
  9715. // var checkCostTotal float64 = 0 //检查费
  9716. // var checkCostSelfTotal float64 = 0 //检查费
  9717. // var checkCostPartSelfTotal float64 = 0 //检查费
  9718. //
  9719. // var laboratoryCostTotal float64 = 0 //化验费
  9720. // var laboratoryCostSelfTotal float64 = 0 //化验费
  9721. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9722. //
  9723. // var treatCostTotal float64 = 0 //治疗费用
  9724. // var treatCostSelfTotal float64 = 0 //治疗费用
  9725. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  9726. //
  9727. // var zhenChaCostTotal float64 = 0 //其他费用
  9728. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  9729. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9730. //
  9731. // decimal.DivisionPrecision = 2
  9732. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9733. //
  9734. // var balanceAccountsType int64
  9735. // if his.ID > 0 {
  9736. // balanceAccountsType = his.BalanceAccountsType
  9737. // } else {
  9738. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9739. // }
  9740. // if balanceAccountsType == 2 {
  9741. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9742. // for _, item := range orderInfos_two {
  9743. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9744. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9745. // item.MedChrgitmType = "09"
  9746. // }
  9747. //
  9748. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9749. // if item.HisPrescriptionProject.Type == 2 {
  9750. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9751. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9752. // case 0:
  9753. // item.MedChrgitmType = "0"
  9754. // break
  9755. // case 1:
  9756. // item.MedChrgitmType = "14"
  9757. // break
  9758. // case 2:
  9759. // item.MedChrgitmType = "05"
  9760. //
  9761. // break
  9762. // case 3:
  9763. // item.MedChrgitmType = "03"
  9764. //
  9765. // break
  9766. // case 4:
  9767. // item.MedChrgitmType = "03"
  9768. //
  9769. // break
  9770. // case 5:
  9771. // item.MedChrgitmType = "08"
  9772. //
  9773. // break
  9774. // case 6:
  9775. // item.MedChrgitmType = "14"
  9776. //
  9777. // break
  9778. // case 7:
  9779. // item.MedChrgitmType = "14"
  9780. //
  9781. // break
  9782. // case 8:
  9783. // item.MedChrgitmType = "03"
  9784. // break
  9785. // case 9:
  9786. // item.MedChrgitmType = "14"
  9787. // break
  9788. // case 10:
  9789. // item.MedChrgitmType = "14"
  9790. // break
  9791. // case 11:
  9792. // item.MedChrgitmType = "06"
  9793. // break
  9794. // case 12:
  9795. // item.MedChrgitmType = "12"
  9796. // break
  9797. // case 13:
  9798. // item.MedChrgitmType = "01"
  9799. // break
  9800. // case 14:
  9801. // item.MedChrgitmType = "04"
  9802. // break
  9803. // case 15:
  9804. // item.MedChrgitmType = "02"
  9805. // break
  9806. //
  9807. // }
  9808. //
  9809. // } else {
  9810. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9811. //
  9812. // case 1:
  9813. // item.MedChrgitmType = "14"
  9814. // break
  9815. // case 2:
  9816. // item.MedChrgitmType = "05"
  9817. //
  9818. // break
  9819. // case 3:
  9820. // item.MedChrgitmType = "03"
  9821. //
  9822. // break
  9823. // case 4:
  9824. // item.MedChrgitmType = "03"
  9825. //
  9826. // break
  9827. // case 5:
  9828. // item.MedChrgitmType = "08"
  9829. //
  9830. // break
  9831. // case 6:
  9832. // item.MedChrgitmType = "14"
  9833. //
  9834. // break
  9835. // case 7:
  9836. // item.MedChrgitmType = "14"
  9837. //
  9838. // break
  9839. // case 8:
  9840. // item.MedChrgitmType = "03"
  9841. // break
  9842. // case 9:
  9843. // item.MedChrgitmType = "14"
  9844. // break
  9845. //
  9846. // }
  9847. //
  9848. // }
  9849. //
  9850. // } else if item.HisPrescriptionProject.Type == 3 {
  9851. // item.MedChrgitmType = "08"
  9852. // }
  9853. // }
  9854. // }
  9855. //
  9856. // for _, item := range orderInfos_two {
  9857. // fmt.Println(item.MedChrgitmType)
  9858. // if item.MedChrgitmType == "01" { //床位费
  9859. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9860. // bedCostSelfTotal = bedCostTotal
  9861. // }
  9862. //
  9863. // if item.MedChrgitmType == "02" { //诊察费
  9864. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9865. // zhenChaCostSelfTotal = zhenChaCostTotal
  9866. // }
  9867. //
  9868. // if item.MedChrgitmType == "03" { //检查费
  9869. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9870. // checkCostSelfTotal = checkCostTotal
  9871. // }
  9872. //
  9873. // if item.MedChrgitmType == "04" { //化验费
  9874. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9875. // laboratoryCostSelfTotal = laboratoryCostTotal
  9876. // }
  9877. //
  9878. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9879. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9880. // treatCostSelfTotal = treatCostTotal
  9881. // }
  9882. //
  9883. // if item.MedChrgitmType == "06" { //手术费
  9884. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9885. // operationCostSelfTotal = treatCostTotal
  9886. // }
  9887. //
  9888. // if item.MedChrgitmType == "08" { //材料费
  9889. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9890. // materialCostSelfTotal = materialCostTotal
  9891. // }
  9892. //
  9893. // if item.MedChrgitmType == "09" { //西药费
  9894. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9895. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9896. // }
  9897. //
  9898. // if item.MedChrgitmType == "11" { //中成费
  9899. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9900. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9901. // }
  9902. //
  9903. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9904. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9905. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9906. // otherCostSelfTotal = otherCostTotal
  9907. // }
  9908. // } else {
  9909. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9910. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9911. // otherCostSelfTotal = otherCostTotal
  9912. // }
  9913. //
  9914. // }
  9915. //
  9916. // }
  9917. //
  9918. // } else {
  9919. // for _, item := range orderInfos {
  9920. // if item.MedChrgitmType == "01" { //床位费
  9921. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9922. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9923. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9924. // }
  9925. //
  9926. // if item.MedChrgitmType == "02" { //诊察费
  9927. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9928. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9929. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9930. // }
  9931. //
  9932. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9933. // if item.MedChrgitmType == "03" { //检查费
  9934. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9935. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9936. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9937. //
  9938. // }
  9939. // } else {
  9940. // if item.MedChrgitmType == "03" { //检查费
  9941. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9942. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9943. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9944. // }
  9945. //
  9946. // }
  9947. //
  9948. // if item.MedChrgitmType == "04" { //化验费
  9949. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9950. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9951. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9952. //
  9953. // }
  9954. //
  9955. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  9956. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9957. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9958. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9959. //
  9960. // }
  9961. //
  9962. // if item.MedChrgitmType == "06" { //手术费
  9963. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9964. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9965. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9966. // }
  9967. //
  9968. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9969. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9970. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9971. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9972. // }
  9973. //
  9974. // if item.MedChrgitmType == "09" { //西药费
  9975. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9976. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9977. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9978. // }
  9979. //
  9980. // if item.MedChrgitmType == "11" { //中成费
  9981. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9982. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9983. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9984. // }
  9985. //
  9986. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9987. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9988. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9989. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9990. // }
  9991. //
  9992. // }
  9993. // }
  9994. // timeLayout := "2006-01-02"
  9995. // loc, _ := time.LoadLocation("Local")
  9996. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9997. // if err != nil {
  9998. // }
  9999. // startRecordDateTime := startTime.Unix()
  10000. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10001. // if err != nil {
  10002. // }
  10003. // endRecordDateTime := endTime.Unix()
  10004. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10005. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10006. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10007. //
  10008. // c.ServeSuccessJSON(map[string]interface{}{
  10009. // "order_number": order.Number, //业务流水号
  10010. // "id_card_no": his.IdCardNo, //社会保障号
  10011. // "department_name": department.Name, //科室
  10012. // "number": his.Number, //门诊号
  10013. // "date": order.SettleAccountsDate, //结算日期
  10014. // "name": order.PsnName, //姓名
  10015. // "gender": patient.Gender, //性别
  10016. // "psn_cash_money": order.PsnCashPay, //个人支付
  10017. // "pay_way": "门诊", //结算方式
  10018. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10019. // "admin_user_name": admin.UserName, //收款员
  10020. // "order": order,
  10021. // "order_info": orderInfos_two,
  10022. // "his": his,
  10023. // "bedCostTotal": bedCostTotal,
  10024. // "bedCostSelfTotal": bedCostSelfTotal,
  10025. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10026. // "operationCostTotal": operationCostTotal,
  10027. // "operationCostSelfTotal": operationCostSelfTotal,
  10028. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10029. // "otherCostTotal": otherCostTotal,
  10030. // "otherCostSelfTotal": otherCostSelfTotal,
  10031. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10032. // "materialCostTotal": materialCostTotal,
  10033. // "materialCostSelfTotal": materialCostSelfTotal,
  10034. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10035. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10036. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10037. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10038. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10039. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10040. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10041. // "checkCostTotal": checkCostTotal,
  10042. // "checkCostSelfTotal": checkCostSelfTotal,
  10043. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10044. // "laboratoryCostTotal": laboratoryCostTotal,
  10045. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10046. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10047. // "treatCostTotal": treatCostTotal,
  10048. // "treatCostSelfTotal": treatCostSelfTotal,
  10049. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10050. // "zhenChaCostTotal": zhenChaCostTotal,
  10051. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10052. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10053. // "his_hospital_record": his_hospital_record,
  10054. // "pre_pay_money": pre_pay_money,
  10055. // "refund_sum": sum,
  10056. // })
  10057. //
  10058. //}
  10059. func (this *HisApiController) GetIncomeStatisticsData() {
  10060. start_time := this.GetString("start_time")
  10061. end_time := this.GetString("end_time")
  10062. key_words := this.GetString("key_words")
  10063. limit, _ := this.GetInt64("limit")
  10064. page, _ := this.GetInt64("page")
  10065. if page <= 0 {
  10066. page = 1
  10067. }
  10068. if limit <= 0 {
  10069. limit = 10
  10070. }
  10071. statistics_type, _ := this.GetInt64("statistics_type")
  10072. admin := this.GetAdminUserInfo()
  10073. timeLayout := "2006-01-02"
  10074. loc, _ := time.LoadLocation("Local")
  10075. var theStartTIme int64
  10076. if len(start_time) > 0 {
  10077. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10078. if err != nil {
  10079. theStartTIme = 0
  10080. }
  10081. theStartTIme = theTime.Unix()
  10082. }
  10083. var theEndtTIme int64
  10084. if len(end_time) > 0 {
  10085. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10086. if err != nil {
  10087. theEndtTIme = 0
  10088. }
  10089. theEndtTIme = theTime.Unix()
  10090. }
  10091. if statistics_type == 1 {
  10092. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10093. this.ServeSuccessJSON(map[string]interface{}{
  10094. "list": list,
  10095. "total": total,
  10096. })
  10097. } else {
  10098. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10099. this.ServeSuccessJSON(map[string]interface{}{
  10100. "list": list,
  10101. "total": total,
  10102. })
  10103. }
  10104. }
  10105. func (c *HisApiController) PostProjectInformation() {
  10106. adminUser := c.GetAdminUserInfo()
  10107. orgId := adminUser.CurrentOrgId
  10108. dataBody := make(map[string]interface{}, 0)
  10109. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10110. if err != nil {
  10111. utils.ErrorLog(err.Error())
  10112. return
  10113. }
  10114. utils.ErrorLog("%v", dataBody)
  10115. var projectList []*models.HisProject
  10116. var total_goods []interface{}
  10117. tempProjects := dataBody["projects"].([]interface{})
  10118. total_goods = tempProjects
  10119. for index, projectMap := range tempProjects {
  10120. projectM := projectMap.(map[string]interface{})
  10121. var project models.HisProject
  10122. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10123. utils.ErrorLog("project_name")
  10124. return
  10125. }
  10126. project_name, _ := projectM["project_name"].(string)
  10127. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10128. err_log := models.ExportErrLog{
  10129. LogType: 6,
  10130. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10131. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10132. Status: 1,
  10133. CreateTime: time.Now().Unix(),
  10134. UpdateTime: time.Now().Unix(),
  10135. ExportTime: time.Now().Unix(),
  10136. }
  10137. service.CreateExportErrLog(&err_log)
  10138. continue
  10139. }
  10140. project.ProjectName = project_name
  10141. prices := projectM["price"].(string)
  10142. price, _ := strconv.ParseFloat(prices, 64)
  10143. if price <= 0 { //名字为空则生成一条导入错误日志
  10144. err_log := models.ExportErrLog{
  10145. LogType: 6,
  10146. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10147. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10148. Status: 1,
  10149. CreateTime: time.Now().Unix(),
  10150. UpdateTime: time.Now().Unix(),
  10151. ExportTime: time.Now().Unix(),
  10152. }
  10153. service.CreateExportErrLog(&err_log)
  10154. continue
  10155. }
  10156. project.Price = price
  10157. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10158. utils.ErrorLog("unit_id")
  10159. return
  10160. }
  10161. unit := projectM["unit"].(string)
  10162. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10163. err_log := models.ExportErrLog{
  10164. LogType: 6,
  10165. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10166. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10167. Status: 1,
  10168. CreateTime: time.Now().Unix(),
  10169. UpdateTime: time.Now().Unix(),
  10170. ExportTime: time.Now().Unix(),
  10171. }
  10172. service.CreateExportErrLog(&err_log)
  10173. continue
  10174. }
  10175. project.Unit = unit
  10176. cost_classify := projectM["cost_classify"].(string)
  10177. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10178. err_log := models.ExportErrLog{
  10179. LogType: 6,
  10180. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10181. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10182. Status: 1,
  10183. CreateTime: time.Now().Unix(),
  10184. UpdateTime: time.Now().Unix(),
  10185. ExportTime: time.Now().Unix(),
  10186. }
  10187. service.CreateExportErrLog(&err_log)
  10188. continue
  10189. }
  10190. var costClassify = "费用类别"
  10191. var cost_classify_id int64
  10192. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10193. if len(cost_classify) != 0 {
  10194. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10195. if errcode == gorm.ErrRecordNotFound {
  10196. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10197. dataconfig := models.DictDataconfig{
  10198. ParentId: costClassifyConfig.ID,
  10199. Module: "system",
  10200. OrgId: orgId,
  10201. Name: cost_classify,
  10202. FieldName: "",
  10203. Value: costConfig.Value + 1,
  10204. CreatedTime: "",
  10205. UpdatedTime: "",
  10206. CreateUserId: adminUser.AdminUser.Id,
  10207. Status: 1,
  10208. Remark: "",
  10209. DeleteIdSystem: 0,
  10210. Title: "",
  10211. Content: "",
  10212. Order: 0,
  10213. Code: "",
  10214. }
  10215. service.CreatedDicConfig(&dataconfig)
  10216. }
  10217. }
  10218. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10219. for _, it := range costClassList {
  10220. if cost_classify == it.Name {
  10221. cost_classify_id = int64(it.Value)
  10222. }
  10223. }
  10224. project.CostClassify = cost_classify_id
  10225. executive_section := projectM["executive_section"].(string)
  10226. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10227. err_log := models.ExportErrLog{
  10228. LogType: 6,
  10229. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10230. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10231. Status: 1,
  10232. CreateTime: time.Now().Unix(),
  10233. UpdateTime: time.Now().Unix(),
  10234. ExportTime: time.Now().Unix(),
  10235. }
  10236. service.CreateExportErrLog(&err_log)
  10237. continue
  10238. }
  10239. if len(executive_section) != 0 {
  10240. //查找科室是否有内容
  10241. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10242. if errcodedepart == gorm.ErrRecordNotFound {
  10243. department := models.XtHisDepartment{
  10244. Name: executive_section,
  10245. Status: 1,
  10246. UserOrgId: adminUser.CurrentOrgId,
  10247. CreatedTime: time.Now().Unix(),
  10248. }
  10249. service.CreateDePartment(&department)
  10250. }
  10251. }
  10252. var executive_section_id int64
  10253. departMentList, _ := service.GetAllDepartMent(orgId)
  10254. for _, it := range departMentList {
  10255. if executive_section == it.Name {
  10256. executive_section_id = it.ID
  10257. }
  10258. }
  10259. project.ExecutiveSection = executive_section_id
  10260. medical_coverage := projectM["medical_coverage"].(string)
  10261. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10262. err_log := models.ExportErrLog{
  10263. LogType: 6,
  10264. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10265. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10266. Status: 1,
  10267. CreateTime: time.Now().Unix(),
  10268. UpdateTime: time.Now().Unix(),
  10269. ExportTime: time.Now().Unix(),
  10270. }
  10271. service.CreateExportErrLog(&err_log)
  10272. continue
  10273. }
  10274. var medicalCoverage = "医保等级"
  10275. var medical_coverage_id int64
  10276. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10277. if len(medical_coverage) != 0 {
  10278. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10279. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10280. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10281. dataconfig := models.DictDataconfig{
  10282. ParentId: medicalCoverageConfig.ID,
  10283. Module: "system",
  10284. OrgId: orgId,
  10285. Name: medical_coverage,
  10286. FieldName: "",
  10287. Value: medicalCoverageConfig.Value + 1,
  10288. CreatedTime: "",
  10289. UpdatedTime: "",
  10290. CreateUserId: adminUser.AdminUser.Id,
  10291. Status: 1,
  10292. Remark: "",
  10293. DeleteIdSystem: 0,
  10294. Title: "",
  10295. Content: "",
  10296. Order: 0,
  10297. Code: "",
  10298. }
  10299. service.CreatedDicConfig(&dataconfig)
  10300. }
  10301. }
  10302. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10303. for _, it := range medicalCoverageList {
  10304. if medical_coverage == it.Name {
  10305. medical_coverage_id = int64(it.Value)
  10306. }
  10307. }
  10308. project.MedicalCoverage = medical_coverage_id
  10309. pinyin := projectM["pinyin"].(string)
  10310. project.Pinyin = pinyin
  10311. wubi := projectM["wubi"].(string)
  10312. project.Wubi = wubi
  10313. statistical_classification := projectM["statistical_classification"].(string)
  10314. var statisticalClassification = "统计分类"
  10315. var statistical_classification_id int64
  10316. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10317. if len(statistical_classification) != 0 {
  10318. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10319. if classificationerrcodes == gorm.ErrRecordNotFound {
  10320. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10321. dataconfig := models.DictDataconfig{
  10322. ParentId: classiFication.ID,
  10323. Module: "system",
  10324. OrgId: orgId,
  10325. Name: statistical_classification,
  10326. FieldName: "",
  10327. Value: classiFicationConfig.Value + 1,
  10328. CreatedTime: "",
  10329. UpdatedTime: "",
  10330. CreateUserId: adminUser.AdminUser.Id,
  10331. Status: 1,
  10332. Remark: "",
  10333. DeleteIdSystem: 0,
  10334. Title: "",
  10335. Content: "",
  10336. Order: 0,
  10337. Code: "",
  10338. }
  10339. service.CreatedDicConfig(&dataconfig)
  10340. }
  10341. }
  10342. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10343. for _, it := range classiFicationList {
  10344. if statistical_classification == it.Name {
  10345. statistical_classification_id = int64(it.Value)
  10346. }
  10347. }
  10348. project.StatisticalClassification = statistical_classification_id
  10349. disease_directory := int64(projectM["disease_directory"].(float64))
  10350. project.DiseaseDirectory = disease_directory
  10351. is_record := int64(projectM["is_record"].(float64))
  10352. project.IsRecord = is_record
  10353. medical_code := projectM["medical_code"].(string)
  10354. project.MedicalCode = medical_code
  10355. tube_color := projectM["tube_color"].(string)
  10356. var tubeColor = "试管颜色"
  10357. var tube_color_id int64
  10358. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10359. if len(tube_color) != 0 {
  10360. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10361. if errcodetube == gorm.ErrRecordNotFound {
  10362. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10363. dataconfig := models.DictDataconfig{
  10364. ParentId: tubeColorConfig.ID,
  10365. Module: "system",
  10366. OrgId: orgId,
  10367. Name: tube_color,
  10368. FieldName: "",
  10369. Value: tubeConfig.Value + 1,
  10370. CreatedTime: "",
  10371. UpdatedTime: "",
  10372. CreateUserId: adminUser.AdminUser.Id,
  10373. Status: 1,
  10374. Remark: "",
  10375. DeleteIdSystem: 0,
  10376. Title: "",
  10377. Content: "",
  10378. Order: 0,
  10379. Code: "",
  10380. }
  10381. service.CreatedDicConfig(&dataconfig)
  10382. }
  10383. }
  10384. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10385. for _, it := range tubeColorList {
  10386. if tube_color == it.Name {
  10387. tube_color_id = int64(it.Value)
  10388. }
  10389. }
  10390. project.TubeColor = tube_color_id
  10391. single_dose := projectM["single_dose"].(string)
  10392. project.SingleDose = single_dose
  10393. execution_frequency := projectM["execution_frequency"].(string)
  10394. project.ExecutionFrequency = execution_frequency
  10395. delivery_way := projectM["delivery_way"].(string)
  10396. project.DeliveryWay = delivery_way
  10397. number_days := projectM["number_days"].(string)
  10398. project.NumberDays = number_days
  10399. total := projectM["total"].(string)
  10400. project.Total = total
  10401. medical_status := int64(projectM["medical_status"].(float64))
  10402. project.MedicalStatus = medical_status
  10403. category := int64(projectM["category"].(float64))
  10404. project.Category = category
  10405. specail_project := int64(projectM["specail_project"].(float64))
  10406. project.SpecailProject = specail_project
  10407. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10408. project.SocialSecurityDirectoryCode = social_security_directory_code
  10409. remark := projectM["remark"].(string)
  10410. project.Remark = remark
  10411. record_date := projectM["record_date"].(string)
  10412. timeLayout := "2006-01-02"
  10413. loc, _ := time.LoadLocation("Local")
  10414. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10415. project.RecordDate = theTime.Unix()
  10416. projectList = append(projectList, &project)
  10417. }
  10418. export_time := time.Now().Unix()
  10419. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  10420. if len(projectList) > 0 {
  10421. for _, item := range projectList {
  10422. hans := item.ProjectName // 要转换的汉字字符串
  10423. // 创建一个拼音转换器
  10424. p := pinyin.NewArgs()
  10425. // 将汉字转为拼音
  10426. pinyinSlice := pinyin.Pinyin(hans, p)
  10427. // 输出拼音
  10428. fmt.Println("Pinyin:", pinyinSlice)
  10429. // 获取首字母
  10430. firstLetter := ""
  10431. for _, py := range pinyinSlice {
  10432. if len(py) > 0 {
  10433. firstLetter += string(py[0][0])
  10434. }
  10435. }
  10436. item.FirstLetter = firstLetter
  10437. project := models.HisProject{
  10438. ProjectName: item.ProjectName,
  10439. Price: item.Price,
  10440. Unit: item.Unit,
  10441. CostClassify: item.CostClassify,
  10442. ExecutiveSection: item.ExecutiveSection,
  10443. MedicalCoverage: item.MedicalCoverage,
  10444. UserOrgId: orgId,
  10445. Status: 1,
  10446. CreatedTime: time.Now().Unix(),
  10447. Pinyin: item.Pinyin,
  10448. Wubi: item.Wubi,
  10449. StatisticalClassification: item.StatisticalClassification,
  10450. DiseaseDirectory: item.DiseaseDirectory,
  10451. IsRecord: item.IsRecord,
  10452. MedicalCode: item.MedicalCode,
  10453. TubeColor: item.TubeColor,
  10454. SingleDose: item.SingleDose,
  10455. DeliveryWay: item.DeliveryWay,
  10456. NumberDays: item.NumberDays,
  10457. Total: item.Total,
  10458. Category: item.Category,
  10459. MedicalStatus: item.MedicalStatus,
  10460. SpecailProject: item.SpecailProject,
  10461. RecordDate: item.RecordDate,
  10462. Remark: item.Remark,
  10463. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10464. ExecutionFrequency: item.ExecutionFrequency,
  10465. FirstLetter: item.FirstLetter,
  10466. }
  10467. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10468. if errcodeproject == gorm.ErrRecordNotFound {
  10469. service.CreateProjectInfomation(&project)
  10470. } else if errcodeproject == nil {
  10471. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10472. }
  10473. log := models.ExportLog{
  10474. LogType: 6,
  10475. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10476. TotalNum: int64(len(total_goods)),
  10477. FailNum: int64(len(errLogs)),
  10478. SuccessNum: int64(len(projectList)),
  10479. CreateTime: time.Now().Unix(),
  10480. UpdateTime: time.Now().Unix(),
  10481. ExportTime: export_time,
  10482. Status: 1,
  10483. }
  10484. service.CreateExportLog(&log)
  10485. c.ServeSuccessJSON(map[string]interface{}{
  10486. "msg": "导入成功",
  10487. "total_num": len(total_goods),
  10488. "success_num": len(projectList),
  10489. "fail_num": int64(len(errLogs)),
  10490. })
  10491. }
  10492. } else {
  10493. log := models.ExportLog{
  10494. LogType: 6,
  10495. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10496. TotalNum: int64(len(total_goods)),
  10497. FailNum: int64(len(errLogs)),
  10498. SuccessNum: int64(len(projectList)),
  10499. CreateTime: time.Now().Unix(),
  10500. UpdateTime: time.Now().Unix(),
  10501. ExportTime: export_time,
  10502. Status: 1,
  10503. }
  10504. service.CreateExportLog(&log)
  10505. c.ServeSuccessJSON(map[string]interface{}{
  10506. "msg": "导入成功",
  10507. "total_num": len(total_goods),
  10508. "success_num": len(projectList),
  10509. "fail_num": int64(len(errLogs)),
  10510. })
  10511. }
  10512. }
  10513. //func (this *HisApiController) EditProjectInformation(){
  10514. //
  10515. // id, _ := this.GetInt64("id")
  10516. // project_team := this.GetString("project_team")
  10517. // price := this.GetString("price")
  10518. // price_float, _ := strconv.ParseFloat(price, 64)
  10519. // pinyin := this.GetString("pinyin")
  10520. // wubi := this.GetString("wubi")
  10521. // tube_color, _ := this.GetInt64("tube_color")
  10522. // team_type, _ := this.GetInt64("team_type")
  10523. // remark := this.GetString("remark")
  10524. // ids := this.GetString("ids")
  10525. // item_id := this.GetString("item_id")
  10526. // projectTeam := models.XtHisProjectTeam{
  10527. // ProjectTeam: project_team,
  10528. // Price: price_float,
  10529. // Pinyin: pinyin,
  10530. // Wubi: wubi,
  10531. // TubeColor: tube_color,
  10532. // TeamType: team_type,
  10533. // Remark: remark,
  10534. // ProjectId: ids,
  10535. // ItemId: item_id,
  10536. // }
  10537. //
  10538. //
  10539. // dataBody := make(map[string]interface{}, 0)
  10540. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10541. // if err != nil {
  10542. // utils.ErrorLog(err.Error())
  10543. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10544. // return
  10545. // }
  10546. //
  10547. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10548. //
  10549. //
  10550. // if err != nil {
  10551. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10552. // return
  10553. // }
  10554. //
  10555. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10556. // infos, _ := dataBody["info"].([]interface{})
  10557. // if len(infos) > 0 {
  10558. // var ids []string
  10559. //
  10560. // for _, item := range infos {
  10561. // items := item.(map[string]interface{})
  10562. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10563. // utils.ErrorLog("id")
  10564. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10565. // return
  10566. // }
  10567. // id := int64(items["id"].(float64))
  10568. //
  10569. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10570. // utils.ErrorLog("type")
  10571. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10572. // return
  10573. // }
  10574. // types := int64(items["type"].(float64))
  10575. //
  10576. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10577. // utils.ErrorLog("number")
  10578. // }
  10579. //
  10580. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10581. //
  10582. // projectList := models.XtHisProjectList{
  10583. // Number: number,
  10584. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10585. // ProjectId: id,
  10586. // Status: 1,
  10587. // CreatedTime: time.Now().Unix(),
  10588. // UpdatedTime: time.Now().Unix(),
  10589. // TeamId: projectTeam.ID,
  10590. // Type: types,
  10591. // }
  10592. // list := projectList
  10593. //
  10594. // service.CreateProjectList(&list)
  10595. //
  10596. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10597. //
  10598. // }
  10599. // ids_str := strings.Join(ids, ",")
  10600. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10601. // service.SaveProjectTeam(&projectTeam)
  10602. // this.ServeSuccessJSON(map[string]interface{}{
  10603. // "projectTeam": projectTeam,
  10604. // })
  10605. // }
  10606. // }
  10607. //}
  10608. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10609. name := c.GetString("name")
  10610. mode_id, _ := c.GetInt64("mode", 0)
  10611. types, _ := c.GetInt64("type", 0)
  10612. patient_id, _ := c.GetInt64("patient_id", 0)
  10613. types = 1
  10614. adminInfo := c.GetAdminUserInfo()
  10615. template := &models.HisPrescriptionTemplate{
  10616. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10617. PatientId: patient_id,
  10618. Type: types,
  10619. Status: 1,
  10620. Ctime: time.Now().Unix(),
  10621. Mtime: time.Now().Unix(),
  10622. Name: name,
  10623. Mode: mode_id,
  10624. }
  10625. dataBody := make(map[string]interface{}, 0)
  10626. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10627. if err != nil {
  10628. utils.ErrorLog(err.Error())
  10629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10630. return
  10631. }
  10632. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10633. //如果已经存在记录则删除处方
  10634. if template_one.ID > 0 {
  10635. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10636. var ids []int64
  10637. var org_id int64
  10638. for _, item := range ps {
  10639. org_id = c.GetAdminUserInfo().CurrentOrgId
  10640. ids = append(ids, item.ID)
  10641. }
  10642. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10643. if err2 == nil {
  10644. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10645. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10646. if len(prescriptions) > 0 {
  10647. for _, item := range prescriptions {
  10648. items := item.(map[string]interface{})
  10649. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10650. utils.ErrorLog("type")
  10651. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10652. return
  10653. }
  10654. types := int64(items["type"].(float64))
  10655. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10656. utils.ErrorLog("med_type")
  10657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10658. return
  10659. }
  10660. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10661. ctime := time.Now().Unix()
  10662. prescription := &models.HisPrescriptionInfoTemplate{
  10663. PatientId: patient_id,
  10664. UserOrgId: adminInfo.CurrentOrgId,
  10665. Ctime: ctime,
  10666. Mtime: ctime,
  10667. Type: types,
  10668. Modifier: adminInfo.AdminUser.Id,
  10669. Creator: adminInfo.AdminUser.Id,
  10670. Status: 1,
  10671. PTemplateId: template_one.ID,
  10672. MedType: med_type,
  10673. }
  10674. service.CreateHisPrescriptionInfoTemplate(prescription)
  10675. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10676. advices := items["advices"].([]interface{})
  10677. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10678. ctime := time.Now().Unix()
  10679. mtime := ctime
  10680. if len(advices) > 0 {
  10681. for _, advice := range advices {
  10682. var s models.HisPrescriptionAdviceTemplate
  10683. s.PrescriptionId = prescription.ID
  10684. s.AdviceType = 2
  10685. s.StopState = 2
  10686. s.ExecutionState = 2
  10687. s.Status = 1
  10688. s.UserOrgId = adminInfo.CurrentOrgId
  10689. s.CreatedTime = ctime
  10690. s.UpdatedTime = mtime
  10691. s.PatientId = patient_id
  10692. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10693. if errcode > 0 {
  10694. c.ServeFailJSONWithSGJErrorCode(errcode)
  10695. return
  10696. }
  10697. service.CreateHisPrescriptionAdviceTemplate(&s)
  10698. }
  10699. }
  10700. }
  10701. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10702. projects := items["project"].([]interface{})
  10703. if len(projects) > 0 {
  10704. for _, project := range projects {
  10705. var p models.HisPrescriptionProjectTemplate
  10706. p.PrescriptionId = prescription.ID
  10707. p.Ctime = time.Now().Unix()
  10708. p.Mtime = time.Now().Unix()
  10709. p.PatientId = patient_id
  10710. p.UserOrgId = adminInfo.CurrentOrgId
  10711. p.Status = 1
  10712. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10713. if errcode > 0 {
  10714. c.ServeFailJSONWithSGJErrorCode(errcode)
  10715. return
  10716. }
  10717. service.CreateHisPrescriptionProjectTemplate(&p)
  10718. }
  10719. }
  10720. }
  10721. }
  10722. c.ServeSuccessJSON(map[string]interface{}{
  10723. "msg": "创建成功",
  10724. })
  10725. }
  10726. }
  10727. } else {
  10728. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10729. return
  10730. }
  10731. } else {
  10732. err3 := service.CreateHisPrescriptionTemplate(template)
  10733. if err3 == nil {
  10734. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10735. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10736. if len(prescriptions) > 0 {
  10737. for _, item := range prescriptions {
  10738. items := item.(map[string]interface{})
  10739. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10740. utils.ErrorLog("type")
  10741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10742. return
  10743. }
  10744. types := int64(items["type"].(float64))
  10745. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10746. utils.ErrorLog("med_type")
  10747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10748. return
  10749. }
  10750. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10751. ctime := time.Now().Unix()
  10752. prescription := &models.HisPrescriptionInfoTemplate{
  10753. PatientId: patient_id,
  10754. UserOrgId: adminInfo.CurrentOrgId,
  10755. Ctime: ctime,
  10756. Mtime: ctime,
  10757. Type: types,
  10758. Modifier: adminInfo.AdminUser.Id,
  10759. Creator: adminInfo.AdminUser.Id,
  10760. Status: 1,
  10761. PTemplateId: template.ID,
  10762. MedType: med_type,
  10763. }
  10764. service.CreateHisPrescriptionInfoTemplate(prescription)
  10765. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10766. advices := items["advices"].([]interface{})
  10767. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10768. ctime := time.Now().Unix()
  10769. mtime := ctime
  10770. if len(advices) > 0 {
  10771. for _, advice := range advices {
  10772. var s models.HisPrescriptionAdviceTemplate
  10773. s.PrescriptionId = prescription.ID
  10774. s.AdviceType = 2
  10775. s.StopState = 2
  10776. s.ExecutionState = 2
  10777. s.Status = 1
  10778. s.UserOrgId = adminInfo.CurrentOrgId
  10779. s.CreatedTime = ctime
  10780. s.UpdatedTime = mtime
  10781. s.PatientId = patient_id
  10782. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10783. if errcode > 0 {
  10784. c.ServeFailJSONWithSGJErrorCode(errcode)
  10785. return
  10786. }
  10787. service.CreateHisPrescriptionAdviceTemplate(&s)
  10788. }
  10789. }
  10790. }
  10791. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10792. projects := items["project"].([]interface{})
  10793. if len(projects) > 0 {
  10794. for _, project := range projects {
  10795. var p models.HisPrescriptionProjectTemplate
  10796. p.PrescriptionId = prescription.ID
  10797. p.Ctime = time.Now().Unix()
  10798. p.Mtime = time.Now().Unix()
  10799. p.PatientId = patient_id
  10800. p.UserOrgId = adminInfo.CurrentOrgId
  10801. p.Status = 1
  10802. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10803. if errcode > 0 {
  10804. c.ServeFailJSONWithSGJErrorCode(errcode)
  10805. return
  10806. }
  10807. service.CreateHisPrescriptionProjectTemplate(&p)
  10808. }
  10809. }
  10810. }
  10811. }
  10812. c.ServeSuccessJSON(map[string]interface{}{
  10813. "msg": "创建成功",
  10814. })
  10815. }
  10816. }
  10817. } else {
  10818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10819. return
  10820. }
  10821. }
  10822. }
  10823. func (c *HisApiController) PreSettle() {
  10824. id, _ := c.GetInt64("id")
  10825. record_time := c.GetString("record_time")
  10826. his_patient_id, _ := c.GetInt64("his_patient_id")
  10827. timeLayout := "2006-01-02"
  10828. loc, _ := time.LoadLocation("Local")
  10829. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10830. diagnosis_id := c.GetString("diagnosis")
  10831. sick_type, _ := c.GetInt64("sick_type")
  10832. reg_type, _ := c.GetInt64("p_type")
  10833. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10834. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10835. if err != nil {
  10836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10837. return
  10838. }
  10839. recordDateTime := theTime.Unix()
  10840. adminUser := c.GetAdminUserInfo()
  10841. var prescriptions []*models.HisPrescription
  10842. var start_time int64
  10843. var end_time int64
  10844. ids_str := c.GetString("ids")
  10845. ids_arr := strings.Split(ids_str, ",")
  10846. fmt.Println(reg_type)
  10847. if settle_accounts_type == 1 { //日结
  10848. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10849. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10850. } else {
  10851. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10852. }
  10853. fmt.Println(prescriptions)
  10854. } else { //月结
  10855. start_time_str := c.GetString("start_time")
  10856. end_time_str := c.GetString("end_time")
  10857. timeLayout := "2006-01-02"
  10858. loc, _ := time.LoadLocation("Local")
  10859. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10860. if err != nil {
  10861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10862. return
  10863. }
  10864. recordStartTime := theStartTime.Unix()
  10865. start_time = recordStartTime
  10866. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10867. if err != nil {
  10868. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10869. return
  10870. }
  10871. recordEndTime := theEndTime.Unix()
  10872. end_time = recordEndTime
  10873. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10874. }
  10875. if reg_type == 1111 || reg_type == 1112 {
  10876. reg_type = 11
  10877. }
  10878. timestamp := time.Now().Unix()
  10879. tempTime := time.Unix(timestamp, 0)
  10880. timeFormat := tempTime.Format("20060102150405")
  10881. chrgBchno := rand.Intn(100000) + 10000
  10882. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10883. strconv.FormatInt(his.PatientId, 10)
  10884. var ids []int64
  10885. for _, item := range prescriptions {
  10886. ids = append(ids, item.ID)
  10887. }
  10888. fmt.Println(ids)
  10889. var total float64
  10890. for _, item := range prescriptions {
  10891. fmt.Println(item)
  10892. if item.Type == 1 { //药品
  10893. for _, subItem := range item.HisDoctorAdviceInfo {
  10894. total = total + (subItem.Price * subItem.PrescribingNumber)
  10895. }
  10896. }
  10897. if item.Type == 2 { //项目
  10898. for _, subItem := range item.HisPrescriptionProject {
  10899. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10900. total = total + (subItem.Price * cnt)
  10901. }
  10902. }
  10903. for _, subItem := range item.HisAdditionalCharge {
  10904. total = total + (subItem.Price * float64(subItem.Count))
  10905. }
  10906. }
  10907. allTotal := fmt.Sprintf("%.2f", total)
  10908. totals, _ := strconv.ParseFloat(allTotal, 64)
  10909. order := &models.HisOrder{
  10910. UserOrgId: adminUser.CurrentOrgId,
  10911. HisPatientId: his.ID,
  10912. PatientId: id,
  10913. SettleAccountsDate: recordDateTime,
  10914. Ctime: time.Now().Unix(),
  10915. Mtime: time.Now().Unix(),
  10916. Status: 1,
  10917. OrderStatus: 1,
  10918. MdtrtId: his.Number,
  10919. Number: chrg_bchno,
  10920. MedfeeSumamt: totals,
  10921. SettleEndTime: end_time,
  10922. SettleStartTime: start_time,
  10923. SettleType: settle_accounts_type,
  10924. PsnPartAmt: totals,
  10925. PsnCashPay: totals,
  10926. PType: 2,
  10927. IsPre: 1,
  10928. MedType: strconv.Itoa(int(reg_type)),
  10929. Diagnosis: diagnosis_id,
  10930. }
  10931. err = service.CreateOrder(order)
  10932. if err != nil {
  10933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10934. return
  10935. }
  10936. var customs []*Custom
  10937. for _, item := range prescriptions {
  10938. fmt.Println(item.Type)
  10939. if item.Type == 1 { //药品
  10940. for _, subItem := range item.HisDoctorAdviceInfo {
  10941. cus := &Custom{
  10942. AdviceId: subItem.ID,
  10943. ProjectId: 0,
  10944. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10945. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10946. FeedetlSn: subItem.FeedetlSn,
  10947. Price: fmt.Sprintf("%.2f", subItem.Price),
  10948. MedListCodg: subItem.MedListCodg,
  10949. Type: 1,
  10950. }
  10951. customs = append(customs, cus)
  10952. }
  10953. }
  10954. if item.Type == 2 { //项目
  10955. for _, subItem := range item.HisPrescriptionProject {
  10956. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10957. cus := &Custom{
  10958. AdviceId: 0,
  10959. ProjectId: subItem.ID,
  10960. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10961. Cut: fmt.Sprintf("%.2f", cnt),
  10962. FeedetlSn: subItem.FeedetlSn,
  10963. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10964. MedListCodg: subItem.MedListCodg,
  10965. Type: 2,
  10966. }
  10967. customs = append(customs, cus)
  10968. }
  10969. }
  10970. for _, item := range item.HisAdditionalCharge {
  10971. cus := &Custom{
  10972. ItemId: item.ID,
  10973. AdviceId: 0,
  10974. ProjectId: 0,
  10975. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10976. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10977. FeedetlSn: item.FeedetlSn,
  10978. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10979. MedListCodg: item.XtHisAddtionConfig.Code,
  10980. Type: 3,
  10981. }
  10982. customs = append(customs, cus)
  10983. }
  10984. }
  10985. fmt.Println(customs)
  10986. for _, item := range customs {
  10987. var advice_id int64 = 0
  10988. var project_id int64 = 0
  10989. var item_id int64 = 0
  10990. var types int64 = 0
  10991. if item.Type == 1 {
  10992. advice_id = item.AdviceId
  10993. project_id = 0
  10994. item_id = 0
  10995. } else if item.Type == 2 {
  10996. advice_id = 0
  10997. item_id = 0
  10998. project_id = item.ProjectId
  10999. } else if item.Type == 3 {
  11000. advice_id = 0
  11001. item_id = item.ItemId
  11002. project_id = 0
  11003. }
  11004. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11005. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11006. pric, _ := strconv.ParseFloat(item.Price, 32)
  11007. info := &models.HisOrderInfo{
  11008. OrderNumber: order.Number,
  11009. UploadDate: time.Now().Unix(),
  11010. AdviceId: advice_id,
  11011. DetItemFeeSumamt: detItemFeeSumamt,
  11012. Cnt: cut,
  11013. Pric: pric,
  11014. PatientId: id,
  11015. Status: 1,
  11016. Mtime: time.Now().Unix(),
  11017. Ctime: time.Now().Unix(),
  11018. UserOrgId: adminUser.CurrentOrgId,
  11019. HisPatientId: his.ID,
  11020. OrderId: order.ID,
  11021. ProjectId: project_id,
  11022. Type: types,
  11023. ItemId: item_id,
  11024. }
  11025. service.CreateOrderInfo(info)
  11026. }
  11027. his.SickType = sick_type
  11028. service.UpdataHisPateint(&his)
  11029. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11030. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11031. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11032. if err == nil {
  11033. c.ServeSuccessJSON(map[string]interface{}{
  11034. "msg": "结算成功",
  11035. })
  11036. }
  11037. }
  11038. type CustomOrderInfo struct {
  11039. Name string
  11040. Spec string
  11041. Unit string
  11042. Count float64
  11043. Price float64
  11044. Total float64
  11045. }
  11046. func (c *HisApiController) GetPrivateExpensesInfo() {
  11047. order_id, _ := c.GetInt64("id", 0)
  11048. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11049. order, _ := service.GetHisOrderByID(order_id)
  11050. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11051. if order.ID == 0 {
  11052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11053. return
  11054. }
  11055. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11056. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11057. org_id := c.GetAdminUserInfo().CurrentOrgId
  11058. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11059. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11060. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11061. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11062. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11063. //var orderInfos_four []*models.HisOrderInfoTwo
  11064. //for _, item := range orderInfos_three {
  11065. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11066. // item.HisPrescriptionProject.IsCheckTeam = 1
  11067. // orderInfos_four = append(orderInfos_four, item)
  11068. //
  11069. // }
  11070. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11071. // item.HisPrescriptionProject.IsCheckTeam = 2
  11072. // orderInfos_two = append(orderInfos_two, item)
  11073. // }
  11074. //}
  11075. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11076. //var cus_slice []CustomOrderInfo
  11077. //for _, item := range new_order_info {
  11078. // var cus CustomOrderInfo
  11079. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11080. // cus.Unit = ""
  11081. // cus.Spec = ""
  11082. // var total float64
  11083. // for _, subItem := range orderInfos_four {
  11084. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11085. // total = total + subItem.DetItemFeeSumamt
  11086. // fmt.Println(subItem.DetItemFeeSumamt)
  11087. // }
  11088. // }
  11089. // cus.Count = 1
  11090. // cus.Total = total
  11091. // cus_slice = append(cus_slice, cus)
  11092. //}
  11093. orderInfos = append(orderInfos, orderInfos_two...)
  11094. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11095. //orderInfos = append(orderInfos, orderInfos_three...)
  11096. //}/**/
  11097. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11098. c.ServeSuccessJSON(map[string]interface{}{
  11099. "order": order,
  11100. "order_info": orderInfos,
  11101. "patient": patient,
  11102. "admin_info": adminInfo,
  11103. "his": his,
  11104. "current_admin": role,
  11105. "org_config": miConfig,
  11106. //"new_order_info": cus_slice,
  11107. })
  11108. }
  11109. func (this *HisApiController) ChangeMedType() {
  11110. med_type := this.GetString("med_type")
  11111. old_med_type := this.GetString("old_med_type")
  11112. ids := this.GetString("ids")
  11113. settle_type, _ := this.GetInt64("settle_type")
  11114. start_time := this.GetString("start_time")
  11115. end_time := this.GetString("end_time")
  11116. ids_arr := strings.Split(ids, ",")
  11117. if settle_type == 1 { //日结
  11118. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11119. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11120. prescription.MedType = med_type
  11121. err := service.SaveHisPrescriptionTwo(&prescription)
  11122. if err == nil {
  11123. this.ServeSuccessJSON(map[string]interface{}{
  11124. "msg": "修改成功",
  11125. })
  11126. } else {
  11127. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11128. return
  11129. }
  11130. } else if settle_type == 2 {
  11131. timeLayout := "2006-01-02"
  11132. loc, _ := time.LoadLocation("Local")
  11133. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11134. if err != nil {
  11135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11136. return
  11137. }
  11138. recordStartTime := theStartTime.Unix()
  11139. start_time_timestamp := recordStartTime
  11140. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11141. if err != nil {
  11142. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11143. return
  11144. }
  11145. recordEndTime := theEndTime.Unix()
  11146. end_time_timestamp := recordEndTime
  11147. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11148. if updateErr == nil {
  11149. this.ServeSuccessJSON(map[string]interface{}{
  11150. "msg": "修改成功",
  11151. })
  11152. } else {
  11153. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11154. return
  11155. }
  11156. }
  11157. }
  11158. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11159. patient_id, _ := c.GetInt64("patient_id")
  11160. his_patient_id, _ := c.GetInt64("his_patient_id")
  11161. record_date := c.GetString("record_date")
  11162. start_time := c.GetString("start_time")
  11163. end_time := c.GetString("end_time")
  11164. order_status, _ := c.GetInt64("type", 0)
  11165. p_type, _ := c.GetInt64("p_type", 0)
  11166. order_id, _ := c.GetInt64("order_id", 0)
  11167. timeLayout := "2006-01-02"
  11168. loc, _ := time.LoadLocation("Local")
  11169. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11170. if err != nil {
  11171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11172. return
  11173. }
  11174. recordDateTime := theTime.Unix()
  11175. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11176. if err != nil {
  11177. }
  11178. startRecordDateTime := startTime.Unix()
  11179. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11180. if err != nil {
  11181. }
  11182. endRecordDateTime := endTime.Unix()
  11183. admin := c.GetAdminUserInfo()
  11184. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11185. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11186. order, _ := service.GetHisOrderByID(order_id)
  11187. var monthPrescriptions []*models.HisPrescription
  11188. if order_status == 1 || order_status == 0 {
  11189. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11190. } else if order_status == 2 {
  11191. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11192. }
  11193. var settle_total float64
  11194. for _, item := range monthPrescriptions {
  11195. if len(item.HisPrescriptionProject) > 0 {
  11196. for _, subItem := range item.HisPrescriptionProject {
  11197. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11198. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11199. settle_total = settle_total + total
  11200. }
  11201. }
  11202. if len(item.HisDoctorAdviceInfo) > 0 {
  11203. for _, subItem := range item.HisDoctorAdviceInfo {
  11204. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11205. settle_total = settle_total + total
  11206. }
  11207. }
  11208. }
  11209. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11210. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11211. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11212. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11213. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11214. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11215. //获取所有科室信息
  11216. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11217. var dia string
  11218. for _, item := range month_p_info {
  11219. if len(dia) == 0 {
  11220. dia = item.Diagnosis
  11221. } else {
  11222. dia = dia + "," + item.Diagnosis
  11223. }
  11224. }
  11225. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11226. dia_arr = removeEmptyStrings(dia_arr)
  11227. c.ServeSuccessJSON(map[string]interface{}{
  11228. "his_info": his_patient_info,
  11229. "xt_info": xt_patient_info,
  11230. "case_history": case_history,
  11231. "info": patientPrescriptionInfo,
  11232. "last_info": lastPatientPrescriptionInfo,
  11233. "month_prescriptions": monthPrescriptions,
  11234. "order": order,
  11235. "doctors": doctors,
  11236. "department": department,
  11237. "settle_total": settle_total,
  11238. "dia_arr": dia_arr,
  11239. })
  11240. return
  11241. }
  11242. func removeEmptyStrings(input []string) []string {
  11243. var output []string
  11244. for _, s := range input {
  11245. if s != "" {
  11246. output = append(output, s)
  11247. }
  11248. }
  11249. return output
  11250. }
  11251. func removeDuplicates(input []string) []string {
  11252. seen := make(map[string]bool)
  11253. output := []string{}
  11254. for _, s := range input {
  11255. if _, exists := seen[s]; !exists {
  11256. seen[s] = true
  11257. output = append(output, s)
  11258. }
  11259. }
  11260. return output
  11261. }
  11262. func (c *HisApiController) GetHisMonthPatientInfo() {
  11263. patient_id, _ := c.GetInt64("patient_id")
  11264. his_patient_id, _ := c.GetInt64("his_patient_id")
  11265. record_date := c.GetString("record_date")
  11266. number := c.GetString("number")
  11267. start_time := c.GetString("start_time")
  11268. end_time := c.GetString("end_time")
  11269. p_type, _ := c.GetInt64("p_type")
  11270. timeLayout := "2006-01-02"
  11271. loc, _ := time.LoadLocation("Local")
  11272. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11273. if err != nil {
  11274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11275. return
  11276. }
  11277. recordDateTime := theTime.Unix()
  11278. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11279. if err != nil {
  11280. }
  11281. startRecordDateTime := startTime.Unix()
  11282. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11283. if err != nil {
  11284. }
  11285. endRecordDateTime := endTime.Unix()
  11286. admin := c.GetAdminUserInfo()
  11287. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11288. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11289. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11290. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11291. var settle_total float64
  11292. for _, item := range monthPrescriptions {
  11293. if len(item.HisPrescriptionProject) > 0 {
  11294. for _, subItem := range item.HisPrescriptionProject {
  11295. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11296. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11297. settle_total = settle_total + total
  11298. }
  11299. }
  11300. if len(item.HisDoctorAdviceInfo) > 0 {
  11301. for _, subItem := range item.HisDoctorAdviceInfo {
  11302. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11303. settle_total = settle_total + total
  11304. }
  11305. }
  11306. }
  11307. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11308. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11309. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11310. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11311. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11312. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11313. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11314. //获取所有科室信息
  11315. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11316. c.ServeSuccessJSON(map[string]interface{}{
  11317. "his_info": his_patient_info,
  11318. "xt_info": xt_patient_info,
  11319. "case_history": case_history,
  11320. "info": patientPrescriptionInfo,
  11321. "month_prescriptions": monthPrescriptions,
  11322. "order": order,
  11323. "doctors": doctors,
  11324. "department": department,
  11325. "count": count,
  11326. "drugStockConfig": drugStockConfig,
  11327. "last_info": lastPatientPrescriptionInfo,
  11328. "settle_total": settle_total,
  11329. })
  11330. return
  11331. }
  11332. func (c *HisApiController) GetAllOrder() {
  11333. org_id := c.GetAdminUserInfo().CurrentOrgId
  11334. orders, _ := service.GetNewHisOrderList(org_id)
  11335. c.ServeSuccessJSON(map[string]interface{}{
  11336. "order": orders,
  11337. })
  11338. return
  11339. }
  11340. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11341. newArr = make([]*models.HisOrderInfoTwo, 0)
  11342. for i := 0; i < len(arr); i++ {
  11343. repeat := false
  11344. for j := i + 1; j < len(arr); j++ {
  11345. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11346. repeat = true
  11347. break
  11348. }
  11349. }
  11350. if !repeat {
  11351. newArr = append(newArr, arr[i])
  11352. }
  11353. }
  11354. return
  11355. }
  11356. // 修改处方退库操作 参数传修改之前的处方数据
  11357. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11358. if advice.ExecutionState == 1 {
  11359. //查询该病人该药品是否有库存记录
  11360. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11361. if errcode == gorm.ErrRecordNotFound {
  11362. } else {
  11363. //退库
  11364. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11365. if advice.PrescribingNumberUnit == drug.MinUnit {
  11366. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11367. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11368. //退库
  11369. warehouseInfo := models.DrugWarehouseInfo{
  11370. StockMinNumber: prescribingNumber,
  11371. }
  11372. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11373. operation_time := time.Now().Unix()
  11374. creater := advice.AdviceDoctor
  11375. ctime := time.Now().Unix()
  11376. timeStr := time.Now().Format("2006-01-02")
  11377. timeArr := strings.Split(timeStr, "-")
  11378. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11379. total = total + 1
  11380. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11381. cancelStock := models.DrugCancelStock{
  11382. OrderNumber: orderNumber,
  11383. OperaTime: operation_time,
  11384. OrgId: advice.UserOrgId,
  11385. Creater: creater,
  11386. Ctime: ctime,
  11387. Status: 1,
  11388. ReturnTime: advice.AdviceDate,
  11389. Dealer: info.Dealer,
  11390. Manufacturer: info.Manufacturer,
  11391. Type: 1,
  11392. }
  11393. service.AddSigleDrugCancelStock(&cancelStock)
  11394. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11395. dealer, _ := service.GetDealerById(info.Dealer)
  11396. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11397. cancelStockInfo := models.DrugCancelStockInfo{
  11398. OrderNumber: cancelInfo.OrderNumber,
  11399. CancelStockId: cancelInfo.ID,
  11400. DrugId: info.DrugId,
  11401. Count: info.Count,
  11402. Status: 1,
  11403. Ctime: ctime,
  11404. OrgId: advice.UserOrgId,
  11405. Type: 1,
  11406. Manufacturer: manufactureName.ManufacturerName,
  11407. Dealer: dealer.DealerName,
  11408. Total: 0,
  11409. RetailPrice: info.RetailPrice,
  11410. RetailTotalPrice: info.RetailTotalPrice,
  11411. Price: info.Price,
  11412. RegisterAccount: "",
  11413. Remark: info.Remark,
  11414. BatchNumber: info.BatchNumber,
  11415. MaxUnit: info.CountUnit,
  11416. ProductDate: info.ProductDate,
  11417. ExpiryDate: info.ExpiryDate,
  11418. BatchNumberId: info.WarehouseInfoId,
  11419. }
  11420. flow := models.DrugFlow{
  11421. WarehousingId: 0,
  11422. DrugId: info.DrugId,
  11423. Number: "",
  11424. BatchNumber: info.BatchNumber,
  11425. Count: info.Count,
  11426. UserOrgId: advice.UserOrgId,
  11427. PatientId: 0,
  11428. SystemTime: ctime,
  11429. ConsumableType: 4,
  11430. IsSys: 0,
  11431. WarehousingOrder: "",
  11432. WarehouseOutId: 0,
  11433. WarehouseOutOrderNumber: "",
  11434. IsEdit: 0,
  11435. CancelStockId: cancelStock.ID,
  11436. CancelOrderNumber: cancelStock.OrderNumber,
  11437. Manufacturer: info.Manufacturer,
  11438. Dealer: info.Dealer,
  11439. Creator: advice.UserOrgId,
  11440. UpdateCreator: 0,
  11441. Status: 1,
  11442. Ctime: time.Now().Unix(),
  11443. Mtime: 0,
  11444. Price: info.Price,
  11445. WarehousingDetailId: 0,
  11446. WarehouseOutDetailId: 0,
  11447. CancelOutDetailId: 0,
  11448. ExpireDate: info.ExpiryDate,
  11449. ProductDate: info.ProductDate,
  11450. MaxUnit: info.CountUnit,
  11451. MinUnit: "",
  11452. }
  11453. service.CreatedCancelStock(cancelStockInfo)
  11454. service.CreateDrugFlowOne(flow)
  11455. } else {
  11456. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11457. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11458. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11459. warehouseInfo := models.DrugWarehouseInfo{
  11460. StockMinNumber: prescribingNumber,
  11461. }
  11462. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11463. }
  11464. operation_time := time.Now().Unix()
  11465. creater := advice.AdviceDoctor
  11466. ctime := time.Now().Unix()
  11467. timeStr := time.Now().Format("2006-01-02")
  11468. timeArr := strings.Split(timeStr, "-")
  11469. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11470. total = total + 1
  11471. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11472. cancelStock := models.DrugCancelStock{
  11473. OrderNumber: orderNumber,
  11474. OperaTime: operation_time,
  11475. OrgId: advice.UserOrgId,
  11476. Creater: creater,
  11477. Ctime: ctime,
  11478. Status: 1,
  11479. ReturnTime: advice.AdviceDate,
  11480. Dealer: info.Dealer,
  11481. Manufacturer: info.Manufacturer,
  11482. Type: 1,
  11483. }
  11484. service.AddSigleDrugCancelStock(&cancelStock)
  11485. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11486. dealer, _ := service.GetDealerById(info.Dealer)
  11487. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11488. cancelStockInfo := models.DrugCancelStockInfo{
  11489. OrderNumber: cancelInfo.OrderNumber,
  11490. CancelStockId: cancelInfo.ID,
  11491. DrugId: info.DrugId,
  11492. Count: info.Count,
  11493. Status: 1,
  11494. Ctime: ctime,
  11495. OrgId: advice.UserOrgId,
  11496. Type: 1,
  11497. Manufacturer: manufactureName.ManufacturerName,
  11498. Dealer: dealer.DealerName,
  11499. Total: 0,
  11500. RetailPrice: info.RetailPrice,
  11501. RetailTotalPrice: info.RetailTotalPrice,
  11502. Price: info.Price,
  11503. RegisterAccount: "",
  11504. Remark: info.Remark,
  11505. BatchNumber: info.BatchNumber,
  11506. MaxUnit: info.CountUnit,
  11507. ProductDate: info.ProductDate,
  11508. ExpiryDate: info.ExpiryDate,
  11509. BatchNumberId: info.WarehouseInfoId,
  11510. }
  11511. flow := models.DrugFlow{
  11512. WarehousingId: 0,
  11513. DrugId: info.DrugId,
  11514. Number: "",
  11515. BatchNumber: info.BatchNumber,
  11516. Count: info.Count,
  11517. UserOrgId: advice.UserOrgId,
  11518. PatientId: 0,
  11519. SystemTime: ctime,
  11520. ConsumableType: 4,
  11521. IsSys: 0,
  11522. WarehousingOrder: "",
  11523. WarehouseOutId: 0,
  11524. WarehouseOutOrderNumber: "",
  11525. IsEdit: 0,
  11526. CancelStockId: cancelStock.ID,
  11527. CancelOrderNumber: cancelStock.OrderNumber,
  11528. Manufacturer: info.Manufacturer,
  11529. Dealer: info.Dealer,
  11530. Creator: advice.AdviceDoctor,
  11531. UpdateCreator: 0,
  11532. Status: 1,
  11533. Ctime: time.Now().Unix(),
  11534. Mtime: 0,
  11535. Price: info.Price,
  11536. WarehousingDetailId: 0,
  11537. WarehouseOutDetailId: 0,
  11538. CancelOutDetailId: 0,
  11539. ExpireDate: info.ExpiryDate,
  11540. ProductDate: info.ProductDate,
  11541. MaxUnit: info.CountUnit,
  11542. MinUnit: "",
  11543. }
  11544. service.CreatedCancelStock(cancelStockInfo)
  11545. service.CreateDrugFlowOne(flow)
  11546. }
  11547. }
  11548. }
  11549. return err
  11550. }
  11551. func (this *HisApiController) DeleteNCDS() {
  11552. id, _ := this.GetInt64("id", 0)
  11553. if id > 0 {
  11554. service.DeletePsnNCDSRecordById(id)
  11555. this.ServeSuccessJSON(map[string]interface{}{
  11556. "msg": "删除成功",
  11557. })
  11558. } else {
  11559. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11560. return
  11561. }
  11562. }
  11563. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11564. id, _ := c.GetInt64("id")
  11565. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11566. c.ServeSuccessJSON(map[string]interface{}{
  11567. "advice": advice,
  11568. })
  11569. return
  11570. }
  11571. func (c *HisApiController) GetHisMonthChargePatientList() {
  11572. record_date := c.GetString("record_date")
  11573. start_time := c.GetString("start_time")
  11574. end_time := c.GetString("end_time")
  11575. timeLayout := "2006-01-02"
  11576. loc, _ := time.LoadLocation("Local")
  11577. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11578. if err != nil {
  11579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11580. return
  11581. }
  11582. if err != nil {
  11583. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11584. return
  11585. }
  11586. recordDateTime := theTime.Unix()
  11587. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11588. if err != nil {
  11589. }
  11590. startRecordDateTime := startTime.Unix()
  11591. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11592. if err != nil {
  11593. }
  11594. endRecordDateTime := endTime.Unix()
  11595. adminInfo := c.GetAdminUserInfo()
  11596. var tempMonthChargePatients []*service.MonthChargePatients
  11597. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11598. for _, item := range tempPatients {
  11599. //过滤没有处方的
  11600. if len(item.HisPrescription) == 0 {
  11601. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11602. }
  11603. }
  11604. c.ServeSuccessJSON(map[string]interface{}{
  11605. "list": tempMonthChargePatients,
  11606. })
  11607. }
  11608. // PrescriptionDifference 医嘱数量差值结构体
  11609. type PrescriptionDrugDifference struct {
  11610. DrugID int64 //基础库药品id
  11611. ID int64 //医嘱id
  11612. Difference float64 //差值
  11613. Unit string //单位
  11614. }
  11615. type PrescriptionGoodDifference struct {
  11616. GoodID int64 //基础库项目耗材id
  11617. ID int64 //医嘱id
  11618. Difference int64 //差值
  11619. Unit string //单位
  11620. Type int64 //类型
  11621. }
  11622. type EditCustomData struct {
  11623. adviceList []*models.HisDoctorAdviceInfo
  11624. projectList []*models.HisPrescriptionProject
  11625. }
  11626. type SrcCustomData struct {
  11627. adviceList []*models.HisDoctorAdviceInfo
  11628. projectList []*models.HisPrescriptionProject
  11629. }
  11630. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11631. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11632. differences := make([]*PrescriptionDrugDifference, 0)
  11633. // 创建一个 map 来存储第一个切片中的药品信息
  11634. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11635. for _, advice := range firstPrescription {
  11636. firstMap[advice.DrugId] = advice
  11637. }
  11638. // 遍历第二个切片中的药品信息,并比较数量差值
  11639. for _, advice := range secondPrescription {
  11640. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11641. diff := &PrescriptionDrugDifference{
  11642. DrugID: advice.DrugId,
  11643. ID: firstAdvice.ID,
  11644. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11645. Unit: firstAdvice.PrescribingNumberUnit,
  11646. }
  11647. differences = append(differences, diff)
  11648. }
  11649. }
  11650. return differences
  11651. }
  11652. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11653. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11654. differences := make([]*PrescriptionGoodDifference, 0)
  11655. // 创建一个 map 来存储第一个切片中的耗材信息
  11656. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11657. for _, good := range firstPrescription {
  11658. firstMap[good.ProjectId] = good
  11659. }
  11660. // 遍历第二个切片中的耗材信息,并比较数量差值
  11661. for _, good := range secondPrescription {
  11662. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11663. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11664. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11665. diff := &PrescriptionGoodDifference{
  11666. GoodID: good.ProjectId,
  11667. ID: firstGood.ID,
  11668. Difference: count - firstCount,
  11669. Unit: firstGood.Unit,
  11670. Type: firstGood.Type,
  11671. }
  11672. differences = append(differences, diff)
  11673. }
  11674. }
  11675. return differences
  11676. }
  11677. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11678. var adviceList []*models.HisDoctorAdviceInfo
  11679. var projectList []*models.HisPrescriptionProject
  11680. var advice_ids []int64
  11681. var project_ids []int64
  11682. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11683. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11684. //var tempPrescription *models.HisPrescriptionProjectscription
  11685. if len(prescriptions) > 0 {
  11686. for _, item := range prescriptions {
  11687. items := item.(map[string]interface{})
  11688. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11689. advices := items["advices"].([]interface{})
  11690. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11691. groupNo := int64(0)
  11692. ctime := time.Now().Unix()
  11693. mtime := ctime
  11694. if len(advices) > 0 {
  11695. for _, advice := range advices {
  11696. var s models.HisDoctorAdviceInfo
  11697. s.AdviceType = 2
  11698. s.StopState = 2
  11699. s.ExecutionState = 2
  11700. s.Status = 1
  11701. s.Groupno = groupNo
  11702. s.CreatedTime = ctime
  11703. s.UpdatedTime = mtime
  11704. s.IsSettle = 2
  11705. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11706. //存储切片中
  11707. if s.ID > 0 {
  11708. advice_ids = append(advice_ids, s.ID)
  11709. adviceList = append(adviceList, &s)
  11710. }
  11711. }
  11712. }
  11713. }
  11714. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11715. projects := items["project"].([]interface{})
  11716. if len(projects) > 0 {
  11717. for _, project := range projects {
  11718. var p models.HisPrescriptionProject
  11719. p.Ctime = time.Now().Unix()
  11720. p.Mtime = time.Now().Unix()
  11721. p.Status = 1
  11722. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11723. if p.ID > 0 {
  11724. project_ids = append(project_ids, p.ID)
  11725. projectList = append(projectList, &p)
  11726. }
  11727. }
  11728. }
  11729. }
  11730. }
  11731. }
  11732. }
  11733. editCustomData.projectList = projectList
  11734. editCustomData.adviceList = adviceList
  11735. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11736. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11737. srcCustomData.adviceList = list
  11738. srcCustomData.projectList = list2
  11739. return
  11740. }