his_api_controller.go 546KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068
  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/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  90. }
  91. func (c *HisApiController) CheckHisPatient() {
  92. record_date := c.GetString("record_date")
  93. patient_id, _ := c.GetInt64("patient_id")
  94. timeLayout := "2006-01-02"
  95. loc, _ := time.LoadLocation("Local")
  96. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  97. if err != nil {
  98. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  99. return
  100. }
  101. recordDateTime := theTime.Unix()
  102. adminInfo := c.GetAdminUserInfo()
  103. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  104. if len(patients) > 1 {
  105. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  106. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  107. c.ServeSuccessJSON(map[string]interface{}{
  108. "status": 1,
  109. "msg": "关联",
  110. "ps": ps,
  111. "his_patient_id": patients[len(patients)-1].ID,
  112. "patient_id": patients[len(patients)-1].PatientId,
  113. })
  114. } else {
  115. c.ServeSuccessJSON(map[string]interface{}{
  116. "status": 0,
  117. "msg": "无需关联",
  118. })
  119. }
  120. } else {
  121. c.ServeSuccessJSON(map[string]interface{}{
  122. "status": 0,
  123. "msg": "无需关联",
  124. })
  125. return
  126. }
  127. }
  128. func (c *HisApiController) AssociationHisPrescription() {
  129. record_date := c.GetString("record_date")
  130. his_patient_id, _ := c.GetInt64("his_patient_id")
  131. patient_id, _ := c.GetInt64("patient_id")
  132. p_ids := c.GetString("p_ids")
  133. p_ids_arr := strings.Split(p_ids, ",")
  134. timeLayout := "2006-01-02"
  135. loc, _ := time.LoadLocation("Local")
  136. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  137. if err != nil {
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. return
  140. }
  141. recordDateTime := theTime.Unix()
  142. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  143. if his_patient_id == 0 || his_patient.ID == 0 {
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  145. return
  146. }
  147. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  148. if err == nil {
  149. c.ServeSuccessJSON(map[string]interface{}{
  150. "msg": "关联处方成功",
  151. })
  152. return
  153. } else {
  154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  155. return
  156. }
  157. }
  158. //func (c *HisApiController) AssociationHisPrescription() {
  159. // record_date, _ := c.GetInt64("record_date")
  160. // his_patient_id, _ := c.GetInt64("his_patient_id")
  161. // patient_id, _ := c.GetInt64("patient_id")
  162. // p_ids := c.GetString("p_ids")
  163. // p_ids_arr := strings.Split(p_ids, ",")
  164. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  165. // if his_patient_id == 0 || his_patient.ID == 0 {
  166. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  167. // return
  168. // }
  169. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  170. // if err == nil {
  171. // c.ServeSuccessJSON(map[string]interface{}{
  172. // "msg": "关联处方成功",
  173. // })
  174. // return
  175. // } else {
  176. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  177. // return
  178. // }
  179. //}
  180. func (c *HisApiController) GetFaPiaoNumber() {
  181. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  182. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  183. fmt.Println(count)
  184. var zero string
  185. number := count + 1
  186. //if number >= 1000 {
  187. // zero = "0000" + strconv.FormatInt(number, 10)
  188. //} else if number >= 10000 {
  189. // zero = "000" + strconv.FormatInt(number, 10)
  190. //} else if number >= 100000 {
  191. // zero = "00" + strconv.FormatInt(number, 10)
  192. //} else if number >= 1000000 {
  193. // zero = "0" + strconv.FormatInt(number, 10)
  194. //} else {
  195. zero = "0" + strconv.FormatInt(number, 10)
  196. //}
  197. c.ServeSuccessJSON(map[string]interface{}{
  198. "fapiao_number": zero,
  199. })
  200. return
  201. }
  202. func (c *HisApiController) ChangeOrderDesc() {
  203. id, _ := c.GetInt64("id")
  204. desc := c.GetString("desc")
  205. change_type := c.GetString("change_type")
  206. order, _ := service.GetHisOrderByID(id)
  207. if order.ID == 0 {
  208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  209. return
  210. }
  211. switch change_type {
  212. case "oth_desc":
  213. order.OthDesc = desc
  214. break
  215. case "cash_pay":
  216. order.CashPay = desc
  217. break
  218. case "jifen_pay":
  219. order.JifenPay = desc
  220. break
  221. case "band_card_pay":
  222. order.BandCardPay = desc
  223. break
  224. case "ali_pay":
  225. order.AliPay = desc
  226. break
  227. case "wechat_pay":
  228. order.WechatPay = desc
  229. break
  230. case "fa_piao_number":
  231. order.FaPiaoNumber = desc
  232. break
  233. case "fa_piao_code":
  234. order.FaPiaoCode = desc
  235. break
  236. }
  237. err := service.SaveHisOrder(&order)
  238. if err == nil {
  239. c.ServeSuccessJSON(map[string]interface{}{
  240. "msg": "修改成功",
  241. })
  242. return
  243. } else {
  244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  245. return
  246. }
  247. }
  248. func (c *HisApiController) GetMonthHisPatient() {
  249. record_date := c.GetString("record_date")
  250. //order_status, _ := c.GetInt64("type")
  251. timeLayout := "2006-01-02"
  252. loc, _ := time.LoadLocation("Local")
  253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  254. if err != nil {
  255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  256. return
  257. }
  258. recordDateTime := theTime.Unix()
  259. adminInfo := c.GetAdminUserInfo()
  260. var tempPatients []service.NewTempPatients
  261. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  262. // 获取当前时间
  263. now := time.Now()
  264. // 获取本月的第一天
  265. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  266. // 获取下个月的第一天
  267. nextMonth := firstDay.AddDate(0, 1, 0)
  268. // 获取本月的最后一天
  269. lastDay := nextMonth.Add(-time.Nanosecond)
  270. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  271. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  272. var patients []service.NewTempPatients
  273. var patients_two []service.NewTempPatients
  274. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  275. for _, item := range tempPatients {
  276. //过滤掉没挂号的和没开处方的
  277. if len(item.HisPrescription) > 0 {
  278. patients = append(patients, item)
  279. patients_two = append(patients_two, item)
  280. }
  281. ////过滤掉没挂号的
  282. //if len(item.HisPatient) > 0 {
  283. //}
  284. }
  285. } else {
  286. for _, item := range tempPatients {
  287. //过滤掉没挂号的和没开处方的
  288. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  289. patients = append(patients, item)
  290. }
  291. ////过滤掉没挂号的
  292. //if len(item.HisPatient) > 0 {
  293. // patients_two = append(patients_two, item)
  294. //}
  295. }
  296. }
  297. c.ServeSuccessJSON(map[string]interface{}{
  298. "list": patients,
  299. "list_two": patients_two,
  300. "chargePatients": chargePatients,
  301. })
  302. }
  303. func (c *HisApiController) GetBatchSettleAccounts() {
  304. order_ids := c.GetString("order_ids")
  305. admin_user_id, _ := c.GetInt64("admin_user_id")
  306. adminUser := c.GetAdminUserInfo()
  307. orders := strings.Split(order_ids, ",")
  308. var newOrders []models.Orders
  309. for _, item := range orders {
  310. order, _ := service.GetHisOrderByIDTenOne(item)
  311. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  312. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  313. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  314. orderInfos = append(orderInfos, orderInfos_two...)
  315. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  316. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  317. var diagnosis_ids []string
  318. if his.ID > 0 {
  319. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  320. } else {
  321. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  322. }
  323. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  324. var dia_config []*models.HisXtDiagnoseConfig
  325. var name string
  326. for _, item := range diagnosis_ids {
  327. id, _ := strconv.ParseInt(item, 10, 64)
  328. diagnosisConfig, _ := service.FindDiagnoseById(id)
  329. dia_config = append(dia_config, diagnosisConfig)
  330. if len(name) == 0 {
  331. name = diagnosisConfig.ClassName
  332. } else {
  333. name = name + "," + diagnosisConfig.ClassName
  334. }
  335. }
  336. var bedCostTotal float64 = 0 //床位总费
  337. var bedCostSelfTotal float64 = 0 //床位自费
  338. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  339. var bedSelfTotal float64 = 0 //床位部分项目自费
  340. var bedInscpTotal float64 = 0 //床位部分项目自费
  341. var operationCostTotal float64 = 0 //手术费
  342. var operationCostSelfTotal float64 = 0 //手术费
  343. var operationCostPartSelfTotal float64 = 0 //手术费
  344. var operationSelfTotal float64 = 0 //床位部分项目自费
  345. var operationInscpTotal float64 = 0 //床位部分项目自费
  346. var otherCostTotal float64 = 0 //其他费用
  347. var otherCostSelfTotal float64 = 0 //其他费用
  348. var otherCostPartSelfTotal float64 = 0 //其他费用
  349. var otherSelfTotal float64 = 0 //床位部分项目自费
  350. var otherInscpTotal float64 = 0 //床位部分项目自费
  351. var materialCostTotal float64 = 0 //材料费
  352. var materialCostSelfTotal float64 = 0 //材料费
  353. var materialCostPartSelfTotal float64 = 0 //材料费
  354. var materialSelfTotal float64 = 0 //床位部分项目自费
  355. var materialInscpTotal float64 = 0 //床位部分项目自费
  356. var westernMedicineCostTotal float64 = 0 //西药费
  357. var westernMedicineCostSelfTotal float64 = 0 //西药费
  358. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  359. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  360. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  361. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  365. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  366. var checkCostTotal float64 = 0 //检查费
  367. var checkCostSelfTotal float64 = 0 //检查费
  368. var checkCostPartSelfTotal float64 = 0 //检查费
  369. var checkSelfTotal float64 = 0 //床位部分项目自费
  370. var checkInscpTotal float64 = 0 //床位部分项目自费
  371. var laboratoryCostTotal float64 = 0 //化验费
  372. var laboratoryCostSelfTotal float64 = 0 //化验费
  373. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  374. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  375. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  376. var treatCostTotal float64 = 0 //治疗费用
  377. var treatCostSelfTotal float64 = 0 //治疗费用
  378. var treatCostPartSelfTotal float64 = 0 //治疗费用
  379. var treatSelfTotal float64 = 0 //床位部分项目自费
  380. var treatInscpTotal float64 = 0 //床位部分项目自费
  381. decimal.DivisionPrecision = 2
  382. for _, item := range orderInfos {
  383. if item.MedChrgitmType == "01" { //床位费
  384. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  385. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  386. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  387. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  388. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  389. }
  390. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  391. if item.MedChrgitmType == "03" { //检查费
  392. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  393. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  394. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  395. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  396. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  397. }
  398. } else {
  399. if item.MedChrgitmType == "03" { //检查费
  400. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  401. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  402. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  403. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  404. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  405. }
  406. }
  407. if item.MedChrgitmType == "04" { //化验费
  408. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  409. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  410. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  411. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  412. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  413. }
  414. if item.MedChrgitmType == "05" { //治疗费
  415. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  416. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  417. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  418. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  419. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  420. }
  421. if item.MedChrgitmType == "06" { //手术费
  422. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  423. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  424. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  425. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  426. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  427. }
  428. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  429. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  430. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  431. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  432. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  433. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  434. }
  435. if item.MedChrgitmType == "09" { //西药费
  436. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  437. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  438. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  439. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  440. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  441. }
  442. if item.MedChrgitmType == "11" { //中成费
  443. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  444. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  445. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  446. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  447. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  448. }
  449. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  450. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  451. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  452. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  453. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  454. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  455. }
  456. }
  457. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  458. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  459. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  460. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  461. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  462. var doctor_name string
  463. if roles.ID == 0 {
  464. doctor_name = "管理员"
  465. } else {
  466. doctor_name = roles.UserName
  467. }
  468. yiliao_leibie := ""
  469. switch order.MedType {
  470. case "11":
  471. yiliao_leibie = "普通门诊"
  472. break
  473. case "12":
  474. yiliao_leibie = "门诊挂号"
  475. break
  476. case "13":
  477. yiliao_leibie = "急诊"
  478. break
  479. case "14":
  480. yiliao_leibie = "门诊特殊病"
  481. break
  482. case "15":
  483. yiliao_leibie = "门诊统筹"
  484. break
  485. case "16":
  486. yiliao_leibie = "门诊慢性病"
  487. break
  488. case "21":
  489. yiliao_leibie = "普通住院"
  490. break
  491. }
  492. var newOrder models.Orders
  493. newOrder.Diagnosis = name
  494. newOrder.OrderInfos = orderInfos
  495. newOrder.Number = order.MdtrtId
  496. newOrder.Date = order.SettleAccountsDate
  497. newOrder.ChargeAdmin = charge_admin
  498. newOrder.PrintorAdmin = printor_admin
  499. newOrder.Order = order
  500. newOrder.BedCostTotal = bedCostTotal
  501. newOrder.BedCostSelfTotal = bedCostSelfTotal
  502. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  503. newOrder.BedSelfTotal = bedSelfTotal
  504. newOrder.BedInscpTotal = bedInscpTotal
  505. newOrder.OperationCostTotal = operationCostTotal
  506. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  507. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  508. newOrder.OperationSelfTotal = operationSelfTotal
  509. newOrder.OperationInscpTotal = operationInscpTotal
  510. newOrder.OtherCostTotal = otherCostTotal
  511. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  512. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  513. newOrder.OtherSelfTotal = otherSelfTotal
  514. newOrder.OtherInscpTotal = otherInscpTotal
  515. newOrder.MaterialCostTotal = materialCostTotal
  516. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  517. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  518. newOrder.MaterialSelfTotal = materialSelfTotal
  519. newOrder.MaterialInscpTotal = materialInscpTotal
  520. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  521. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  522. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  523. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  524. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  525. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  526. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  527. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  528. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  529. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  530. newOrder.CheckCostTotal = checkCostTotal
  531. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  532. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  533. newOrder.CheckSelfTotal = checkSelfTotal
  534. newOrder.CheckInscpTotal = checkInscpTotal
  535. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  536. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  537. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  538. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  539. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  540. newOrder.TreatCostTotal = treatCostTotal
  541. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  542. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  543. newOrder.TreatSelfTotal = treatSelfTotal
  544. newOrder.TreatInscpTotal = treatInscpTotal
  545. newOrder.DoctorInfo = doctor_info
  546. newOrder.DoctorName = doctor_name
  547. newOrder.HealthCardNo = order.PsnNo
  548. newOrder.YiliaoLeibie = yiliao_leibie
  549. newOrder.Patient = patient
  550. newOrder.OrgName = miConfig.OrgName
  551. newOrder.OrgCode = miConfig.Code
  552. newOrder.OrderNumber = order.Number
  553. newOrder.HisPatient = his
  554. newOrder.DiaConfig = dia_config
  555. newOrders = append(newOrders, newOrder)
  556. }
  557. c.ServeSuccessJSON(map[string]interface{}{
  558. "orders": newOrders,
  559. })
  560. }
  561. func (c *HisApiController) GetTestOrder() {
  562. order_id, _ := c.GetInt64("order_id")
  563. admin_user_id, _ := c.GetInt64("admin_user_id")
  564. adminUser := c.GetAdminUserInfo()
  565. order, _ := service.GetHisOrderByID(order_id)
  566. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  567. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  568. orderInfos = append(orderInfos, orderInfos_two...)
  569. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  570. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  571. var dia_config []*models.HisXtDiagnoseConfig
  572. var name string
  573. var bedCostTotal float64 = 0 //床位总费
  574. var bedCostSelfTotal float64 = 0 //床位自费
  575. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  576. var bedSelfTotal float64 = 0 //床位部分项目自费
  577. var bedInscpTotal float64 = 0 //床位部分项目自费
  578. var operationCostTotal float64 = 0 //手术费
  579. var operationCostSelfTotal float64 = 0 //手术费
  580. var operationCostPartSelfTotal float64 = 0 //手术费
  581. var operationSelfTotal float64 = 0 //床位部分项目自费
  582. var operationInscpTotal float64 = 0 //床位部分项目自费
  583. var otherCostTotal float64 = 0 //其他费用
  584. var otherCostSelfTotal float64 = 0 //其他费用
  585. var otherCostPartSelfTotal float64 = 0 //其他费用
  586. var otherSelfTotal float64 = 0 //床位部分项目自费
  587. var otherInscpTotal float64 = 0 //床位部分项目自费
  588. var materialCostTotal float64 = 0 //材料费
  589. var materialCostSelfTotal float64 = 0 //材料费
  590. var materialCostPartSelfTotal float64 = 0 //材料费
  591. var materialSelfTotal float64 = 0 //床位部分项目自费
  592. var materialInscpTotal float64 = 0 //床位部分项目自费
  593. var westernMedicineCostTotal float64 = 0 //西药费
  594. var westernMedicineCostSelfTotal float64 = 0 //西药费
  595. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  596. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  597. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  598. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  602. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  603. var checkCostTotal float64 = 0 //检查费
  604. var checkCostSelfTotal float64 = 0 //检查费
  605. var checkCostPartSelfTotal float64 = 0 //检查费
  606. var checkSelfTotal float64 = 0 //床位部分项目自费
  607. var checkInscpTotal float64 = 0 //床位部分项目自费
  608. var laboratoryCostTotal float64 = 0 //化验费
  609. var laboratoryCostSelfTotal float64 = 0 //化验费
  610. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  611. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  612. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  613. var treatCostTotal float64 = 0 //治疗费用
  614. var treatCostSelfTotal float64 = 0 //治疗费用
  615. var treatCostPartSelfTotal float64 = 0 //治疗费用
  616. var treatSelfTotal float64 = 0 //床位部分项目自费
  617. var treatInscpTotal float64 = 0 //床位部分项目自费
  618. decimal.DivisionPrecision = 2
  619. for _, item := range orderInfos {
  620. if item.MedChrgitmType == "01" { //床位费
  621. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  622. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  623. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  624. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  625. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  626. }
  627. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  628. if item.MedChrgitmType == "03" { //检查费
  629. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  630. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  631. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  632. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  633. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  634. }
  635. } else {
  636. if item.MedChrgitmType == "03" { //检查费
  637. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  638. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  639. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  640. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  641. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  642. }
  643. }
  644. if item.MedChrgitmType == "04" { //化验费
  645. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  646. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  647. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  648. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  649. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  650. }
  651. if item.MedChrgitmType == "05" { //治疗费
  652. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  653. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  654. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  655. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  656. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  657. }
  658. if item.MedChrgitmType == "06" { //手术费
  659. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  660. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  661. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  662. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  663. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  664. }
  665. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  666. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  667. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  668. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  669. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  670. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  671. }
  672. if item.MedChrgitmType == "09" { //西药费
  673. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  674. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  675. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  676. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  677. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  678. }
  679. if item.MedChrgitmType == "11" { //中成费
  680. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  681. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  682. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  683. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  684. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  685. }
  686. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  687. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  688. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  689. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  690. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  691. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  692. }
  693. }
  694. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  695. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  696. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  697. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  698. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  699. var doctor_name string
  700. if roles.ID == 0 {
  701. doctor_name = "管理员"
  702. } else {
  703. doctor_name = roles.UserName
  704. }
  705. yiliao_leibie := ""
  706. switch order.MedType {
  707. case "11":
  708. yiliao_leibie = "普通门诊"
  709. break
  710. case "12":
  711. yiliao_leibie = "门诊挂号"
  712. break
  713. case "13":
  714. yiliao_leibie = "急诊"
  715. break
  716. case "14":
  717. yiliao_leibie = "门诊特殊病"
  718. break
  719. case "15":
  720. yiliao_leibie = "门诊统筹"
  721. break
  722. case "16":
  723. yiliao_leibie = "门诊慢性病"
  724. break
  725. case "21":
  726. yiliao_leibie = "普通住院"
  727. break
  728. }
  729. c.ServeSuccessJSON(map[string]interface{}{
  730. "diagnosis": name,
  731. "order_infos": orderInfos,
  732. "number": order.MdtrtId,
  733. "date": order.SettleAccountsDate,
  734. "charge_admin": charge_admin,
  735. "printor_admin": printor_admin,
  736. "info": order,
  737. "order": order,
  738. "bedCostTotal": bedCostTotal,
  739. "bedCostSelfTotal": bedCostSelfTotal,
  740. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  741. "bedSelfTotal": bedSelfTotal,
  742. "bedInscpTotal": bedInscpTotal,
  743. "operationCostTotal": operationCostTotal,
  744. "operationCostSelfTotal": operationCostSelfTotal,
  745. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  746. "operationSelfTotal": operationSelfTotal,
  747. "operationInscpTotal": operationInscpTotal,
  748. "otherCostTotal": otherCostTotal,
  749. "otherCostSelfTotal": otherCostSelfTotal,
  750. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  751. "otherSelfTotal": otherSelfTotal,
  752. "otherInscpTotal": otherInscpTotal,
  753. "materialCostTotal": materialCostTotal,
  754. "materialCostSelfTotal": materialCostSelfTotal,
  755. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  756. "materialSelfTotal": materialSelfTotal,
  757. "materialInscpTotal": materialInscpTotal,
  758. "westernMedicineCostTotal": westernMedicineCostTotal,
  759. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  760. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  761. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  762. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  763. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  764. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  765. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  766. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  767. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  768. "checkCostTotal": checkCostTotal,
  769. "checkCostSelfTotal": checkCostSelfTotal,
  770. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  771. "checkSelfTotal": checkSelfTotal,
  772. "checkInscpTotal": checkInscpTotal,
  773. "laboratoryCostTotal": laboratoryCostTotal,
  774. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  775. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  776. "laboratorySelfTotal": laboratorySelfTotal,
  777. "laboratoryInscpTotal": laboratoryInscpTotal,
  778. "treatCostTotal": treatCostTotal,
  779. "treatCostSelfTotal": treatCostSelfTotal,
  780. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  781. "treatSelfTotal": treatSelfTotal,
  782. "treatInscpTotal": treatInscpTotal,
  783. "doctor_info": doctor_info,
  784. "doctor_name": doctor_name,
  785. "health_card_no": order.PsnNo,
  786. "yiliao_leibie": yiliao_leibie,
  787. "patient": patient,
  788. "org_name": miConfig.OrgName,
  789. "org_code": miConfig.Code,
  790. "order_number": order.Number,
  791. "his_hospital": his_hospital,
  792. "dia_config": dia_config,
  793. })
  794. }
  795. type CustomFundPay struct {
  796. FundPayType string `json:"fund_pay_type"`
  797. FundPayamt float64 `json:"fund_payamt"`
  798. InscpScpAmt float64 `json:"inscp_scp_amt"`
  799. }
  800. func (c *PublicApiController) GetBaiLinExportData() {
  801. data := service.GetBaiLinOrderData()
  802. fmt.Println(len(data))
  803. var new_data []*models.NewCustomHisOrder
  804. for _, item := range data {
  805. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  806. new_data = append(new_data, item)
  807. }
  808. }
  809. fmt.Println(len(new_data))
  810. c.ServeSuccessJSON(map[string]interface{}{
  811. "list": new_data,
  812. })
  813. }
  814. func (c *HisApiController) GetHisUnChargePatientList() {
  815. record_date := c.GetString("record_date")
  816. sch_type, _ := c.GetInt64("sch_type")
  817. timeLayout := "2006-01-02"
  818. loc, _ := time.LoadLocation("Local")
  819. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  820. if err != nil {
  821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  822. return
  823. }
  824. recordDateTime := theTime.Unix()
  825. adminInfo := c.GetAdminUserInfo()
  826. var tempPatients []*service.NewTempPatients
  827. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  828. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  829. var patients []*service.NewTempPatients
  830. var patients_two []*service.NewTempPatients
  831. for _, item := range tempPatients {
  832. //过滤掉没挂号的和没开处方的
  833. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  834. patients = append(patients, item)
  835. }
  836. //过滤掉没挂号的
  837. if len(item.HisPatient) > 0 {
  838. patients_two = append(patients_two, item)
  839. }
  840. }
  841. c.ServeSuccessJSON(map[string]interface{}{
  842. "list": patients,
  843. "list_two": patients_two,
  844. })
  845. }
  846. func (c *HisApiController) GetPrivateExpensesOrder() {
  847. //id, _ := c.GetInt64("id")
  848. //record_time := c.GetString("record_time")
  849. order_id, _ := c.GetInt64("order_id")
  850. admin_user_id, _ := c.GetInt64("admin_user_id")
  851. //timeLayout := "2006-01-02"
  852. //loc, _ := time.LoadLocation("Local")
  853. //
  854. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  855. //if err != nil {
  856. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  857. // return
  858. //}
  859. //recordDateTime := theTime.Unix()
  860. adminUser := c.GetAdminUserInfo()
  861. order, _ := service.GetHisOrderByID(order_id)
  862. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  863. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  864. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  866. //var config []*models.HisXtDiagnoseConfig
  867. var name string
  868. if order.PType == 1 {
  869. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  870. for _, item := range diagnosis_ids {
  871. id, _ := strconv.ParseInt(item, 10, 64)
  872. diagnosisConfig, _ := service.FindDiagnoseById(id)
  873. if len(name) == 0 {
  874. name = diagnosisConfig.ClassName
  875. } else {
  876. name = name + "," + diagnosisConfig.ClassName
  877. }
  878. }
  879. } else {
  880. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  881. for _, item := range diagnosis_ids {
  882. id, _ := strconv.ParseInt(item, 10, 64)
  883. diagnosisConfig, _ := service.FindDiagnoseById(id)
  884. if len(name) == 0 {
  885. name = diagnosisConfig.ClassName
  886. } else {
  887. name = name + "," + diagnosisConfig.ClassName
  888. }
  889. }
  890. }
  891. var bedCostTotal float64 = 0 //床位总费
  892. //var bedCostSelfTotal float64 = 0 //床位自费
  893. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  894. var operationCostTotal float64 = 0 //手术费
  895. //var operationCostSelfTotal float64 = 0 //手术费
  896. var operationCostPartSelfTotal float64 = 0 //手术费
  897. var otherCostTotal float64 = 0 //其他费用
  898. //var otherCostSelfTotal float64 = 0 //其他费用
  899. var otherCostPartSelfTotal float64 = 0 //其他费用
  900. var materialCostTotal float64 = 0 //材料费
  901. //var materialCostSelfTotal float64 = 0 //材料费
  902. var materialCostPartSelfTotal float64 = 0 //材料费
  903. var westernMedicineCostTotal float64 = 0 //西药费
  904. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  905. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  906. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  907. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  908. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  909. var checkCostTotal float64 = 0 //检查费
  910. //var checkCostSelfTotal float64 = 0 //检查费
  911. var checkCostPartSelfTotal float64 = 0 //检查费
  912. var laboratoryCostTotal float64 = 0 //化验费
  913. //var laboratoryCostSelfTotal float64 = 0 //化验费
  914. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  915. var treatCostTotal float64 = 0 //治疗费用
  916. //var treatCostSelfTotal float64 = 0 //治疗费用
  917. var treatCostPartSelfTotal float64 = 0 //治疗费用
  918. var zhenChaCostTotal float64 = 0 //其他费用
  919. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  920. decimal.DivisionPrecision = 2
  921. for _, item := range orderInfos {
  922. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  923. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  924. item.MedChrgitmType = "09"
  925. }
  926. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  927. if item.HisPrescriptionProject.Type == 2 {
  928. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  929. fmt.Println("CostClassify")
  930. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  931. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  932. case 0:
  933. item.MedChrgitmType = "0"
  934. break
  935. case 1:
  936. item.MedChrgitmType = "14"
  937. break
  938. case 2:
  939. item.MedChrgitmType = "05"
  940. break
  941. case 3:
  942. item.MedChrgitmType = "03"
  943. break
  944. case 4:
  945. item.MedChrgitmType = "03"
  946. break
  947. case 5:
  948. item.MedChrgitmType = "08"
  949. break
  950. case 6:
  951. item.MedChrgitmType = "14"
  952. break
  953. case 7:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 8:
  957. item.MedChrgitmType = "03"
  958. break
  959. case 9:
  960. item.MedChrgitmType = "14"
  961. break
  962. case 10:
  963. item.MedChrgitmType = "14"
  964. break
  965. case 11:
  966. item.MedChrgitmType = "06"
  967. break
  968. case 12:
  969. item.MedChrgitmType = "12"
  970. break
  971. case 13:
  972. item.MedChrgitmType = "01"
  973. break
  974. case 14:
  975. item.MedChrgitmType = "04"
  976. break
  977. case 15:
  978. item.MedChrgitmType = "14"
  979. break
  980. }
  981. } else {
  982. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  983. case 1:
  984. item.MedChrgitmType = "14"
  985. break
  986. case 2:
  987. item.MedChrgitmType = "05"
  988. break
  989. case 3:
  990. item.MedChrgitmType = "04"
  991. break
  992. case 4:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 5:
  996. item.MedChrgitmType = "08"
  997. break
  998. case 6:
  999. item.MedChrgitmType = "14"
  1000. break
  1001. case 7:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. case 8:
  1005. item.MedChrgitmType = "03"
  1006. break
  1007. case 9:
  1008. item.MedChrgitmType = "14"
  1009. break
  1010. default:
  1011. item.MedChrgitmType = "14"
  1012. break
  1013. }
  1014. }
  1015. } else if item.HisPrescriptionProject.Type == 3 {
  1016. item.MedChrgitmType = "08"
  1017. }
  1018. }
  1019. }
  1020. if order.IsMedicineInsurance != 1 {
  1021. order.PsnCashPay = order.MedfeeSumamt
  1022. }
  1023. for _, item := range orderInfos {
  1024. if item.MedChrgitmType == "01" { //床位费
  1025. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1026. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1027. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1028. }
  1029. if item.MedChrgitmType == "02" { //诊察费
  1030. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1031. //zhenChaCostSelfTotal = zhenChaCostTotal
  1032. }
  1033. if item.MedChrgitmType == "03" { //检查费
  1034. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1035. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1036. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1037. }
  1038. if item.MedChrgitmType == "02" { //检查费
  1039. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1040. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1041. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1042. }
  1043. if item.MedChrgitmType == "04" { //化验费
  1044. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1045. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1046. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1047. }
  1048. if item.MedChrgitmType == "05" { //治疗费
  1049. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1050. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1051. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1052. }
  1053. if item.MedChrgitmType == "06" { //手术费
  1054. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1055. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1056. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1057. }
  1058. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1059. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1060. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1061. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1062. }
  1063. if item.MedChrgitmType == "09" { //西药费
  1064. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1065. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1066. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1067. }
  1068. if item.MedChrgitmType == "11" { //中成费
  1069. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1070. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1071. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1072. }
  1073. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1074. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1075. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1076. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1077. }
  1078. }
  1079. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1080. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1081. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1082. var dia_config []*models.HisXtDiagnoseConfig
  1083. var diagnosis_ids []string
  1084. if his.ID > 0 {
  1085. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1086. } else {
  1087. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1088. }
  1089. for _, item := range diagnosis_ids {
  1090. id, _ := strconv.ParseInt(item, 10, 64)
  1091. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1092. dia_config = append(dia_config, diagnosisConfig)
  1093. }
  1094. var rf []CustomFundPay
  1095. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1096. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1097. c.ServeSuccessJSON(map[string]interface{}{
  1098. "patient": patient,
  1099. "order_infos": orderInfos,
  1100. "diagnosis": name,
  1101. "bedCostTotal": bedCostTotal,
  1102. "bedCostSelfTotal": bedCostTotal,
  1103. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1104. "operationCostTotal": operationCostTotal,
  1105. "operationCostSelfTotal": operationCostTotal,
  1106. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1107. "otherCostTotal": otherCostTotal,
  1108. "otherCostSelfTotal": otherCostTotal,
  1109. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1110. "materialCostTotal": materialCostTotal,
  1111. "materialCostSelfTotal": materialCostTotal,
  1112. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1113. "westernMedicineCostTotal": westernMedicineCostTotal,
  1114. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1116. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1117. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1119. "checkCostTotal": checkCostTotal,
  1120. "checkCostSelfTotal": checkCostTotal,
  1121. "zhenChaCostTotal": zhenChaCostTotal,
  1122. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1123. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1124. "laboratoryCostTotal": laboratoryCostTotal,
  1125. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1126. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1127. "treatCostTotal": treatCostTotal,
  1128. "treatCostSelfTotal": treatCostTotal,
  1129. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1130. "charge_admin": charge_admin,
  1131. "printor_admin": printor_admin,
  1132. "org_name": org.OrgName,
  1133. "org_code": miConfig.Code,
  1134. "name": patient.Name,
  1135. "number": order.MdtrtId,
  1136. "date": order.SettleAccountsDate,
  1137. "info": order,
  1138. "new_order": order,
  1139. "his_hospital": his_hospital,
  1140. "his": his,
  1141. "funds": rf,
  1142. "dia_config": dia_config,
  1143. })
  1144. }
  1145. func (c *HisApiController) RefudDetail() {
  1146. order_id, _ := c.GetInt64("order_id")
  1147. order, _ := service.GetHisOrderByID(order_id)
  1148. adminUser := c.GetAdminUserInfo()
  1149. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1150. c.ServeSuccessJSON(map[string]interface{}{
  1151. "msg": "撤销成功",
  1152. })
  1153. }
  1154. func (c *HisApiController) Sscard() {
  1155. //r := CardInit()
  1156. //if r == 0 {
  1157. // GetBaseInfo()
  1158. //}
  1159. //c.ServeSuccessJSON(map[string]interface{}{
  1160. // "list": "11",
  1161. //})
  1162. }
  1163. func GetBaseInfo() error {
  1164. //handle := syscall.MustLoadDLL("SSCard.dll")
  1165. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1166. //
  1167. //str := make([]byte, 256)
  1168. //str1 := make([]byte, 256)
  1169. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1170. //if ferr != nil {
  1171. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1172. // return ferr
  1173. //}
  1174. //
  1175. //fmt.Println(string(str))
  1176. //
  1177. //fmt.Println(r)
  1178. return nil
  1179. }
  1180. func CardInit() int {
  1181. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1182. //add := DllTestDef.MustFindProc("Init")
  1183. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1184. //if err != nil {
  1185. // fmt.Println("SSCard的运算结果为:", ret)
  1186. //}
  1187. //result := int(ret)
  1188. return 0
  1189. }
  1190. func IntPtr(n int) uintptr {
  1191. return uintptr(n)
  1192. }
  1193. func StrPtr(s string) uintptr {
  1194. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1195. }
  1196. func (c *HisApiController) GetHisPatientList() {
  1197. //types, _ := c.GetInt64("type", 0)
  1198. record_date := c.GetString("record_date")
  1199. sch_type, _ := c.GetInt64("sch_type")
  1200. timeLayout := "2006-01-02"
  1201. loc, _ := time.LoadLocation("Local")
  1202. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1203. if err != nil {
  1204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1205. return
  1206. }
  1207. recordDateTime := theTime.Unix()
  1208. adminInfo := c.GetAdminUserInfo()
  1209. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1210. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1211. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1212. //patient_three, _ := service.GetNewHisPatientListTwo(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1213. //patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1214. //获取当前用户的信息
  1215. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1216. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1217. //获取所有科室信息
  1218. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1219. //var aa []service.PatientThree
  1220. noElementsSlice := make([]service.PatientThree, 0)
  1221. c.ServeSuccessJSON(map[string]interface{}{
  1222. "list": patients,
  1223. "list_two": patients_two,
  1224. "list_three": noElementsSlice,
  1225. "info": adminUserInfo,
  1226. "doctors": doctors,
  1227. "department": department,
  1228. })
  1229. }
  1230. type CustomTemplate struct {
  1231. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1232. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1233. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1234. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1235. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1236. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1237. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1238. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1239. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1240. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1241. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1242. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1243. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1244. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1245. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1246. }
  1247. func (c *HisApiController) GetHisPatientInfo() {
  1248. patient_id, _ := c.GetInt64("patient_id")
  1249. his_patient_id, _ := c.GetInt64("his_patient_id")
  1250. record_date := c.GetString("record_date")
  1251. number := c.GetString("number")
  1252. //start_time := c.GetString("start_time")
  1253. //end_time := c.GetString("end_time")
  1254. p_type, _ := c.GetInt64("p_type")
  1255. timeLayout := "2006-01-02"
  1256. loc, _ := time.LoadLocation("Local")
  1257. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1258. if err != nil {
  1259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1260. return
  1261. }
  1262. recordDateTime := theTime.Unix()
  1263. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1264. //if err != nil {
  1265. //
  1266. //}
  1267. //startRecordDateTime := startTime.Unix()
  1268. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1269. //if err != nil {
  1270. //
  1271. //}
  1272. //endRecordDateTime := endTime.Unix()
  1273. admin := c.GetAdminUserInfo()
  1274. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1275. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1276. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1277. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1278. var prescriptions []*models.HisPrescription
  1279. var last_prescriptions []*models.HisPrescription
  1280. var sch_prescriptions []CustomTemplate
  1281. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1282. if p_type == 1 { //住院
  1283. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1284. for _, item := range prescriptions {
  1285. for _, subItem := range item.HisDoctorAdviceInfo {
  1286. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1287. if info.RetailPrice > 0 {
  1288. subItem.Drug.MinPrice = info.RetailPrice
  1289. }
  1290. }
  1291. }
  1292. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1293. } else { //门诊
  1294. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1295. for _, item := range prescriptions {
  1296. for _, subItem := range item.HisDoctorAdviceInfo {
  1297. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1298. if info.RetailPrice > 0 {
  1299. subItem.Drug.MinPrice = info.RetailPrice
  1300. }
  1301. }
  1302. }
  1303. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1304. }
  1305. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1306. if sch.ID > 0 {
  1307. var week string
  1308. t := time.Now()
  1309. switch t.Weekday().String() {
  1310. case "Monday":
  1311. week = "周一"
  1312. break
  1313. case "Tuesday":
  1314. week = "周二"
  1315. break
  1316. case "Wednesday":
  1317. week = "周三"
  1318. break
  1319. case "Thursday":
  1320. week = "周四"
  1321. break
  1322. case "Friday":
  1323. week = "周五"
  1324. break
  1325. case "Saturday":
  1326. week = "周六"
  1327. break
  1328. case "Sunday":
  1329. week = "周日"
  1330. break
  1331. }
  1332. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1333. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1334. //根据推送频率组装新的数组
  1335. for _, item := range temp_sch_prescriptions {
  1336. var cus CustomTemplate
  1337. cus.ID = item.ID
  1338. cus.UserOrgId = item.UserOrgId
  1339. cus.PatientId = item.PatientId
  1340. cus.MedType = item.MedType
  1341. cus.RecordDate = item.RecordDate
  1342. cus.Type = item.Type
  1343. cus.PType = item.PType
  1344. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1345. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1346. if subItem.FrequencyType == 1 { //每次必推
  1347. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1348. }
  1349. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1350. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1351. }
  1352. if subItem.FrequencyType == 2 { //按照天数频率
  1353. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1354. now := p.Unix()
  1355. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1356. dayStr2 := "-" + dayStr
  1357. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1358. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1359. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1360. if len(advices) == 0 {
  1361. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1362. }
  1363. }
  1364. }
  1365. }
  1366. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1367. if subItem.Type == 2 {
  1368. if subItem.XtHisProject.MedicalStatus != 1 {
  1369. if subItem.FrequencyType == 1 {
  1370. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1371. }
  1372. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1373. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1374. }
  1375. if subItem.FrequencyType == 2 {
  1376. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1377. now := p.Unix()
  1378. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1379. dayStr2 := "-" + dayStr
  1380. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1381. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1382. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1383. if len(projects) == 0 {
  1384. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1385. }
  1386. }
  1387. }
  1388. } else if subItem.Type == 3 {
  1389. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1390. if subItem.FrequencyType == 1 {
  1391. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1392. }
  1393. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1394. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1395. }
  1396. if subItem.FrequencyType == 2 {
  1397. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1398. now := p.Unix()
  1399. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1400. dayStr2 := "-" + dayStr
  1401. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1402. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1403. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1404. if len(projects) == 0 {
  1405. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1406. }
  1407. }
  1408. }
  1409. }
  1410. }
  1411. sch_prescriptions = append(sch_prescriptions, cus)
  1412. }
  1413. for _, item := range sch_prescriptions {
  1414. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1415. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1416. }
  1417. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1418. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1419. }
  1420. }
  1421. }
  1422. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1423. if config.ID > 0 && config.IsOpen == 1 {
  1424. for _, item := range sch_prescriptions {
  1425. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1426. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1427. if info.RetailPrice > 0 {
  1428. subItem.Drug.MinPrice = info.RetailPrice
  1429. if admin.CurrentOrgId != 10598 {
  1430. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1431. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1432. }
  1433. }
  1434. }
  1435. }
  1436. }
  1437. if config.ID > 0 && config.IsOpen == 1 {
  1438. for _, item := range sch_prescriptions {
  1439. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1440. if subItem.Type == 3 {
  1441. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1442. if info.Price > 0 {
  1443. subItem.GoodInfo.PackingPrice = info.Price
  1444. if admin.CurrentOrgId != 10598 {
  1445. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1446. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1447. }
  1448. }
  1449. }
  1450. }
  1451. }
  1452. }
  1453. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1454. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1455. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1456. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1457. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1458. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1459. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1460. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1461. //获取所有科室信息
  1462. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1463. beforThrity, _ := service.GetAssessmentBeforThrity(admin.CurrentOrgId, patient_id, recordDateTime)
  1464. LastCaseHistory, _ := service.GetLastHisPatientCaseHistory(admin.CurrentOrgId, patient_id)
  1465. c.ServeSuccessJSON(map[string]interface{}{
  1466. "his_info": his_patient_info,
  1467. "xt_info": xt_patient_info,
  1468. "prescription": prescriptions,
  1469. "case_history": case_history,
  1470. "info": patientPrescriptionInfo,
  1471. //"month_prescriptions": monthPrescriptions,
  1472. "order": order,
  1473. "doctors": doctors,
  1474. "department": department,
  1475. "sch_prescriptions": sch_prescriptions,
  1476. "last_prescriptions": last_prescriptions,
  1477. "schedule": sch,
  1478. "count": count,
  1479. "drugStockConfig": drugStockConfig,
  1480. "last_info": lastPatientPrescriptionInfo,
  1481. "befor": beforThrity,
  1482. "LastCaseHistory": LastCaseHistory,
  1483. })
  1484. return
  1485. }
  1486. func (c *HisApiController) GetHisPrescriptionConfig() {
  1487. adminInfo := c.GetAdminUserInfo()
  1488. //获取医嘱模版
  1489. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1490. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1491. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1492. //获取所有基础药
  1493. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1494. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1495. if config.ID > 0 && config.IsOpen == 1 {
  1496. for _, item := range drugs {
  1497. var index = 0
  1498. for _, subItem := range item.OtherDrugWarehouseInfo {
  1499. if index == 0 {
  1500. index = index + 1
  1501. if subItem.RetailPrice > 0 {
  1502. item.MinPrice = subItem.RetailPrice
  1503. }
  1504. }
  1505. }
  1506. }
  1507. }
  1508. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1509. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1510. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1511. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1512. //获取所有科室信息
  1513. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1514. //获取诊断信息
  1515. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1516. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1517. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1518. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1519. //获取是否开启保存耗材出库的开关
  1520. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1521. c.ServeSuccessJSON(map[string]interface{}{
  1522. "drugs": drugs,
  1523. "advices_template": advices,
  1524. "drugways": drugways,
  1525. "efs": efs,
  1526. "doctors": doctors,
  1527. "department": department,
  1528. "sick": sick,
  1529. "additions": additions,
  1530. "diagnose": diagnose,
  1531. "manufacturers": manufacturers,
  1532. "goodOutOpen": goodOutOpen,
  1533. "patientDiagnose": patientDiagnose,
  1534. })
  1535. }
  1536. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1537. //获取所有基础药
  1538. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1539. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1540. if config.ID > 0 && config.IsOpen == 1 {
  1541. for _, item := range drugs {
  1542. var index = 0
  1543. for _, subItem := range item.OtherDrugWarehouseInfo {
  1544. if index == 0 {
  1545. index = index + 1
  1546. if subItem.RetailPrice > 0 {
  1547. item.MinPrice = subItem.RetailPrice
  1548. }
  1549. }
  1550. }
  1551. }
  1552. }
  1553. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1554. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1555. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1556. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1557. //获取所有科室信息
  1558. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1559. //获取诊断信息
  1560. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1561. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1562. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1563. //获取是否开启保存耗材出库的开关
  1564. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1565. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1566. c.ServeSuccessJSON(map[string]interface{}{
  1567. "drugs": drugs,
  1568. "advices_template": advices,
  1569. "drugways": drugways,
  1570. "efs": efs,
  1571. "doctors": doctors,
  1572. "department": department,
  1573. "sick": sick,
  1574. "additions": additions,
  1575. "diagnose": diagnose,
  1576. "manufacturers": manufacturers,
  1577. "goodOutOpen": goodOutOpen,
  1578. "patientDiagnose": patientDiagnose,
  1579. })
  1580. }
  1581. }
  1582. func (c *HisApiController) CreateHisPrescription() {
  1583. record_date := c.GetString("record_date")
  1584. patient_id, _ := c.GetInt64("patient_id")
  1585. reg_type, _ := c.GetInt64("reg_type")
  1586. diagnose := c.GetString("diagnose")
  1587. sick_type, _ := c.GetInt64("sick_type")
  1588. sick_history := c.GetString("sick_history")
  1589. doctor_id, _ := c.GetInt64("doctor", 0)
  1590. department, _ := c.GetInt64("department", 0)
  1591. his_patient_id, _ := c.GetInt64("his_patient_id")
  1592. p_type, _ := c.GetInt64("p_type")
  1593. patient_diagnose := c.GetString("patient_diagnose")
  1594. dataBody := make(map[string]interface{}, 0)
  1595. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1596. if err != nil {
  1597. utils.ErrorLog(err.Error())
  1598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1599. return
  1600. }
  1601. //edit, src := GetCompareData(dataBody)
  1602. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1603. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1604. //fmt.Println(drugResult)
  1605. //fmt.Println(goodResult)
  1606. timeLayout := "2006-01-02"
  1607. loc, _ := time.LoadLocation("Local")
  1608. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1609. if err != nil {
  1610. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1611. return
  1612. }
  1613. adminInfo := c.GetAdminUserInfo()
  1614. recordDateTime := theTime.Unix()
  1615. //查询默认出库仓库库存
  1616. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1617. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1618. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1619. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1620. if len(lists) == 1 {
  1621. his_patient_id = lists[0].ID
  1622. }
  1623. }
  1624. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1625. //自动出库的开关开启
  1626. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1627. //自动出库
  1628. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1629. //耗材保存处方出库
  1630. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1631. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1632. //已发药和已收费限制逻辑
  1633. isMidicine := false
  1634. isCharge := false
  1635. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1636. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1637. if len(prescriptions) > 0 {
  1638. for _, item := range prescriptions {
  1639. items := item.(map[string]interface{})
  1640. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1641. utils.ErrorLog("id")
  1642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1643. return
  1644. }
  1645. id := int64(items["id"].(float64))
  1646. if id > 0 {
  1647. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1648. if err != nil {
  1649. if new_prescription.OrderStatus == 4 {
  1650. isCharge = true
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. if isMidicine == true {
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1659. return
  1660. }
  1661. if isCharge == true {
  1662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1663. return
  1664. }
  1665. // 开始主事务
  1666. db := service.XTWriteDB()
  1667. tx := db.Begin()
  1668. // 在函数结束时处理事务回滚
  1669. defer func() {
  1670. if r := recover(); r != nil {
  1671. tx.Rollback()
  1672. }
  1673. }()
  1674. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1675. //药品发药出库
  1676. if pharmacyConfig.IsOpen == 1 {
  1677. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1678. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1679. if len(prescriptions) > 0 {
  1680. for _, item := range prescriptions {
  1681. items := item.(map[string]interface{})
  1682. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1683. advices := items["advices"].([]interface{})
  1684. if len(advices) > 0 {
  1685. for _, advice := range advices {
  1686. var drug_id int64
  1687. var prescribing_number float64
  1688. var prescribingNumberUnit string
  1689. var adviceId int64
  1690. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1691. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1692. }
  1693. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1694. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1695. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1696. }
  1697. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1698. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1699. }
  1700. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1701. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1702. }
  1703. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1704. if drug.ID == 0 {
  1705. tx.Rollback()
  1706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1707. return
  1708. }
  1709. //查询药品的所有库存
  1710. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1711. var total_count int64
  1712. for _, it := range list {
  1713. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1714. }
  1715. totals := strconv.FormatInt(total_count, 10)
  1716. //查询该药品是否存在开药记录
  1717. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1718. //新增处方盘点库存是否充足
  1719. if advicelist.ID == 0 {
  1720. all_count, _ := strconv.ParseFloat(totals, 64)
  1721. if prescribingNumberUnit == drug.MinUnit {
  1722. if drug.IsUse != 1 {
  1723. if drug.IsProject == 0 || drug.IsProject == 2 {
  1724. if all_count == 0 {
  1725. tx.Rollback()
  1726. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1727. return
  1728. }
  1729. if prescribing_number > all_count {
  1730. tx.Rollback()
  1731. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1732. return
  1733. }
  1734. }
  1735. }
  1736. }
  1737. if prescribingNumberUnit == drug.MaxUnit {
  1738. num := prescribing_number * float64(drug.MinNumber)
  1739. if drug.IsUse != 1 {
  1740. if drug.IsProject == 0 || drug.IsProject == 2 {
  1741. if all_count == 0 {
  1742. tx.Rollback()
  1743. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1744. return
  1745. }
  1746. if num > all_count {
  1747. tx.Rollback()
  1748. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1749. return
  1750. }
  1751. }
  1752. }
  1753. }
  1754. }
  1755. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1756. //不使用保存处方出库
  1757. if drugOutConfig.IsOpen != 1 {
  1758. //修改处方
  1759. for _, advice := range advices {
  1760. var drug_id int64
  1761. var prescribing_number float64
  1762. var prescribingNumberUnit string
  1763. var prescribingNumber string
  1764. var adviceId int64
  1765. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1766. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1767. }
  1768. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1769. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1770. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1771. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1772. }
  1773. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1774. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1775. }
  1776. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1777. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1778. }
  1779. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1780. if drug.ID == 0 {
  1781. tx.Rollback()
  1782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1783. return
  1784. }
  1785. //查询药品的所有库存
  1786. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1787. var total_count int64
  1788. for _, it := range list {
  1789. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1790. }
  1791. totals := strconv.FormatInt(total_count, 10)
  1792. //查询该药品是否存在开药记录
  1793. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1794. //新增处方
  1795. if advicelist.ID == 0 {
  1796. all_count, _ := strconv.ParseFloat(totals, 64)
  1797. if prescribingNumberUnit == drug.MinUnit {
  1798. if drug.IsUse != 1 {
  1799. if drug.IsProject == 0 || drug.IsProject == 2 {
  1800. if all_count == 0 {
  1801. tx.Rollback()
  1802. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1803. return
  1804. }
  1805. if prescribing_number > all_count {
  1806. tx.Rollback()
  1807. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足,保存失败")
  1808. return
  1809. }
  1810. }
  1811. }
  1812. } else {
  1813. if prescribingNumberUnit == drug.MaxUnit {
  1814. num := prescribing_number * float64(drug.MinNumber)
  1815. if drug.IsUse != 1 {
  1816. if drug.IsProject == 0 || drug.IsProject == 2 {
  1817. if all_count == 0 {
  1818. tx.Rollback()
  1819. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1820. return
  1821. }
  1822. if num > all_count {
  1823. tx.Rollback()
  1824. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1825. return
  1826. }
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. //修改处方
  1833. if advicelist.ID > 0 {
  1834. var device_number int64
  1835. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1836. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1837. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1838. device_number = prescribingNumberInt * drug.MinNumber
  1839. }
  1840. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1841. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1842. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1843. device_number = prescribingNumberInt
  1844. }
  1845. var number_count int64
  1846. if prescribingNumberUnit == drug.MaxUnit {
  1847. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1848. number_count = prescribingNumberInt * drug.MinNumber
  1849. }
  1850. if prescribingNumberUnit == drug.MinUnit {
  1851. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1852. number_count = prescribingNumberInt
  1853. }
  1854. //如果修改的数量大于之前修改的数量
  1855. if (number_count - device_number) > 0 {
  1856. //如果修改的差数量 大于库存数量
  1857. if drug.IsUse != 1 {
  1858. if (number_count - device_number) > total_count {
  1859. tx.Rollback()
  1860. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1861. return
  1862. }
  1863. }
  1864. }
  1865. }
  1866. }
  1867. }
  1868. }
  1869. }
  1870. }
  1871. }
  1872. }
  1873. }
  1874. }
  1875. //已发药和已收费限制逻辑
  1876. //执行出库的逻辑
  1877. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1878. //校验库存总量
  1879. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1880. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1881. if len(prescriptions) > 0 {
  1882. for _, item := range prescriptions {
  1883. items := item.(map[string]interface{})
  1884. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1885. advices := items["advices"].([]interface{})
  1886. if len(advices) > 0 {
  1887. for _, advice := range advices {
  1888. var drug_id int64
  1889. var prescribing_number float64
  1890. var prescribingNumberUnit string
  1891. var adviceId int64
  1892. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1893. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1894. }
  1895. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1896. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1897. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1898. }
  1899. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1900. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1901. }
  1902. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1903. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1904. }
  1905. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1906. if drug.ID == 0 {
  1907. tx.Rollback()
  1908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1909. return
  1910. }
  1911. //查询药品的所有库存
  1912. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1913. var total_count int64
  1914. for _, it := range list {
  1915. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1916. }
  1917. totals := strconv.FormatInt(total_count, 10)
  1918. //查询该药品是否存在开药记录
  1919. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1920. //查询最新批次库存
  1921. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1922. var batch_number_count int64
  1923. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1924. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1925. //新增处方
  1926. if advicelist.ID == 0 {
  1927. all_count, _ := strconv.ParseFloat(totals, 64)
  1928. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1929. if prescribingNumberUnit == drug.MinUnit {
  1930. if drug.IsUse != 1 {
  1931. if drug.IsProject == 0 || drug.IsProject == 2 {
  1932. if all_count == 0 {
  1933. tx.Rollback()
  1934. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1935. return
  1936. }
  1937. if prescribing_number > all_count {
  1938. tx.Rollback()
  1939. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1940. return
  1941. }
  1942. }
  1943. if adminInfo.CurrentOrgId == 10215 {
  1944. if prescribing_number > batch_number_all_count {
  1945. tx.Rollback()
  1946. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1947. return
  1948. }
  1949. }
  1950. }
  1951. }
  1952. if prescribingNumberUnit == drug.MaxUnit {
  1953. num := prescribing_number * float64(drug.MinNumber)
  1954. if drug.IsUse != 1 {
  1955. if drug.IsProject == 0 || drug.IsProject == 2 {
  1956. if all_count == 0 {
  1957. tx.Rollback()
  1958. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1959. return
  1960. }
  1961. if num > all_count {
  1962. tx.Rollback()
  1963. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1964. return
  1965. }
  1966. }
  1967. if adminInfo.CurrentOrgId == 10215 {
  1968. if num > batch_number_all_count {
  1969. tx.Rollback()
  1970. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1971. return
  1972. }
  1973. }
  1974. }
  1975. }
  1976. }
  1977. //不是保存处方出库
  1978. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1979. if drugOutConfig.IsOpen != 1 {
  1980. //修改处方
  1981. for _, advice := range advices {
  1982. var drug_id int64
  1983. var prescribing_number float64
  1984. var prescribingNumberUnit string
  1985. var prescribingNumber string
  1986. var adviceId int64
  1987. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1988. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1989. }
  1990. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1991. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1992. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1993. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1994. }
  1995. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1996. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1997. }
  1998. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1999. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2000. }
  2001. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2002. if drug.ID == 0 {
  2003. tx.Rollback()
  2004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2005. return
  2006. }
  2007. //查询药品的所有库存
  2008. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2009. var total_count int64
  2010. for _, it := range list {
  2011. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2012. }
  2013. totals := strconv.FormatInt(total_count, 10)
  2014. //查询该药品是否存在开药记录
  2015. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2016. //新增处方
  2017. if advicelist.ID == 0 {
  2018. //查询最新批次库存
  2019. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2020. var batch_number_count int64
  2021. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2022. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2023. all_count, _ := strconv.ParseFloat(totals, 64)
  2024. if all_count == 0 {
  2025. tx.Rollback()
  2026. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2027. return
  2028. }
  2029. if prescribingNumberUnit == drug.MinUnit {
  2030. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2031. if drug.IsUse != 1 {
  2032. if drug.IsProject == 0 || drug.IsProject == 2 {
  2033. if all_count == 0 {
  2034. tx.Rollback()
  2035. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2036. return
  2037. }
  2038. if prescribing_number > all_count {
  2039. tx.Rollback()
  2040. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2041. return
  2042. }
  2043. }
  2044. if adminInfo.CurrentOrgId == 10215 {
  2045. if prescribing_number > batch_number_all_count {
  2046. tx.Rollback()
  2047. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2048. return
  2049. }
  2050. }
  2051. }
  2052. } else {
  2053. if prescribingNumberUnit == drug.MaxUnit {
  2054. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2055. num := prescribing_number * float64(drug.MinNumber)
  2056. if drug.IsUse != 1 {
  2057. if drug.IsProject == 0 || drug.IsProject == 2 {
  2058. if all_count == 0 {
  2059. tx.Rollback()
  2060. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2061. return
  2062. }
  2063. if num > all_count {
  2064. tx.Rollback()
  2065. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2066. return
  2067. }
  2068. }
  2069. if adminInfo.CurrentOrgId == 10215 {
  2070. if prescribing_number > batch_number_all_count {
  2071. tx.Rollback()
  2072. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2073. return
  2074. }
  2075. }
  2076. }
  2077. }
  2078. }
  2079. }
  2080. //修改处方
  2081. if advicelist.ID > 0 {
  2082. //查询最新批次库存
  2083. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2084. var batch_number_count int64
  2085. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2086. var device_number int64
  2087. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2088. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2089. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2090. device_number = prescribingNumberInt * drug.MinNumber
  2091. }
  2092. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2093. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2094. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2095. device_number = prescribingNumberInt
  2096. //回退库存
  2097. }
  2098. var number_count int64
  2099. if prescribingNumberUnit == drug.MaxUnit {
  2100. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2101. number_count = prescribingNumberInt * drug.MinNumber
  2102. //回退库存
  2103. }
  2104. if prescribingNumberUnit == drug.MinUnit {
  2105. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2106. number_count = prescribingNumberInt
  2107. //回退库存
  2108. }
  2109. //如果修改的数量大于之前修改的数量
  2110. if (number_count - device_number) > 0 {
  2111. //如果修改的差数量 大于库存数量
  2112. if drug.IsUse != 1 {
  2113. if drug.IsProject == 0 || drug.IsProject == 2 {
  2114. if total_count == 0 {
  2115. tx.Rollback()
  2116. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2117. return
  2118. }
  2119. if (number_count - device_number) > total_count {
  2120. tx.Rollback()
  2121. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2122. return
  2123. }
  2124. if (number_count - device_number) > batch_number_count {
  2125. tx.Rollback()
  2126. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2127. return
  2128. }
  2129. }
  2130. if adminInfo.CurrentOrgId == 10215 {
  2131. // 查询该药品最后一次出库记录
  2132. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2133. var out_count int64
  2134. var in_count int64
  2135. var stock_max_number int64
  2136. var stock_min_number int64
  2137. for _, it := range outInfo {
  2138. if it.CountUnit == drug.MaxUnit {
  2139. it.Count = it.Count * drug.MinNumber
  2140. }
  2141. out_count += it.Count
  2142. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2143. stock_max_number = warehouseInfoList.StockMaxNumber
  2144. stock_min_number = warehouseInfoList.StockMinNumber
  2145. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2146. }
  2147. if out_count > 0 {
  2148. if (number_count - device_number) > in_count {
  2149. tx.Rollback()
  2150. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2151. return
  2152. }
  2153. }
  2154. // 未出库
  2155. if out_count == 0 {
  2156. var sum_in_count int64
  2157. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2158. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2159. //如果修改的数量大于有库存的第一个批次
  2160. if number_count > sum_in_count {
  2161. tx.Rollback()
  2162. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2163. return
  2164. }
  2165. }
  2166. }
  2167. }
  2168. }
  2169. //药品发药
  2170. //pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2171. //不使用药品发药的功能
  2172. //if pharmacyConfig.IsOpen != 1 {
  2173. // if device_number != number_count {
  2174. //
  2175. // //查询该药品的出库记录
  2176. // outListExport, _ := service.GetWarehouseOutListExport(drug_id, patient_id, recordDateTime, adviceId)
  2177. // if len(outListExport) > 0 {
  2178. // //
  2179. // for _, item := range outListExport {
  2180. // //回退库存
  2181. // if item.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2182. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, number_count)
  2183. // }
  2184. // if item.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2185. // var stock_max_number int64
  2186. // var stock_min_number int64
  2187. //
  2188. // if number_count >= drug.MinNumber {
  2189. //
  2190. // stock_max_number = device_number / drug.MinNumber
  2191. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, stock_max_number)
  2192. //
  2193. // stock_min_number = device_number % drug.MinNumber
  2194. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, stock_min_number)
  2195. //
  2196. // } else {
  2197. //
  2198. // service.ModefyDrugByWarehouseInfoOne(item.WarehouseInfoId, device_number)
  2199. //
  2200. // }
  2201. // }
  2202. //
  2203. // if item.CountUnit == drug.MaxUnit && item.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2204. // service.ModefyDrugByWarehouseInfo(item.WarehouseInfoId, device_number)
  2205. // }
  2206. // }
  2207. // }
  2208. //
  2209. // service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2210. // var sum_count int64
  2211. // orgId := c.GetAdminUserInfo().CurrentOrgId
  2212. // stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, orgId, drug_id)
  2213. // for _, its := range stockInfo {
  2214. // if its.MaxUnit == drug.MaxUnit {
  2215. // its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2216. // }
  2217. // sum_count += its.StockMaxNumber + its.StockMinNumber
  2218. // }
  2219. // //更新字典里面的库存
  2220. // service.UpdateBaseDrugSumTwo(drug_id, sum_count, orgId)
  2221. //
  2222. // //剩余库存
  2223. // service.UpdateDrugStockCount(drug_id, orgId, storeConfig.DrugStorehouseOut, sum_count)
  2224. //
  2225. // over, _ := service.FindOverCount(drug_id, orgId, storeConfig.DrugStorehouseOut)
  2226. // //减少出库数量
  2227. // service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  2228. //
  2229. // }
  2230. //}
  2231. }
  2232. }
  2233. }
  2234. //保存处方开药
  2235. if drugOutConfig.IsOpen == 1 {
  2236. //修改处方
  2237. for _, advice := range advices {
  2238. var drug_id int64
  2239. var prescribing_number float64
  2240. var prescribingNumberUnit string
  2241. var prescribingNumber string
  2242. var adviceId int64
  2243. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2244. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2245. }
  2246. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2247. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2248. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2249. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2250. }
  2251. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2252. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2253. }
  2254. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2255. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2256. }
  2257. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2258. if drug.ID == 0 {
  2259. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2260. return
  2261. }
  2262. //查询药品的所有库存
  2263. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2264. var total_count int64
  2265. for _, it := range list {
  2266. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2267. }
  2268. totals := strconv.FormatInt(total_count, 10)
  2269. //查询该药品是否存在开药记录
  2270. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2271. //新增处方
  2272. if advicelist.ID == 0 {
  2273. //查询最新批次库存
  2274. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2275. var batch_number_count int64
  2276. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2277. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2278. all_count, _ := strconv.ParseFloat(totals, 64)
  2279. if prescribingNumberUnit == drug.MinUnit {
  2280. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2281. if drug.IsUse != 1 {
  2282. if drug.IsProject == 0 || drug.IsProject == 2 {
  2283. if all_count == 0 {
  2284. tx.Rollback()
  2285. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2286. return
  2287. }
  2288. if prescribing_number > all_count {
  2289. tx.Rollback()
  2290. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2291. return
  2292. }
  2293. }
  2294. if adminInfo.CurrentOrgId == 10215 {
  2295. if prescribing_number > batch_number_all_count {
  2296. tx.Rollback()
  2297. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2298. return
  2299. }
  2300. }
  2301. }
  2302. } else {
  2303. if prescribingNumberUnit == drug.MaxUnit {
  2304. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2305. num := prescribing_number * float64(drug.MinNumber)
  2306. if drug.IsUse != 1 {
  2307. if drug.IsProject == 0 || drug.IsProject == 2 {
  2308. if all_count == 0 {
  2309. tx.Rollback()
  2310. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2311. return
  2312. }
  2313. if num > all_count {
  2314. tx.Rollback()
  2315. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2316. return
  2317. }
  2318. }
  2319. if adminInfo.CurrentOrgId == 10215 {
  2320. if prescribing_number > batch_number_all_count {
  2321. tx.Rollback()
  2322. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2323. return
  2324. }
  2325. }
  2326. }
  2327. }
  2328. }
  2329. }
  2330. //修改处方
  2331. if advicelist.ID > 0 {
  2332. //查询最新批次库存
  2333. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2334. var batch_number_count int64
  2335. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2336. var device_number int64
  2337. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2338. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2339. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2340. device_number = prescribingNumberInt * drug.MinNumber
  2341. }
  2342. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2343. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2344. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2345. device_number = prescribingNumberInt
  2346. }
  2347. var number_count int64
  2348. if prescribingNumberUnit == drug.MaxUnit {
  2349. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2350. number_count = prescribingNumberInt * drug.MinNumber
  2351. }
  2352. if prescribingNumberUnit == drug.MinUnit {
  2353. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2354. number_count = prescribingNumberInt
  2355. }
  2356. //如果修改的数量大于之前修改的数量
  2357. if (number_count - device_number) > 0 {
  2358. //如果修改的差数量 大于库存数量
  2359. if drug.IsUse != 1 {
  2360. if drug.IsProject == 0 || drug.IsProject == 2 {
  2361. if total_count == 0 {
  2362. tx.Rollback()
  2363. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2364. return
  2365. }
  2366. if (number_count - device_number) > total_count {
  2367. tx.Rollback()
  2368. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2369. return
  2370. }
  2371. }
  2372. if adminInfo.CurrentOrgId == 10215 {
  2373. if (number_count - device_number) > batch_number_count {
  2374. tx.Rollback()
  2375. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2376. return
  2377. }
  2378. }
  2379. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2380. //查询历史出库数据总批次
  2381. // 查询该药品最后一次出库记录
  2382. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2383. var out_count int64
  2384. var in_count int64
  2385. var stock_max_number int64
  2386. var stock_min_number int64
  2387. for _, it := range outInfo {
  2388. if it.CountUnit == drug.MaxUnit {
  2389. it.Count = it.Count * drug.MinNumber
  2390. }
  2391. out_count += it.Count
  2392. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2393. stock_max_number = warehouseInfoList.StockMaxNumber
  2394. stock_min_number = warehouseInfoList.StockMinNumber
  2395. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2396. }
  2397. if out_count > 0 {
  2398. if (number_count - device_number) > in_count {
  2399. tx.Rollback()
  2400. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2401. return
  2402. }
  2403. }
  2404. // 未出库
  2405. if out_count == 0 {
  2406. var sum_in_count int64
  2407. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2408. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2409. if sum_in_count == 0 {
  2410. tx.Rollback()
  2411. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2412. return
  2413. }
  2414. //如果修改的数量大于有库存的第一个批次
  2415. if number_count > sum_in_count {
  2416. tx.Rollback()
  2417. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2418. return
  2419. }
  2420. }
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. }
  2431. }
  2432. }
  2433. }
  2434. //校验耗材库存
  2435. if goodOutConfig.IsOpen == 1 {
  2436. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2437. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2438. if len(prescriptions) > 0 {
  2439. for _, item := range prescriptions {
  2440. items := item.(map[string]interface{})
  2441. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2442. projects := items["project"].([]interface{})
  2443. if len(projects) > 0 {
  2444. for _, project := range projects {
  2445. var project_id int64
  2446. var project_type int64
  2447. var totals float64
  2448. var project_name string
  2449. var parsetotal int64
  2450. var id int64
  2451. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2452. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2453. }
  2454. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2455. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2456. }
  2457. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2458. total, _ := project.(map[string]interface{})["total"].(string)
  2459. totals, _ = strconv.ParseFloat(total, 64)
  2460. }
  2461. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2462. project_name = project.(map[string]interface{})["project_name"].(string)
  2463. }
  2464. if project_type == 3 {
  2465. //查找该耗材的出库记录
  2466. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2467. if len(goodWarehouseInfo) == 0 {
  2468. //查询耗材库存
  2469. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2470. var stock_count int64
  2471. for _, it := range list {
  2472. stock_count += it.StockCount
  2473. }
  2474. stock_counts := strconv.FormatInt(stock_count, 10)
  2475. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2476. if stock_total_count == 0 {
  2477. tx.Rollback()
  2478. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2479. return
  2480. }
  2481. if totals > stock_total_count {
  2482. tx.Rollback()
  2483. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2484. return
  2485. }
  2486. }
  2487. if len(goodWarehouseInfo) > 0 {
  2488. //查询该患者耗材的历史数据
  2489. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2490. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2491. //数量发生改变
  2492. if parsetotal != count {
  2493. //如果现在的数量大于历史数量,就要看库存是否足够
  2494. if parsetotal > count {
  2495. //查询耗材所有库存
  2496. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2497. var stock_count int64
  2498. for _, it := range list {
  2499. stock_count += it.StockCount
  2500. }
  2501. //库存不足
  2502. if stock_count == 0 {
  2503. tx.Rollback()
  2504. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2505. return
  2506. }
  2507. if (parsetotal - count) > stock_count {
  2508. tx.Rollback()
  2509. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2510. return
  2511. }
  2512. }
  2513. }
  2514. }
  2515. }
  2516. }
  2517. }
  2518. }
  2519. }
  2520. }
  2521. }
  2522. }
  2523. //不使用耗材保存处方出库
  2524. if goodOutConfig.IsOpen != 1 {
  2525. if stockConfig.IsOpen == 1 {
  2526. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2527. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2528. if len(prescriptions) > 0 {
  2529. for _, item := range prescriptions {
  2530. items := item.(map[string]interface{})
  2531. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2532. projects := items["project"].([]interface{})
  2533. if len(projects) > 0 {
  2534. for _, project := range projects {
  2535. var project_id int64
  2536. var project_type int64
  2537. var totals float64
  2538. var project_name string
  2539. var parsetotal int64
  2540. var id int64
  2541. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2542. id = int64(project.(map[string]interface{})["id"].(float64))
  2543. }
  2544. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2545. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2546. }
  2547. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2548. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2549. }
  2550. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2551. total, _ := project.(map[string]interface{})["total"].(string)
  2552. totals, _ = strconv.ParseFloat(total, 64)
  2553. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2554. }
  2555. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2556. project_name = project.(map[string]interface{})["project_name"].(string)
  2557. }
  2558. if project_type == 3 {
  2559. //查找该耗材的出库记录
  2560. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2561. //没有出库记录
  2562. if len(goodWarehouseInfo) == 0 {
  2563. //查询耗材库存
  2564. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2565. var stock_count int64
  2566. for _, it := range list {
  2567. stock_count += it.StockCount
  2568. }
  2569. stock_counts := strconv.FormatInt(stock_count, 10)
  2570. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2571. if stock_total_count == 0 {
  2572. tx.Rollback()
  2573. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2574. return
  2575. }
  2576. if totals > stock_total_count {
  2577. tx.Rollback()
  2578. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2579. return
  2580. }
  2581. //查找今日该患者已经出库的所有耗材
  2582. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2583. for _, item := range goodList {
  2584. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2585. var flush_count int64
  2586. for _, it := range goodListSix {
  2587. flush_count += it.StockCount
  2588. }
  2589. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2590. creater := adminInfo.AdminUser.Id
  2591. if errs != nil {
  2592. goodErrcode := models.XtGoodErrcode{
  2593. UserOrgId: item.OrgId,
  2594. Errcode: "手动出库更新剩余出库失败",
  2595. GoodId: item.GoodId,
  2596. Status: 1,
  2597. Ctime: time.Now().Unix(),
  2598. Mtime: 0,
  2599. Count: 0,
  2600. StockCount: 0,
  2601. Creater: creater,
  2602. BatchNumberId: 0,
  2603. WarehouseOutId: 0,
  2604. }
  2605. service.CreateGoodErrcode(goodErrcode)
  2606. }
  2607. }
  2608. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2609. }
  2610. //有出库记录
  2611. if len(goodWarehouseInfo) > 0 {
  2612. //查询该患者耗材的历史数据
  2613. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2614. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2615. //数量发生改变
  2616. if parsetotal != count {
  2617. //查找今日该患者已经出库的所有耗材
  2618. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2619. for _, item := range goodList {
  2620. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2621. var flush_count int64
  2622. for _, it := range goodListSix {
  2623. flush_count += it.StockCount
  2624. }
  2625. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2626. //减少出库数量
  2627. creater := adminInfo.AdminUser.Id
  2628. if errs != nil {
  2629. goodErrcode := models.XtGoodErrcode{
  2630. UserOrgId: item.OrgId,
  2631. Errcode: "手动出库更新剩余出库失败",
  2632. GoodId: item.GoodId,
  2633. Status: 1,
  2634. Ctime: time.Now().Unix(),
  2635. Mtime: 0,
  2636. Count: 0,
  2637. StockCount: 0,
  2638. Creater: creater,
  2639. BatchNumberId: 0,
  2640. WarehouseOutId: 0,
  2641. }
  2642. service.CreateGoodErrcode(goodErrcode)
  2643. }
  2644. //查询默认仓库
  2645. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2646. var total_count int64
  2647. for _, it := range stockList {
  2648. total_count += it.StockCount
  2649. }
  2650. //基础库插入数据
  2651. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2652. }
  2653. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2654. }
  2655. }
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. }
  2662. }
  2663. }
  2664. }
  2665. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2666. var hpInfo models.HisPrescriptionInfo
  2667. if info.ID == 0 {
  2668. var randNum int
  2669. randNum = rand.Intn(10000) + 1000
  2670. timestamp := time.Now().Unix()
  2671. tempTime := time.Unix(timestamp, 0)
  2672. timeFormat := tempTime.Format("20060102150405")
  2673. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2674. hpInfo = models.HisPrescriptionInfo{
  2675. HisPatientId: his_patient_id,
  2676. UserOrgId: adminInfo.CurrentOrgId,
  2677. RecordDate: theTime.Unix(),
  2678. PatientId: patient_id,
  2679. Status: 1,
  2680. Ctime: time.Now().Unix(),
  2681. Mtime: time.Now().Unix(),
  2682. Creator: adminInfo.AdminUser.Id,
  2683. Modifier: adminInfo.AdminUser.Id,
  2684. Diagnosis: diagnose,
  2685. SickHistory: sick_history,
  2686. Departments: department,
  2687. RegisterType: reg_type,
  2688. PrescriptionNumber: p_number,
  2689. PrescriptionStatus: 1,
  2690. Doctor: role.UserName,
  2691. DoctorId: doctor_id,
  2692. SickType: sick_type,
  2693. PType: p_type,
  2694. PatientDiagnosis: patient_diagnose,
  2695. }
  2696. service.SavePatientPrescriptionInfo(hpInfo)
  2697. //创建步骤表
  2698. finish := models.XtDialysisFinish{
  2699. IsFinish: 1,
  2700. UserOrgId: adminInfo.CurrentOrgId,
  2701. Status: 1,
  2702. Ctime: time.Now().Unix(),
  2703. Mtime: 0,
  2704. Module: 4,
  2705. RecordDate: theTime.Unix(),
  2706. Sourse: 1,
  2707. PatientId: patient_id,
  2708. }
  2709. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2710. if dialysisFinish.ID == 0 {
  2711. service.CreateDialysisFinish(finish)
  2712. }
  2713. redis := service.RedisClient()
  2714. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2715. redis.Set(key, "", time.Second)
  2716. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2717. redis.Set(keyOne, "", time.Second)
  2718. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2719. redis.Set(keySeven, "", time.Second)
  2720. defer redis.Close()
  2721. } else {
  2722. hpInfo = models.HisPrescriptionInfo{
  2723. ID: info.ID,
  2724. UserOrgId: adminInfo.CurrentOrgId,
  2725. RecordDate: info.RecordDate,
  2726. PatientId: info.PatientId,
  2727. Status: 1,
  2728. Ctime: info.Ctime,
  2729. Mtime: time.Now().Unix(),
  2730. Creator: info.Creator,
  2731. Modifier: adminInfo.AdminUser.Id,
  2732. Diagnosis: diagnose,
  2733. SickHistory: sick_history,
  2734. Departments: department,
  2735. RegisterType: reg_type,
  2736. PrescriptionNumber: info.PrescriptionNumber,
  2737. Doctor: role.UserName,
  2738. PrescriptionStatus: info.PrescriptionStatus,
  2739. DoctorId: doctor_id,
  2740. SickType: sick_type,
  2741. PType: info.PType,
  2742. HisPatientId: info.HisPatientId,
  2743. PatientDiagnosis: patient_diagnose,
  2744. }
  2745. service.SavePatientPrescriptionInfo(hpInfo)
  2746. //创建步骤表
  2747. finish := models.XtDialysisFinish{
  2748. IsFinish: 1,
  2749. UserOrgId: adminInfo.CurrentOrgId,
  2750. Status: 1,
  2751. Ctime: time.Now().Unix(),
  2752. Mtime: 0,
  2753. Module: 4,
  2754. RecordDate: info.RecordDate,
  2755. Sourse: 1,
  2756. PatientId: info.PatientId,
  2757. }
  2758. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2759. if dialysisFinish.ID == 0 {
  2760. service.CreateDialysisFinish(finish)
  2761. }
  2762. redis := service.RedisClient()
  2763. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2764. redis.Set(key, "", time.Second)
  2765. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2766. redis.Set(keyOne, "", time.Second)
  2767. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2768. redis.Set(keySeven, "", time.Second)
  2769. defer redis.Close()
  2770. }
  2771. //定义切片
  2772. var adviceList []models.HisDoctorAdviceInfo
  2773. var projectList []models.HisPrescriptionProject
  2774. 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 == 10537 || adminInfo.CurrentOrgId == 10265 {
  2775. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2776. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2777. var tempPrescription *models.HisPrescription
  2778. if len(prescriptions) > 0 {
  2779. for _, item := range prescriptions {
  2780. // 开始外部循环的事务
  2781. tx := db.Begin()
  2782. // 在函数结束时处理事务回滚
  2783. defer func() {
  2784. if r := recover(); r != nil {
  2785. tx.Rollback()
  2786. }
  2787. }()
  2788. items := item.(map[string]interface{})
  2789. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2790. utils.ErrorLog("id")
  2791. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2792. return
  2793. }
  2794. id := int64(items["id"].(float64))
  2795. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2796. tempPrescription = &new_prescription
  2797. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2798. utils.ErrorLog("type")
  2799. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2800. return
  2801. }
  2802. types := int64(items["type"].(float64))
  2803. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2804. utils.ErrorLog("med_type")
  2805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2806. return
  2807. }
  2808. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2809. if med_type == "0" {
  2810. med_type = "14"
  2811. }
  2812. //if order_status == 0 {
  2813. // order_status = 1
  2814. //}
  2815. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2816. utils.ErrorLog("pre_time")
  2817. }
  2818. preTime, _ := items["pre_time"].(string)
  2819. fmt.Println("preTime", preTime)
  2820. timeLayout := "2006-01-02"
  2821. loc, _ := time.LoadLocation("Local")
  2822. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2823. result := strings.Split(preTime, " ")
  2824. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2825. if err != nil {
  2826. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2827. return
  2828. }
  2829. pTime := theTime2.Unix()
  2830. ctime := time.Now().Unix()
  2831. if tempPrescription.ID == 0 {
  2832. prescription := &models.HisPrescription{
  2833. ID: 0,
  2834. PatientId: patient_id,
  2835. UserOrgId: adminInfo.CurrentOrgId,
  2836. RecordDate: recordDateTime,
  2837. Ctime: ctime,
  2838. Mtime: ctime,
  2839. Type: types,
  2840. Modifier: adminInfo.AdminUser.Id,
  2841. Creator: adminInfo.AdminUser.Id,
  2842. Status: 1,
  2843. Doctor: role.UserName,
  2844. HisPatientId: his_patient_id,
  2845. OrderStatus: 1,
  2846. BatchNumber: "",
  2847. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2848. PreTime: pTime,
  2849. PType: p_type,
  2850. MedType: med_type,
  2851. }
  2852. tempPrescription = prescription
  2853. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2854. redis := service.RedisClient()
  2855. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2856. redis.Set(key, "", time.Second)
  2857. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2858. redis.Set(keyOne, "", time.Second)
  2859. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2860. redis.Set(keySeven, "", time.Second)
  2861. defer redis.Close()
  2862. } else {
  2863. tempPrescription.ID = id
  2864. tempPrescription.Type = types
  2865. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2866. tempPrescription.Mtime = time.Now().Unix()
  2867. tempPrescription.Doctor = role.UserName
  2868. //tempPrescription.OrderStatus = order_status
  2869. tempPrescription.PreTime = pTime
  2870. tempPrescription.MedType = med_type
  2871. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2872. redis := service.RedisClient()
  2873. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2874. redis.Set(key, "", time.Second)
  2875. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2876. redis.Set(keyOne, "", time.Second)
  2877. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2878. redis.Set(keySeven, "", time.Second)
  2879. defer redis.Close()
  2880. }
  2881. //service.SaveHisPrescription(prescription)
  2882. //更改患者挂号状态
  2883. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2884. fmt.Println("更改失败", err2)
  2885. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2886. advices := items["advices"].([]interface{})
  2887. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2888. groupNo := int64(0)
  2889. if len(advices) > 0 {
  2890. for _, advice := range advices {
  2891. tx := db.Begin()
  2892. // 在函数结束时处理事务回滚
  2893. defer func() {
  2894. if r := recover(); r != nil {
  2895. tx.Rollback()
  2896. }
  2897. }()
  2898. var s models.HisDoctorAdviceInfo
  2899. s.PrescriptionId = tempPrescription.ID
  2900. s.AdviceType = 2
  2901. s.AdviceDoctor = doctor_id
  2902. s.StopState = 2
  2903. s.ExecutionState = 2
  2904. s.AdviceDate = theTime3.Unix()
  2905. s.Status = 1
  2906. s.UserOrgId = adminInfo.CurrentOrgId
  2907. s.RecordDate = theTime3.Unix()
  2908. s.StartTime = tempPrescription.PreTime
  2909. s.Groupno = groupNo
  2910. s.PatientId = patient_id
  2911. s.HisPatientId = his_patient_id
  2912. s.StartTime = pTime
  2913. s.IsSettle = 2
  2914. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2915. if errcode > 0 {
  2916. c.ServeFailJSONWithSGJErrorCode(errcode)
  2917. return
  2918. }
  2919. s.StartTime = pTime
  2920. var total_count int64 //处方总库存
  2921. //查询改药品信息
  2922. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2923. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2924. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2925. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2926. total_count += prescribingNumberSeven * medical.MinNumber
  2927. }
  2928. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2929. total_count += prescribingNumberSeven
  2930. }
  2931. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2932. total_count += prescribingNumberSeven
  2933. }
  2934. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2935. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2936. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2937. if s.Price != lastWarehouse.RetailPrice {
  2938. s.Price = lastWarehouse.RetailPrice
  2939. }
  2940. if s.Price == 0 {
  2941. if lastWarehouse.ID == 0 {
  2942. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2943. s.Price = lastWarehouseTwo.RetailPrice
  2944. }
  2945. }
  2946. }
  2947. //查询保存处方出库开关是否打开
  2948. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2949. if s.PatientId != 30038 {
  2950. if drugOutConfig.IsOpen == 1 {
  2951. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2952. // 查询该药品最后一次出库记录
  2953. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2954. var is_user_total int64
  2955. var no_user_total int64
  2956. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2957. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2958. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2959. no_user_total += prescribingNumberSevenTy * drug.MinNumber
  2960. }
  2961. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2962. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2963. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2964. no_user_total += prescribingNumberSevenTy
  2965. }
  2966. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2967. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2968. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  2969. no_user_total += prescribingNumberSevenTy
  2970. }
  2971. if len(druginfo) > 0 {
  2972. for _, it := range druginfo {
  2973. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2974. it.Count = it.Count * drug.MinNumber
  2975. is_user_total += it.Count
  2976. }
  2977. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2978. is_user_total += it.Count
  2979. }
  2980. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2981. is_user_total += it.Count
  2982. }
  2983. }
  2984. }
  2985. //fmt.Println("药品名称----------------------", drug.DrugName)
  2986. //fmt.Println("药品名称----------------------", drug.IsUse)
  2987. //fmt.Println("is_user_total-------------------------", is_user_total)
  2988. //fmt.Println("no_user_total-------------------------", no_user_total)
  2989. if is_user_total != no_user_total {
  2990. //出库
  2991. if drug.IsUse == 2 {
  2992. creater := adminInfo.AdminUser.Id
  2993. newadviceInfo := &models.HisDoctorAdviceInfo{
  2994. ID: s.ID,
  2995. UserOrgId: s.UserOrgId,
  2996. PatientId: s.PatientId,
  2997. HisPatientId: s.HisPatientId,
  2998. AdviceType: s.AdviceType,
  2999. AdviceDate: s.AdviceDate,
  3000. StartTime: s.StartTime,
  3001. AdviceName: s.AdviceName,
  3002. AdviceDesc: s.AdviceDesc,
  3003. ReminderDate: s.ReminderDate,
  3004. SingleDose: s.SingleDose,
  3005. SingleDoseUnit: s.SingleDoseUnit,
  3006. PrescribingNumber: s.PrescribingNumber,
  3007. PrescribingNumberUnit: s.PrescribingNumberUnit,
  3008. DeliveryWay: s.DeliveryWay,
  3009. ExecutionFrequency: s.ExecutionFrequency,
  3010. AdviceDoctor: s.AdviceDoctor,
  3011. Status: s.Status,
  3012. CreatedTime: s.CreatedTime,
  3013. UpdatedTime: s.UpdatedTime,
  3014. AdviceAffirm: s.AdviceAffirm,
  3015. Remark: s.Remark,
  3016. StopTime: s.StopTime,
  3017. StopReason: s.StopReason,
  3018. StopDoctor: s.StopDoctor,
  3019. StopState: s.StopState,
  3020. ParentId: s.ParentId,
  3021. ExecutionTime: s.ExecutionTime,
  3022. ExecutionStaff: s.ExecutionStaff,
  3023. ExecutionState: s.ExecutionState,
  3024. Checker: s.Checker,
  3025. RecordDate: s.RecordDate,
  3026. DialysisOrderId: s.DialysisOrderId,
  3027. CheckTime: s.CheckTime,
  3028. CheckState: s.CheckState,
  3029. DrugSpec: s.DrugSpec,
  3030. DrugSpecUnit: s.DrugSpecUnit,
  3031. Groupno: s.Groupno,
  3032. RemindType: s.RemindType,
  3033. FrequencyType: s.FrequencyType,
  3034. DayCount: s.DayCount,
  3035. WeekDay: s.WeekDay,
  3036. TemplateId: s.TemplateId,
  3037. Modifier: s.Modifier,
  3038. DrugId: s.DrugId,
  3039. Price: s.Price,
  3040. PrescriptionId: s.PrescriptionId,
  3041. MedListCodg: s.MedListCodg,
  3042. FeedetlSn: s.FeedetlSn,
  3043. Day: s.DayCount,
  3044. ChildDoctorAdvice: nil,
  3045. Drug: models.Drug{},
  3046. Diagnosis: s.Diagnosis,
  3047. Way: s.Way,
  3048. HospApprFlag: s.HospApprFlag,
  3049. LmtUsedFlag: s.LmtUsedFlag,
  3050. HisOrderInfo: models.HisOrderInfo{},
  3051. IsMedicine: s.IsMedicine,
  3052. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3053. Child: nil,
  3054. IsSettle: s.IsSettle,
  3055. IsMobile: s.IsMobile,
  3056. IsSelfDrug: s.IsSelfDrug,
  3057. DrugWayCount: s.DrugWayCount,
  3058. }
  3059. var history_count int64
  3060. var local_count int64
  3061. //查找已经开过的医嘱信息
  3062. adviceHistory, _ := service.GetHistory(s.ID, s.UserOrgId, tx)
  3063. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3064. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3065. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3066. local_count += prescribingNumberSevenTy * drug.MinNumber
  3067. }
  3068. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3069. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3070. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3071. local_count += prescribingNumberSevenTy
  3072. }
  3073. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3074. prescribingNumberTenty := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3075. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3076. local_count += prescribingNumberSevenTy
  3077. }
  3078. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3079. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3080. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3081. history_count += prescribingNumberSevenTy * drug.MinNumber
  3082. }
  3083. if adviceHistory.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3084. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3085. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3086. history_count += prescribingNumberSevenTy
  3087. }
  3088. if adviceHistory.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3089. prescribingNumberTenty := strconv.FormatFloat(adviceHistory.PrescribingNumber, 'f', -1, 64)
  3090. prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3091. history_count += prescribingNumberSevenTy
  3092. }
  3093. //如果当前出库数量大于历史出库数量则需要出库
  3094. if local_count > history_count {
  3095. //按最小单位出库
  3096. var cha_count = local_count - history_count
  3097. newadviceInfo.PrescribingNumber = float64(cha_count)
  3098. newadviceInfo.PrescribingNumberUnit = drug.MinUnit
  3099. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3100. }
  3101. //如果当前出库数量小于历史出库数量则需要退库
  3102. if local_count < history_count {
  3103. var cha_count = history_count - local_count
  3104. service.NewHisDrugCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3105. service.NewHisDrugAutoCancelInfo(s.UserOrgId, creater, newadviceInfo, cha_count, drug, tx)
  3106. }
  3107. if local_count == history_count {
  3108. if is_user_total == 0 {
  3109. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3110. }
  3111. }
  3112. }
  3113. //更新字典里面的库存
  3114. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3115. var sum_count int64
  3116. for _, its := range stockInfo {
  3117. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3118. if its.MaxUnit == baseDrug.MaxUnit {
  3119. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3120. }
  3121. sum_count += its.StockMaxNumber + its.StockMinNumber
  3122. }
  3123. //更新基础库存
  3124. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3125. //剩余库存
  3126. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3127. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3128. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3129. //创建医嘱
  3130. service.CreateHisDoctorAdviceOne(&s, tx)
  3131. adviceObj, _ := service.GetLastHisDoctorAdviceById(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3132. outInfoTwo, _ := service.GetDrugWarehouseOutInfoByAdviceId(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3133. if len(outInfoTwo) > 0 {
  3134. for _, item := range outInfoTwo {
  3135. service.UpdateDrugOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3136. }
  3137. }
  3138. drugAutoDetail, _ := service.GetDrugAutoDetail(s.PatientId, s.UserOrgId, s.AdviceDate, s.DrugId, tx)
  3139. if len(drugAutoDetail) > 0 {
  3140. for _, item := range drugAutoDetail {
  3141. service.UpdateDrugAutoDetail(item.ID, adviceObj.ID, tx)
  3142. }
  3143. }
  3144. }
  3145. }
  3146. }
  3147. //记录日志
  3148. byterequest, _ := json.Marshal(s)
  3149. adviceLog := models.XtDoctorAdviceLog{
  3150. UserOrgId: s.UserOrgId,
  3151. PatientId: s.PatientId,
  3152. AdminUserId: adminInfo.AdminUser.Id,
  3153. Module: 1,
  3154. ErrLog: string(byterequest),
  3155. Status: 1,
  3156. Ctime: time.Now().Unix(),
  3157. Mtime: 0,
  3158. Source: "电脑端新建his医嘱",
  3159. RecordDate: s.AdviceDate,
  3160. }
  3161. service.CreateDoctorAdviceLog(adviceLog)
  3162. //存储切片中
  3163. adviceList = append(adviceList, s)
  3164. redis := service.RedisClient()
  3165. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3166. redis.Set(key, "", time.Second)
  3167. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3168. redis.Set(keyOne, "", time.Second)
  3169. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3170. redis.Set(keySeven, "", time.Second)
  3171. var randNum int
  3172. randNum = rand.Intn(10000) + 1000
  3173. timestamp := time.Now().Unix()
  3174. tempTime := time.Unix(timestamp, 0)
  3175. timeFormat := tempTime.Format("20060102150405")
  3176. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3177. if s.ID == 0 {
  3178. //查询改药品是否已经停用
  3179. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3180. if base.ID > 0 {
  3181. tx.Rollback()
  3182. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3183. return
  3184. }
  3185. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3186. if drugMedical.SumCount == 0 {
  3187. tx.Rollback()
  3188. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3189. return
  3190. }
  3191. }
  3192. //赤峰
  3193. if adminInfo.CurrentOrgId == 10265 {
  3194. drug, _ := service.FindNewBaseDrugLibRecord(adminInfo.CurrentOrgId, s.DrugId, tx)
  3195. info, _ := service.FindNewLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut, tx)
  3196. if info.RetailPrice > 0 {
  3197. if s.DeliveryWay == "口服" {
  3198. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3199. s.Price = drug.RetailPrice
  3200. }
  3201. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3202. s.Price = info.RetailPrice
  3203. }
  3204. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3205. s.Price = info.RetailPrice
  3206. }
  3207. }
  3208. }
  3209. }
  3210. service.CreateHisDoctorAdviceOne(&s, tx)
  3211. tx.Commit()
  3212. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3213. redis.Set(keySix, "", time.Second)
  3214. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3215. redis.Set(keyFive, "", time.Second)
  3216. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3217. redis.Set(keyEight, "", time.Second)
  3218. defer redis.Close()
  3219. }
  3220. }
  3221. }
  3222. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3223. projects := items["project"].([]interface{})
  3224. if len(projects) > 0 {
  3225. for _, project := range projects {
  3226. tx := db.Begin()
  3227. // 在函数结束时处理事务回滚
  3228. defer func() {
  3229. if r := recover(); r != nil {
  3230. tx.Rollback()
  3231. }
  3232. }()
  3233. var p models.HisPrescriptionProject
  3234. p.PrescriptionId = tempPrescription.ID
  3235. p.PatientId = patient_id
  3236. p.RecordDate = theTime3.Unix()
  3237. p.Doctor = doctor_id
  3238. p.UserOrgId = adminInfo.CurrentOrgId
  3239. p.HisPatientId = his_patient_id
  3240. p.Status = 1
  3241. p.StartTime = pTime
  3242. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3243. if errcode > 0 {
  3244. c.ServeFailJSONWithSGJErrorCode(errcode)
  3245. return
  3246. }
  3247. if p.ID == 0 {
  3248. p.IsOut = 2
  3249. }
  3250. if p.ID > 0 {
  3251. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3252. p.IsOut = projectDetail.IsOut
  3253. }
  3254. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 10265 {
  3255. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3256. if p.Type == 3 {
  3257. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3258. if p.Price != lastWarehouse.PackingPrice {
  3259. p.Price = lastWarehouse.PackingPrice
  3260. }
  3261. if p.Price == 0 {
  3262. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  3263. p.Price = lastWarehouseTwo.PackingPrice
  3264. }
  3265. if p.Unit == "" {
  3266. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3267. p.Unit = goodInfoOne.PackingUnit
  3268. }
  3269. }
  3270. }
  3271. if p.Type == 3 {
  3272. if p.ID == 0 {
  3273. //查询该耗材是否停用
  3274. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3275. //表示该耗材已经停用,不能保存
  3276. if goodInfoSeven.ID == 0 {
  3277. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3278. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3279. return
  3280. }
  3281. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3282. if goodInfoOne.SumCount == 0 {
  3283. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  3284. return
  3285. }
  3286. }
  3287. }
  3288. //查询保存耗材出库开关是否打开
  3289. if p.PatientId != 30038 {
  3290. if goodOutConfig.IsOpen == 1 {
  3291. //耗材出库
  3292. if p.Type == 3 {
  3293. //对比当前数据和历史出库数据
  3294. historyProject, _ := service.GetHistoryProject(p.PatientId, p.UserOrgId, p.RecordDate, p.ID, p.ProjectId, tx)
  3295. historyCount, _ := strconv.ParseInt(historyProject.Count, 10, 64)
  3296. nowCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3297. //如果当前处方数量大于历史数据,则需要出库
  3298. if nowCount > historyCount {
  3299. var cha_count int64
  3300. cha_count = nowCount - historyCount
  3301. timeStr := time.Now().Format("2006-01-02")
  3302. timeArr := strings.Split(timeStr, "-")
  3303. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3304. total = total + 1
  3305. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3306. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3307. number = number + total
  3308. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3309. operation_time := time.Now().Unix()
  3310. creater := c.GetAdminUserInfo().AdminUser.Id
  3311. recordDateStr := time.Now().Format("2006-01-02")
  3312. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3313. nowtime := recordDate.Unix()
  3314. warehouseOut := models.WarehouseOut{
  3315. WarehouseOutOrderNumber: warehousing_out_order,
  3316. OperationTime: operation_time,
  3317. OrgId: adminInfo.CurrentOrgId,
  3318. Creater: creater,
  3319. Ctime: time.Now().Unix(),
  3320. Status: 1,
  3321. WarehouseOutTime: nowtime,
  3322. Type: 1,
  3323. StorehouseId: storeConfig.StorehouseOutInfo,
  3324. IsCheck: 1,
  3325. IsSys: 1,
  3326. }
  3327. //查询是否生成出库单
  3328. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3329. if out.ID == 0 {
  3330. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3331. }
  3332. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3333. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3334. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3335. dialyPrepareOne := models.DialysisBeforePrepare{
  3336. GoodTypeId: goodObj.GoodTypeId,
  3337. GoodId: p.ProjectId,
  3338. PatientId: p.PatientId,
  3339. RecordDate: p.RecordDate,
  3340. UserOrgId: adminInfo.CurrentOrgId,
  3341. Count: cha_count,
  3342. Ctime: time.Now().Unix(),
  3343. Creater: creater,
  3344. Status: 1,
  3345. StorehouseId: houseConfig.StorehouseOutInfo,
  3346. ProjectId: p.ID,
  3347. }
  3348. //出库
  3349. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3350. }
  3351. //如果当前处方数量小于历史数据,怎需要退库
  3352. if nowCount < historyCount {
  3353. var cha_count int64
  3354. cha_count = historyCount - nowCount
  3355. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3356. creater := c.GetAdminUserInfo().AdminUser.Id
  3357. newPrescriptionProject := &models.HisPrescriptionProject{
  3358. ID: p.ID,
  3359. ProjectId: p.ProjectId,
  3360. Price: p.Price,
  3361. UserOrgId: p.UserOrgId,
  3362. Status: 1,
  3363. Ctime: time.Now().Unix(),
  3364. Mtime: time.Now().Unix(),
  3365. PatientId: p.PatientId,
  3366. HisPatientId: p.HisPatientId,
  3367. RecordDate: p.RecordDate,
  3368. PrescriptionId: p.PrescriptionId,
  3369. Count: p.Count,
  3370. FeedetlSn: p.FeedetlSn,
  3371. MedListCodg: p.MedListCodg,
  3372. SingleDose: p.SingleDose,
  3373. DeliveryWay: p.DeliveryWay,
  3374. ExecutionFrequency: p.ExecutionFrequency,
  3375. Day: p.Day,
  3376. HisProject: models.HisProject{},
  3377. GoodInfo: models.GoodInfo{},
  3378. Remark: p.Remark,
  3379. Unit: p.Unit,
  3380. Type: p.Type,
  3381. Doctor: p.Doctor,
  3382. ExecutionTime: p.ExecutionTime,
  3383. ExecutionStaff: p.ExecutionStaff,
  3384. ExecutionState: p.ExecutionState,
  3385. CheckTime: p.CheckTime,
  3386. CheckState: p.CheckState,
  3387. Checker: p.Checker,
  3388. StartTime: p.StartTime,
  3389. TeamId: p.TeamId,
  3390. XtHisProjectTeam: models.XtHisProjectTeam{},
  3391. FrequencyType: p.FrequencyType,
  3392. DayCount: p.DayCount,
  3393. WeekDay: p.WeekDay,
  3394. IsCheckTeam: p.IsCheckTeam,
  3395. HisOrderInfo: models.HisOrderInfo{},
  3396. ExecutionFrequencyId: p.ExecutionFrequencyId,
  3397. IsOut: p.IsOut,
  3398. YbSyncStatus: p.YbSyncStatus,
  3399. }
  3400. service.NewHisGoodCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3401. service.NewHisGoodAutoCancelInfo(adminInfo.CurrentOrgId, creater, newPrescriptionProject, cha_count, goodObj, tx)
  3402. }
  3403. if nowCount == historyCount {
  3404. if historyCount == 0 {
  3405. recordDateStr := time.Now().Format("2006-01-02")
  3406. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3407. nowtime := recordDate.Unix()
  3408. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3409. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3410. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3411. creater := c.GetAdminUserInfo().AdminUser.Id
  3412. dialyPrepareOne := models.DialysisBeforePrepare{
  3413. GoodTypeId: goodObj.GoodTypeId,
  3414. GoodId: p.ProjectId,
  3415. PatientId: p.PatientId,
  3416. RecordDate: p.RecordDate,
  3417. UserOrgId: adminInfo.CurrentOrgId,
  3418. Count: nowCount,
  3419. Ctime: time.Now().Unix(),
  3420. Creater: creater,
  3421. Status: 1,
  3422. StorehouseId: houseConfig.StorehouseOutInfo,
  3423. ProjectId: p.ID,
  3424. }
  3425. //出库
  3426. service.ConsumableNewHisPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, tx)
  3427. }
  3428. }
  3429. //lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3430. ////查询历史出库数据
  3431. //flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3432. //
  3433. //var out_count_five int64
  3434. //for _, item := range flowGood {
  3435. // out_count_five += item.Count
  3436. //}
  3437. //parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3438. //
  3439. ////如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3440. //if out_count_five != parseIntCount {
  3441. // //查询耗材最后一次出库记录
  3442. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3443. // //查询默认出库仓库库存
  3444. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3445. // if len(wareOut) > 0 {
  3446. //
  3447. // for _, it := range wareOut {
  3448. // //回退库存
  3449. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3450. //
  3451. // //删除出库记录
  3452. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3453. //
  3454. // }
  3455. // }
  3456. //
  3457. // timeStr := time.Now().Format("2006-01-02")
  3458. // timeArr := strings.Split(timeStr, "-")
  3459. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3460. //
  3461. // total = total + 1
  3462. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3463. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3464. // number = number + total
  3465. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3466. //
  3467. // operation_time := time.Now().Unix()
  3468. // creater := c.GetAdminUserInfo().AdminUser.Id
  3469. //
  3470. // recordDateStr := time.Now().Format("2006-01-02")
  3471. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3472. // nowtime := recordDate.Unix()
  3473. // warehouseOut := models.WarehouseOut{
  3474. // WarehouseOutOrderNumber: warehousing_out_order,
  3475. // OperationTime: operation_time,
  3476. // OrgId: adminInfo.CurrentOrgId,
  3477. // Creater: creater,
  3478. // Ctime: time.Now().Unix(),
  3479. // Status: 1,
  3480. // WarehouseOutTime: nowtime,
  3481. // Type: 1,
  3482. // StorehouseId: storeConfig.StorehouseOutInfo,
  3483. // IsCheck: 1,
  3484. // IsSys: 1,
  3485. // }
  3486. // //查询是否生成出库单
  3487. // out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3488. // if out.ID == 0 {
  3489. // service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3490. // }
  3491. //
  3492. // lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3493. //
  3494. // goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3495. // houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3496. //
  3497. // dialyPrepareOne := models.DialysisBeforePrepare{
  3498. // GoodTypeId: goodObj.GoodTypeId,
  3499. // GoodId: p.ProjectId,
  3500. // PatientId: p.PatientId,
  3501. // RecordDate: p.RecordDate,
  3502. // UserOrgId: adminInfo.CurrentOrgId,
  3503. // Count: parseIntCount,
  3504. // Ctime: time.Now().Unix(),
  3505. // Creater: creater,
  3506. // Status: 1,
  3507. // StorehouseId: houseConfig.StorehouseOutInfo,
  3508. // ProjectId: lastHisProject.ID,
  3509. // }
  3510. // //判断是否是零用耗材(非零用)
  3511. // if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3512. //
  3513. // //查询历史出库数据
  3514. // flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3515. // var out_count int64
  3516. // for _, item := range flowGood {
  3517. // out_count += item.Count
  3518. // }
  3519. // //如果历史数和当前数据不想等才进行退库出库
  3520. // if out_count != parseIntCount {
  3521. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3522. //
  3523. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3524. // detail := models.AutomaticReduceDetail{
  3525. // WarehouseOutId: 0,
  3526. // WarehouseOutOrderNumber: "",
  3527. // PatientId: p.PatientId,
  3528. // Ctime: time.Now().Unix(),
  3529. // Mtime: 0,
  3530. // Status: 1,
  3531. // RecordTime: p.RecordDate,
  3532. // OrgId: p.UserOrgId,
  3533. // GoodId: p.ProjectId,
  3534. // GoodTypeId: 0,
  3535. // Count: parseIntCount,
  3536. // Type: 0,
  3537. // ProjectId: lastHisProject.ID,
  3538. // StorehouseId: 0,
  3539. // }
  3540. //
  3541. // service.CreateNewAutoDetail(detail, tx)
  3542. //
  3543. // //查询剩余库存
  3544. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3545. // var sum_count int64
  3546. // for _, item := range goodList {
  3547. // sum_count += item.StockCount
  3548. // }
  3549. //
  3550. // //更新剩余库存
  3551. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3552. //
  3553. // //耗材
  3554. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3555. //
  3556. // }
  3557. // //判断是否是零用耗材(零用但是是出库耗材)
  3558. // if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3559. //
  3560. // //查询历史出库数据
  3561. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3562. // var out_count int64
  3563. // for _, item := range flowGood {
  3564. // out_count += item.Count
  3565. // }
  3566. // //如果历史数和当前数据不想等才进行退库出库
  3567. // if out_count != parseIntCount {
  3568. // service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3569. //
  3570. // service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3571. // detail := models.AutomaticReduceDetail{
  3572. // WarehouseOutId: 0,
  3573. // WarehouseOutOrderNumber: "",
  3574. // PatientId: p.PatientId,
  3575. // Ctime: time.Now().Unix(),
  3576. // Mtime: 0,
  3577. // Status: 1,
  3578. // RecordTime: p.RecordDate,
  3579. // OrgId: p.UserOrgId,
  3580. // GoodId: p.ProjectId,
  3581. // GoodTypeId: 0,
  3582. // Count: parseIntCount,
  3583. // Type: 0,
  3584. // ProjectId: p.ID,
  3585. // StorehouseId: 0,
  3586. // }
  3587. //
  3588. // service.CreateNewAutoDetail(detail, tx)
  3589. //
  3590. // //查询剩余库存
  3591. // goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3592. // var sum_count int64
  3593. // for _, item := range goodList {
  3594. // sum_count += item.StockCount
  3595. // }
  3596. //
  3597. // //更新剩余库存
  3598. // service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3599. //
  3600. // //耗材
  3601. // service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3602. // }
  3603. //
  3604. // }
  3605. //
  3606. // }
  3607. //
  3608. //}
  3609. //记录日志
  3610. byterequest, _ := json.Marshal(p)
  3611. adviceLog := models.XtDoctorAdviceLog{
  3612. UserOrgId: p.UserOrgId,
  3613. PatientId: p.PatientId,
  3614. AdminUserId: adminInfo.AdminUser.Id,
  3615. Module: 1,
  3616. ErrLog: string(byterequest),
  3617. Status: 1,
  3618. Ctime: time.Now().Unix(),
  3619. Mtime: 0,
  3620. Source: "电脑端新建his项目",
  3621. RecordDate: p.RecordDate,
  3622. }
  3623. service.CreateDoctorAdviceLog(adviceLog)
  3624. projectList = append(projectList, p)
  3625. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3626. //新增或者编辑项目,修改对应的标签数据
  3627. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3628. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3629. var label models.HisLabelPrintInfo
  3630. project, _ := service.GetProjectDetail(p.ProjectId)
  3631. if project.CostClassify == 3 { //类别为检验检查
  3632. if p.TeamId > 0 { //检验检查组套
  3633. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3634. if tempLabel.ID == 0 {
  3635. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3636. label.Number = tempPrescription.PrescriptionNumber
  3637. label.ProjectId = project.ID
  3638. label.Status = 1
  3639. label.IsPrint = 2
  3640. label.DoctorId = info.DoctorId
  3641. label.UserOrgId = p.UserOrgId
  3642. label.PatientId = patient_id
  3643. label.RecordDate = recordDateTime
  3644. label.Ctime = time.Now().Unix()
  3645. label.Mtime = time.Now().Unix()
  3646. label.ItemId = p.TeamId
  3647. label.FeedetlSn = p.FeedetlSn
  3648. label.PProjectId = p.ID
  3649. label.ProjectName = team.ProjectTeam
  3650. label.PatientName = patient.Name
  3651. service.CreateNewHisLabelRecord(&label, tx)
  3652. }
  3653. } else { //单条检验检查项目
  3654. label.Number = tempPrescription.PrescriptionNumber
  3655. label.ProjectId = project.ID
  3656. label.Status = 1
  3657. label.DoctorId = info.DoctorId
  3658. label.UserOrgId = p.UserOrgId
  3659. label.PatientId = patient_id
  3660. label.RecordDate = recordDateTime
  3661. label.IsPrint = 2
  3662. label.Ctime = time.Now().Unix()
  3663. label.Mtime = time.Now().Unix()
  3664. label.FeedetlSn = p.FeedetlSn
  3665. label.PProjectId = p.ID
  3666. label.ItemId = p.TeamId
  3667. label.ProjectName = project.ProjectName
  3668. label.PatientName = patient.Name
  3669. service.CreateNewHisLabelRecord(&label, tx)
  3670. }
  3671. }
  3672. }
  3673. }
  3674. }
  3675. }
  3676. }
  3677. service.CreateNewHisProjectTwo(&p, tx)
  3678. var randNum int
  3679. randNum = rand.Intn(10000) + 1000
  3680. timestamp := time.Now().Unix()
  3681. tempTime := time.Unix(timestamp, 0)
  3682. timeFormat := tempTime.Format("20060102150405")
  3683. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3684. goodBase, _ := service.GetBaseGoodById(p.ProjectId, p.UserOrgId)
  3685. if goodBase.ID > 0 {
  3686. tx.Rollback()
  3687. c.ServeDynamicFailJsonSend(goodBase.SpecificationName + "已停用!请更换其他耗材")
  3688. return
  3689. }
  3690. service.CreateNewHisProjectTwo(&p, tx)
  3691. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3692. //查询剩余库存
  3693. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3694. var sum_count int64
  3695. for _, item := range goodList {
  3696. sum_count += item.StockCount
  3697. }
  3698. //更新剩余库存
  3699. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3700. //耗材
  3701. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3702. adviceObj, _ := service.GetLastHisProjectById(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3703. outInfoTwo, _ := service.GetGoodWarehouseOutInfoByAdviceId(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3704. if len(outInfoTwo) > 0 {
  3705. for _, item := range outInfoTwo {
  3706. service.UpdateGoodOutInfoByAdviceId(item.ID, adviceObj.ID, tx)
  3707. }
  3708. }
  3709. drugAutoDetail, _ := service.GetGoodAutoDetail(p.PatientId, p.UserOrgId, p.RecordDate, p.ProjectId, tx)
  3710. if len(drugAutoDetail) > 0 {
  3711. for _, item := range drugAutoDetail {
  3712. service.UpdateGoodAutoDetail(item.ID, adviceObj.ID, tx)
  3713. }
  3714. }
  3715. tx.Commit()
  3716. }
  3717. }
  3718. }
  3719. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3720. // addition := items["addition"].([]interface{})
  3721. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3722. // ctime := time.Now().Unix()
  3723. // mtime := ctime
  3724. // if len(addition) > 0 {
  3725. // for _, item := range addition {
  3726. // var s models.HisAdditionalCharge
  3727. // s.PrescriptionId = tempPrescription.ID
  3728. // s.Status = 1
  3729. // s.UserOrgId = adminInfo.CurrentOrgId
  3730. // s.RecordDate = recordDateTime
  3731. // s.CreatedTime = ctime
  3732. // s.UpdatedTime = mtime
  3733. // s.PatientId = patient_id
  3734. // s.HisPatientId = his_patient_id
  3735. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3736. // if errcode > 0 {
  3737. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3738. // return
  3739. // }
  3740. // service.CreateAdditionalCharge(&s)
  3741. // var randNum int
  3742. // randNum = rand.Intn(10000) + 1000
  3743. // timestamp := time.Now().Unix()
  3744. // tempTime := time.Unix(timestamp, 0)
  3745. // timeFormat := tempTime.Format("20060102150405")
  3746. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3747. // service.CreateAdditionalCharge(&s)
  3748. //
  3749. // }
  3750. // }
  3751. //}
  3752. }
  3753. }
  3754. }
  3755. tx.Commit()
  3756. if err == nil {
  3757. c.ServeSuccessJSON(map[string]interface{}{
  3758. "msg": "保存成功",
  3759. })
  3760. return
  3761. } else {
  3762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3763. return
  3764. }
  3765. } else {
  3766. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3767. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3768. var tempPrescription *models.HisPrescription
  3769. if len(prescriptions) > 0 {
  3770. for _, item := range prescriptions {
  3771. items := item.(map[string]interface{})
  3772. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3773. utils.ErrorLog("id")
  3774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3775. return
  3776. }
  3777. id := int64(items["id"].(float64))
  3778. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3779. tempPrescription = &new_prescription
  3780. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3781. utils.ErrorLog("type")
  3782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3783. return
  3784. }
  3785. types := int64(items["type"].(float64))
  3786. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3787. utils.ErrorLog("med_type")
  3788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3789. return
  3790. }
  3791. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3792. if med_type == "0" {
  3793. med_type = "14"
  3794. }
  3795. //if order_status == 0 {
  3796. // order_status = 1
  3797. //}
  3798. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3799. utils.ErrorLog("pre_time")
  3800. }
  3801. preTime, _ := items["pre_time"].(string)
  3802. timeLayout := "2006-01-02"
  3803. loc, _ := time.LoadLocation("Local")
  3804. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3805. result := strings.Split(preTime, " ")
  3806. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3807. if err != nil {
  3808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3809. return
  3810. }
  3811. pTime := theTime2.Unix()
  3812. ctime := time.Now().Unix()
  3813. if tempPrescription.ID == 0 {
  3814. prescription := &models.HisPrescription{
  3815. ID: 0,
  3816. PatientId: patient_id,
  3817. UserOrgId: adminInfo.CurrentOrgId,
  3818. RecordDate: recordDateTime,
  3819. Ctime: ctime,
  3820. Mtime: ctime,
  3821. Type: types,
  3822. Modifier: adminInfo.AdminUser.Id,
  3823. Creator: adminInfo.AdminUser.Id,
  3824. Status: 1,
  3825. Doctor: role.UserName,
  3826. HisPatientId: his_patient_id,
  3827. OrderStatus: 1,
  3828. BatchNumber: "",
  3829. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3830. PreTime: pTime,
  3831. PType: p_type,
  3832. MedType: med_type,
  3833. }
  3834. tempPrescription = prescription
  3835. service.SaveHisPrescription(tempPrescription)
  3836. redis := service.RedisClient()
  3837. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3838. redis.Set(key, "", time.Second)
  3839. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3840. redis.Set(keyOne, "", time.Second)
  3841. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3842. redis.Set(keySeven, "", time.Second)
  3843. defer redis.Close()
  3844. } else {
  3845. tempPrescription.ID = id
  3846. tempPrescription.Type = types
  3847. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3848. tempPrescription.Mtime = time.Now().Unix()
  3849. tempPrescription.Doctor = role.UserName
  3850. //tempPrescription.OrderStatus = order_status
  3851. tempPrescription.PreTime = pTime
  3852. tempPrescription.MedType = med_type
  3853. service.SaveHisPrescription(tempPrescription)
  3854. redis := service.RedisClient()
  3855. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3856. redis.Set(key, "", time.Second)
  3857. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3858. redis.Set(keyOne, "", time.Second)
  3859. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3860. redis.Set(keySeven, "", time.Second)
  3861. defer redis.Close()
  3862. }
  3863. //service.SaveHisPrescription(prescription)
  3864. //更改患者挂号状态
  3865. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3866. fmt.Println("更改失败", err2)
  3867. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3868. advices := items["advices"].([]interface{})
  3869. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3870. groupNo := int64(0)
  3871. if len(advices) > 0 {
  3872. for _, advice := range advices {
  3873. var s models.HisDoctorAdviceInfo
  3874. s.PrescriptionId = tempPrescription.ID
  3875. s.AdviceType = 2
  3876. s.AdviceDoctor = doctor_id
  3877. s.StopState = 2
  3878. s.ExecutionState = 2
  3879. s.AdviceDate = theTime3.Unix()
  3880. s.Status = 1
  3881. s.UserOrgId = adminInfo.CurrentOrgId
  3882. s.RecordDate = theTime3.Unix()
  3883. s.StartTime = tempPrescription.PreTime
  3884. s.Groupno = groupNo
  3885. s.PatientId = patient_id
  3886. s.HisPatientId = his_patient_id
  3887. s.StartTime = pTime
  3888. s.IsSettle = 2
  3889. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3890. if errcode > 0 {
  3891. c.ServeFailJSONWithSGJErrorCode(errcode)
  3892. return
  3893. }
  3894. s.StartTime = pTime
  3895. var total_count int64 //处方总库存
  3896. //查询改药品信息
  3897. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3898. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3899. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3900. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3901. total_count += prescribingNumberSeven * medical.MinNumber
  3902. }
  3903. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3904. total_count += prescribingNumberSeven
  3905. }
  3906. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3907. total_count += prescribingNumberSeven
  3908. }
  3909. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3910. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3911. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3912. if s.Price != lastWarehouse.RetailPrice {
  3913. s.Price = lastWarehouse.RetailPrice
  3914. }
  3915. if s.Price == 0 {
  3916. if lastWarehouse.ID == 0 {
  3917. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  3918. s.Price = lastWarehouseTwo.RetailPrice
  3919. }
  3920. }
  3921. }
  3922. if s.ID == 0 {
  3923. //查询改药品是否已经停用
  3924. base, _ := service.GetBasedrugById(s.DrugId, s.UserOrgId)
  3925. if base.ID > 0 {
  3926. c.ServeDynamicFailJsonSend(base.DrugName + "已停用!请更换其他药品")
  3927. return
  3928. }
  3929. drugMedical, _ := service.GetBaseDrugMedical(s.DrugId)
  3930. if drugMedical.SumCount == 0 {
  3931. c.ServeDynamicFailJsonSend(drugMedical.DrugName + "库存不足,保存失败!")
  3932. return
  3933. }
  3934. }
  3935. //赤峰
  3936. if s.UserOrgId == 10265 {
  3937. drug, _ := service.GetDrugByGoodId(s.DrugId)
  3938. info, _ := service.GetWarehoseInfoByDrugId(s.DrugId, s.UserOrgId)
  3939. if info.RetailPrice > 0 {
  3940. if s.DeliveryWay == "口服" {
  3941. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3942. s.Price = drug.RetailPrice
  3943. }
  3944. if s.PrescribingNumberUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3945. s.Price = info.RetailPrice
  3946. }
  3947. if s.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3948. s.Price = info.RetailPrice
  3949. }
  3950. }
  3951. }
  3952. }
  3953. service.CreateHisDoctorAdvice(&s)
  3954. //记录日志
  3955. byterequest, _ := json.Marshal(s)
  3956. adviceLog := models.XtDoctorAdviceLog{
  3957. UserOrgId: s.UserOrgId,
  3958. PatientId: s.PatientId,
  3959. AdminUserId: adminInfo.AdminUser.Id,
  3960. Module: 1,
  3961. ErrLog: string(byterequest),
  3962. Status: 1,
  3963. Ctime: time.Now().Unix(),
  3964. Mtime: 0,
  3965. Source: "电脑端新建his医嘱",
  3966. RecordDate: s.AdviceDate,
  3967. }
  3968. service.CreateDoctorAdviceLog(adviceLog)
  3969. //存储切片中
  3970. adviceList = append(adviceList, s)
  3971. redis := service.RedisClient()
  3972. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3973. redis.Set(key, "", time.Second)
  3974. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3975. redis.Set(keyOne, "", time.Second)
  3976. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3977. redis.Set(keySeven, "", time.Second)
  3978. var randNum int
  3979. randNum = rand.Intn(10000) + 1000
  3980. timestamp := time.Now().Unix()
  3981. tempTime := time.Unix(timestamp, 0)
  3982. timeFormat := tempTime.Format("20060102150405")
  3983. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3984. service.CreateHisDoctorAdvice(&s)
  3985. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3986. redis.Set(keySix, "", time.Second)
  3987. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3988. redis.Set(keyFive, "", time.Second)
  3989. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3990. redis.Set(keyEight, "", time.Second)
  3991. defer redis.Close()
  3992. }
  3993. }
  3994. }
  3995. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3996. projects := items["project"].([]interface{})
  3997. if len(projects) > 0 {
  3998. for _, project := range projects {
  3999. var p models.HisPrescriptionProject
  4000. p.PrescriptionId = tempPrescription.ID
  4001. p.PatientId = patient_id
  4002. p.RecordDate = theTime3.Unix()
  4003. p.Doctor = doctor_id
  4004. p.UserOrgId = adminInfo.CurrentOrgId
  4005. p.HisPatientId = his_patient_id
  4006. p.Status = 1
  4007. p.StartTime = pTime
  4008. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  4009. if errcode > 0 {
  4010. c.ServeFailJSONWithSGJErrorCode(errcode)
  4011. return
  4012. }
  4013. if p.ID == 0 {
  4014. p.IsOut = 2
  4015. }
  4016. if p.ID > 0 {
  4017. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  4018. p.IsOut = projectDetail.IsOut
  4019. }
  4020. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4021. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4022. if p.Type == 3 {
  4023. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  4024. if p.Price != lastWarehouse.PackingPrice {
  4025. p.Price = lastWarehouse.PackingPrice
  4026. }
  4027. if p.Price == 0 {
  4028. lastWarehouseTwo, _ := service.FindFirstWarehousingInfoByStockFour(p.ProjectId, storeConfig.DrugStorehouseOut)
  4029. p.Price = lastWarehouseTwo.PackingPrice
  4030. }
  4031. if p.Unit == "" {
  4032. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4033. p.Unit = goodInfoOne.PackingUnit
  4034. }
  4035. }
  4036. }
  4037. if p.Type == 3 {
  4038. if p.ID == 0 {
  4039. //查询该耗材是否停用
  4040. goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  4041. //表示该耗材已经停用,不能保存
  4042. if goodInfoSeven.ID == 0 {
  4043. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4044. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  4045. return
  4046. }
  4047. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  4048. if goodInfoOne.SumCount == 0 {
  4049. c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材无库存,保存失败!")
  4050. return
  4051. }
  4052. }
  4053. }
  4054. service.CreateHisProjectTwo(&p)
  4055. //记录日志
  4056. byterequest, _ := json.Marshal(p)
  4057. adviceLog := models.XtDoctorAdviceLog{
  4058. UserOrgId: p.UserOrgId,
  4059. PatientId: p.PatientId,
  4060. AdminUserId: adminInfo.AdminUser.Id,
  4061. Module: 1,
  4062. ErrLog: string(byterequest),
  4063. Status: 1,
  4064. Ctime: time.Now().Unix(),
  4065. Mtime: 0,
  4066. Source: "电脑端新建his项目",
  4067. RecordDate: p.RecordDate,
  4068. }
  4069. service.CreateDoctorAdviceLog(adviceLog)
  4070. projectList = append(projectList, p)
  4071. var randNum int
  4072. randNum = rand.Intn(10000) + 1000
  4073. timestamp := time.Now().Unix()
  4074. tempTime := time.Unix(timestamp, 0)
  4075. timeFormat := tempTime.Format("20060102150405")
  4076. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  4077. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  4078. //新增或者编辑项目,修改对应的标签数据
  4079. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  4080. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  4081. var label models.HisLabelPrintInfo
  4082. project, _ := service.GetProjectDetail(p.ProjectId)
  4083. if project.CostClassify == 3 { //类别为检验检查
  4084. if p.TeamId > 0 { //检验检查组套
  4085. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  4086. if tempLabel.ID == 0 {
  4087. team, _ := service.GetProjectTeamDetail(p.TeamId)
  4088. label.Number = tempPrescription.PrescriptionNumber
  4089. label.ProjectId = project.ID
  4090. label.Status = 1
  4091. label.IsPrint = 2
  4092. label.DoctorId = info.DoctorId
  4093. label.UserOrgId = p.UserOrgId
  4094. label.PatientId = patient_id
  4095. label.RecordDate = recordDateTime
  4096. label.Ctime = time.Now().Unix()
  4097. label.Mtime = time.Now().Unix()
  4098. label.ItemId = p.TeamId
  4099. label.FeedetlSn = p.FeedetlSn
  4100. label.PProjectId = p.ID
  4101. label.ProjectName = team.ProjectTeam
  4102. label.PatientName = patient.Name
  4103. service.CreateHisLabelRecord(&label)
  4104. }
  4105. } else { //单条检验检查项目
  4106. label.Number = tempPrescription.PrescriptionNumber
  4107. label.ProjectId = project.ID
  4108. label.Status = 1
  4109. label.DoctorId = info.DoctorId
  4110. label.UserOrgId = p.UserOrgId
  4111. label.PatientId = patient_id
  4112. label.RecordDate = recordDateTime
  4113. label.IsPrint = 2
  4114. label.Ctime = time.Now().Unix()
  4115. label.Mtime = time.Now().Unix()
  4116. label.FeedetlSn = p.FeedetlSn
  4117. label.PProjectId = p.ID
  4118. label.ItemId = p.TeamId
  4119. label.ProjectName = project.ProjectName
  4120. label.PatientName = patient.Name
  4121. service.CreateHisLabelRecord(&label)
  4122. }
  4123. }
  4124. }
  4125. }
  4126. service.SaveHisProjectTwo(&p)
  4127. }
  4128. }
  4129. }
  4130. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4131. // addition := items["addition"].([]interface{})
  4132. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4133. // ctime := time.Now().Unix()
  4134. // mtime := ctime
  4135. // if len(addition) > 0 {
  4136. // for _, item := range addition {
  4137. // var s models.HisAdditionalCharge
  4138. // s.PrescriptionId = tempPrescription.ID
  4139. // s.Status = 1
  4140. // s.UserOrgId = adminInfo.CurrentOrgId
  4141. // s.RecordDate = recordDateTime
  4142. // s.CreatedTime = ctime
  4143. // s.UpdatedTime = mtime
  4144. // s.PatientId = patient_id
  4145. // s.HisPatientId = his_patient_id
  4146. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4147. // if errcode > 0 {
  4148. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4149. // return
  4150. // }
  4151. // service.CreateAdditionalCharge(&s)
  4152. // var randNum int
  4153. // randNum = rand.Intn(10000) + 1000
  4154. // timestamp := time.Now().Unix()
  4155. // tempTime := time.Unix(timestamp, 0)
  4156. // timeFormat := tempTime.Format("20060102150405")
  4157. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  4158. // service.CreateAdditionalCharge(&s)
  4159. //
  4160. // }
  4161. // }
  4162. //}
  4163. }
  4164. }
  4165. //查询今日该患者开的药品处方
  4166. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4167. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  4168. //药品出库
  4169. if drugOutConfig.IsOpen == 1 {
  4170. for _, item := range hisdoctorlist {
  4171. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  4172. // 查询该药品最后一次出库记录
  4173. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4174. if len(druginfo) > 0 {
  4175. //回退库存
  4176. for _, it := range druginfo {
  4177. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4178. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4179. }
  4180. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4181. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4182. }
  4183. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4184. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4185. }
  4186. }
  4187. }
  4188. //删除记录
  4189. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4190. //查询最后一次数据
  4191. if drugOutConfig.IsOpen == 1 {
  4192. //出库
  4193. if drug.IsUse == 2 {
  4194. creater := adminInfo.AdminUser.Id
  4195. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4196. }
  4197. //更新字典里面的库存
  4198. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4199. var sum_count int64
  4200. for _, its := range stockInfo {
  4201. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4202. if its.MaxUnit == baseDrug.MaxUnit {
  4203. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4204. }
  4205. sum_count += its.StockMaxNumber + its.StockMinNumber
  4206. }
  4207. //更新基础库存
  4208. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4209. //剩余库存
  4210. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4211. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4212. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4213. }
  4214. }
  4215. }
  4216. //耗材保存处方出库
  4217. if goodOutConfig.IsOpen == 1 {
  4218. //查询今日耗材出库数量
  4219. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4220. for _, item := range hisgoodlist {
  4221. //查询历史出库数据
  4222. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4223. var out_count_five int64
  4224. for _, item := range flowGood {
  4225. out_count_five += item.Count
  4226. }
  4227. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4228. if out_count_five != parseIntCount {
  4229. //查询耗材最后一次出库记录
  4230. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4231. //查询默认出库仓库库存
  4232. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4233. if len(wareOut) > 0 {
  4234. for _, it := range wareOut {
  4235. //回退库存
  4236. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4237. //删除出库记录
  4238. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4239. }
  4240. }
  4241. timeStr := time.Now().Format("2006-01-02")
  4242. timeArr := strings.Split(timeStr, "-")
  4243. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4244. total = total + 1
  4245. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4246. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4247. number = number + total
  4248. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4249. operation_time := time.Now().Unix()
  4250. creater := c.GetAdminUserInfo().AdminUser.Id
  4251. recordDateStr := time.Now().Format("2006-01-02")
  4252. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4253. nowtime := recordDate.Unix()
  4254. warehouseOut := models.WarehouseOut{
  4255. WarehouseOutOrderNumber: warehousing_out_order,
  4256. OperationTime: operation_time,
  4257. OrgId: adminInfo.CurrentOrgId,
  4258. Creater: creater,
  4259. Ctime: time.Now().Unix(),
  4260. Status: 1,
  4261. WarehouseOutTime: nowtime,
  4262. Type: 1,
  4263. StorehouseId: storeConfig.StorehouseOutInfo,
  4264. IsCheck: 1,
  4265. IsSys: 1,
  4266. }
  4267. //查询是否生成出库单
  4268. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4269. if out.ID == 0 {
  4270. service.AddSigleWarehouseOut(&warehouseOut)
  4271. }
  4272. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4273. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4274. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4275. dialyPrepareOne := models.DialysisBeforePrepare{
  4276. GoodTypeId: goodObj.GoodTypeId,
  4277. GoodId: item.ProjectId,
  4278. PatientId: item.PatientId,
  4279. RecordDate: item.RecordDate,
  4280. UserOrgId: adminInfo.CurrentOrgId,
  4281. Count: parseIntCount,
  4282. Ctime: time.Now().Unix(),
  4283. Creater: creater,
  4284. Status: 1,
  4285. StorehouseId: houseConfig.StorehouseOutInfo,
  4286. ProjectId: item.ID,
  4287. }
  4288. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4289. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4290. //查询历史出库数据
  4291. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4292. var out_count int64
  4293. for _, item := range flowGood {
  4294. out_count += item.Count
  4295. }
  4296. //如果历史数和当前数据不想等才进行退库出库
  4297. if out_count != parseIntCount {
  4298. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4299. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4300. detail := models.AutomaticReduceDetail{
  4301. WarehouseOutId: 0,
  4302. WarehouseOutOrderNumber: "",
  4303. PatientId: item.PatientId,
  4304. Ctime: time.Now().Unix(),
  4305. Mtime: 0,
  4306. Status: 1,
  4307. RecordTime: item.RecordDate,
  4308. OrgId: item.UserOrgId,
  4309. GoodId: item.ProjectId,
  4310. GoodTypeId: 0,
  4311. Count: parseIntCount,
  4312. Type: 0,
  4313. ProjectId: item.ID,
  4314. StorehouseId: 0,
  4315. }
  4316. service.CreateAutoDetail(detail)
  4317. //查询剩余库存
  4318. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4319. var sum_count int64
  4320. for _, item := range goodList {
  4321. sum_count += item.StockCount
  4322. }
  4323. //更新剩余库存
  4324. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4325. //耗材
  4326. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4327. }
  4328. }
  4329. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4330. //查询历史出库数据
  4331. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4332. var out_count int64
  4333. for _, item := range flowGood {
  4334. out_count += item.Count
  4335. }
  4336. //如果历史数和当前数据不想等才进行退库出库
  4337. if out_count != parseIntCount {
  4338. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4339. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4340. detail := models.AutomaticReduceDetail{
  4341. WarehouseOutId: 0,
  4342. WarehouseOutOrderNumber: "",
  4343. PatientId: item.PatientId,
  4344. Ctime: time.Now().Unix(),
  4345. Mtime: 0,
  4346. Status: 1,
  4347. RecordTime: item.RecordDate,
  4348. OrgId: item.UserOrgId,
  4349. GoodId: item.ProjectId,
  4350. GoodTypeId: 0,
  4351. Count: parseIntCount,
  4352. Type: 0,
  4353. ProjectId: item.ID,
  4354. StorehouseId: 0,
  4355. }
  4356. service.CreateAutoDetail(detail)
  4357. //查询剩余库存
  4358. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4359. var sum_count int64
  4360. for _, item := range goodList {
  4361. sum_count += item.StockCount
  4362. }
  4363. //更新剩余库存
  4364. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4365. //耗材
  4366. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4367. }
  4368. }
  4369. }
  4370. }
  4371. }
  4372. ////同步到自备药
  4373. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(adminInfo.CurrentOrgId)
  4374. if selfPrescriptionOpen.IsOpen == 1 {
  4375. timeStr := time.Now().Format("2006-01-02")
  4376. timeArr := strings.Split(timeStr, "-")
  4377. total, _ := service.FindSelfAllWarehouseTotal(adminInfo.CurrentOrgId, tx)
  4378. total = total + 1
  4379. operation_time := time.Now().Unix()
  4380. creater := adminInfo.AdminUser.Id
  4381. warehousing_order := "YPRKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4382. warehousing := models.XtSelfDrugWarehouse{
  4383. WarehousingOrder: warehousing_order,
  4384. OperationTime: operation_time,
  4385. OrgId: adminInfo.CurrentOrgId,
  4386. Creater: creater,
  4387. Ctime: time.Now().Unix(),
  4388. Status: 1,
  4389. WarehousingTime: recordDateTime,
  4390. Type: 0,
  4391. StorehouseId: 0,
  4392. IsCheck: 1,
  4393. PatientId: patient_id,
  4394. IsSys: 1,
  4395. }
  4396. selfDrugWarehouse, _ := service.GetSelfDrugWarehouseByWaresingId(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  4397. if selfDrugWarehouse.ID == 0 {
  4398. service.AddSelfDrugWarehouse(&warehousing, tx)
  4399. }
  4400. if selfDrugWarehouse.ID > 0 {
  4401. service.UpdateSelfDrugWarehouse(&warehousing, tx)
  4402. }
  4403. info, _ := service.FindLastSelfWarehousing(adminInfo.CurrentOrgId, patient_id, tx)
  4404. fmt.Println(info)
  4405. for _, item := range hisdoctorlist {
  4406. //查询该病人的该药品是否已经入库
  4407. selfdruginfo, _ := service.GetSelfDrugWarehouseInfoByInfo(item.ID, item.PatientId, item.AdviceDate, item.UserOrgId, item.DrugId, tx)
  4408. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  4409. var in_count int64
  4410. if len(selfdruginfo) > 0 {
  4411. for _, item := range selfdruginfo {
  4412. var in_count_one int64
  4413. if item.WarehouseingUnit != selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4414. in_count_one = item.WarehousingCount * selfBasedrug.MinNumber
  4415. }
  4416. if item.WarehouseingUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4417. in_count_one = item.WarehousingCount
  4418. }
  4419. if item.WarehouseingUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4420. in_count_one = item.WarehousingCount
  4421. }
  4422. in_count += in_count_one
  4423. }
  4424. }
  4425. if selfBasedrug.IsSelfDrug == 1 {
  4426. var total_count int64
  4427. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  4428. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  4429. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4430. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  4431. }
  4432. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4433. total_count += prescribingNumberSeven
  4434. }
  4435. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4436. total_count += prescribingNumberSeven
  4437. }
  4438. //入库
  4439. if total_count > in_count {
  4440. selfwarehouseInfo := &models.XtSelfDrugWarehouseInfo{
  4441. WarehousingOrder: warehousing_order,
  4442. WarehousingId: info.ID,
  4443. DrugId: item.DrugId,
  4444. Number: "",
  4445. ProductDate: 0,
  4446. ExpiryDate: 0,
  4447. WarehousingCount: total_count - in_count,
  4448. WarehouseingUnit: selfBasedrug.MinUnit,
  4449. Price: 0,
  4450. TotalPrice: 0,
  4451. Status: 1,
  4452. Ctime: time.Now().Unix(),
  4453. Remark: "",
  4454. OrgId: adminInfo.CurrentOrgId,
  4455. Type: 0,
  4456. Manufacturer: selfBasedrug.Manufacturer,
  4457. Dealer: selfBasedrug.Dealer,
  4458. StockMaxNumber: total_count - in_count,
  4459. RetailTotalPrice: 0,
  4460. BatchNumber: "",
  4461. MaxUnit: selfBasedrug.MinUnit,
  4462. MinUnit: selfBasedrug.MinUnit,
  4463. RetailPrice: 0,
  4464. StorehouseId: 0,
  4465. IsCheck: 1,
  4466. StockMinNumber: 0,
  4467. PatientId: patient_id,
  4468. IsSys: 1,
  4469. RecordDate: item.RecordDate,
  4470. AdviceId: item.ID,
  4471. }
  4472. service.CreateSelfDrugWarehouseInfo(selfwarehouseInfo, tx)
  4473. lastDrugWarhouseInfo, _ := service.GetLastSelfDrugWarehouseInfoById(adminInfo.CurrentOrgId, tx)
  4474. Creator := adminInfo.AdminUser.Id
  4475. //查询默认仓库剩余多少库存
  4476. list, _ := service.GetDrugSumCountByPatient(patient_id, adminInfo.CurrentOrgId, item.DrugId, tx)
  4477. var sum_count int64
  4478. for _, it := range list {
  4479. baseDrug, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  4480. if it.MaxUnit == baseDrug.MaxUnit {
  4481. it.StockMaxNumber = it.StockMaxNumber * baseDrug.MinNumber
  4482. it.WarehousingCount = it.WarehousingCount * baseDrug.MinNumber
  4483. }
  4484. sum_count += it.StockMaxNumber + it.StockMinNumber
  4485. }
  4486. flow := &models.XtSelfDrugFlow{
  4487. WarehousingId: info.ID,
  4488. DrugId: item.DrugId,
  4489. Number: "",
  4490. BatchNumber: "",
  4491. Count: total_count - in_count,
  4492. UserOrgId: adminInfo.CurrentOrgId,
  4493. PatientId: item.PatientId,
  4494. SystemTime: time.Now().Unix(),
  4495. ConsumableType: 1,
  4496. IsSys: 1,
  4497. WarehousingOrder: warehousing_order,
  4498. WarehouseOutId: 0,
  4499. WarehouseOutOrderNumber: "",
  4500. IsEdit: 0,
  4501. CancelStockId: 0,
  4502. CancelOrderNumber: "",
  4503. Manufacturer: selfBasedrug.Manufacturer,
  4504. Dealer: selfBasedrug.Dealer,
  4505. Creator: Creator,
  4506. UpdateCreator: Creator,
  4507. Status: 1,
  4508. Ctime: item.AdviceDate,
  4509. Mtime: 0,
  4510. Price: item.Price,
  4511. WarehousingDetailId: lastDrugWarhouseInfo.ID,
  4512. WarehouseOutDetailId: 0,
  4513. CancelOutDetailId: 0,
  4514. ExpireDate: 0,
  4515. ProductDate: 0,
  4516. MaxUnit: selfBasedrug.MinUnit,
  4517. MinUnit: selfBasedrug.MinUnit,
  4518. StorehouseId: 0,
  4519. OverCount: sum_count,
  4520. OperateTime: time.Now().Unix(),
  4521. AdviceId: item.ID,
  4522. }
  4523. service.CreateSelfDrugFlow(flow, tx)
  4524. drugInfolist, _ := service.GetSelfDrugSumCountByStorehouseId(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4525. var total_count int64 // 入库总数量
  4526. var over_count int64 //剩余库存
  4527. for _, it := range drugInfolist {
  4528. if it.MaxUnit == selfBasedrug.MaxUnit {
  4529. it.WarehousingCount = it.WarehousingCount * selfBasedrug.MinNumber
  4530. it.StockMaxNumber = it.StockMaxNumber * selfBasedrug.MinNumber
  4531. }
  4532. }
  4533. for _, it := range drugInfolist {
  4534. total_count += it.WarehousingCount
  4535. over_count += it.StockMaxNumber + it.StockMinNumber
  4536. }
  4537. //查询该仓库是否有默认数据
  4538. selfDrugStock, _ := service.GetSelfDrugStockCount(item.PatientId, item.DrugId, item.UserOrgId, tx)
  4539. if selfDrugStock.ID == 0 {
  4540. drugStock := models.XtSelfDrugStockCount{
  4541. UserOrgId: item.UserOrgId,
  4542. PatientId: item.PatientId,
  4543. SumInCount: total_count,
  4544. SumOutCount: 0,
  4545. SumCancelCount: 0,
  4546. DrugId: item.DrugId,
  4547. Ctime: time.Now().Unix(),
  4548. Mtime: 0,
  4549. Status: 1,
  4550. FlushCount: over_count,
  4551. SumActOutCount: 0,
  4552. }
  4553. service.CreateSelfDrugStockSum(drugStock, tx)
  4554. }
  4555. if selfDrugStock.ID > 0 {
  4556. service.UpdateSelfDrugStockSum(item.PatientId, item.DrugId, item.UserOrgId, total_count, over_count, tx)
  4557. }
  4558. }
  4559. //查询这个单据的出库数量
  4560. drugFlowList, _ := service.GetSelfDrugWarehouseOutDrugFlow(item.PatientId, item.DrugId, item.UserOrgId, item.ID, tx)
  4561. var his_out_count int64
  4562. for _, item := range drugFlowList {
  4563. his_out_count += item.Count
  4564. }
  4565. //如果已经出库的数量加上现有的数量 小于或等于 总的入库数量
  4566. if (total_count + his_out_count) <= in_count {
  4567. // 出库
  4568. if total_count < in_count {
  4569. var cha_count int64
  4570. cha_count = in_count - total_count
  4571. var stock_number int64 = 0
  4572. //查询库存是否充足
  4573. warehouse, _ := service.FindSelfLastDrugWarehousingInfoByID(item.DrugId, item.PatientId, tx)
  4574. // 将该批次的剩余库存数量转换为拆零数量
  4575. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4576. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4577. }
  4578. if warehouse.MaxUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4579. stock_number = warehouse.StockMaxNumber + warehouse.StockMinNumber
  4580. }
  4581. if warehouse.MaxUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4582. stock_number = warehouse.StockMaxNumber*selfBasedrug.MinNumber + warehouse.StockMinNumber
  4583. }
  4584. if stock_number >= cha_count {
  4585. var maxNumber int64 = 0
  4586. var minNumber int64 = 0
  4587. maxNumber = cha_count / selfBasedrug.MinNumber
  4588. minNumber = cha_count % selfBasedrug.MinNumber
  4589. if warehouse.StockMaxNumber == 0 && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4590. minNumber = maxNumber
  4591. }
  4592. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4593. if warehouse.StockMaxNumber < maxNumber && warehouse.StockMinNumber < minNumber {
  4594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4595. return
  4596. }
  4597. }
  4598. if selfBasedrug.MinUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4599. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber*selfBasedrug.MinNumber
  4600. }
  4601. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4602. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4603. }
  4604. if selfBasedrug.MaxUnit == warehouse.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  4605. warehouse.StockMaxNumber = warehouse.StockMaxNumber - maxNumber
  4606. }
  4607. if warehouse.StockMaxNumber < 0 {
  4608. warehouse.StockMaxNumber = 0
  4609. }
  4610. if warehouse.StockMinNumber < 0 {
  4611. warehouse.StockMinNumber = 0
  4612. }
  4613. warehouse.Mtime = time.Now().Unix()
  4614. if warehouse.StockMinNumber < minNumber {
  4615. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4616. if warehouse.MaxUnit != warehouse.MinUnit {
  4617. warehouse.StockMinNumber = warehouse.StockMinNumber + selfBasedrug.MinNumber - minNumber
  4618. }
  4619. if minNumber == 2 && warehouse.MaxUnit == warehouse.MinUnit && warehouse.StockMinNumber == 0 {
  4620. warehouse.StockMaxNumber = warehouse.StockMaxNumber - 1
  4621. }
  4622. } else {
  4623. if minNumber > 0 {
  4624. if (warehouse.StockMinNumber - minNumber) >= 0 {
  4625. warehouse.StockMinNumber = warehouse.StockMinNumber - minNumber
  4626. }
  4627. }
  4628. if minNumber == 0 && maxNumber != 1 && warehouse.StockMaxNumber <= 0 {
  4629. if warehouse.StockMinNumber > 0 {
  4630. if warehouse.StockMinNumber-cha_count >= 0 {
  4631. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4632. }
  4633. }
  4634. }
  4635. }
  4636. if maxNumber == 1 && minNumber == 0 && selfBasedrug.MaxUnit != selfBasedrug.MinUnit && warehouse.MaxUnit != warehouse.MinUnit {
  4637. if (warehouse.StockMinNumber - cha_count) >= 0 {
  4638. warehouse.StockMinNumber = warehouse.StockMinNumber - cha_count
  4639. }
  4640. }
  4641. if selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  4642. if warehouse.StockMaxNumber < 0 && warehouse.StockMinNumber < 0 {
  4643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4644. return
  4645. }
  4646. }
  4647. if warehouse.StockMinNumber <= 0 {
  4648. warehouse.StockMinNumber = 0
  4649. }
  4650. service.UpDateSelfDrugWarehouseInfoByStock(&warehouse, tx)
  4651. //查询该药品剩余库存
  4652. infolist, _ := service.FindSelfDrugWarehouseInfoFlushCount(item.DrugId, item.UserOrgId, tx)
  4653. var over_count int64
  4654. for _, its := range infolist {
  4655. if its.MaxUnit == selfBasedrug.MaxUnit {
  4656. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4657. }
  4658. over_count += its.StockMaxNumber + its.StockMinNumber
  4659. }
  4660. drugWareInfo, _ := service.GetSelfLastWarehouseOutInfoById(item.DrugId, tx)
  4661. drugflow := models.XtSelfDrugFlow{
  4662. WarehouseOutId: 0,
  4663. WarehouseOutOrderNumber: warehousing_order,
  4664. WarehousingOrder: warehousing_order,
  4665. DrugId: item.DrugId,
  4666. Number: warehouse.Number,
  4667. ProductDate: warehouse.ProductDate,
  4668. ExpireDate: warehouse.ExpiryDate,
  4669. Count: cha_count,
  4670. Price: warehouse.RetailPrice,
  4671. Status: 1,
  4672. Ctime: item.AdviceDate,
  4673. Mtime: time.Now().Unix(),
  4674. UserOrgId: item.UserOrgId,
  4675. Manufacturer: warehouse.Manufacturer,
  4676. Dealer: warehouse.Dealer,
  4677. BatchNumber: warehouse.BatchNumber,
  4678. MaxUnit: selfBasedrug.MinUnit,
  4679. ConsumableType: 20,
  4680. IsEdit: 1,
  4681. Creator: 0,
  4682. IsSys: 3,
  4683. WarehouseOutDetailId: drugWareInfo.ID,
  4684. AdviceId: item.ID,
  4685. SupplyWarehouseId: warehouse.SupplyWarehouseId,
  4686. StorehouseId: 0,
  4687. AdminUserId: creater,
  4688. LastPrice: warehouse.Price,
  4689. StockCount: "",
  4690. WarehousingDetailId: 0,
  4691. OverCount: over_count,
  4692. RetailPrice: item.Price, //手动出库出库价格
  4693. WarehousingId: warehouse.ID,
  4694. SystemTime: item.AdviceDate,
  4695. PatientId: item.PatientId,
  4696. Remark: "保存处方入库数据差",
  4697. OperateTime: time.Now().Unix(),
  4698. }
  4699. if warehouse.RetailPrice == 0 {
  4700. drugflow.Price = item.Price
  4701. }
  4702. service.CreateSelfDrugFlowOne(drugflow, tx)
  4703. var out_count int64
  4704. out_count = in_count - total_count
  4705. fmt.Println("in_count------------------", in_count)
  4706. fmt.Println("total_count------------------", total_count)
  4707. //添加出库数量
  4708. service.AddSelfDrugCount(item.DrugId, item.UserOrgId, patient_id, out_count, tx)
  4709. //查询剩余库存
  4710. stockInfo, _ := service.GetSelfDrugAllStockInfo(item.PatientId, item.UserOrgId, item.DrugId, tx)
  4711. var sum_count int64
  4712. for _, its := range stockInfo {
  4713. if its.MaxUnit == selfBasedrug.MaxUnit {
  4714. its.StockMaxNumber = its.StockMaxNumber * selfBasedrug.MinNumber
  4715. }
  4716. sum_count += its.StockMaxNumber + its.StockMinNumber
  4717. }
  4718. service.UpdateSelfDrugStockCount(item.DrugId, item.UserOrgId, item.PatientId, sum_count, tx)
  4719. } else {
  4720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  4721. return
  4722. }
  4723. }
  4724. }
  4725. }
  4726. }
  4727. }
  4728. }
  4729. tx.Commit()
  4730. if err == nil {
  4731. c.ServeSuccessJSON(map[string]interface{}{
  4732. "msg": "保存成功",
  4733. })
  4734. return
  4735. } else {
  4736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4737. return
  4738. }
  4739. }
  4740. }
  4741. //func (c *HisApiController) EditHisPrescription() {
  4742. // record_date := c.GetString("record_date")
  4743. // patient_id, _ := c.GetInt64("patient_id")
  4744. // reg_type, _ := c.GetInt64("reg_type")
  4745. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4746. // diagnose := c.GetString("diagnose")
  4747. // sick_type, _ := c.GetInt64("sick_type")
  4748. // sick_history := c.GetString("sick_history")
  4749. // doctor_id, _ := c.GetInt64("doctor", 0)
  4750. // department, _ := c.GetInt64("department", 0)
  4751. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4752. // p_type, _ := c.GetInt64("p_type")
  4753. //
  4754. // dataBody := make(map[string]interface{}, 0)
  4755. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4756. // if err != nil {
  4757. // utils.ErrorLog(err.Error())
  4758. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4759. // return
  4760. // }
  4761. //
  4762. // timeLayout := "2006-01-02"
  4763. // loc, _ := time.LoadLocation("Local")
  4764. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4765. // if err != nil {
  4766. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4767. // return
  4768. // }
  4769. // adminInfo := c.GetAdminUserInfo()
  4770. // recordDateTime := theTime.Unix()
  4771. //
  4772. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4773. //
  4774. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4775. // var hpInfo models.HisPrescriptionInfo
  4776. // if info.ID == 0 {
  4777. // var randNum int
  4778. // randNum = rand.Intn(10000) + 1000
  4779. // timestamp := time.Now().Unix()
  4780. // tempTime := time.Unix(timestamp, 0)
  4781. // timeFormat := tempTime.Format("20060102150405")
  4782. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4783. //
  4784. // hpInfo = models.HisPrescriptionInfo{
  4785. // UserOrgId: adminInfo.CurrentOrgId,
  4786. // RecordDate: theTime.Unix(),
  4787. // PatientId: patient_id,
  4788. // Status: 1,
  4789. // Ctime: time.Now().Unix(),
  4790. // Mtime: time.Now().Unix(),
  4791. // Creator: adminInfo.AdminUser.Id,
  4792. // Modifier: adminInfo.AdminUser.Id,
  4793. // Diagnosis: diagnose,
  4794. // SickHistory: sick_history,
  4795. // Departments: department,
  4796. // RegisterType: reg_type,
  4797. // PrescriptionNumber: p_number,
  4798. // PrescriptionStatus: 1,
  4799. // Doctor: role.UserName,
  4800. // DoctorId: doctor_id,
  4801. // SickType: sick_type,
  4802. // PType: p_type,
  4803. // }
  4804. // service.SavePatientPrescriptionInfo(hpInfo)
  4805. //
  4806. // } else {
  4807. // hpInfo = models.HisPrescriptionInfo{
  4808. // ID: info.ID,
  4809. // UserOrgId: adminInfo.CurrentOrgId,
  4810. // RecordDate: info.RecordDate,
  4811. // PatientId: info.PatientId,
  4812. // Status: 1,
  4813. // Ctime: info.Ctime,
  4814. // Mtime: time.Now().Unix(),
  4815. // Creator: info.Creator,
  4816. // Modifier: adminInfo.AdminUser.Id,
  4817. // Diagnosis: diagnose,
  4818. // SickHistory: sick_history,
  4819. // Departments: department,
  4820. // RegisterType: reg_type,
  4821. // PrescriptionNumber: info.PrescriptionNumber,
  4822. // Doctor: role.UserName,
  4823. // PrescriptionStatus: info.PrescriptionStatus,
  4824. // DoctorId: doctor_id,
  4825. // SickType: sick_type,
  4826. // PType: info.PType,
  4827. // }
  4828. // service.SavePatientPrescriptionInfo(hpInfo)
  4829. // }
  4830. //
  4831. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4832. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4833. //
  4834. // if len(prescriptions) > 0 {
  4835. // for _, item := range prescriptions {
  4836. // items := item.(map[string]interface{})
  4837. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4838. // utils.ErrorLog("id")
  4839. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4840. // return
  4841. // }
  4842. // id := int64(items["id"].(float64))
  4843. //
  4844. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4845. // utils.ErrorLog("type")
  4846. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4847. // return
  4848. // }
  4849. // types := int64(items["type"].(float64))
  4850. //
  4851. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4852. // utils.ErrorLog("med_type")
  4853. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4854. // return
  4855. // }
  4856. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4857. //
  4858. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4859. //
  4860. // ctime := time.Now().Unix()
  4861. //
  4862. // prescription := &models.HisPrescription{
  4863. // ID: id,
  4864. // PatientId: patient_id,
  4865. // UserOrgId: adminInfo.CurrentOrgId,
  4866. // RecordDate: recordDateTime,
  4867. // Ctime: ctime,
  4868. // Mtime: ctime,
  4869. // Type: types,
  4870. // Modifier: adminInfo.AdminUser.Id,
  4871. // Creator: adminInfo.AdminUser.Id,
  4872. // Status: 1,
  4873. // Doctor: role.UserName,
  4874. // HisPatientId: his_patient_id,
  4875. // OrderStatus: 1,
  4876. // BatchNumber: "",
  4877. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4878. // PType: hpInfo.PType,
  4879. // MedType: med_type,
  4880. // }
  4881. //
  4882. // if historyPrescription.ID > 0 {
  4883. // prescription.PreTime = historyPrescription.PreTime
  4884. //
  4885. // }
  4886. //
  4887. // service.SaveHisPrescription(prescription)
  4888. //
  4889. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4890. // advices := items["advices"].([]interface{})
  4891. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4892. // groupNo := int64(0)
  4893. // ctime := time.Now().Unix()
  4894. // mtime := ctime
  4895. // if len(advices) > 0 {
  4896. // for _, advice := range advices {
  4897. // var s models.HisDoctorAdviceInfo
  4898. // s.PrescriptionId = prescription.ID
  4899. // s.AdviceType = 2
  4900. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4901. // s.StopState = 2
  4902. // s.ExecutionState = 2
  4903. // s.AdviceDate = recordDateTime
  4904. // s.Status = 1
  4905. // s.UserOrgId = adminInfo.CurrentOrgId
  4906. // s.RecordDate = recordDateTime
  4907. // s.StartTime = prescription.PreTime
  4908. // s.Groupno = groupNo
  4909. // s.CreatedTime = ctime
  4910. // s.UpdatedTime = mtime
  4911. // s.PatientId = patient_id
  4912. // s.HisPatientId = his_patient_id
  4913. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4914. // if errcode > 0 {
  4915. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4916. // return
  4917. // }
  4918. //
  4919. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4920. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4921. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4922. // if s.Price == 0 {
  4923. // s.Price = lastWarehouse.RetailPrice
  4924. // }
  4925. // }
  4926. //
  4927. // service.CreateHisDoctorAdvice(&s)
  4928. // //记录日志
  4929. // byterequest, _ := json.Marshal(s)
  4930. // adviceLog := models.XtDoctorAdviceLog{
  4931. // UserOrgId: s.UserOrgId,
  4932. // PatientId: s.PatientId,
  4933. // AdminUserId: adminInfo.AdminUser.Id,
  4934. // Module: 1,
  4935. // ErrLog: string(byterequest),
  4936. // Status: 1,
  4937. // Ctime: time.Now().Unix(),
  4938. // Mtime: 0,
  4939. // Source: "电脑端his医嘱修改",
  4940. // RecordDate: s.AdviceDate,
  4941. // }
  4942. // service.CreateDoctorAdviceLog(adviceLog)
  4943. // redis := service.RedisClient()
  4944. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4945. // redis.Set(key, "", time.Second)
  4946. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4947. // fmt.Println("keyOne", keyOne)
  4948. // redis.Set(keyOne, "", time.Second)
  4949. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4950. // redis.Set(keySeven, "", time.Second)
  4951. // redis.Close()
  4952. //
  4953. // }
  4954. // }
  4955. // }
  4956. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4957. // projects := items["project"].([]interface{})
  4958. // if len(projects) > 0 {
  4959. // for _, project := range projects {
  4960. // var p models.HisPrescriptionProject
  4961. // p.PrescriptionId = prescription.ID
  4962. // p.Ctime = time.Now().Unix()
  4963. // p.Mtime = time.Now().Unix()
  4964. // p.PatientId = patient_id
  4965. // p.RecordDate = recordDateTime
  4966. // p.UserOrgId = adminInfo.CurrentOrgId
  4967. // p.HisPatientId = his_patient_id
  4968. // p.Status = 1
  4969. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4970. // if errcode > 0 {
  4971. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4972. // return
  4973. // }
  4974. // service.CreateHisProjectTwo(&p)
  4975. //
  4976. // //记录日志
  4977. // byterequest, _ := json.Marshal(p)
  4978. // adviceLog := models.XtDoctorAdviceLog{
  4979. // UserOrgId: p.UserOrgId,
  4980. // PatientId: p.PatientId,
  4981. // AdminUserId: adminInfo.AdminUser.Id,
  4982. // Module: 1,
  4983. // ErrLog: string(byterequest),
  4984. // Status: 1,
  4985. // Ctime: time.Now().Unix(),
  4986. // Mtime: 0,
  4987. // Source: "电脑端his项目修改",
  4988. // RecordDate: p.RecordDate,
  4989. // }
  4990. // service.CreateDoctorAdviceLog(adviceLog)
  4991. // }
  4992. // }
  4993. // }
  4994. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4995. // addition := items["addition"].([]interface{})
  4996. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4997. // ctime := time.Now().Unix()
  4998. // mtime := ctime
  4999. // if len(addition) > 0 {
  5000. // for _, item := range addition {
  5001. // var s models.HisAdditionalCharge
  5002. // s.PrescriptionId = prescription.ID
  5003. // s.Status = 1
  5004. // s.UserOrgId = adminInfo.CurrentOrgId
  5005. // s.RecordDate = recordDateTime
  5006. // s.CreatedTime = ctime
  5007. // s.UpdatedTime = mtime
  5008. // s.PatientId = patient_id
  5009. // s.HisPatientId = his_patient_id
  5010. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  5011. // if errcode > 0 {
  5012. // c.ServeFailJSONWithSGJErrorCode(errcode)
  5013. // return
  5014. // }
  5015. // service.CreateAdditionalCharge(&s)
  5016. // }
  5017. // }
  5018. // }
  5019. //
  5020. // }
  5021. // }
  5022. // }
  5023. // if err == nil {
  5024. // c.ServeSuccessJSON(map[string]interface{}{
  5025. // "msg": "保存成功",
  5026. // })
  5027. // return
  5028. //
  5029. // } else {
  5030. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5031. // return
  5032. // }
  5033. //}
  5034. func (c *HisApiController) DeletePrescription() {
  5035. prescription_id, _ := c.GetInt64("id")
  5036. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  5037. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  5038. ////同步到自备药
  5039. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5040. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5041. if selfPrescriptionOpen.IsOpen == 1 {
  5042. // 在函数结束时处理事务回滚
  5043. db := service.XTWriteDB()
  5044. tx := db.Begin()
  5045. defer func() {
  5046. if r := recover(); r != nil {
  5047. tx.Rollback()
  5048. } else {
  5049. tx.Commit()
  5050. }
  5051. }()
  5052. advicesList, _ := service.GetSelfHisPrescriptionAdviceByID(prescription_id, tx)
  5053. for _, item := range advicesList {
  5054. timeStr := time.Now().Format("2006-01-02")
  5055. timeArr := strings.Split(timeStr, "-")
  5056. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5057. total = total + 1
  5058. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5059. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5060. number = number + total
  5061. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5062. operation_time := time.Now().Unix()
  5063. creater := c.GetAdminUserInfo().AdminUser.Id
  5064. //创建一个出库单
  5065. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5066. WarehouseOutOrderNumber: warehousing_out_order,
  5067. OperationTime: operation_time,
  5068. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5069. Creater: creater,
  5070. Ctime: time.Now().Unix(),
  5071. Status: 1,
  5072. WarehouseOutTime: item.AdviceDate,
  5073. Type: 0,
  5074. PatientId: item.PatientId,
  5075. IsCheck: 1,
  5076. }
  5077. //查询今日是否有出库数据
  5078. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, item.AdviceDate, tx, 1)
  5079. fmt.Println("lastWarehouseOut-----------------------------------", lastWarehouseOut)
  5080. if lastWarehouseOut.ID == 0 {
  5081. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5082. }
  5083. selfBasedrug, _ := service.GetSelfBasedrugById(item.DrugId, item.UserOrgId, tx)
  5084. var total_count int64
  5085. prescribingNumberSix := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 64)
  5086. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5087. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5088. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5089. }
  5090. if item.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5091. total_count += prescribingNumberSeven
  5092. }
  5093. if item.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5094. total_count += prescribingNumberSeven
  5095. }
  5096. //出库
  5097. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5098. WarehouseOutOrderNumber: warehousing_out_order,
  5099. WarehouseOutId: lastWarehouseOut.ID,
  5100. DrugId: item.DrugId,
  5101. Count: total_count,
  5102. Price: 0,
  5103. TotalPrice: 0,
  5104. Status: 1,
  5105. Ctime: item.AdviceDate,
  5106. Mtime: item.AdviceDate,
  5107. Remark: "",
  5108. OrgId: item.UserOrgId,
  5109. Type: 0,
  5110. Manufacturer: selfBasedrug.Manufacturer,
  5111. Dealer: selfBasedrug.Dealer,
  5112. RetailPrice: 0,
  5113. RetailTotalPrice: 0,
  5114. CountUnit: selfBasedrug.MinUnit,
  5115. ExpiryDate: 0,
  5116. ProductDate: 0,
  5117. Number: "",
  5118. BatchNumber: "",
  5119. IsSys: 1,
  5120. WarehouseInfoId: 0,
  5121. AdminUserId: 0,
  5122. StockCount: "",
  5123. IsCheck: 1,
  5124. SysRecordTime: item.AdviceDate,
  5125. PatientId: item.PatientId,
  5126. ClassType: "",
  5127. AdviceId: item.ID,
  5128. }
  5129. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5130. }
  5131. fmt.Println("长度-------------------------------", warehousingOutInfo)
  5132. for _, it := range warehousingOutInfo {
  5133. //查询今日是否有出库数据
  5134. lastWarehouseOutOne, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, it.SysRecordTime, tx, 1)
  5135. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5136. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5137. //出库逻辑
  5138. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOutOne, &drup, it, it.CountUnit, tx)
  5139. //查询剩余库存
  5140. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5141. var sum_count int64
  5142. for _, its := range stockInfo {
  5143. if its.MaxUnit == medical.MaxUnit {
  5144. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5145. }
  5146. sum_count += its.StockMaxNumber + its.StockMinNumber
  5147. }
  5148. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5149. }
  5150. }
  5151. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5152. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5153. //耗材保存处方出库
  5154. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5155. //已收费和已发药限制逻辑
  5156. isCharge := false
  5157. isMedicine := false
  5158. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5159. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5160. if new_prescription.IsMedicine == 1 {
  5161. isMedicine = true
  5162. }
  5163. for _, item := range new_prescriptions {
  5164. if item.OrderStatus == 4 {
  5165. isCharge = true
  5166. }
  5167. }
  5168. if p_err != nil {
  5169. if new_prescription.ID > 0 {
  5170. if new_prescription.OrderStatus == 2 {
  5171. isCharge = true
  5172. }
  5173. }
  5174. }
  5175. for _, item := range advices {
  5176. if item.IsMedicine == 1 {
  5177. isMedicine = true
  5178. }
  5179. }
  5180. if isCharge {
  5181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5182. return
  5183. }
  5184. if isMedicine {
  5185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5186. return
  5187. }
  5188. //已收费和已发药限制逻辑
  5189. if len(projects) > 0 {
  5190. for _, item := range projects {
  5191. service.DeletePrintInfo(item.ID) //删除打印信息
  5192. if goodOutConfig.IsOpen != 1 {
  5193. if stockConfig.IsOpen == 1 {
  5194. if item.Type == 3 && item.IsOut == 1 {
  5195. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5196. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5197. good.Total = good.Total + f_count
  5198. service.UpdateGoodInfo(&good)
  5199. operation_time := time.Now().Unix()
  5200. creater := c.GetAdminUserInfo().AdminUser.Id
  5201. //创建退库单
  5202. timeStr := time.Now().Format("2006-01-02")
  5203. timeArr := strings.Split(timeStr, "-")
  5204. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5205. total = total + 1
  5206. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5207. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5208. cancelStock := models.CancelStock{
  5209. OrderNumber: orderNumber,
  5210. OperaTime: operation_time,
  5211. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5212. Creater: creater,
  5213. Ctime: time.Now().Unix(),
  5214. Status: 1,
  5215. ReturnTime: item.RecordDate,
  5216. Type: 1,
  5217. StorehouseId: houseConfig.StorehouseOutInfo,
  5218. IsCheck: 1,
  5219. }
  5220. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5221. if msgerrkonde == gorm.ErrRecordNotFound {
  5222. service.AddSigleCancelStock(&cancelStock)
  5223. }
  5224. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5225. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5226. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5227. //查询该耗材是否出库
  5228. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5229. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5230. deaerler, _ := service.GetDealerById(info.Dealer)
  5231. var total_count int64
  5232. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5233. total_count += count
  5234. if info.ID > 0 {
  5235. if info.Count >= total_count {
  5236. //回退库存
  5237. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5238. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5239. var flush_count int64
  5240. for _, it := range goodList {
  5241. flush_count += it.StockCount
  5242. }
  5243. cancelStockInfo := models.CancelStockInfo{
  5244. GoodId: item.ProjectId,
  5245. CancelStockId: cancel.ID,
  5246. GoodTypeId: good.GoodTypeId,
  5247. Count: prescribingNumber,
  5248. Price: info.Price,
  5249. Total: 0,
  5250. ProductDate: info.ProductDate,
  5251. ExpiryDate: info.ExpiryDate,
  5252. Ctime: time.Now().Unix(),
  5253. Status: 1,
  5254. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5255. OrderNumber: cancel.OrderNumber,
  5256. Type: 0,
  5257. Dealer: deaerler.DealerName,
  5258. Manufacturer: manufacturer.ManufacturerName,
  5259. Number: info.Number,
  5260. RegisterAccount: "",
  5261. Remark: "",
  5262. WarehouseInfoId: info.WarehouseInfotId,
  5263. PatientId: info.PatientId,
  5264. RecordDate: info.SysRecordTime,
  5265. StorehouseId: houseConfig.StorehouseOutInfo,
  5266. IsCheck: 1,
  5267. }
  5268. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5269. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5270. flow := models.VmStockFlow{
  5271. WarehousingId: info.WarehouseInfotId,
  5272. GoodId: item.ProjectId,
  5273. Number: info.Number,
  5274. LicenseNumber: info.LicenseNumber,
  5275. Count: prescribingNumber,
  5276. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5277. PatientId: item.PatientId,
  5278. SystemTime: info.SysRecordTime,
  5279. ConsumableType: 7,
  5280. IsSys: 0,
  5281. WarehousingOrder: "",
  5282. WarehouseOutId: info.WarehouseOutId,
  5283. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5284. IsEdit: 0,
  5285. CancelStockId: cancel.ID,
  5286. CancelOrderNumber: cancel.OrderNumber,
  5287. Manufacturer: manufacturer.ID,
  5288. Dealer: 0,
  5289. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5290. UpdateCreator: 0,
  5291. Status: 1,
  5292. Ctime: time.Now().Unix(),
  5293. Mtime: 0,
  5294. Price: info.Price,
  5295. WarehousingDetailId: info.WarehouseInfotId,
  5296. WarehouseOutDetailId: info.ID,
  5297. CancelOutDetailId: cancelInfo.ID,
  5298. ProductDate: info.ProductDate,
  5299. ExpireDate: info.ExpiryDate,
  5300. StorehouseId: houseConfig.StorehouseOutInfo,
  5301. OverCount: flush_count,
  5302. OperateTime: time.Now().Unix(),
  5303. }
  5304. service.CreateStockFlowOne(flow)
  5305. //退库数量增加
  5306. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5307. //出库数量减少
  5308. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5309. }
  5310. if info.Count < total_count {
  5311. //回退库存
  5312. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  5313. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5314. var flush_count int64
  5315. for _, it := range goodList {
  5316. flush_count += it.StockCount
  5317. }
  5318. cancelStockInfo := models.CancelStockInfo{
  5319. GoodId: item.ProjectId,
  5320. CancelStockId: cancel.ID,
  5321. GoodTypeId: good.GoodTypeId,
  5322. Count: info.Count,
  5323. Price: info.Price,
  5324. Total: 0,
  5325. ProductDate: info.ProductDate,
  5326. ExpiryDate: info.ExpiryDate,
  5327. Ctime: time.Now().Unix(),
  5328. Status: 1,
  5329. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5330. OrderNumber: cancel.OrderNumber,
  5331. Type: 0,
  5332. Dealer: deaerler.DealerName,
  5333. Manufacturer: manufacturer.ManufacturerName,
  5334. Number: info.Number,
  5335. RegisterAccount: "",
  5336. Remark: "",
  5337. WarehouseInfoId: info.WarehouseInfotId,
  5338. PatientId: info.PatientId,
  5339. RecordDate: info.SysRecordTime,
  5340. StorehouseId: houseConfig.StorehouseOutInfo,
  5341. IsCheck: 1,
  5342. }
  5343. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5344. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5345. flow := models.VmStockFlow{
  5346. WarehousingId: info.WarehouseInfotId,
  5347. GoodId: item.ProjectId,
  5348. Number: info.Number,
  5349. LicenseNumber: info.LicenseNumber,
  5350. Count: info.Count,
  5351. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5352. PatientId: item.PatientId,
  5353. SystemTime: info.SysRecordTime,
  5354. ConsumableType: 7,
  5355. IsSys: 0,
  5356. WarehousingOrder: "",
  5357. WarehouseOutId: info.WarehouseOutId,
  5358. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5359. IsEdit: 0,
  5360. CancelStockId: cancel.ID,
  5361. CancelOrderNumber: cancel.OrderNumber,
  5362. Manufacturer: manufacturer.ID,
  5363. Dealer: 0,
  5364. Creator: c.GetAdminUserInfo().CurrentOrgId,
  5365. UpdateCreator: 0,
  5366. Status: 1,
  5367. Ctime: time.Now().Unix(),
  5368. Mtime: 0,
  5369. Price: info.Price,
  5370. WarehousingDetailId: info.WarehouseInfotId,
  5371. WarehouseOutDetailId: info.ID,
  5372. CancelOutDetailId: cancelInfo.ID,
  5373. ProductDate: info.ProductDate,
  5374. ExpireDate: info.ExpiryDate,
  5375. StorehouseId: houseConfig.StorehouseOutInfo,
  5376. OverCount: flush_count,
  5377. OperateTime: time.Now().Unix(),
  5378. }
  5379. service.CreateStockFlowOne(flow)
  5380. //退库数量增加
  5381. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5382. //出库数量减少
  5383. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  5384. }
  5385. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5386. var flush_count int64
  5387. for _, it := range goodList {
  5388. flush_count += it.StockCount
  5389. }
  5390. //查询已出库数量
  5391. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5392. if prescribingNumber < dialysisInfo.Count {
  5393. //改变数量
  5394. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5395. }
  5396. if prescribingNumber >= dialysisInfo.Count {
  5397. //删除出库表
  5398. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5399. }
  5400. //更新库存
  5401. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  5402. //更新基础库库存
  5403. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  5404. }
  5405. }
  5406. }
  5407. }
  5408. //保存耗材出库
  5409. if goodOutConfig.IsOpen == 1 {
  5410. if item.Type == 3 {
  5411. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  5412. f_count, _ := strconv.ParseFloat(item.Count, 64)
  5413. good.Total = good.Total + f_count
  5414. service.UpdateGoodInfo(&good)
  5415. operation_time := time.Now().Unix()
  5416. creater := c.GetAdminUserInfo().AdminUser.Id
  5417. //创建退库单
  5418. timeStr := time.Now().Format("2006-01-02")
  5419. timeArr := strings.Split(timeStr, "-")
  5420. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  5421. total = total + 1
  5422. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5423. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5424. cancelStock := models.CancelStock{
  5425. OrderNumber: orderNumber,
  5426. OperaTime: operation_time,
  5427. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5428. Creater: creater,
  5429. Ctime: time.Now().Unix(),
  5430. Status: 1,
  5431. ReturnTime: item.RecordDate,
  5432. Type: 1,
  5433. StorehouseId: houseConfig.StorehouseOutInfo,
  5434. IsCheck: 1,
  5435. }
  5436. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  5437. if msgerrkonde == gorm.ErrRecordNotFound {
  5438. service.AddSigleCancelStock(&cancelStock)
  5439. }
  5440. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  5441. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5442. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5443. //查询该耗材是否出库
  5444. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  5445. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5446. deaerler, _ := service.GetDealerById(info.Dealer)
  5447. var total_count int64
  5448. count, _ := strconv.ParseInt(item.Count, 10, 64)
  5449. total_count += count
  5450. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5451. var flush_count int64
  5452. for _, it := range goodList {
  5453. flush_count += it.StockCount
  5454. }
  5455. fmt.Println("历史出库数据", info.Count)
  5456. fmt.Println("出库数量", total_count)
  5457. if info.ID > 0 {
  5458. cancelStockInfo := models.CancelStockInfo{
  5459. GoodId: item.ProjectId,
  5460. CancelStockId: cancel.ID,
  5461. GoodTypeId: good.GoodTypeId,
  5462. Count: prescribingNumber,
  5463. Price: info.Price,
  5464. Total: 0,
  5465. ProductDate: info.ProductDate,
  5466. ExpiryDate: info.ExpiryDate,
  5467. Ctime: time.Now().Unix(),
  5468. Status: 1,
  5469. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5470. OrderNumber: cancel.OrderNumber,
  5471. Type: 0,
  5472. Dealer: deaerler.DealerName,
  5473. Manufacturer: manufacturer.ManufacturerName,
  5474. Number: info.Number,
  5475. RegisterAccount: "",
  5476. Remark: "",
  5477. WarehouseInfoId: info.WarehouseInfotId,
  5478. PatientId: info.PatientId,
  5479. RecordDate: info.SysRecordTime,
  5480. StorehouseId: houseConfig.StorehouseOutInfo,
  5481. IsCheck: 1,
  5482. }
  5483. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5484. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  5485. //查询出库数量
  5486. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  5487. //出库数据 大于 退库数量
  5488. if len(list) > 0 {
  5489. for _, it := range list {
  5490. //回退库存
  5491. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5492. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5493. var flush_count_one int64
  5494. for _, it := range goodList {
  5495. flush_count_one += it.StockCount
  5496. }
  5497. //查询该批次是否有退库数据
  5498. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  5499. creater := c.GetAdminUserInfo().AdminUser.Id
  5500. flow := models.VmStockFlow{
  5501. WarehousingId: it.WarehouseInfotId,
  5502. GoodId: it.GoodId,
  5503. Number: it.Number,
  5504. LicenseNumber: it.LicenseNumber,
  5505. Count: it.Count,
  5506. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5507. PatientId: it.PatientId,
  5508. SystemTime: it.SysRecordTime,
  5509. ConsumableType: 7,
  5510. IsSys: 0,
  5511. WarehousingOrder: "",
  5512. WarehouseOutId: it.WarehouseOutId,
  5513. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5514. IsEdit: 0,
  5515. CancelStockId: cancel.ID,
  5516. CancelOrderNumber: cancel.OrderNumber,
  5517. Manufacturer: manufacturer.ID,
  5518. Dealer: 0,
  5519. Creator: creater,
  5520. UpdateCreator: 0,
  5521. Status: 1,
  5522. Ctime: time.Now().Unix(),
  5523. Mtime: 0,
  5524. Price: it.Price,
  5525. WarehousingDetailId: it.WarehouseInfotId,
  5526. WarehouseOutDetailId: it.ID,
  5527. CancelOutDetailId: cancelInfo.ID,
  5528. ProductDate: it.ProductDate,
  5529. ExpireDate: it.ExpiryDate,
  5530. StorehouseId: houseConfig.StorehouseOutInfo,
  5531. OverCount: flush_count_one,
  5532. }
  5533. service.CreateStockFlowOne(flow)
  5534. //if flow.ID > 0 {
  5535. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  5536. //}
  5537. }
  5538. }
  5539. //flow := models.VmStockFlow{
  5540. // WarehousingId: info.WarehouseInfotId,
  5541. // GoodId: item.ProjectId,
  5542. // Number: info.Number,
  5543. // LicenseNumber: info.LicenseNumber,
  5544. // Count: prescribingNumber,
  5545. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5546. // PatientId: item.PatientId,
  5547. // SystemTime: info.SysRecordTime,
  5548. // ConsumableType: 7,
  5549. // IsSys: 0,
  5550. // WarehousingOrder: "",
  5551. // WarehouseOutId: info.WarehouseOutId,
  5552. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5553. // IsEdit: 0,
  5554. // CancelStockId: cancel.ID,
  5555. // CancelOrderNumber: cancel.OrderNumber,
  5556. // Manufacturer: manufacturer.ID,
  5557. // Dealer: 0,
  5558. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  5559. // UpdateCreator: 0,
  5560. // Status: 1,
  5561. // Ctime: time.Now().Unix(),
  5562. // Mtime: 0,
  5563. // Price: info.Price,
  5564. // WarehousingDetailId: info.WarehouseInfotId,
  5565. // WarehouseOutDetailId: info.ID,
  5566. // CancelOutDetailId: cancelInfo.ID,
  5567. // ProductDate: info.ProductDate,
  5568. // ExpireDate: info.ExpiryDate,
  5569. // StorehouseId: houseConfig.StorehouseOutInfo,
  5570. // OverCount: flush_count,
  5571. //}
  5572. //service.CreateStockFlowOne(flow)
  5573. //退库数量增加
  5574. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  5575. //出库数量减少
  5576. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  5577. //查询已出库数量
  5578. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  5579. if prescribingNumber < dialysisInfo.Count {
  5580. //改变数量
  5581. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  5582. }
  5583. if prescribingNumber >= dialysisInfo.Count {
  5584. //删除出库表
  5585. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  5586. }
  5587. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  5588. var flush_count_one int64
  5589. for _, it := range goodList {
  5590. flush_count_one += it.StockCount
  5591. }
  5592. //更新库存
  5593. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  5594. fmt.Println("msgerrkonde23332323", msgerrkonde)
  5595. //更新基础库库存
  5596. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  5597. }
  5598. }
  5599. }
  5600. }
  5601. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5602. fmt.Println(err)
  5603. }
  5604. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  5605. fmt.Println(err)
  5606. if len(advices) > 0 {
  5607. for _, item := range advices {
  5608. redis := service.RedisClient()
  5609. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  5610. redis.Set(keyFive, "", time.Second)
  5611. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  5612. redis.Set(keyOne, "", time.Second)
  5613. redis.Close()
  5614. }
  5615. }
  5616. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5617. if len(advices) > 0 {
  5618. for _, item := range advices {
  5619. creater := c.GetAdminUserInfo().AdminUser.Id
  5620. service.DrugAutoAddCancelInfo(item, creater)
  5621. }
  5622. }
  5623. } else {
  5624. if drugOutConfig.IsOpen == 1 {
  5625. if len(advices) > 0 {
  5626. for _, item := range advices {
  5627. creater := c.GetAdminUserInfo().AdminUser.Id
  5628. service.DrugAutoAddCancelInfo(item, creater)
  5629. }
  5630. }
  5631. } else {
  5632. if len(advices) > 0 {
  5633. for _, item := range advices {
  5634. creater := c.GetAdminUserInfo().AdminUser.Id
  5635. service.DrugAutoAddCancelInfo(item, creater)
  5636. }
  5637. }
  5638. }
  5639. }
  5640. c.ServeSuccessJSON(map[string]interface{}{
  5641. "msg": "删除成功",
  5642. })
  5643. return
  5644. }
  5645. func (c *HisApiController) DeleteDoctorAdvice() {
  5646. id, _ := c.GetInt64("id")
  5647. advice, _ := service.GetHisDoctorAdvicesById(id)
  5648. ////同步到自备药
  5649. selfPrescriptionOpen, _ := service.GeteSelfPrescriptionOpen(c.GetAdminUserInfo().CurrentOrgId)
  5650. var warehousingOutInfo []*models.XtSelfDrugWarehouseOutInfo
  5651. if selfPrescriptionOpen.IsOpen == 1 {
  5652. db := service.XTWriteDB()
  5653. tx := db.Begin()
  5654. defer func() {
  5655. if r := recover(); r != nil {
  5656. tx.Rollback()
  5657. } else {
  5658. tx.Commit()
  5659. }
  5660. }()
  5661. selfBasedrug, _ := service.GetSelfBasedrugById(advice.DrugId, advice.UserOrgId, tx)
  5662. var total_count int64
  5663. prescribingNumberSix := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 64)
  5664. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  5665. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5666. total_count += prescribingNumberSeven * selfBasedrug.MinNumber
  5667. }
  5668. if advice.PrescribingNumberUnit == selfBasedrug.MinUnit && selfBasedrug.MaxUnit != selfBasedrug.MinUnit {
  5669. total_count += prescribingNumberSeven
  5670. }
  5671. if advice.PrescribingNumberUnit == selfBasedrug.MaxUnit && selfBasedrug.MaxUnit == selfBasedrug.MinUnit {
  5672. total_count += prescribingNumberSeven
  5673. }
  5674. timeStr := time.Now().Format("2006-01-02")
  5675. timeArr := strings.Split(timeStr, "-")
  5676. total, _ := service.FindAllSelfDrugWarehouseOut(c.GetAdminUserInfo().CurrentOrgId, tx)
  5677. total = total + 1
  5678. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5679. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5680. number = number + total
  5681. warehousing_out_order = "YPCKD" + strconv.FormatInt(number, 10)
  5682. operation_time := time.Now().Unix()
  5683. creater := c.GetAdminUserInfo().AdminUser.Id
  5684. //创建一个出库单
  5685. drugWarehouseOut := models.XtSelfDrugWarehouseOut{
  5686. WarehouseOutOrderNumber: warehousing_out_order,
  5687. OperationTime: operation_time,
  5688. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  5689. Creater: creater,
  5690. Ctime: time.Now().Unix(),
  5691. Status: 1,
  5692. WarehouseOutTime: advice.AdviceDate,
  5693. Type: 0,
  5694. PatientId: advice.PatientId,
  5695. IsCheck: 1,
  5696. }
  5697. //查询今日是否有出库数据
  5698. lastWarehouseOut, _ := service.GetSelfDrugLastWarehouseOutTwety(c.GetAdminUserInfo().CurrentOrgId, advice.AdviceDate, tx, 1)
  5699. if lastWarehouseOut.ID == 0 {
  5700. service.AddSelfSigleDrugWarehouseOut(&drugWarehouseOut, tx)
  5701. }
  5702. //出库
  5703. warehouseOutInfo := &models.XtSelfDrugWarehouseOutInfo{
  5704. WarehouseOutId: lastWarehouseOut.ID,
  5705. WarehouseOutOrderNumber: warehousing_out_order,
  5706. DrugId: advice.DrugId,
  5707. Count: total_count,
  5708. Price: 0,
  5709. TotalPrice: 0,
  5710. Status: 1,
  5711. Ctime: advice.AdviceDate,
  5712. Mtime: advice.AdviceDate,
  5713. Remark: "",
  5714. OrgId: advice.UserOrgId,
  5715. Type: 0,
  5716. Manufacturer: selfBasedrug.Manufacturer,
  5717. Dealer: selfBasedrug.Dealer,
  5718. RetailPrice: 0,
  5719. RetailTotalPrice: 0,
  5720. CountUnit: advice.PrescribingNumberUnit,
  5721. ExpiryDate: 0,
  5722. ProductDate: 0,
  5723. Number: "",
  5724. BatchNumber: "",
  5725. IsSys: 0,
  5726. WarehouseInfoId: 0,
  5727. AdminUserId: 0,
  5728. StockCount: "",
  5729. IsCheck: 1,
  5730. SysRecordTime: advice.AdviceDate,
  5731. PatientId: advice.PatientId,
  5732. AdviceId: advice.ID,
  5733. ClassType: "",
  5734. }
  5735. warehousingOutInfo = append(warehousingOutInfo, warehouseOutInfo)
  5736. for _, it := range warehousingOutInfo {
  5737. medical, _ := service.GetSelfBaseDrugMedical(it.DrugId, tx)
  5738. drup, _ := service.FindSelfBaseDrugLibRecord(it.OrgId, it.DrugId, tx)
  5739. //出库逻辑
  5740. service.AutoSelfDrugDeliverInfoFourtyTwo(c.GetAdminUserInfo().CurrentOrgId, it.Count, &lastWarehouseOut, &drup, it, it.CountUnit, tx)
  5741. //查询剩余库存
  5742. stockInfo, _ := service.GetSelfDrugAllStockInfo(it.PatientId, it.OrgId, it.DrugId, tx)
  5743. var sum_count int64
  5744. for _, its := range stockInfo {
  5745. if its.MaxUnit == medical.MaxUnit {
  5746. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5747. }
  5748. sum_count += its.StockMaxNumber + its.StockMinNumber
  5749. }
  5750. service.UpdateSelfDrugStockCount(it.DrugId, it.OrgId, it.PatientId, sum_count, tx)
  5751. }
  5752. }
  5753. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5754. //已收费和已发药的限制逻辑
  5755. isCharge := false
  5756. isMedicine := false
  5757. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5758. //获取今天该患者所有处方,判断是否发药或者收费
  5759. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5760. //for _, item := range new_prescriptions {
  5761. if new_prescription.IsMedicine == 1 {
  5762. isMedicine = true
  5763. }
  5764. //}
  5765. for _, item := range new_prescriptions {
  5766. if item.OrderStatus == 4 {
  5767. isCharge = true
  5768. }
  5769. }
  5770. if isMedicine {
  5771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5772. return
  5773. }
  5774. if isCharge {
  5775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5776. return
  5777. }
  5778. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5779. for _, item := range advices {
  5780. if item.IsMedicine == 1 {
  5781. isMedicine = true
  5782. }
  5783. }
  5784. if isMedicine {
  5785. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5786. return
  5787. }
  5788. if new_prescription.ID > 0 {
  5789. if new_prescription.OrderStatus == 2 {
  5790. isCharge = true
  5791. }
  5792. }
  5793. if isCharge {
  5794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5795. return
  5796. }
  5797. //已收费和已发药的限制逻辑
  5798. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5799. redis := service.RedisClient()
  5800. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5801. redis.Set(keyFive, "", time.Second)
  5802. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5803. redis.Set(keyOne, "", time.Second)
  5804. defer redis.Close()
  5805. if err == nil {
  5806. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5807. //查询是否在处方中出库
  5808. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5809. if openConfig.IsOpen != 1 {
  5810. //判断该医嘱是否执行了
  5811. if advice.ExecutionState == 1 {
  5812. creater := c.GetAdminUserInfo().AdminUser.Id
  5813. service.DrugAutoAddCancelInfo(&advice, creater)
  5814. }
  5815. }
  5816. //开启保存处方扣减功能
  5817. if openConfig.IsOpen == 1 {
  5818. creater := c.GetAdminUserInfo().AdminUser.Id
  5819. service.DrugAutoAddCancelInfo(&advice, creater)
  5820. }
  5821. } else {
  5822. if drugOutConfig.IsOpen == 1 {
  5823. //查询是否在处方中出库
  5824. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5825. if openConfig.IsOpen != 1 {
  5826. //判断该医嘱是否执行了
  5827. if advice.ExecutionState == 1 {
  5828. creater := c.GetAdminUserInfo().AdminUser.Id
  5829. service.DrugAutoAddCancelInfo(&advice, creater)
  5830. }
  5831. }
  5832. //开启保存处方扣减功能
  5833. if openConfig.IsOpen == 1 {
  5834. creater := c.GetAdminUserInfo().AdminUser.Id
  5835. service.DrugAutoAddCancelInfo(&advice, creater)
  5836. }
  5837. } else {
  5838. //判断该医嘱是否执行了
  5839. if advice.ExecutionState == 1 {
  5840. creater := c.GetAdminUserInfo().AdminUser.Id
  5841. service.DrugAutoAddCancelInfo(&advice, creater)
  5842. }
  5843. }
  5844. }
  5845. c.ServeSuccessJSON(map[string]interface{}{
  5846. "msg": "删除成功",
  5847. })
  5848. return
  5849. } else {
  5850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5851. return
  5852. }
  5853. }
  5854. func (c *HisApiController) DeleteProject() {
  5855. id, _ := c.GetInt64("id")
  5856. adminInfo := c.GetAdminUserInfo()
  5857. project, _ := service.GetHisProjectByID(id)
  5858. // var consumable models.DialysisBeforePrepare
  5859. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5860. //耗材保存处方出库
  5861. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5862. isCharge := false
  5863. isMedicine := false
  5864. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5865. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5866. for _, item := range new_prescriptions {
  5867. if item.IsMedicine == 1 {
  5868. isMedicine = true
  5869. }
  5870. }
  5871. for _, item := range new_prescriptions {
  5872. if item.OrderStatus == 4 {
  5873. isCharge = true
  5874. }
  5875. }
  5876. if isMedicine {
  5877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5878. return
  5879. }
  5880. if isCharge {
  5881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5882. return
  5883. }
  5884. if new_prescription.ID > 0 {
  5885. if new_prescription.OrderStatus == 2 {
  5886. isCharge = true
  5887. }
  5888. }
  5889. if isCharge {
  5890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5891. return
  5892. }
  5893. service.DeletePrintInfo(id)
  5894. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5895. label.Status = 0
  5896. service.CreateHisLabelRecordTwo(&label)
  5897. fmt.Println(goodOutConfig.IsOpen)
  5898. if goodOutConfig.IsOpen != 1 {
  5899. if stockConfig.IsOpen == 1 {
  5900. if project.Type == 2 {
  5901. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5902. fmt.Println(err)
  5903. }
  5904. if project.Type == 3 && project.IsOut == 1 {
  5905. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5906. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5907. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5908. operation_time := time.Now().Unix()
  5909. creater := adminInfo.AdminUser.Id
  5910. //创建退库单
  5911. timeStr := time.Now().Format("2006-01-02")
  5912. timeArr := strings.Split(timeStr, "-")
  5913. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5914. total = total + 1
  5915. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5916. cancelStock := models.CancelStock{
  5917. OrderNumber: orderNumber,
  5918. OperaTime: operation_time,
  5919. OrgId: adminInfo.CurrentOrgId,
  5920. Creater: creater,
  5921. Ctime: time.Now().Unix(),
  5922. Status: 1,
  5923. ReturnTime: project.RecordDate,
  5924. Type: 1,
  5925. StorehouseId: houseConfig.StorehouseOutInfo,
  5926. IsCheck: 1,
  5927. }
  5928. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5929. if msgerrkonde == gorm.ErrRecordNotFound {
  5930. service.AddSigleCancelStock(&cancelStock)
  5931. }
  5932. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5933. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5934. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5935. //查询是否有出库
  5936. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5937. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5938. deaerler, _ := service.GetDealerById(info.Dealer)
  5939. if info.ID > 0 {
  5940. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5941. if info.Count >= prescribingNumber {
  5942. cancelStockInfo := models.CancelStockInfo{
  5943. GoodId: project.ProjectId,
  5944. CancelStockId: cancel.ID,
  5945. GoodTypeId: good.GoodTypeId,
  5946. Count: prescribingNumber,
  5947. Price: info.Price,
  5948. Total: 0,
  5949. ProductDate: info.ProductDate,
  5950. ExpiryDate: info.ExpiryDate,
  5951. Ctime: time.Now().Unix(),
  5952. Status: 1,
  5953. OrgId: adminInfo.CurrentOrgId,
  5954. OrderNumber: cancel.OrderNumber,
  5955. Type: 0,
  5956. Dealer: deaerler.DealerName,
  5957. Manufacturer: manufacturer.ManufacturerName,
  5958. Number: info.Number,
  5959. RegisterAccount: "",
  5960. Remark: "",
  5961. WarehouseInfoId: info.WarehouseInfotId,
  5962. PatientId: info.PatientId,
  5963. RecordDate: info.SysRecordTime,
  5964. StorehouseId: houseConfig.StorehouseOutInfo,
  5965. IsCheck: 1,
  5966. }
  5967. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5968. //回退库存
  5969. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5970. //退库数量增加
  5971. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5972. //出库数量减少
  5973. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5974. }
  5975. if info.Count < prescribingNumber {
  5976. cancelStockInfo := models.CancelStockInfo{
  5977. GoodId: project.ProjectId,
  5978. CancelStockId: cancel.ID,
  5979. GoodTypeId: good.GoodTypeId,
  5980. Count: info.Count,
  5981. Price: info.Price,
  5982. Total: 0,
  5983. ProductDate: info.ProductDate,
  5984. ExpiryDate: info.ExpiryDate,
  5985. Ctime: time.Now().Unix(),
  5986. Status: 1,
  5987. OrgId: adminInfo.CurrentOrgId,
  5988. OrderNumber: cancel.OrderNumber,
  5989. Type: 0,
  5990. Dealer: deaerler.DealerName,
  5991. Manufacturer: manufacturer.ManufacturerName,
  5992. Number: info.Number,
  5993. RegisterAccount: "",
  5994. Remark: "",
  5995. WarehouseInfoId: info.WarehouseInfotId,
  5996. PatientId: info.PatientId,
  5997. RecordDate: info.SysRecordTime,
  5998. StorehouseId: houseConfig.StorehouseOutInfo,
  5999. IsCheck: 1,
  6000. }
  6001. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6002. //回退库存
  6003. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6004. //退库数量增加
  6005. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  6006. //出库数量减少
  6007. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  6008. }
  6009. //查询剩余库存
  6010. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6011. var over_count int64
  6012. for _, it := range goodList {
  6013. over_count += it.StockCount
  6014. }
  6015. //出库数据 大于 退库数量
  6016. if info.Count >= prescribingNumber {
  6017. flow := models.VmStockFlow{
  6018. WarehousingId: info.WarehouseInfotId,
  6019. GoodId: project.ProjectId,
  6020. Number: info.Number,
  6021. LicenseNumber: info.LicenseNumber,
  6022. Count: prescribingNumber,
  6023. UserOrgId: adminInfo.CurrentOrgId,
  6024. PatientId: project.PatientId,
  6025. SystemTime: info.SysRecordTime,
  6026. ConsumableType: 7,
  6027. IsSys: 0,
  6028. WarehousingOrder: "",
  6029. WarehouseOutId: info.WarehouseOutId,
  6030. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6031. IsEdit: 0,
  6032. CancelStockId: cancel.ID,
  6033. CancelOrderNumber: cancel.OrderNumber,
  6034. Manufacturer: manufacturer.ID,
  6035. Dealer: 0,
  6036. Creator: adminInfo.AdminUser.Id,
  6037. UpdateCreator: 0,
  6038. Status: 1,
  6039. Ctime: time.Now().Unix(),
  6040. Mtime: 0,
  6041. Price: info.Price,
  6042. WarehousingDetailId: info.WarehouseInfotId,
  6043. WarehouseOutDetailId: info.ID,
  6044. CancelOutDetailId: cancelInfo.ID,
  6045. ProductDate: info.ProductDate,
  6046. ExpireDate: info.ExpiryDate,
  6047. StorehouseId: houseConfig.StorehouseOutInfo,
  6048. OverCount: over_count,
  6049. OperateTime: time.Now().Unix(),
  6050. }
  6051. service.CreateStockFlowOne(flow)
  6052. }
  6053. //出库数据小于退库数据
  6054. if info.Count < prescribingNumber {
  6055. flow := models.VmStockFlow{
  6056. WarehousingId: info.WarehouseInfotId,
  6057. GoodId: project.ProjectId,
  6058. Number: info.Number,
  6059. LicenseNumber: info.LicenseNumber,
  6060. Count: info.Count,
  6061. UserOrgId: adminInfo.CurrentOrgId,
  6062. PatientId: project.PatientId,
  6063. SystemTime: info.SysRecordTime,
  6064. ConsumableType: 7,
  6065. IsSys: 0,
  6066. WarehousingOrder: "",
  6067. WarehouseOutId: info.WarehouseOutId,
  6068. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  6069. IsEdit: 0,
  6070. CancelStockId: cancel.ID,
  6071. CancelOrderNumber: cancel.OrderNumber,
  6072. Manufacturer: manufacturer.ID,
  6073. Dealer: 0,
  6074. Creator: adminInfo.AdminUser.Id,
  6075. UpdateCreator: 0,
  6076. Status: 1,
  6077. Ctime: time.Now().Unix(),
  6078. Mtime: 0,
  6079. Price: info.Price,
  6080. WarehousingDetailId: info.WarehouseInfotId,
  6081. WarehouseOutDetailId: info.ID,
  6082. CancelOutDetailId: cancelInfo.ID,
  6083. ProductDate: info.ProductDate,
  6084. ExpireDate: info.ExpiryDate,
  6085. StorehouseId: houseConfig.StorehouseOutInfo,
  6086. OverCount: over_count,
  6087. OperateTime: time.Now().Unix(),
  6088. }
  6089. service.CreateStockFlowOne(flow)
  6090. }
  6091. //查询已出库数量
  6092. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6093. //fmt.Println("aiwohonguo --------------------", prescribingNumber)
  6094. //fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  6095. if prescribingNumber < dialysisInfo.Count {
  6096. //改变数量
  6097. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6098. }
  6099. if prescribingNumber >= dialysisInfo.Count {
  6100. //删除出库表
  6101. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6102. }
  6103. //更新剩余库存
  6104. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6105. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6106. var total_count_one int64
  6107. for _, it := range stockList {
  6108. total_count_one += it.StockCount
  6109. }
  6110. //基础库插入数据
  6111. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6112. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6113. var flush_count int64
  6114. for _, it := range goodListOne {
  6115. flush_count += it.StockCount
  6116. }
  6117. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6118. if errs != nil {
  6119. goodErrcode := models.XtGoodErrcode{
  6120. UserOrgId: project.UserOrgId,
  6121. Errcode: "手动出库更新剩余出库失败",
  6122. GoodId: project.ProjectId,
  6123. Status: 1,
  6124. Ctime: time.Now().Unix(),
  6125. Mtime: 0,
  6126. Count: 0,
  6127. StockCount: 0,
  6128. Creater: creater,
  6129. BatchNumberId: 0,
  6130. WarehouseOutId: 0,
  6131. }
  6132. service.CreateGoodErrcode(goodErrcode)
  6133. }
  6134. }
  6135. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6136. fmt.Println(err)
  6137. } else {
  6138. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6139. fmt.Println(err)
  6140. }
  6141. } else {
  6142. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6143. fmt.Println(err)
  6144. }
  6145. }
  6146. //保存处方出库
  6147. if goodOutConfig.IsOpen == 1 {
  6148. if project.Type == 3 {
  6149. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  6150. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6151. f_count, _ := strconv.ParseFloat(project.Count, 64)
  6152. operation_time := time.Now().Unix()
  6153. creater := adminInfo.AdminUser.Id
  6154. //创建退库单
  6155. timeStr := time.Now().Format("2006-01-02")
  6156. timeArr := strings.Split(timeStr, "-")
  6157. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  6158. total = total + 1
  6159. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6160. cancelStock := models.CancelStock{
  6161. OrderNumber: orderNumber,
  6162. OperaTime: operation_time,
  6163. OrgId: adminInfo.CurrentOrgId,
  6164. Creater: creater,
  6165. Ctime: time.Now().Unix(),
  6166. Status: 1,
  6167. ReturnTime: project.RecordDate,
  6168. Type: 1,
  6169. StorehouseId: houseConfig.StorehouseOutInfo,
  6170. IsCheck: 1,
  6171. }
  6172. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  6173. if msgerrkonde == gorm.ErrRecordNotFound {
  6174. service.AddSigleCancelStock(&cancelStock)
  6175. }
  6176. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  6177. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  6178. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6179. //获取出库数据
  6180. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  6181. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  6182. deaerler, _ := service.GetDealerById(info.Dealer)
  6183. if info.ID > 0 {
  6184. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  6185. if info.Count >= prescribingNumber {
  6186. cancelStockInfo := models.CancelStockInfo{
  6187. GoodId: project.ProjectId,
  6188. CancelStockId: cancel.ID,
  6189. GoodTypeId: good.GoodTypeId,
  6190. Count: prescribingNumber,
  6191. Price: info.Price,
  6192. Total: 0,
  6193. ProductDate: info.ProductDate,
  6194. ExpiryDate: info.ExpiryDate,
  6195. Ctime: time.Now().Unix(),
  6196. Status: 1,
  6197. OrgId: adminInfo.CurrentOrgId,
  6198. OrderNumber: cancel.OrderNumber,
  6199. Type: 0,
  6200. Dealer: deaerler.DealerName,
  6201. Manufacturer: manufacturer.ManufacturerName,
  6202. Number: info.Number,
  6203. RegisterAccount: "",
  6204. Remark: "",
  6205. WarehouseInfoId: info.WarehouseInfotId,
  6206. PatientId: info.PatientId,
  6207. RecordDate: info.SysRecordTime,
  6208. StorehouseId: houseConfig.StorehouseOutInfo,
  6209. IsCheck: 1,
  6210. }
  6211. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6212. //退库数量增加
  6213. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  6214. //出库数量减少
  6215. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  6216. }
  6217. if info.Count < prescribingNumber {
  6218. cancelStockInfo := models.CancelStockInfo{
  6219. GoodId: project.ProjectId,
  6220. CancelStockId: cancel.ID,
  6221. GoodTypeId: good.GoodTypeId,
  6222. Count: prescribingNumber,
  6223. Price: info.Price,
  6224. Total: 0,
  6225. ProductDate: info.ProductDate,
  6226. ExpiryDate: info.ExpiryDate,
  6227. Ctime: time.Now().Unix(),
  6228. Status: 1,
  6229. OrgId: adminInfo.CurrentOrgId,
  6230. OrderNumber: cancel.OrderNumber,
  6231. Type: 0,
  6232. Dealer: deaerler.DealerName,
  6233. Manufacturer: manufacturer.ManufacturerName,
  6234. Number: info.Number,
  6235. RegisterAccount: "",
  6236. Remark: "",
  6237. WarehouseInfoId: info.WarehouseInfotId,
  6238. PatientId: info.PatientId,
  6239. RecordDate: info.SysRecordTime,
  6240. StorehouseId: houseConfig.StorehouseOutInfo,
  6241. IsCheck: 1,
  6242. }
  6243. service.CreateCancelStockInfoOne(&cancelStockInfo)
  6244. //回退库存
  6245. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  6246. }
  6247. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6248. var over_count int64
  6249. for _, it := range goodList {
  6250. over_count += it.StockCount
  6251. }
  6252. //查询出库数量
  6253. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  6254. //出库数据 大于 退库数量
  6255. if len(list) > 0 {
  6256. for _, it := range list {
  6257. //回退库存
  6258. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  6259. //退库数量增加
  6260. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  6261. //出库数量减少
  6262. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  6263. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6264. var over_count_one int64
  6265. for _, it := range goodList {
  6266. over_count_one += it.StockCount
  6267. }
  6268. //查询该批次是否有退库数据
  6269. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  6270. flow := models.VmStockFlow{
  6271. WarehousingId: it.WarehouseInfotId,
  6272. GoodId: it.GoodId,
  6273. Number: it.Number,
  6274. LicenseNumber: it.LicenseNumber,
  6275. Count: it.Count,
  6276. UserOrgId: adminInfo.CurrentOrgId,
  6277. PatientId: it.PatientId,
  6278. SystemTime: it.SysRecordTime,
  6279. ConsumableType: 7,
  6280. IsSys: 0,
  6281. WarehousingOrder: "",
  6282. WarehouseOutId: it.WarehouseOutId,
  6283. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  6284. IsEdit: 0,
  6285. CancelStockId: cancel.ID,
  6286. CancelOrderNumber: cancel.OrderNumber,
  6287. Manufacturer: manufacturer.ID,
  6288. Dealer: 0,
  6289. Creator: adminInfo.AdminUser.Id,
  6290. UpdateCreator: 0,
  6291. Status: 1,
  6292. Ctime: time.Now().Unix(),
  6293. Mtime: 0,
  6294. Price: it.Price,
  6295. WarehousingDetailId: it.WarehouseInfotId,
  6296. WarehouseOutDetailId: it.ID,
  6297. CancelOutDetailId: cancelInfo.ID,
  6298. ProductDate: it.ProductDate,
  6299. ExpireDate: it.ExpiryDate,
  6300. StorehouseId: houseConfig.StorehouseOutInfo,
  6301. OverCount: over_count_one,
  6302. OperateTime: time.Now().Unix(),
  6303. }
  6304. service.CreateStockFlowOne(flow)
  6305. }
  6306. }
  6307. //查询已出库数量
  6308. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  6309. if prescribingNumber < dialysisInfo.Count {
  6310. //改变数量
  6311. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  6312. }
  6313. if prescribingNumber >= dialysisInfo.Count {
  6314. //删除出库表
  6315. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  6316. }
  6317. //更新剩余库存
  6318. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  6319. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  6320. var total_count_one int64
  6321. for _, it := range stockList {
  6322. total_count_one += it.StockCount
  6323. }
  6324. //基础库插入数据
  6325. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  6326. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  6327. var flush_count int64
  6328. for _, it := range goodListOne {
  6329. flush_count += it.StockCount
  6330. }
  6331. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  6332. if errs != nil {
  6333. goodErrcode := models.XtGoodErrcode{
  6334. UserOrgId: project.UserOrgId,
  6335. Errcode: "手动出库更新剩余出库失败",
  6336. GoodId: project.ProjectId,
  6337. Status: 1,
  6338. Ctime: time.Now().Unix(),
  6339. Mtime: 0,
  6340. Count: 0,
  6341. StockCount: 0,
  6342. Creater: creater,
  6343. BatchNumberId: 0,
  6344. WarehouseOutId: 0,
  6345. }
  6346. service.CreateGoodErrcode(goodErrcode)
  6347. }
  6348. }
  6349. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6350. fmt.Println(err)
  6351. } else {
  6352. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  6353. fmt.Println(err)
  6354. }
  6355. }
  6356. c.ServeSuccessJSON(map[string]interface{}{
  6357. "msg": "删除成功",
  6358. })
  6359. return
  6360. }
  6361. func (c *HisApiController) CreateHisAdditionalCharge() {
  6362. his_patient_id, _ := c.GetInt64("his_patient_id")
  6363. patient_id, _ := c.GetInt64("patient_id")
  6364. record_date := c.GetString("record_date")
  6365. timeLayout := "2006-01-02"
  6366. loc, _ := time.LoadLocation("Local")
  6367. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6368. if err != nil {
  6369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6370. return
  6371. }
  6372. adminInfo := c.GetAdminUserInfo()
  6373. recordDateTime := theTime.Unix()
  6374. dataBody := make(map[string]interface{}, 0)
  6375. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6376. if err != nil {
  6377. utils.ErrorLog(err.Error())
  6378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6379. return
  6380. }
  6381. var additions []*models.HisAdditionalCharge
  6382. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  6383. additions, _ := dataBody["addition"].([]interface{})
  6384. if len(additions) > 0 {
  6385. for _, item := range additions {
  6386. items := item.(map[string]interface{})
  6387. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  6388. utils.ErrorLog("item_id")
  6389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6390. return
  6391. }
  6392. item_id := int64(items["item_id"].(float64))
  6393. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  6394. utils.ErrorLog("item_name")
  6395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6396. return
  6397. }
  6398. item_name := items["item_name"].(string)
  6399. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  6400. utils.ErrorLog("price")
  6401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6402. return
  6403. }
  6404. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  6405. ctime := time.Now().Unix()
  6406. additional := &models.HisAdditionalCharge{
  6407. PatientId: patient_id,
  6408. HisPatientId: his_patient_id,
  6409. UserOrgId: adminInfo.CurrentOrgId,
  6410. RecordDate: recordDateTime,
  6411. CreatedTime: ctime,
  6412. UpdatedTime: ctime,
  6413. Modifier: adminInfo.AdminUser.Id,
  6414. Creator: adminInfo.AdminUser.Id,
  6415. Price: price,
  6416. ItemName: item_name,
  6417. ItemId: item_id,
  6418. Status: 1,
  6419. }
  6420. additions = append(additions, additional)
  6421. }
  6422. }
  6423. }
  6424. for _, item := range additions {
  6425. service.CreateAddtionalCharge(item)
  6426. }
  6427. c.ServeSuccessJSON(map[string]interface{}{
  6428. "msg": "创建成功",
  6429. })
  6430. }
  6431. func (c *HisApiController) CreateHisPatientCaseHistory() {
  6432. blood_fat := c.GetString("blood_fat")
  6433. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  6434. blood_sugar := c.GetString("blood_sugar")
  6435. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  6436. chief_conplaint := c.GetString("chief_conplaint")
  6437. dbp := c.GetString("dbp")
  6438. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  6439. delivery_way, _ := c.GetInt64("delivery_way")
  6440. diagnostic := c.GetString("diagnostic")
  6441. family_history := c.GetString("family_history")
  6442. height := c.GetString("height")
  6443. history_of_present_illness := c.GetString("history_of_present_illness")
  6444. is_infect, _ := c.GetInt64("is_infect")
  6445. past_history := c.GetString("past_history")
  6446. patient_id, _ := c.GetInt64("patient_id")
  6447. his_patient_id, _ := c.GetInt64("his_patient_id")
  6448. personal_history := c.GetString("personal_history")
  6449. pulse := c.GetString("pulse")
  6450. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  6451. sbp := c.GetString("sbp")
  6452. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  6453. heightfloat, _ := strconv.ParseFloat(height, 64)
  6454. sicktype := c.GetString("sick_type")
  6455. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  6456. symptom := c.GetString("symptom")
  6457. sick_date := c.GetString("sick_date")
  6458. temperatures := c.GetString("temperature")
  6459. temperature, _ := strconv.ParseFloat(temperatures, 64)
  6460. record_date := c.GetString("record_date")
  6461. breathing := c.GetString("breathing")
  6462. doctor_advice := c.GetString("doctor_advice")
  6463. remark := c.GetString("remark")
  6464. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  6465. sick, _ := c.GetInt64("sick")
  6466. diagnose, _ := c.GetInt64("diagnose")
  6467. //id, _ := c.GetInt64("id")
  6468. timeLayout := "2006-01-02"
  6469. loc, _ := time.LoadLocation("Local")
  6470. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6471. allergic_history := c.GetString("allergic_history")
  6472. if err != nil {
  6473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6474. return
  6475. }
  6476. recordDateTime := theTime.Unix()
  6477. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  6478. if err != nil {
  6479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6480. return
  6481. }
  6482. sickTimes := sickTime.Unix()
  6483. ctime := time.Now().Unix()
  6484. primary_disease := c.GetString("primary_disease")
  6485. confirm_failure_date := c.GetString("confirm_failure_date")
  6486. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  6487. drug_allergy_history := c.GetString("drug_allergy_history")
  6488. physical_examination := c.GetString("physical_examination")
  6489. special_inspection := c.GetString("special_inspection")
  6490. lab_apparatus := c.GetString("lab_apparatus")
  6491. caseHistory := models.HisPatientCaseHistory{
  6492. HisPatientId: his_patient_id,
  6493. PatientId: patient_id,
  6494. Temperature: temperature,
  6495. BloodSugar: bloodsugarfloat,
  6496. Pulse: pulsefloat,
  6497. Sbp: sbpfloat,
  6498. Dbp: dbpfloat,
  6499. Height: heightfloat,
  6500. BloodFat: bloodfatfloat,
  6501. SickType: sick_type,
  6502. Symptom: symptom,
  6503. SickDate: sickTimes,
  6504. IsInfect: is_infect,
  6505. HistoryOfPresentIllness: history_of_present_illness,
  6506. PastHistory: past_history,
  6507. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  6508. ChiefConplaint: chief_conplaint,
  6509. PersonalHistory: personal_history,
  6510. FamilyHistory: family_history,
  6511. Diagnostic: diagnostic,
  6512. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6513. Status: 1,
  6514. Ctime: ctime,
  6515. Mtime: ctime,
  6516. RecordDate: recordDateTime,
  6517. DeliveryWay: delivery_way,
  6518. Breathing: breathingfloat,
  6519. DoctorAdvice: doctor_advice,
  6520. Remark: remark,
  6521. Sick: sick,
  6522. Diagnose: diagnose,
  6523. AllergicHistory: allergic_history,
  6524. PrimaryDisease: primary_disease,
  6525. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  6526. DrugAllergyHistory: drug_allergy_history,
  6527. PhysicalExamination: physical_examination,
  6528. SpecialInspection: special_inspection,
  6529. LabApparatus: lab_apparatus,
  6530. }
  6531. //查询该患者是否有病历
  6532. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  6533. if errcodes == gorm.ErrRecordNotFound {
  6534. err = service.SaveHisPatientCaseHistory(&caseHistory)
  6535. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6536. if err != nil {
  6537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6538. return
  6539. }
  6540. c.ServeSuccessJSON(map[string]interface{}{
  6541. "caseHistory": caseHistory,
  6542. "historyInfo": historyInfo,
  6543. })
  6544. return
  6545. } else if errcodes == nil {
  6546. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  6547. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  6548. if err != nil {
  6549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6550. return
  6551. }
  6552. c.ServeSuccessJSON(map[string]interface{}{
  6553. "caseHistory": caseHistory,
  6554. "historyInfo": historyInfo,
  6555. })
  6556. }
  6557. //查询该患者是否有病历
  6558. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  6559. //if errcode == gorm.ErrRecordNotFound {
  6560. // err = service.SaveHisPatientCaseHistory(caseHistory)
  6561. // if err != nil {
  6562. // c.ServeSuccessJSON(map[string]interface{}{
  6563. // "msg": "保存成功",
  6564. // })
  6565. // }
  6566. //} else if errcode == nil {
  6567. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6568. // return
  6569. //}
  6570. }
  6571. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  6572. patient_id, _ := c.GetInt64("patient_id", 0)
  6573. adminUser := c.GetAdminUserInfo()
  6574. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  6575. c.ServeSuccessJSON(map[string]interface{}{
  6576. "list": caseHistorys,
  6577. })
  6578. }
  6579. func (c *HisApiController) GetHisPatientCaseHistory() {
  6580. record_date, _ := c.GetInt64("record_date", 0)
  6581. patient_id, _ := c.GetInt64("patient_id", 0)
  6582. admin := c.GetAdminUserInfo()
  6583. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  6584. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  6585. c.ServeSuccessJSON(map[string]interface{}{
  6586. "info": info,
  6587. "case_history": case_history,
  6588. })
  6589. }
  6590. func (c *HisApiController) CreateCaseHistoryTemplate() {
  6591. template_name := c.GetString("template_name")
  6592. template_remark := c.GetString("template_remark")
  6593. doctor := c.GetAdminUserInfo().AdminUser.Id
  6594. diagnostic := c.GetString("diagnostic")
  6595. chief_conplaint := c.GetString("chief_conplain")
  6596. history_of_present_illness := c.GetString("history_of_present_illness")
  6597. past_history := c.GetString("past_history")
  6598. personal_history := c.GetString("personal_history")
  6599. family_history := c.GetString("family_history")
  6600. user_name := c.GetString("user_name")
  6601. doctor_advice := c.GetString("doctor_advice")
  6602. remark := c.GetString("remark")
  6603. //record_date := c.GetString("record_date")
  6604. //fmt.Println("record_date--------",record_date)
  6605. //timeLayout := "2006-01-02"
  6606. //loc, _ := time.LoadLocation("Local")
  6607. //
  6608. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6609. //if err != nil {
  6610. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6611. // return
  6612. //}
  6613. //recordDateTime := theTime.Unix()
  6614. ctime := time.Now().Unix()
  6615. template := models.HisCaseHistoryTemplate{
  6616. HistoryOfPresentIllness: history_of_present_illness,
  6617. PastHistory: past_history,
  6618. ChiefConplaint: chief_conplaint,
  6619. PersonalHistory: personal_history,
  6620. FamilyHistory: family_history,
  6621. Diagnostic: diagnostic,
  6622. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6623. Status: 1,
  6624. Ctime: ctime,
  6625. Mtime: ctime,
  6626. RecordDate: time.Now().Unix(),
  6627. TemplateName: template_name,
  6628. TemplateRemark: template_remark,
  6629. Creator: doctor,
  6630. Modifier: doctor,
  6631. UserName: user_name,
  6632. DoctorAdvice: doctor_advice,
  6633. Remark: remark,
  6634. }
  6635. err := service.SaveHisPatientCaseHistoryTemplate(template)
  6636. if err == nil {
  6637. c.ServeSuccessJSON(map[string]interface{}{
  6638. "msg": "保存成功",
  6639. })
  6640. } else {
  6641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6642. return
  6643. }
  6644. }
  6645. func (c *HisApiController) GetCaseHistoryTemplate() {
  6646. timeLayout := "2006-01-02"
  6647. loc, _ := time.LoadLocation("Local")
  6648. keyword := c.GetString("keyword")
  6649. start_time := c.GetString("start_time")
  6650. end_time := c.GetString("end_time")
  6651. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6652. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6653. admin := c.GetAdminUserInfo()
  6654. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  6655. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  6656. c.ServeSuccessJSON(map[string]interface{}{
  6657. "template": template,
  6658. //"history": history,
  6659. })
  6660. }
  6661. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6662. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6663. utils.ErrorLog("drug_name")
  6664. return enums.ErrorCodeParamWrong
  6665. }
  6666. adviceName, _ := json["drug_name"].(string)
  6667. if len(adviceName) == 0 {
  6668. utils.ErrorLog("len(advice_name) == 0")
  6669. return enums.ErrorCodeParamWrong
  6670. }
  6671. advice.AdviceName = adviceName
  6672. adviceDesc, _ := json["advice_desc"].(string)
  6673. advice.AdviceDesc = adviceDesc
  6674. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6675. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6676. advice.DrugSpec = drugSpec
  6677. }
  6678. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6679. remark, _ := json["remark"].(string)
  6680. advice.Remark = remark
  6681. }
  6682. if json["id"] == nil {
  6683. advice.DrugId = 0
  6684. } else {
  6685. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6686. drug_id := int64(json["id"].(float64))
  6687. advice.DrugId = drug_id
  6688. }
  6689. }
  6690. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6691. advice_id := int64(json["advice_id"].(float64))
  6692. advice.ID = advice_id
  6693. if advice.ID > 0 {
  6694. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6695. if err == nil {
  6696. if hisAdvice.ID > 0 {
  6697. advice.ExecutionTime = hisAdvice.ExecutionTime
  6698. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6699. advice.ExecutionState = hisAdvice.ExecutionState
  6700. advice.CheckTime = hisAdvice.CheckTime
  6701. advice.Checker = hisAdvice.Checker
  6702. advice.CheckState = hisAdvice.CheckState
  6703. advice.StartTime = hisAdvice.StartTime
  6704. advice.FeedetlSn = hisAdvice.FeedetlSn
  6705. }
  6706. }
  6707. }
  6708. }
  6709. //
  6710. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6711. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6712. // advice.ExecutionTime = execution_time
  6713. //}
  6714. //
  6715. //
  6716. //
  6717. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6718. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6719. // advice.ExecutionStaff = execution_staff
  6720. //}
  6721. //
  6722. //
  6723. //
  6724. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6725. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6726. // advice.ExecutionState = execution_state
  6727. //}
  6728. //
  6729. //
  6730. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6731. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6732. // advice.CheckTime = check_time
  6733. //}
  6734. //
  6735. //
  6736. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6737. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6738. // advice.CheckState = check_state
  6739. //}
  6740. //
  6741. //
  6742. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6743. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6744. // advice.Checker = checker
  6745. //}
  6746. //
  6747. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6748. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6749. // advice.StartTime = start_time
  6750. //}
  6751. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6752. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6753. advice.IsSelfDrug = is_self_drug
  6754. }
  6755. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6756. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6757. drug_way_count, _ := json["drug_way_count"].(string)
  6758. advice.DrugWayCount = drug_way_count
  6759. }
  6760. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6761. drugSpecUnit, _ := json["min_unit"].(string)
  6762. advice.DrugSpecUnit = drugSpecUnit
  6763. }
  6764. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6765. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6766. advice.SingleDose = singleDose
  6767. }
  6768. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6769. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6770. advice.SingleDoseUnit = singleDoseUnit
  6771. }
  6772. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6773. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6774. advice.PrescribingNumber = prescribingNumber
  6775. }
  6776. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6777. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6778. advice.PrescribingNumberUnit = prescribingNumberUnit
  6779. }
  6780. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6781. deliveryWay, _ := json["delivery_way"].(string)
  6782. advice.DeliveryWay = deliveryWay
  6783. }
  6784. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6785. executionFrequency, _ := json["execution_frequency"].(string)
  6786. advice.ExecutionFrequency = executionFrequency
  6787. }
  6788. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6789. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6790. advice.Price = price
  6791. }
  6792. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6793. med_list_codg, _ := json["medical_insurance_number"].(string)
  6794. advice.MedListCodg = med_list_codg
  6795. }
  6796. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6797. day := int64(json["day"].(float64))
  6798. advice.Day = day
  6799. }
  6800. return 0
  6801. }
  6802. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6803. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6804. id := int64(json["id"].(float64))
  6805. project.ID = id
  6806. historyProject, _ := service.GetHisProjectByID(id)
  6807. project.FeedetlSn = historyProject.FeedetlSn
  6808. }
  6809. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6810. project_id := int64(json["project_id"].(float64))
  6811. project.ProjectId = project_id
  6812. }
  6813. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6814. // price := int64(json["price"].(float64))
  6815. // formatInt_price := strconv.FormatInt(price, 10)
  6816. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6817. // project.Price = float_price
  6818. // }
  6819. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6820. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6821. project.Price = price
  6822. }
  6823. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6824. total, _ := json["total"].(string)
  6825. project.Count = total
  6826. }
  6827. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6828. medical_code, _ := json["medical_code"].(string)
  6829. project.MedListCodg = medical_code
  6830. }
  6831. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6832. single_dose, _ := json["single_dose"].(string)
  6833. project.SingleDose = single_dose
  6834. }
  6835. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6836. delivery_way, _ := json["delivery_way"].(string)
  6837. project.DeliveryWay = delivery_way
  6838. }
  6839. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6840. execution_frequency, _ := json["execution_frequency"].(string)
  6841. project.ExecutionFrequency = execution_frequency
  6842. }
  6843. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6844. remark, _ := json["remark"].(string)
  6845. project.Remark = remark
  6846. }
  6847. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6848. day, _ := json["number_days"].(string)
  6849. project.Day = day
  6850. }
  6851. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6852. unit, _ := json["unit"].(string)
  6853. project.Unit = unit
  6854. }
  6855. return 0
  6856. }
  6857. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6858. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6859. id := int64(json["id"].(float64))
  6860. historyAddtions, _ := service.GetHisAdditionByID(id)
  6861. additionalCharge.ID = id
  6862. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6863. }
  6864. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6865. item_id := int64(json["item_id"].(float64))
  6866. additionalCharge.ItemId = item_id
  6867. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6868. if config.ID > 0 {
  6869. if len(config.Code) > 0 {
  6870. additionalCharge.MedListCodg = config.Code
  6871. }
  6872. }
  6873. }
  6874. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6875. // price := int64(json["price"].(float64))
  6876. // formatInt_price := strconv.FormatInt(price, 10)
  6877. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6878. // additionalCharge.Price = float_price
  6879. // }
  6880. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6881. // price := int64(json["price"].(float64))
  6882. // formatInt_price := strconv.FormatInt(price, 10)
  6883. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6884. // additionalCharge.Price = float_price
  6885. //}
  6886. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6887. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6888. additionalCharge.Price = price
  6889. }
  6890. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6891. count, _ := json["count"].(string)
  6892. counts, _ := strconv.ParseInt(count, 10, 64)
  6893. additionalCharge.Count = counts
  6894. }
  6895. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6896. item_name, _ := json["item_name"].(string)
  6897. additionalCharge.ItemName = item_name
  6898. }
  6899. return 0
  6900. }
  6901. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6902. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6903. utils.ErrorLog("drug_name")
  6904. return enums.ErrorCodeParamWrong
  6905. }
  6906. adviceName, _ := json["drug_name"].(string)
  6907. if len(adviceName) == 0 {
  6908. utils.ErrorLog("len(advice_name) == 0")
  6909. return enums.ErrorCodeParamWrong
  6910. }
  6911. advice.AdviceName = adviceName
  6912. adviceDesc, _ := json["advice_desc"].(string)
  6913. advice.AdviceDesc = adviceDesc
  6914. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6915. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6916. advice.DrugSpec = drugSpec
  6917. }
  6918. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6919. remark, _ := json["remark"].(string)
  6920. advice.Remark = remark
  6921. }
  6922. if json["id"] == nil {
  6923. advice.DrugId = 0
  6924. } else {
  6925. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6926. drug_id := int64(json["id"].(float64))
  6927. advice.DrugId = drug_id
  6928. }
  6929. }
  6930. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6931. groupno := int64(json["groupno"].(float64))
  6932. advice.Groupno = groupno
  6933. }
  6934. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6935. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6936. advice.IsSelfDrug = is_self_drug
  6937. }
  6938. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6939. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6940. drug_way_count, _ := json["drug_way_count"].(string)
  6941. advice.DrugWayCount = drug_way_count
  6942. }
  6943. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6944. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6945. advice.HospApprFlag = hosp_appr_flag
  6946. }
  6947. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6948. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6949. advice.PrescribingNumber = prescribingNumber
  6950. }
  6951. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6952. // frequency_type := int64(json["frequency_type"].(float64))
  6953. // advice.FrequencyType = frequency_type
  6954. //}
  6955. //
  6956. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6957. // day_count := int64(json["day_count"].(float64))
  6958. // advice.DayCount = day_count
  6959. //}
  6960. //
  6961. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6962. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6963. // week_day, _ := json["week_day"].(string)
  6964. // advice.WeekDay = week_day
  6965. //}
  6966. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6967. drugSpecUnit, _ := json["min_unit"].(string)
  6968. advice.DrugSpecUnit = drugSpecUnit
  6969. }
  6970. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6971. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6972. advice.SingleDose = singleDose
  6973. }
  6974. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6975. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6976. advice.SingleDoseUnit = singleDoseUnit
  6977. }
  6978. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6979. deliveryWay, _ := json["delivery_way"].(string)
  6980. advice.DeliveryWay = deliveryWay
  6981. }
  6982. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6983. executionFrequency, _ := json["execution_frequency"].(string)
  6984. advice.ExecutionFrequency = executionFrequency
  6985. }
  6986. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6987. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6988. advice.Price = price
  6989. }
  6990. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6991. med_list_codg, _ := json["medical_insurance_number"].(string)
  6992. advice.MedListCodg = med_list_codg
  6993. }
  6994. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6995. day := int64(json["day"].(float64))
  6996. advice.Day = day
  6997. }
  6998. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6999. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7000. advice.PrescribingNumberUnit = prescribingNumberUnit
  7001. }
  7002. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7003. advice_id := int64(json["advice_id"].(float64))
  7004. advice.ID = advice_id
  7005. if advice.ID > 0 {
  7006. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7007. if err == nil {
  7008. if hisAdvice.ID > 0 {
  7009. advice.ExecutionTime = hisAdvice.ExecutionTime
  7010. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7011. advice.ExecutionState = hisAdvice.ExecutionState
  7012. advice.CheckTime = hisAdvice.CheckTime
  7013. advice.Checker = hisAdvice.Checker
  7014. advice.CheckState = hisAdvice.CheckState
  7015. advice.StartTime = hisAdvice.StartTime
  7016. advice.HospApprFlag = hisAdvice.HospApprFlag
  7017. advice.IsMedicine = hisAdvice.IsMedicine
  7018. if hisAdvice.UserOrgId == 10028 {
  7019. 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 {
  7020. advice.ExecutionTime = 0
  7021. advice.ExecutionStaff = 0
  7022. advice.ExecutionState = 2
  7023. advice.CheckTime = 0
  7024. advice.Checker = 0
  7025. advice.CheckState = 2
  7026. }
  7027. } else {
  7028. 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 {
  7029. advice.ExecutionTime = 0
  7030. advice.ExecutionStaff = 0
  7031. advice.ExecutionState = 2
  7032. advice.CheckTime = 0
  7033. advice.Checker = 0
  7034. advice.CheckState = 2
  7035. advice.UpdatedTime = time.Now().Unix()
  7036. }
  7037. }
  7038. //advice.Groupno = hisAdvice.Groupno
  7039. }
  7040. }
  7041. }
  7042. }
  7043. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7044. //
  7045. //if drugStockConfig.IsOpen == 1 {
  7046. //
  7047. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7048. // if advice.ID == 0 { //医嘱不存在
  7049. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7050. // drug.Total = drug.Total - advice.PrescribingNumber
  7051. // service.UpdateBaseDrugLib(&drug)
  7052. //
  7053. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7054. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7055. // drug.Total = drug.Total - num
  7056. // service.UpdateBaseDrugLib(&drug)
  7057. // }
  7058. //
  7059. // } else if advice.ID > 0 { //医嘱存在
  7060. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7061. // var num float64
  7062. //
  7063. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7064. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7065. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7066. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7067. // drug.Total = drug.Total + num
  7068. // service.UpdateBaseDrugLib(&drug)
  7069. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7070. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7071. // drug.Total = drug.Total - num
  7072. // service.UpdateBaseDrugLib(&drug)
  7073. // }
  7074. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7075. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7076. // if num2 > advice.PrescribingNumber {
  7077. // num = num2 - advice.PrescribingNumber
  7078. // drug.Total = drug.Total + num
  7079. // service.UpdateBaseDrugLib(&drug)
  7080. // } else if num2 < advice.PrescribingNumber {
  7081. // num = advice.PrescribingNumber - num2
  7082. // drug.Total = drug.Total - num
  7083. // service.UpdateBaseDrugLib(&drug)
  7084. // }
  7085. //
  7086. // }
  7087. //
  7088. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7089. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7090. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7091. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7092. // if num1 > num2 {
  7093. // num = num1 - num2
  7094. // drug.Total = drug.Total + num
  7095. // service.UpdateBaseDrugLib(&drug)
  7096. // } else if num1 < num2 {
  7097. // num = num2 - num1
  7098. // drug.Total = drug.Total - num
  7099. // service.UpdateBaseDrugLib(&drug)
  7100. // }
  7101. //
  7102. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7103. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7104. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7105. // if hisAdvice.PrescribingNumber > num2 {
  7106. // num = hisAdvice.PrescribingNumber - num2
  7107. // drug.Total = drug.Total + num
  7108. // service.UpdateBaseDrugLib(&drug)
  7109. // } else if num2 < advice.PrescribingNumber {
  7110. // num = num2 - hisAdvice.PrescribingNumber
  7111. // drug.Total = drug.Total - num
  7112. // service.UpdateBaseDrugLib(&drug)
  7113. // }
  7114. //
  7115. // }
  7116. // }
  7117. // }
  7118. //}
  7119. //
  7120. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7121. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7122. // advice.ExecutionTime = execution_time
  7123. //}
  7124. //
  7125. //
  7126. //
  7127. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7128. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7129. // advice.ExecutionStaff = execution_staff
  7130. //}
  7131. //
  7132. //
  7133. //
  7134. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7135. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7136. // advice.ExecutionState = execution_state
  7137. //}
  7138. //
  7139. //
  7140. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7141. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7142. // advice.CheckTime = check_time
  7143. //}
  7144. //
  7145. //
  7146. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7147. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7148. // advice.CheckState = check_state
  7149. //}
  7150. //
  7151. //
  7152. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7153. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7154. // advice.Checker = checker
  7155. //}
  7156. //
  7157. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7158. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7159. // advice.StartTime = start_time
  7160. //}
  7161. return 0
  7162. }
  7163. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7164. project.ExecutionStaff = 0
  7165. project.ExecutionState = 2
  7166. project.ExecutionTime = 0
  7167. project.Checker = 0
  7168. project.CheckState = 2
  7169. project.CheckTime = 0
  7170. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7171. id := int64(json["id"].(float64))
  7172. project.ID = id
  7173. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7174. project.ExecutionStaff = temp_project.ExecutionStaff
  7175. project.ExecutionState = temp_project.ExecutionState
  7176. project.ExecutionTime = temp_project.ExecutionTime
  7177. project.Checker = temp_project.Checker
  7178. project.CheckState = temp_project.CheckState
  7179. project.CheckTime = temp_project.CheckTime
  7180. project.TeamId = temp_project.TeamId
  7181. }
  7182. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7183. types := int64(json["type"].(float64))
  7184. project.Type = types
  7185. }
  7186. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7187. project_id := int64(json["project_id"].(float64))
  7188. project.ProjectId = project_id
  7189. }
  7190. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7191. team_id := int64(json["team_id"].(float64))
  7192. project.TeamId = team_id
  7193. }
  7194. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7195. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7196. project.Price = price
  7197. }
  7198. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7199. total, _ := json["total"].(string)
  7200. //totals, _ := strconv.ParseInt(total, 10, 64)
  7201. project.Count = total
  7202. }
  7203. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7204. medical_code, _ := json["medical_code"].(string)
  7205. project.MedListCodg = medical_code
  7206. }
  7207. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7208. single_dose, _ := json["single_dose"].(string)
  7209. project.SingleDose = single_dose
  7210. }
  7211. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7212. delivery_way, _ := json["delivery_way"].(string)
  7213. project.DeliveryWay = delivery_way
  7214. }
  7215. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7216. execution_frequency, _ := json["execution_frequency"].(string)
  7217. project.ExecutionFrequency = execution_frequency
  7218. }
  7219. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7220. remark, _ := json["remark"].(string)
  7221. project.Remark = remark
  7222. }
  7223. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7224. day, _ := json["number_days"].(string)
  7225. project.Day = day
  7226. }
  7227. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7228. unit, _ := json["unit"].(string)
  7229. project.Unit = unit
  7230. }
  7231. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7232. // frequency_type := int64(json["frequency_type"].(float64))
  7233. // project.FrequencyType = frequency_type
  7234. //}
  7235. //
  7236. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7237. // day_count := int64(json["day_count"].(float64))
  7238. // project.DayCount = day_count
  7239. //}
  7240. //
  7241. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7242. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7243. // week_day, _ := json["week_day"].(string)
  7244. // project.WeekDay = week_day
  7245. //}
  7246. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7247. //
  7248. //if project.ID == 0 {
  7249. // if stockConfig.IsOpen == 1 {
  7250. // if project.Type == 3 {
  7251. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7252. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7253. // good.Total = good.Total - f_count
  7254. // service.UpdateGoodInfo(&good)
  7255. // }
  7256. // }
  7257. //
  7258. //} else {
  7259. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7260. //
  7261. // if stockConfig.IsOpen == 1 {
  7262. // if project.Type == 3 {
  7263. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7264. // if project.Count < temp_project.Count {
  7265. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7266. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7267. //
  7268. // other_count := f_count_two - f_count_one
  7269. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7270. // good.Total = good.Total + other_count_two
  7271. // service.UpdateGoodInfo(&good)
  7272. // } else if project.Count > temp_project.Count {
  7273. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7274. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7275. //
  7276. // other_count := f_count_one - f_count_two
  7277. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7278. // good.Total = good.Total - other_count_two
  7279. // service.UpdateGoodInfo(&good)
  7280. // }
  7281. //
  7282. // }
  7283. // }
  7284. //
  7285. //}
  7286. return 0
  7287. }
  7288. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  7289. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7290. utils.ErrorLog("drug_name")
  7291. return enums.ErrorCodeParamWrong
  7292. }
  7293. adviceName, _ := json["drug_name"].(string)
  7294. if len(adviceName) == 0 {
  7295. utils.ErrorLog("len(advice_name) == 0")
  7296. return enums.ErrorCodeParamWrong
  7297. }
  7298. advice.AdviceName = adviceName
  7299. adviceDesc, _ := json["advice_desc"].(string)
  7300. advice.AdviceDesc = adviceDesc
  7301. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7302. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7303. advice.DrugSpec = drugSpec
  7304. }
  7305. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7306. remark, _ := json["remark"].(string)
  7307. advice.Remark = remark
  7308. }
  7309. if json["id"] == nil {
  7310. advice.DrugId = 0
  7311. } else {
  7312. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7313. drug_id := int64(json["id"].(float64))
  7314. advice.DrugId = drug_id
  7315. }
  7316. }
  7317. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7318. groupno := int64(json["groupno"].(float64))
  7319. advice.Groupno = groupno
  7320. }
  7321. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  7322. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  7323. advice.IsSelfDrug = is_self_drug
  7324. }
  7325. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  7326. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  7327. drug_way_count, _ := json["drug_way_count"].(string)
  7328. advice.DrugWayCount = drug_way_count
  7329. }
  7330. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  7331. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  7332. advice.HospApprFlag = hosp_appr_flag
  7333. }
  7334. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7335. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7336. advice.PrescribingNumber = prescribingNumber
  7337. }
  7338. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7339. // frequency_type := int64(json["frequency_type"].(float64))
  7340. // advice.FrequencyType = frequency_type
  7341. //}
  7342. //
  7343. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7344. // day_count := int64(json["day_count"].(float64))
  7345. // advice.DayCount = day_count
  7346. //}
  7347. //
  7348. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7349. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7350. // week_day, _ := json["week_day"].(string)
  7351. // advice.WeekDay = week_day
  7352. //}
  7353. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7354. drugSpecUnit, _ := json["min_unit"].(string)
  7355. advice.DrugSpecUnit = drugSpecUnit
  7356. }
  7357. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7358. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7359. advice.SingleDose = singleDose
  7360. }
  7361. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7362. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7363. advice.SingleDoseUnit = singleDoseUnit
  7364. }
  7365. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7366. deliveryWay, _ := json["delivery_way"].(string)
  7367. advice.DeliveryWay = deliveryWay
  7368. }
  7369. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7370. executionFrequency, _ := json["execution_frequency"].(string)
  7371. advice.ExecutionFrequency = executionFrequency
  7372. }
  7373. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7374. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7375. advice.Price = price
  7376. }
  7377. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7378. med_list_codg, _ := json["medical_insurance_number"].(string)
  7379. advice.MedListCodg = med_list_codg
  7380. }
  7381. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7382. day := int64(json["day"].(float64))
  7383. advice.Day = day
  7384. }
  7385. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7386. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7387. advice.PrescribingNumberUnit = prescribingNumberUnit
  7388. }
  7389. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  7390. advice_id := int64(json["advice_id"].(float64))
  7391. advice.ID = advice_id
  7392. if advice.ID > 0 {
  7393. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  7394. if err == nil {
  7395. if hisAdvice.ID > 0 {
  7396. advice.ExecutionTime = hisAdvice.ExecutionTime
  7397. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  7398. advice.ExecutionState = hisAdvice.ExecutionState
  7399. advice.CheckTime = hisAdvice.CheckTime
  7400. advice.Checker = hisAdvice.Checker
  7401. advice.CheckState = hisAdvice.CheckState
  7402. advice.StartTime = hisAdvice.StartTime
  7403. advice.HospApprFlag = hisAdvice.HospApprFlag
  7404. advice.IsMedicine = hisAdvice.IsMedicine
  7405. if hisAdvice.UserOrgId == 10028 {
  7406. 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 {
  7407. advice.ExecutionTime = 0
  7408. advice.ExecutionStaff = 0
  7409. advice.ExecutionState = 2
  7410. advice.CheckTime = 0
  7411. advice.Checker = 0
  7412. advice.CheckState = 2
  7413. }
  7414. } else {
  7415. 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 {
  7416. advice.ExecutionTime = 0
  7417. advice.ExecutionStaff = 0
  7418. advice.ExecutionState = 2
  7419. advice.CheckTime = 0
  7420. advice.Checker = 0
  7421. advice.CheckState = 2
  7422. //advice.UpdatedTime = time.Now().Unix()
  7423. advice.CreatedTime = hisAdvice.CreatedTime
  7424. advice.UpdatedTime = time.Now().Unix()
  7425. } else {
  7426. advice.CreatedTime = hisAdvice.CreatedTime
  7427. advice.UpdatedTime = hisAdvice.UpdatedTime
  7428. }
  7429. }
  7430. //advice.Groupno = hisAdvice.Groupno
  7431. } else {
  7432. advice.IsMedicine = 0
  7433. ctime := time.Now().Unix()
  7434. advice.CreatedTime = ctime
  7435. advice.UpdatedTime = ctime
  7436. }
  7437. }
  7438. } else {
  7439. advice.IsMedicine = 0
  7440. ctime := time.Now().Unix()
  7441. advice.CreatedTime = ctime
  7442. advice.UpdatedTime = ctime
  7443. }
  7444. }
  7445. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  7446. //
  7447. //if drugStockConfig.IsOpen == 1 {
  7448. //
  7449. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  7450. // if advice.ID == 0 { //医嘱不存在
  7451. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  7452. // drug.Total = drug.Total - advice.PrescribingNumber
  7453. // service.UpdateBaseDrugLib(&drug)
  7454. //
  7455. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  7456. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  7457. // drug.Total = drug.Total - num
  7458. // service.UpdateBaseDrugLib(&drug)
  7459. // }
  7460. //
  7461. // } else if advice.ID > 0 { //医嘱存在
  7462. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  7463. // var num float64
  7464. //
  7465. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  7466. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  7467. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  7468. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  7469. // drug.Total = drug.Total + num
  7470. // service.UpdateBaseDrugLib(&drug)
  7471. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  7472. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  7473. // drug.Total = drug.Total - num
  7474. // service.UpdateBaseDrugLib(&drug)
  7475. // }
  7476. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  7477. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7478. // if num2 > advice.PrescribingNumber {
  7479. // num = num2 - advice.PrescribingNumber
  7480. // drug.Total = drug.Total + num
  7481. // service.UpdateBaseDrugLib(&drug)
  7482. // } else if num2 < advice.PrescribingNumber {
  7483. // num = advice.PrescribingNumber - num2
  7484. // drug.Total = drug.Total - num
  7485. // service.UpdateBaseDrugLib(&drug)
  7486. // }
  7487. //
  7488. // }
  7489. //
  7490. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  7491. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  7492. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  7493. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7494. // if num1 > num2 {
  7495. // num = num1 - num2
  7496. // drug.Total = drug.Total + num
  7497. // service.UpdateBaseDrugLib(&drug)
  7498. // } else if num1 < num2 {
  7499. // num = num2 - num1
  7500. // drug.Total = drug.Total - num
  7501. // service.UpdateBaseDrugLib(&drug)
  7502. // }
  7503. //
  7504. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  7505. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  7506. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  7507. // if hisAdvice.PrescribingNumber > num2 {
  7508. // num = hisAdvice.PrescribingNumber - num2
  7509. // drug.Total = drug.Total + num
  7510. // service.UpdateBaseDrugLib(&drug)
  7511. // } else if num2 < advice.PrescribingNumber {
  7512. // num = num2 - hisAdvice.PrescribingNumber
  7513. // drug.Total = drug.Total - num
  7514. // service.UpdateBaseDrugLib(&drug)
  7515. // }
  7516. //
  7517. // }
  7518. // }
  7519. // }
  7520. //}
  7521. //
  7522. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  7523. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  7524. // advice.ExecutionTime = execution_time
  7525. //}
  7526. //
  7527. //
  7528. //
  7529. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  7530. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  7531. // advice.ExecutionStaff = execution_staff
  7532. //}
  7533. //
  7534. //
  7535. //
  7536. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  7537. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  7538. // advice.ExecutionState = execution_state
  7539. //}
  7540. //
  7541. //
  7542. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  7543. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  7544. // advice.CheckTime = check_time
  7545. //}
  7546. //
  7547. //
  7548. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  7549. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  7550. // advice.CheckState = check_state
  7551. //}
  7552. //
  7553. //
  7554. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  7555. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  7556. // advice.Checker = checker
  7557. //}
  7558. //
  7559. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  7560. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  7561. // advice.StartTime = start_time
  7562. //}
  7563. return 0
  7564. }
  7565. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  7566. project.ExecutionStaff = 0
  7567. project.ExecutionState = 2
  7568. project.ExecutionTime = 0
  7569. project.Checker = 0
  7570. project.CheckState = 2
  7571. project.CheckTime = 0
  7572. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7573. id := int64(json["id"].(float64))
  7574. project.ID = id
  7575. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7576. project.ExecutionStaff = temp_project.ExecutionStaff
  7577. project.ExecutionState = temp_project.ExecutionState
  7578. project.ExecutionTime = temp_project.ExecutionTime
  7579. project.Checker = temp_project.Checker
  7580. project.CheckState = temp_project.CheckState
  7581. project.CheckTime = temp_project.CheckTime
  7582. project.TeamId = temp_project.TeamId
  7583. }
  7584. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7585. types := int64(json["type"].(float64))
  7586. project.Type = types
  7587. }
  7588. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7589. project_id := int64(json["project_id"].(float64))
  7590. project.ProjectId = project_id
  7591. }
  7592. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  7593. team_id := int64(json["team_id"].(float64))
  7594. project.TeamId = team_id
  7595. }
  7596. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7597. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7598. project.Price = price
  7599. }
  7600. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7601. total, _ := json["total"].(string)
  7602. //totals, _ := strconv.ParseInt(total, 10, 64)
  7603. project.Count = total
  7604. }
  7605. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7606. medical_code, _ := json["medical_code"].(string)
  7607. project.MedListCodg = medical_code
  7608. }
  7609. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7610. single_dose, _ := json["single_dose"].(string)
  7611. project.SingleDose = single_dose
  7612. }
  7613. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7614. delivery_way, _ := json["delivery_way"].(string)
  7615. project.DeliveryWay = delivery_way
  7616. }
  7617. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7618. execution_frequency, _ := json["execution_frequency"].(string)
  7619. project.ExecutionFrequency = execution_frequency
  7620. }
  7621. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7622. remark, _ := json["remark"].(string)
  7623. project.Remark = remark
  7624. }
  7625. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7626. day, _ := json["number_days"].(string)
  7627. project.Day = day
  7628. }
  7629. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7630. unit, _ := json["unit"].(string)
  7631. project.Unit = unit
  7632. }
  7633. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  7634. // frequency_type := int64(json["frequency_type"].(float64))
  7635. // project.FrequencyType = frequency_type
  7636. //}
  7637. //
  7638. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  7639. // day_count := int64(json["day_count"].(float64))
  7640. // project.DayCount = day_count
  7641. //}
  7642. //
  7643. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  7644. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  7645. // week_day, _ := json["week_day"].(string)
  7646. // project.WeekDay = week_day
  7647. //}
  7648. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  7649. //
  7650. //if project.ID == 0 {
  7651. // if stockConfig.IsOpen == 1 {
  7652. // if project.Type == 3 {
  7653. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7654. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  7655. // good.Total = good.Total - f_count
  7656. // service.UpdateGoodInfo(&good)
  7657. // }
  7658. // }
  7659. //
  7660. //} else {
  7661. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  7662. //
  7663. // if stockConfig.IsOpen == 1 {
  7664. // if project.Type == 3 {
  7665. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  7666. // if project.Count < temp_project.Count {
  7667. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7668. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7669. //
  7670. // other_count := f_count_two - f_count_one
  7671. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7672. // good.Total = good.Total + other_count_two
  7673. // service.UpdateGoodInfo(&good)
  7674. // } else if project.Count > temp_project.Count {
  7675. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  7676. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  7677. //
  7678. // other_count := f_count_one - f_count_two
  7679. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  7680. // good.Total = good.Total - other_count_two
  7681. // service.UpdateGoodInfo(&good)
  7682. // }
  7683. //
  7684. // }
  7685. // }
  7686. //
  7687. //}
  7688. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7689. id := int64(json["id"].(float64))
  7690. if id > 0 {
  7691. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  7692. if temp_project.ExecutionFrequency != project.ExecutionFrequency || temp_project.Count != project.Count || temp_project.Remark != project.Remark {
  7693. fmt.Println("666666")
  7694. project.Mtime = time.Now().Unix()
  7695. project.Ctime = temp_project.Ctime
  7696. } else {
  7697. project.Mtime = temp_project.Mtime
  7698. project.Ctime = temp_project.Ctime
  7699. }
  7700. } else {
  7701. ctime := time.Now().Unix()
  7702. project.Mtime = ctime
  7703. project.Ctime = ctime
  7704. }
  7705. }
  7706. return 0
  7707. }
  7708. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  7709. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7710. id := int64(json["id"].(float64))
  7711. additionalCharge.ID = id
  7712. }
  7713. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  7714. item_id := int64(json["item_id"].(float64))
  7715. additionalCharge.ItemId = item_id
  7716. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  7717. if config.ID > 0 {
  7718. if len(config.Code) > 0 {
  7719. additionalCharge.MedListCodg = config.Code
  7720. }
  7721. }
  7722. }
  7723. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7724. // price := int64(json["price"].(float64))
  7725. // formatInt_price := strconv.FormatInt(price, 10)
  7726. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7727. // additionalCharge.Price = float_price
  7728. // }
  7729. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  7730. // price := int64(json["price"].(float64))
  7731. // formatInt_price := strconv.FormatInt(price, 10)
  7732. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  7733. // additionalCharge.Price = float_price
  7734. //}
  7735. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7736. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7737. additionalCharge.Price = price
  7738. }
  7739. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  7740. count, _ := json["count"].(string)
  7741. counts, _ := strconv.ParseInt(count, 10, 64)
  7742. additionalCharge.Count = counts
  7743. }
  7744. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  7745. item_name, _ := json["item_name"].(string)
  7746. additionalCharge.ItemName = item_name
  7747. }
  7748. return 0
  7749. }
  7750. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  7751. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  7752. utils.ErrorLog("drug_name")
  7753. return enums.ErrorCodeParamWrong
  7754. }
  7755. adviceName, _ := json["drug_name"].(string)
  7756. if len(adviceName) == 0 {
  7757. utils.ErrorLog("len(advice_name) == 0")
  7758. return enums.ErrorCodeParamWrong
  7759. }
  7760. advice.AdviceName = adviceName
  7761. adviceDesc, _ := json["advice_desc"].(string)
  7762. advice.AdviceDesc = adviceDesc
  7763. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  7764. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  7765. advice.DrugSpec = drugSpec
  7766. }
  7767. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7768. remark, _ := json["remark"].(string)
  7769. advice.Remark = remark
  7770. }
  7771. if json["id"] == nil {
  7772. advice.DrugId = 0
  7773. } else {
  7774. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7775. drug_id := int64(json["id"].(float64))
  7776. advice.DrugId = drug_id
  7777. }
  7778. }
  7779. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7780. groupno := int64(json["groupno"].(float64))
  7781. advice.Groupno = groupno
  7782. }
  7783. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7784. drugSpecUnit, _ := json["min_unit"].(string)
  7785. advice.DrugSpecUnit = drugSpecUnit
  7786. }
  7787. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7788. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7789. advice.SingleDose = singleDose
  7790. }
  7791. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7792. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7793. advice.SingleDoseUnit = singleDoseUnit
  7794. }
  7795. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7796. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7797. advice.PrescribingNumber = prescribingNumber
  7798. }
  7799. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7800. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7801. advice.PrescribingNumberUnit = prescribingNumberUnit
  7802. }
  7803. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7804. deliveryWay, _ := json["delivery_way"].(string)
  7805. advice.DeliveryWay = deliveryWay
  7806. }
  7807. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7808. executionFrequency, _ := json["execution_frequency"].(string)
  7809. advice.ExecutionFrequency = executionFrequency
  7810. }
  7811. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7812. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7813. advice.Price = price
  7814. }
  7815. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7816. med_list_codg, _ := json["medical_insurance_number"].(string)
  7817. advice.MedListCodg = med_list_codg
  7818. }
  7819. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7820. day := int64(json["day"].(float64))
  7821. advice.Day = day
  7822. }
  7823. advice.FrequencyType = 1
  7824. return 0
  7825. }
  7826. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7827. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7828. types := int64(json["type"].(float64))
  7829. project.Type = types
  7830. }
  7831. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7832. project_id := int64(json["project_id"].(float64))
  7833. project.ProjectId = project_id
  7834. }
  7835. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7836. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7837. project.Price = price
  7838. }
  7839. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7840. total, _ := json["total"].(string)
  7841. //totals, _ := strconv.ParseInt(total, 10, 64)
  7842. project.Count = total
  7843. }
  7844. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7845. medical_code, _ := json["medical_code"].(string)
  7846. project.MedListCodg = medical_code
  7847. }
  7848. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7849. single_dose, _ := json["single_dose"].(string)
  7850. project.SingleDose = single_dose
  7851. }
  7852. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7853. delivery_way, _ := json["delivery_way"].(string)
  7854. project.DeliveryWay = delivery_way
  7855. }
  7856. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7857. execution_frequency, _ := json["execution_frequency"].(string)
  7858. project.ExecutionFrequency = execution_frequency
  7859. }
  7860. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7861. remark, _ := json["remark"].(string)
  7862. project.Remark = remark
  7863. }
  7864. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7865. day, _ := json["number_days"].(string)
  7866. project.Day = day
  7867. }
  7868. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7869. unit, _ := json["unit"].(string)
  7870. project.Unit = unit
  7871. }
  7872. project.FrequencyType = 1
  7873. return 0
  7874. }
  7875. func (c *HisApiController) GetHisOrderListTwo() {
  7876. start_time := c.GetString("start_time")
  7877. end_time := c.GetString("end_time")
  7878. timeLayout := "2006-01-02"
  7879. loc, _ := time.LoadLocation("Local")
  7880. var startTime int64
  7881. if len(start_time) > 0 {
  7882. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7883. if err != nil {
  7884. //fmt.Println(err)
  7885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7886. return
  7887. }
  7888. startTime = theTime.Unix()
  7889. }
  7890. var endTime int64
  7891. if len(end_time) > 0 {
  7892. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7893. if err != nil {
  7894. utils.ErrorLog(err.Error())
  7895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7896. return
  7897. }
  7898. endTime = theTime.Unix()
  7899. }
  7900. adminUser := c.GetAdminUserInfo()
  7901. org_id := adminUser.CurrentOrgId
  7902. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7903. if err == nil {
  7904. c.ServeSuccessJSON(map[string]interface{}{
  7905. "order2": order,
  7906. })
  7907. } else {
  7908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7909. return
  7910. }
  7911. }
  7912. func (c *HisApiController) GetHisOrderList() {
  7913. page, _ := c.GetInt64("page", -1)
  7914. limit, _ := c.GetInt64("limit", -1)
  7915. start_time := c.GetString("start_time")
  7916. end_time := c.GetString("end_time")
  7917. types, _ := c.GetInt64("type", 0)
  7918. keywords := c.GetString("keywords")
  7919. p_type, _ := c.GetInt64("p_type", 0)
  7920. sort_type, _ := c.GetInt64("sort_type", 0)
  7921. charge_type, _ := c.GetInt64("charge_type", 0)
  7922. sch_type, _ := c.GetInt64("sch_type", 0)
  7923. zone_type, _ := c.GetInt64("zone_type", 0)
  7924. med_type, _ := c.GetInt64("med_type", 0)
  7925. timeLayout := "2006-01-02"
  7926. loc, _ := time.LoadLocation("Local")
  7927. var startTime int64
  7928. if len(start_time) > 0 {
  7929. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7930. if err != nil {
  7931. //fmt.Println(err)
  7932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7933. return
  7934. }
  7935. startTime = theTime.Unix()
  7936. }
  7937. var endTime int64
  7938. if len(end_time) > 0 {
  7939. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7940. if err != nil {
  7941. utils.ErrorLog(err.Error())
  7942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7943. return
  7944. }
  7945. endTime = theTime.Unix()
  7946. }
  7947. adminUser := c.GetAdminUserInfo()
  7948. org_id := adminUser.CurrentOrgId
  7949. 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)
  7950. for _, item := range order {
  7951. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7952. item.DoctorName = info.Doctor
  7953. item.DepartmentName = info.XtHisDepartment.Name
  7954. }
  7955. if err == nil {
  7956. c.ServeSuccessJSON(map[string]interface{}{
  7957. "order": order,
  7958. "total": total,
  7959. })
  7960. } else {
  7961. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7962. return
  7963. }
  7964. }
  7965. func (c *HisApiController) GetHisOrder() {
  7966. patient_id, _ := c.GetInt64("patient_id", 0)
  7967. number := c.GetString("number")
  7968. adminInfo := c.GetAdminUserInfo()
  7969. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7970. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7971. if err == nil {
  7972. c.ServeSuccessJSON(map[string]interface{}{
  7973. "order": order,
  7974. "prescription": prescriptions,
  7975. })
  7976. } else {
  7977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7978. return
  7979. }
  7980. }
  7981. func (c *HisApiController) GetHisPrescriptionList() {
  7982. record_date := c.GetString("record_date")
  7983. keywords := c.GetString("keywords")
  7984. page, _ := c.GetInt64("page")
  7985. limit, _ := c.GetInt64("limit")
  7986. sch_type, _ := c.GetInt64("sch_type")
  7987. timeLayout := "2006-01-02"
  7988. loc, _ := time.LoadLocation("Local")
  7989. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7990. if err != nil {
  7991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7992. return
  7993. }
  7994. recordDateTime := theTime.Unix()
  7995. adminInfo := c.GetAdminUserInfo()
  7996. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7997. //adminInfo := c.GetAdminUserInfo()
  7998. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7999. //fmt.Println(prescriptionOrder)
  8000. if err == nil {
  8001. c.ServeSuccessJSON(map[string]interface{}{
  8002. "order": prescriptionOrder,
  8003. "total": total,
  8004. })
  8005. } else {
  8006. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8007. return
  8008. }
  8009. }
  8010. func (c *HisApiController) GetHisPrescriptionInfo() {
  8011. id, _ := c.GetInt64("id")
  8012. adminInfo := c.GetAdminUserInfo()
  8013. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  8014. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  8015. if err == nil {
  8016. c.ServeSuccessJSON(map[string]interface{}{
  8017. "order": prescriptionOrder,
  8018. "prescription": prescription,
  8019. })
  8020. } else {
  8021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8022. return
  8023. }
  8024. }
  8025. func (c *HisApiController) GetMedicalInsuranceConfig() {
  8026. adminUser := c.GetAdminUserInfo()
  8027. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  8028. c.ServeSuccessJSON(map[string]interface{}{
  8029. "config": config,
  8030. })
  8031. }
  8032. type ResultTwo struct {
  8033. ErrMsg interface{} `json:"err_msg"`
  8034. InfRefmsgid string `json:"inf_refmsgid"`
  8035. Infcode int64 `json:"infcode"`
  8036. Output struct {
  8037. Baseinfo struct {
  8038. Age float64 `json:"age"`
  8039. Brdy string `json:"brdy"`
  8040. Certno string `json:"certno"`
  8041. Gend string `json:"gend"`
  8042. Naty string `json:"naty"`
  8043. PsnCertType string `json:"psn_cert_type"`
  8044. PsnName string `json:"psn_name"`
  8045. PsnNo string `json:"psn_no"`
  8046. } `json:"baseinfo"`
  8047. Idetinfo []interface{} `json:"idetinfo"`
  8048. Iinfo []struct {
  8049. Balc float64 `json:"balc"`
  8050. CvlservFlag string `json:"cvlserv_flag"`
  8051. EmpName string `json:"emp_name"`
  8052. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  8053. Insutype string `json:"insutype"`
  8054. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  8055. PausInsuDate interface{} `json:"paus_insu_date"`
  8056. PsnInsuDate string `json:"psn_insu_date"`
  8057. PsnInsuStas string `json:"psn_insu_stas"`
  8058. PsnType string `json:"psn_type"`
  8059. } `json:"insuinfo"`
  8060. } `json:"output"`
  8061. RefmsgTime string `json:"refmsg_time"`
  8062. RespondTime string `json:"respond_time"`
  8063. Signtype interface{} `json:"signtype"`
  8064. WarnInfo interface{} `json:"warn_info"`
  8065. }
  8066. type ResultThree struct {
  8067. Cainfo interface{} `json:"cainfo"`
  8068. ErrMsg interface{} `json:"err_msg"`
  8069. InfRefmsgid string `json:"inf_refmsgid"`
  8070. Infcode int64 `json:"infcode"`
  8071. Output struct {
  8072. Data struct {
  8073. IptOtpNo string `json:"ipt_otp_no"`
  8074. MdtrtID string `json:"mdtrt_id"`
  8075. PsnNo string `json:"psn_no"`
  8076. } `json:"data"`
  8077. } `json:"output"`
  8078. RefmsgTime string `json:"refmsg_time"`
  8079. RespondTime string `json:"respond_time"`
  8080. Signtype interface{} `json:"signtype"`
  8081. WarnMsg interface{} `json:"warn_msg"`
  8082. }
  8083. type ResultFour struct {
  8084. Cainfo string `json:"cainfo"`
  8085. ErrMsg string `json:"err_msg"`
  8086. InfRefmsgid string `json:"inf_refmsgid"`
  8087. Infcode int64 `json:"infcode"`
  8088. Output struct {
  8089. Result []struct {
  8090. BasMednFlag string `json:"bas_medn_flag"`
  8091. ChldMedcFlag string `json:"chld_medc_flag"`
  8092. ChrgitmLv string `json:"chrgitm_lv"`
  8093. Cnt float64 `json:"cnt"`
  8094. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  8095. DrtReimFlag string `json:"drt_reim_flag"`
  8096. FeedetlSn string `json:"feedetl_sn"`
  8097. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8098. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  8099. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8100. ListSpItemFlag string `json:"list_sp_item_flag"`
  8101. LmtUsedFlag string `json:"lmt_used_flag"`
  8102. MedChrgitmType string `json:"med_chrgitm_type"`
  8103. Memo string `json:"memo"`
  8104. OverlmtAmt float64 `json:"overlmt_amt"`
  8105. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8106. Pric float64 `json:"pric"`
  8107. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  8108. SelfpayProp float64 `json:"selfpay_prop"`
  8109. } `json:"result"`
  8110. } `json:"output"`
  8111. RefmsgTime string `json:"refmsg_time"`
  8112. RespondTime string `json:"respond_time"`
  8113. Signtype string `json:"signtype"`
  8114. WarnMsg string `json:"warn_msg"`
  8115. }
  8116. type ResultFive struct {
  8117. Insutype string `json:"insutype"`
  8118. }
  8119. type ResultSix struct {
  8120. Cainfo interface{} `json:"cainfo"`
  8121. ErrMsg interface{} `json:"err_msg"`
  8122. InfRefmsgid string `json:"inf_refmsgid"`
  8123. Infcode int64 `json:"infcode"`
  8124. Output struct {
  8125. } `json:"output"`
  8126. RefmsgTime string `json:"refmsg_time"`
  8127. RespondTime string `json:"respond_time"`
  8128. Signtype interface{} `json:"signtype"`
  8129. WarnMsg interface{} `json:"warn_msg"`
  8130. }
  8131. type ResultSeven struct {
  8132. Cainfo string `json:"cainfo"`
  8133. ErrMsg string `json:"err_msg"`
  8134. InfRefmsgid string `json:"inf_refmsgid"`
  8135. Infcode int64 `json:"infcode"`
  8136. Output struct {
  8137. Setldetail []interface{} `json:"setldetail"`
  8138. Setlinfo struct {
  8139. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8140. AcctPay float64 `json:"acct_pay"`
  8141. ActPayDedc float64 `json:"act_pay_dedc"`
  8142. Age float64 `json:"age"`
  8143. Balc float64 `json:"balc"`
  8144. Brdy string `json:"brdy"`
  8145. Certno string `json:"certno"`
  8146. ClrOptins string `json:"clr_optins"`
  8147. ClrType string `json:"clr_type"`
  8148. ClrWay string `json:"clr_way"`
  8149. CvlservFlag string `json:"cvlserv_flag"`
  8150. CvlservPay float64 `json:"cvlserv_pay"`
  8151. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8152. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8153. Gend string `json:"gend"`
  8154. HifesPay float64 `json:"hifes_pay"`
  8155. HifmiPay float64 `json:"hifmi_pay"`
  8156. HifobPay float64 `json:"hifob_pay"`
  8157. HifpPay float64 `json:"hifp_pay"`
  8158. HospPartAmt float64 `json:"hosp_part_amt"`
  8159. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8160. Insutype string `json:"insutype"`
  8161. MafPay float64 `json:"maf_pay"`
  8162. MdtrtCertType string `json:"mdtrt_cert_type"`
  8163. MdtrtID string `json:"mdtrt_id"`
  8164. MedType string `json:"med_type"`
  8165. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8166. MedinsSetlID string `json:"medins_setl_id"`
  8167. Naty string `json:"naty"`
  8168. OthPay float64 `json:"oth_pay"`
  8169. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8170. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8171. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8172. PsnCashPay float64 `json:"psn_cash_pay"`
  8173. PsnCertType string `json:"psn_cert_type"`
  8174. PsnName string `json:"psn_name"`
  8175. PsnNo string `json:"psn_no"`
  8176. PsnPartAmt float64 `json:"psn_part_amt"`
  8177. PsnType string `json:"psn_type"`
  8178. SetlID string `json:"setl_id"`
  8179. SetlTime string `json:"setl_time"`
  8180. } `json:"setlinfo"`
  8181. } `json:"output"`
  8182. RefmsgTime string `json:"refmsg_time"`
  8183. RespondTime string `json:"respond_time"`
  8184. Signtype interface{} `json:"signtype"`
  8185. WarnMsg interface{} `json:"warn_msg"`
  8186. }
  8187. type ResultEight struct {
  8188. Cainfo string `json:"cainfo"`
  8189. ErrMsg string `json:"err_msg"`
  8190. InfRefmsgid string `json:"inf_refmsgid"`
  8191. Infcode int64 `json:"infcode"`
  8192. Output struct {
  8193. Stmtinfo struct {
  8194. SetlOptins string `json:"setl_optins"`
  8195. StmtRslt string `json:"stmt_rslt"`
  8196. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  8197. } `json:"stmtinfo"`
  8198. } `json:"output"`
  8199. RefmsgTime string `json:"refmsg_time"`
  8200. RespondTime string `json:"respond_time"`
  8201. Signtype interface{} `json:"signtype"`
  8202. WarnMsg interface{} `json:"warn_msg"`
  8203. }
  8204. type ResultNine struct {
  8205. Cainfo string `json:"cainfo"`
  8206. ErrMsg string `json:"err_msg"`
  8207. InfRefmsgid string `json:"inf_refmsgid"`
  8208. Infcode int64 `json:"infcode"`
  8209. Output struct {
  8210. FileQuryNo string `json:"file_qury_no"`
  8211. } `json:"output"`
  8212. RefmsgTime string `json:"refmsg_time"`
  8213. RespondTime string `json:"respond_time"`
  8214. Signtype interface{} `json:"signtype"`
  8215. WarnMsg interface{} `json:"warn_msg"`
  8216. }
  8217. type ResultTen struct {
  8218. Cainfo string `json:"cainfo"`
  8219. ErrMsg string `json:"err_msg"`
  8220. InfRefmsgid string `json:"inf_refmsgid"`
  8221. Infcode int64 `json:"infcode"`
  8222. Output struct {
  8223. DldEndtime string `json:"dld_endtime"`
  8224. FileQuryNo string `json:"file_qury_no"`
  8225. Filename string `json:"filename"`
  8226. } `json:"output"`
  8227. RefmsgTime string `json:"refmsg_time"`
  8228. RespondTime string `json:"respond_time"`
  8229. Signtype interface{} `json:"signtype"`
  8230. WarnMsg interface{} `json:"warn_msg"`
  8231. }
  8232. type ResultEleven struct {
  8233. Cainfo string `json:"cainfo"`
  8234. ErrMsg string `json:"err_msg"`
  8235. InfRefmsgid string `json:"inf_refmsgid"`
  8236. Infcode int64 `json:"infcode"`
  8237. Output struct {
  8238. Setlinfo struct {
  8239. FixmedinsName string `json:"fixmedins_name"`
  8240. FixmedinsCode string `json:"fixmedins_code"`
  8241. PsnNo string `json:"psn_no"`
  8242. PsnName string `json:"psn_name"`
  8243. HifobPay float64 `json:"hifob_pay"`
  8244. Gend string `json:"gend"`
  8245. Brdy string `json:"brdy"`
  8246. PsnCertType string `json:"psn_cert_type"`
  8247. PsnType string `json:"psn_type"`
  8248. EmpName string `json:"emp_name"`
  8249. Certno string `json:"certno"`
  8250. Insutype string `json:"insutype"`
  8251. MedfeeSumamt float64 `json:"medfee_sumamt"`
  8252. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  8253. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  8254. PreselfpayAmt float64 `json:"preselfpay_amt"`
  8255. InscpScpAmt float64 `json:"inscp_scp_amt"`
  8256. ActPayDedc float64 `json:"act_pay_dedc"`
  8257. HifpPay float64 `json:"hifp_pay"`
  8258. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  8259. CvlservPay float64 `json:"cvlserv_pay"`
  8260. HifesPay float64 `json:"hifes_pay"`
  8261. HifmiPay float64 `json:"hifmi_pay"`
  8262. MafPay float64 `json:"maf_pay"`
  8263. OthPay float64 `json:"oth_pay"`
  8264. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  8265. PsnPay float64 `json:"psn_pay"`
  8266. AcctPay float64 `json:"acct_pay"`
  8267. CashPayamt float64 `json:"cash_payamt"`
  8268. Balc float64 `json:"balc"`
  8269. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  8270. MedinsSetlId string `json:"medins_setl_id"`
  8271. RefdSetlFlag string `json:"refd_setl_flag"`
  8272. SetlTime string `json:"setl_time"`
  8273. MedType string `json:"med_type"`
  8274. } `json:"setlinfo"`
  8275. } `json:"output"`
  8276. RefmsgTime string `json:"refmsg_time"`
  8277. RespondTime string `json:"respond_time"`
  8278. Signtype interface{} `json:"signtype"`
  8279. WarnMsg interface{} `json:"warn_msg"`
  8280. }
  8281. type Custom struct {
  8282. DetItemFeeSumamt string
  8283. Cut string
  8284. FeedetlSn string
  8285. Price string
  8286. MedListCodg string
  8287. Type int64
  8288. AdviceId int64
  8289. ProjectId int64
  8290. ItemId int64
  8291. }
  8292. // 获取个人信息----挂号-----上传就诊信息
  8293. func (c *HisApiController) GetRegisterInfo() {
  8294. id, _ := c.GetInt64("id")
  8295. record_time := c.GetString("record_time")
  8296. settlementValue, _ := c.GetInt64("settlement_value")
  8297. medical_insurance_card := c.GetString("medical_insurance_card")
  8298. name := c.GetString("name")
  8299. id_card_type, _ := c.GetInt64("id_card_type")
  8300. certificates, _ := c.GetInt64("certificates")
  8301. medical_care, _ := c.GetInt64("medical_care")
  8302. birthday := c.GetString("birthday")
  8303. age, _ := c.GetInt64("age")
  8304. id_card := c.GetString("id_card")
  8305. register_type, _ := c.GetInt64("register")
  8306. doctor, _ := c.GetInt64("doctor")
  8307. department, _ := c.GetInt64("department")
  8308. gender, _ := c.GetInt64("sex")
  8309. phone := c.GetString("phone")
  8310. registration_fee, _ := c.GetFloat("registration_fee")
  8311. medical_expenses, _ := c.GetFloat("medical_expenses")
  8312. social_type, _ := c.GetInt64("social_type")
  8313. //diagnosis_id, _ := c.GetInt64("diagnosis")
  8314. diagnosis_ids := c.GetString("diagnosis")
  8315. sick_type, _ := c.GetInt64("sick_type")
  8316. reg_type := c.GetString("p_type")
  8317. timeLayout := "2006-01-02"
  8318. loc, _ := time.LoadLocation("Local")
  8319. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  8320. birthUnix := birthdays.Unix()
  8321. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8322. if err != nil {
  8323. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8324. return
  8325. }
  8326. recordDateTime := theTime.Unix()
  8327. adminInfo := c.GetAdminUserInfo()
  8328. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  8329. if tempPatient.ID == 0 {
  8330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  8331. return
  8332. }
  8333. var patient service.Patients
  8334. if id == 0 {
  8335. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  8336. } else {
  8337. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  8338. }
  8339. if patient.ID == 0 {
  8340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  8341. return
  8342. }
  8343. if len(patient.IdCardNo) == 0 {
  8344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  8345. return
  8346. }
  8347. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8348. if len(his) >= 1 {
  8349. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  8350. if len(his) >= 1 && order.ID == 0 {
  8351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  8352. return
  8353. }
  8354. }
  8355. timeStr := time.Now().Format("2006-01-02 15:04:05")
  8356. fmt.Println(timeStr)
  8357. timeArr := strings.Split(timeStr, " ")
  8358. fmt.Println(timeArr)
  8359. timeArrTwo := strings.Split(timeArr[0], "-")
  8360. timeArrThree := strings.Split(timeArr[1], ":")
  8361. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  8362. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  8363. if len(lists) == 0 {
  8364. var hisPatient models.XtHisPatient
  8365. hisPatient = models.XtHisPatient{
  8366. Name: name,
  8367. Age: age,
  8368. Gender: gender,
  8369. Birthday: birthUnix,
  8370. Phone: phone,
  8371. MedicalTreatmentType: medical_care,
  8372. IdType: certificates,
  8373. IdCardNo: id_card,
  8374. BalanceAccountsType: settlementValue,
  8375. SocialType: social_type,
  8376. MedicalInsuranceNumber: medical_insurance_card,
  8377. RegisterType: register_type,
  8378. RegisterCost: registration_fee,
  8379. TreatmentCost: medical_expenses,
  8380. AdminUserId: adminInfo.AdminUser.Id,
  8381. UserOrgId: adminInfo.CurrentOrgId,
  8382. Status: 1,
  8383. RecordDate: recordDateTime,
  8384. IsReturn: 1,
  8385. PatientId: patient.ID,
  8386. Ctime: time.Now().Unix(),
  8387. Mtime: time.Now().Unix(),
  8388. Number: str,
  8389. IdCardType: id_card_type,
  8390. Departments: department,
  8391. Doctor: doctor,
  8392. PType: reg_type,
  8393. Diagnosis: diagnosis_ids,
  8394. SickType: sick_type,
  8395. }
  8396. service.CreateHisPatient(&hisPatient)
  8397. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8398. c.ServeSuccessJSON(map[string]interface{}{
  8399. "his_info": hisPatient,
  8400. })
  8401. } else {
  8402. //chrgBchno := rand.Intn(1000000) + 10000
  8403. var hisPatient models.XtHisPatient
  8404. hisPatient = models.XtHisPatient{
  8405. Name: name,
  8406. Age: age,
  8407. Gender: gender,
  8408. Birthday: birthUnix,
  8409. Phone: phone,
  8410. MedicalTreatmentType: medical_care,
  8411. IdType: certificates,
  8412. IdCardNo: id_card,
  8413. BalanceAccountsType: settlementValue,
  8414. SocialType: social_type,
  8415. MedicalInsuranceNumber: medical_insurance_card,
  8416. RegisterType: register_type,
  8417. RegisterCost: registration_fee,
  8418. TreatmentCost: medical_expenses,
  8419. AdminUserId: adminInfo.AdminUser.Id,
  8420. UserOrgId: adminInfo.CurrentOrgId,
  8421. Status: 1,
  8422. RecordDate: recordDateTime,
  8423. IsReturn: 1,
  8424. PatientId: patient.ID,
  8425. Ctime: time.Now().Unix(),
  8426. Mtime: time.Now().Unix(),
  8427. Number: str,
  8428. IdCardType: id_card_type,
  8429. Departments: department,
  8430. Doctor: doctor,
  8431. PType: reg_type,
  8432. Diagnosis: diagnosis_ids,
  8433. SickType: sick_type,
  8434. }
  8435. service.CreateHisPatient(&hisPatient)
  8436. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  8437. c.ServeSuccessJSON(map[string]interface{}{
  8438. "his_info": hisPatient,
  8439. })
  8440. }
  8441. }
  8442. // 上传明细----结算
  8443. func (c *HisApiController) GetUploadInfo() {
  8444. id, _ := c.GetInt64("id")
  8445. record_time := c.GetString("record_time")
  8446. his_patient_id, _ := c.GetInt64("his_patient_id")
  8447. oth_desc := c.GetString("oth_desc")
  8448. pay_way, _ := c.GetInt64("pay_way")
  8449. pay_ways := c.GetString("pay_ways")
  8450. pay_price, _ := c.GetFloat("pay_price")
  8451. pay_card_no := c.GetString("pay_card_no")
  8452. discount_price, _ := c.GetFloat("discount_price")
  8453. preferential_price, _ := c.GetFloat("preferential_price")
  8454. reality_price, _ := c.GetFloat("reality_price")
  8455. found_price, _ := c.GetFloat("found_price")
  8456. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  8457. private_price, _ := c.GetFloat("private_price")
  8458. timeLayout := "2006-01-02"
  8459. loc, _ := time.LoadLocation("Local")
  8460. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8461. fapiao_code := c.GetString("fapiao_code")
  8462. fapiao_number := c.GetString("fapiao_number")
  8463. diagnosis_id := c.GetString("diagnosis")
  8464. sick_type, _ := c.GetInt64("sick_type")
  8465. reg_type, _ := c.GetInt64("p_type")
  8466. order_id, _ := c.GetInt64("order_id")
  8467. cash_pay := c.GetString("cash_pay")
  8468. wechat_pay := c.GetString("wechat_pay")
  8469. ali_pay := c.GetString("ali_pay")
  8470. jifen_pay := c.GetString("jifen_pay")
  8471. band_card_pay := c.GetString("band_card_pay")
  8472. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  8473. tmp_decimal := c.GetString("tmp_decimal")
  8474. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  8475. var decimal float64 //本次使用的押金
  8476. var errmsg error
  8477. tx := service.XTWriteDB().Begin() //开了事务
  8478. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  8479. defer func() {
  8480. if errmsg != nil {
  8481. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  8482. tx.Rollback()
  8483. } else {
  8484. tx.Commit()
  8485. }
  8486. }()
  8487. fmt.Println("dec_way", dec_way)
  8488. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  8489. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  8490. return
  8491. }
  8492. if len(tmp_decimal) > 0 {
  8493. if tmp_decimal[0] == 45 {
  8494. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  8495. return
  8496. }
  8497. }
  8498. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  8499. fmt.Println(errs)
  8500. decimal = tt
  8501. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  8502. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  8503. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8504. if err != nil {
  8505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8506. return
  8507. }
  8508. recordDateTime := theTime.Unix()
  8509. adminUser := c.GetAdminUserInfo()
  8510. var prescriptions []*models.HisPrescription
  8511. var prescriptionsOne []*models.HisPrescription
  8512. var start_time int64
  8513. var end_time int64
  8514. ids_str := c.GetString("ids")
  8515. ids_arr := strings.Split(ids_str, ",")
  8516. if tempOrder.ID == 0 {
  8517. if settle_accounts_type == 1 { //日结
  8518. fmt.Println(reg_type)
  8519. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8520. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  8521. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  8522. } else {
  8523. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8524. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8525. }
  8526. } else { //月结
  8527. start_time_str := c.GetString("start_time")
  8528. end_time_str := c.GetString("end_time")
  8529. timeLayout := "2006-01-02"
  8530. loc, _ := time.LoadLocation("Local")
  8531. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8532. if err != nil {
  8533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8534. return
  8535. }
  8536. recordStartTime := theStartTime.Unix()
  8537. start_time = recordStartTime
  8538. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8539. if err != nil {
  8540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8541. return
  8542. }
  8543. recordEndTime := theEndTime.Unix()
  8544. end_time = recordEndTime
  8545. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  8546. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  8547. }
  8548. var goods []*models.DialysisBeforePrepareGoods
  8549. var newGoods []*models.NewDialysisBeforePrepareGoods
  8550. var oldGoods []*models.OldDialysisBeforePrepareGoods
  8551. var infos []*models.HisDoctorAdviceInfo
  8552. var infoList []*models.HisDoctorAdviceInfo
  8553. var hisAdvice []*models.HisDoctorAdviceInfo
  8554. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  8555. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  8556. //判断库存不足
  8557. //结算出库开关
  8558. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8559. if settConfig.IsOpen == 1 {
  8560. //判断库存的地方
  8561. for _, info := range prescriptions {
  8562. if info.Type == 1 {
  8563. infos = append(infos, info.HisDoctorAdviceInfo...)
  8564. }
  8565. if info.Type == 2 {
  8566. for _, sumItem := range info.HisPrescriptionProject {
  8567. if sumItem.Type == 3 {
  8568. var good models.DialysisBeforePrepareGoods
  8569. var newGood models.NewDialysisBeforePrepareGoods
  8570. good.GoodId = sumItem.GoodInfo.ID
  8571. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8572. count, _ := strconv.Atoi(sumItem.Count)
  8573. good.Count = int64(count)
  8574. good.StorehouseId = houseConfig.StorehouseOutInfo
  8575. good.ProjectId = sumItem.ID
  8576. goods = append(goods, &good)
  8577. newGood.GoodId = sumItem.GoodInfo.ID
  8578. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8579. count2, _ := strconv.Atoi(sumItem.Count)
  8580. newGood.Count = int64(count2)
  8581. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8582. newGood.ProjectId = sumItem.ID
  8583. newGoods = append(newGoods, &newGood)
  8584. }
  8585. }
  8586. }
  8587. }
  8588. for _, info := range prescriptionsOne {
  8589. if info.Type == 1 {
  8590. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  8591. }
  8592. if info.Type == 2 {
  8593. for _, sumItem := range info.HisPrescriptionProject {
  8594. if sumItem.Type == 3 {
  8595. var newGood models.NewDialysisBeforePrepareGoods
  8596. newGood.GoodId = sumItem.GoodInfo.ID
  8597. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8598. count2, _ := strconv.Atoi(sumItem.Count)
  8599. newGood.Count = int64(count2)
  8600. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8601. newGood.ProjectId = sumItem.ID
  8602. newGoodOne = append(newGoodOne, &newGood)
  8603. }
  8604. }
  8605. }
  8606. }
  8607. //判断
  8608. for _, itemOne := range infos {
  8609. for _, itemTwo := range hisAdvice {
  8610. if itemOne.DrugId == itemTwo.DrugId {
  8611. itemTwo.Child = append(itemTwo.Child, itemOne)
  8612. }
  8613. }
  8614. }
  8615. for _, itemTwo := range hisAdvice {
  8616. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  8617. var sum_out_count int64
  8618. for _, itemThree := range itemTwo.Child {
  8619. var prescribing_number int64
  8620. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  8621. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  8622. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  8623. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  8624. }
  8625. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  8626. prescribing_number = parseIntPrescribingNumber
  8627. }
  8628. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  8629. prescribing_number = parseIntPrescribingNumber
  8630. }
  8631. sum_out_count += prescribing_number
  8632. }
  8633. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  8634. if sum_out_count > drugStockOut.FlushCount {
  8635. c.ServeSuccessJSON(map[string]interface{}{
  8636. "msg": "2",
  8637. "drug": medical,
  8638. })
  8639. return
  8640. }
  8641. }
  8642. for _, itemOne := range newGoods {
  8643. for _, item := range newGoodOne {
  8644. if itemOne.GoodId == item.GoodId {
  8645. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  8646. }
  8647. }
  8648. }
  8649. for _, item := range newGoodOne {
  8650. var sum_out_count_one int64
  8651. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  8652. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  8653. sum_out_count_one += itemOne.Count
  8654. }
  8655. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8656. fmt.Println("sum_out_count_one", sum_out_count_one)
  8657. fmt.Println("list.FlushCount", list.FlushCount)
  8658. if sum_out_count_one > list.FlushCount {
  8659. c.ServeSuccessJSON(map[string]interface{}{
  8660. "msg": "3",
  8661. "good": good,
  8662. })
  8663. return
  8664. }
  8665. }
  8666. }
  8667. timestamp := time.Now().Unix()
  8668. tempTime := time.Unix(timestamp, 0)
  8669. timeFormat := tempTime.Format("20060102150405")
  8670. chrgBchno := rand.Intn(100000) + 10000
  8671. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8672. strconv.FormatInt(his.PatientId, 10)
  8673. var ids []int64
  8674. for _, item := range prescriptions {
  8675. ids = append(ids, item.ID)
  8676. }
  8677. var total float64
  8678. for _, item := range prescriptions {
  8679. fmt.Println(item)
  8680. if item.Type == 1 { //药品
  8681. for _, subItem := range item.HisDoctorAdviceInfo {
  8682. total = total + (subItem.Price * subItem.PrescribingNumber)
  8683. }
  8684. }
  8685. if item.Type == 2 { //项目
  8686. for _, subItem := range item.HisPrescriptionProject {
  8687. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8688. total = total + (subItem.Price * cnt)
  8689. }
  8690. }
  8691. for _, subItem := range item.HisAdditionalCharge {
  8692. total = total + (subItem.Price * float64(subItem.Count))
  8693. }
  8694. }
  8695. if reg_type == 1111 || reg_type == 1112 {
  8696. reg_type = 11
  8697. }
  8698. tm := time.Unix(time.Now().Unix(), 0)
  8699. allTotal := fmt.Sprintf("%.4f", total)
  8700. totals, _ := strconv.ParseFloat(allTotal, 64)
  8701. order := &models.HisOrder{
  8702. UserOrgId: adminUser.CurrentOrgId,
  8703. HisPatientId: his.ID,
  8704. PatientId: id,
  8705. SettleAccountsDate: recordDateTime,
  8706. Ctime: time.Now().Unix(),
  8707. Mtime: time.Now().Unix(),
  8708. Status: 1,
  8709. OrderStatus: 2,
  8710. MdtrtId: his.Number,
  8711. Number: chrg_bchno,
  8712. MedfeeSumamt: totals,
  8713. PayWay: pay_way,
  8714. PayWays: pay_ways,
  8715. PayPrice: pay_price,
  8716. MedType: strconv.Itoa(int(reg_type)),
  8717. PayCardNo: pay_card_no,
  8718. DiscountPrice: discount_price,
  8719. PreferentialPrice: preferential_price,
  8720. RealityPrice: reality_price,
  8721. FoundPrice: found_price,
  8722. MedicalInsurancePrice: medical_insurance_price,
  8723. PrivatePrice: private_price,
  8724. SettleEndTime: end_time,
  8725. SettleStartTime: start_time,
  8726. PsnPartAmt: totals,
  8727. PsnCashPay: totals,
  8728. SettleType: settle_accounts_type,
  8729. FaPiaoCode: fapiao_code,
  8730. FaPiaoNumber: fapiao_number,
  8731. Diagnosis: diagnosis_id,
  8732. PType: 2,
  8733. SetlTime: tm.Format("2006-01-02 15:04:05"),
  8734. Decimal: decimal,
  8735. OthDesc: oth_desc,
  8736. CashPay: cash_pay,
  8737. WechatPay: wechat_pay,
  8738. AliPay: ali_pay,
  8739. JifenPay: jifen_pay,
  8740. BandCardPay: band_card_pay,
  8741. Creator: adminUser.AdminUser.Id,
  8742. }
  8743. err = service.CreateOrderTX(order, tx)
  8744. if err != nil {
  8745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8746. return
  8747. }
  8748. var customs []*Custom
  8749. for _, item := range prescriptions {
  8750. if item.Type == 1 { //药品a
  8751. for _, subItem := range item.HisDoctorAdviceInfo {
  8752. cus := &Custom{
  8753. AdviceId: subItem.ID,
  8754. ProjectId: 0,
  8755. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  8756. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  8757. FeedetlSn: subItem.FeedetlSn,
  8758. Price: fmt.Sprintf("%.4f", subItem.Price),
  8759. MedListCodg: subItem.MedListCodg,
  8760. Type: 1,
  8761. }
  8762. customs = append(customs, cus)
  8763. }
  8764. }
  8765. if item.Type == 2 { //项目
  8766. for _, subItem := range item.HisPrescriptionProject {
  8767. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8768. cus := &Custom{
  8769. AdviceId: 0,
  8770. ProjectId: subItem.ID,
  8771. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8772. Cut: fmt.Sprintf("%.4f", cnt),
  8773. FeedetlSn: subItem.FeedetlSn,
  8774. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8775. MedListCodg: subItem.MedListCodg,
  8776. Type: 2,
  8777. }
  8778. customs = append(customs, cus)
  8779. }
  8780. }
  8781. for _, item := range item.HisAdditionalCharge {
  8782. cus := &Custom{
  8783. ItemId: item.ID,
  8784. AdviceId: 0,
  8785. ProjectId: 0,
  8786. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8787. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8788. FeedetlSn: item.FeedetlSn,
  8789. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8790. MedListCodg: item.XtHisAddtionConfig.Code,
  8791. Type: 3,
  8792. }
  8793. customs = append(customs, cus)
  8794. }
  8795. }
  8796. for _, item := range customs {
  8797. var advice_id int64 = 0
  8798. var project_id int64 = 0
  8799. var item_id int64 = 0
  8800. var types int64 = 0
  8801. if item.Type == 1 {
  8802. advice_id = item.AdviceId
  8803. project_id = 0
  8804. item_id = 0
  8805. } else if item.Type == 2 {
  8806. advice_id = 0
  8807. item_id = 0
  8808. project_id = item.ProjectId
  8809. } else if item.Type == 3 {
  8810. advice_id = 0
  8811. item_id = item.ItemId
  8812. project_id = 0
  8813. }
  8814. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8815. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8816. pric, _ := strconv.ParseFloat(item.Price, 32)
  8817. info := &models.HisOrderInfo{
  8818. OrderNumber: order.Number,
  8819. UploadDate: time.Now().Unix(),
  8820. AdviceId: advice_id,
  8821. DetItemFeeSumamt: detItemFeeSumamt,
  8822. Cnt: cut,
  8823. Pric: pric,
  8824. PatientId: id,
  8825. Status: 1,
  8826. Mtime: time.Now().Unix(),
  8827. Ctime: time.Now().Unix(),
  8828. UserOrgId: adminUser.CurrentOrgId,
  8829. HisPatientId: his.ID,
  8830. OrderId: order.ID,
  8831. ProjectId: project_id,
  8832. Type: types,
  8833. ItemId: item_id,
  8834. }
  8835. service.CreateOrderInfoTX(info, tx)
  8836. }
  8837. his.Diagnosis = diagnosis_id
  8838. his.SickType = sick_type
  8839. his.RegisterType = reg_type
  8840. his.MedicalTreatmentType = reg_type
  8841. service.UpdataHisPateintTX(&his, tx)
  8842. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8843. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8844. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8845. //判断是否使用了押金
  8846. if dec_way == "true" {
  8847. tmpstring := strconv.FormatInt(order.ID, 10)
  8848. //扣押金
  8849. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8850. order.Decimal = decimal
  8851. service.UpDateOrderTwo(order, tx)
  8852. if errmsg != nil {
  8853. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8854. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8855. return
  8856. }
  8857. }
  8858. if err == nil {
  8859. for _, info := range prescriptions {
  8860. if info.Type == 1 {
  8861. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8862. }
  8863. if info.Type == 2 {
  8864. for _, sumItem := range info.HisPrescriptionProject {
  8865. if sumItem.Type == 3 {
  8866. var good models.DialysisBeforePrepareGoods
  8867. var newGood models.NewDialysisBeforePrepareGoods
  8868. var oldGood models.OldDialysisBeforePrepareGoods
  8869. good.GoodId = sumItem.GoodInfo.ID
  8870. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8871. count, _ := strconv.Atoi(sumItem.Count)
  8872. good.Count = int64(count)
  8873. good.StorehouseId = houseConfig.StorehouseOutInfo
  8874. good.ProjectId = sumItem.ID
  8875. good.PatientId = sumItem.PatientId
  8876. goods = append(goods, &good)
  8877. newGood.GoodId = sumItem.GoodInfo.ID
  8878. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8879. count2, _ := strconv.Atoi(sumItem.Count)
  8880. newGood.Count = int64(count2)
  8881. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8882. newGood.ProjectId = sumItem.ID
  8883. newGood.PatientId = sumItem.HisPatientId
  8884. newGoods = append(newGoods, &newGood)
  8885. oldGood.GoodId = sumItem.GoodInfo.ID
  8886. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8887. count3, _ := strconv.Atoi(sumItem.Count)
  8888. oldGood.Count = int64(count3)
  8889. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8890. oldGood.ProjectId = sumItem.ID
  8891. oldGood.RecordDate = sumItem.RecordDate
  8892. oldGood.PatientId = sumItem.HisPatientId
  8893. oldGoods = append(oldGoods, &oldGood)
  8894. }
  8895. }
  8896. }
  8897. }
  8898. if settConfig.IsOpen == 1 {
  8899. for _, item := range infoList {
  8900. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8901. if medical.IsUse == 2 {
  8902. //药品出库
  8903. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8904. //查询默认仓库
  8905. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8906. //查询默认仓库剩余多少库存
  8907. var sum_count int64
  8908. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8909. for _, its := range stockInfo {
  8910. if its.MaxUnit == medical.MaxUnit {
  8911. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8912. }
  8913. sum_count += its.StockMaxNumber + its.StockMinNumber
  8914. }
  8915. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8916. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8917. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8918. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8919. }
  8920. }
  8921. orgId := c.GetAdminUserInfo().CurrentOrgId
  8922. if len(oldGoods) > 0 {
  8923. timeStr := time.Now().Format("2006-01-02")
  8924. timeArr := strings.Split(timeStr, "-")
  8925. total, _ := service.FindAllWarehouseOut(orgId)
  8926. total = total + 1
  8927. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8928. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8929. number = number + total
  8930. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8931. operation_time := time.Now().Unix()
  8932. creater := c.GetAdminUserInfo().AdminUser.Id
  8933. //查询默认出库仓库库存
  8934. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8935. recordDateStr := time.Now().Format("2006-01-02")
  8936. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8937. nowtime := recordDate.Unix()
  8938. warehouseOut := models.WarehouseOut{
  8939. WarehouseOutOrderNumber: warehousing_out_order,
  8940. OperationTime: operation_time,
  8941. OrgId: orgId,
  8942. Creater: creater,
  8943. Ctime: time.Now().Unix(),
  8944. Status: 1,
  8945. WarehouseOutTime: nowtime,
  8946. Type: 1,
  8947. StorehouseId: storeConfig.StorehouseOutInfo,
  8948. IsCheck: 1,
  8949. OrderId: order.ID,
  8950. IsSys: 5,
  8951. }
  8952. //查询是否生成出库单
  8953. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8954. if out.ID == 0 {
  8955. service.AddSigleWarehouseOut(&warehouseOut)
  8956. }
  8957. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8958. for _, item := range oldGoods {
  8959. dialyPrepareOne := models.DialysisBeforePrepare{
  8960. GoodTypeId: item.GoodTypeId,
  8961. GoodId: item.GoodId,
  8962. PatientId: his.PatientId,
  8963. RecordDate: item.RecordDate,
  8964. UserOrgId: adminUser.CurrentOrgId,
  8965. Count: item.Count,
  8966. Ctime: time.Now().Unix(),
  8967. Creater: adminUser.AdminUser.Id,
  8968. CommdityCode: item.CommdityCode,
  8969. Status: 1,
  8970. StorehouseId: houseConfig.StorehouseOutInfo,
  8971. }
  8972. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8973. //非零用
  8974. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8975. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8976. //查询剩余库存
  8977. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8978. var sum_count int64
  8979. for _, item := range goodList {
  8980. sum_count += item.StockCount
  8981. }
  8982. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8983. //耗材
  8984. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8985. }
  8986. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8987. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8988. //查询剩余库存
  8989. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8990. var sum_count int64
  8991. for _, item := range goodList {
  8992. sum_count += item.StockCount
  8993. }
  8994. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8995. //耗材
  8996. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8997. }
  8998. }
  8999. }
  9000. }
  9001. c.ServeSuccessJSON(map[string]interface{}{
  9002. "msg": "结算成功",
  9003. })
  9004. }
  9005. }
  9006. }
  9007. // 退款
  9008. func (c *HisApiController) Refund() {
  9009. order_id, _ := c.GetInt64("order_id")
  9010. order, _ := service.GetHisOrderByID(order_id)
  9011. adminUser := c.GetAdminUserInfo()
  9012. orgid := c.GetAdminUserInfo().CurrentOrgId
  9013. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  9014. if err != nil {
  9015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9016. return
  9017. }
  9018. tmp := strconv.FormatInt(order.ID, 10)
  9019. //当押金不为零时产生退费记录
  9020. if order.Decimal != 0 {
  9021. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  9022. if err != nil {
  9023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9024. return
  9025. }
  9026. }
  9027. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  9028. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  9029. var goods []*models.DialysisBeforePrepareGoods
  9030. var newGoods []*models.NewDialysisBeforePrepareGoods
  9031. var infos []*models.HisDoctorAdviceInfo
  9032. for _, info := range orders {
  9033. if info.AdviceId > 0 && info.ProjectId == 0 {
  9034. infos = append(infos, &info.HisDoctorAdviceInfo)
  9035. }
  9036. if info.ProjectId > 0 && info.AdviceId == 0 {
  9037. if info.HisPrescriptionProject.Type == 3 {
  9038. var good models.DialysisBeforePrepareGoods
  9039. var newGood models.NewDialysisBeforePrepareGoods
  9040. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9041. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9042. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9043. good.Count = int64(count)
  9044. good.StorehouseId = houseConfig.StorehouseOutInfo
  9045. good.ProjectId = info.HisPrescriptionProject.ID
  9046. good.PatientId = info.PatientId
  9047. good.OrderId = order_id
  9048. goods = append(goods, &good)
  9049. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  9050. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  9051. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  9052. newGood.Count = int64(count2)
  9053. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  9054. newGood.ProjectId = info.HisPrescriptionProject.ID
  9055. newGood.RecordDate = order.SettleAccountsDate
  9056. newGood.UserOrgId = order.UserOrgId
  9057. newGood.PatientId = info.PatientId
  9058. newGood.OrderId = order_id
  9059. newGoods = append(newGoods, &newGood)
  9060. }
  9061. }
  9062. }
  9063. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  9064. if settConfig.IsOpen == 1 {
  9065. for _, item := range infos {
  9066. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9067. }
  9068. for _, item := range newGoods {
  9069. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  9070. }
  9071. }
  9072. c.ServeSuccessJSON(map[string]interface{}{
  9073. "msg": "退费成功",
  9074. })
  9075. }
  9076. func (c *HisApiController) RefundNumber() {
  9077. his_patient_id, _ := c.GetInt64("id")
  9078. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9079. info.Status = 0
  9080. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  9081. if count > 0 {
  9082. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  9083. return
  9084. }
  9085. err := service.SaveHisPatient(info)
  9086. if err == nil {
  9087. c.ServeSuccessJSON(map[string]interface{}{
  9088. "msg": "退号成功",
  9089. })
  9090. } else {
  9091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9092. return
  9093. }
  9094. }
  9095. func (this *HisApiController) AdditionalCharge() {
  9096. dataBody := make(map[string]interface{}, 0)
  9097. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9098. fmt.Println(err)
  9099. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  9100. patient_id := int64(dataBody["patient_id"].(float64))
  9101. medicineData, _ := dataBody["medicineData"].([]interface{})
  9102. adminUserInfo := this.GetAdminUserInfo()
  9103. orgId := adminUserInfo.CurrentOrgId
  9104. admin_user_id := adminUserInfo.AdminUser.Id
  9105. timeStr := time.Now().Format("2006-01-02")
  9106. timeLayout := "2006-01-02 15:04:05"
  9107. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  9108. timenow := timeStringToTime.Unix()
  9109. var additionalCharges []*models.HisAdditionalCharge
  9110. for _, item := range medicineData {
  9111. var randNum int
  9112. randNum = rand.Intn(10000) + 1000
  9113. timestamp := time.Now().Unix()
  9114. tempTime := time.Unix(timestamp, 0)
  9115. timeFormat := tempTime.Format("20060102150405")
  9116. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  9117. items := item.(map[string]interface{})
  9118. money := items["price"].(string)
  9119. item_id_str := items["item_id"].(string)
  9120. name := items["name"].(string)
  9121. id_str := items["id"].(string)
  9122. moneys, _ := strconv.ParseInt(money, 10, 64)
  9123. monStr := strconv.FormatInt(moneys, 10)
  9124. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  9125. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  9126. id, _ := strconv.ParseInt(id_str, 10, 64)
  9127. additionalCharge := &models.HisAdditionalCharge{
  9128. ID: id,
  9129. HisPatientId: his_patient_id,
  9130. UserOrgId: orgId,
  9131. PatientId: patient_id,
  9132. RecordDate: timenow,
  9133. Price: monneyStr,
  9134. Status: 1,
  9135. ItemName: name,
  9136. ItemId: item_id,
  9137. AdminUserId: admin_user_id,
  9138. CreatedTime: time.Now().Unix(),
  9139. OrderStatus: 0,
  9140. PrescriptionNumber: "",
  9141. BatchNumber: "",
  9142. FeedetlSn: p_number,
  9143. }
  9144. service.CreateAdditionalCharge(additionalCharge)
  9145. additionalCharges = append(additionalCharges, additionalCharge)
  9146. }
  9147. this.ServeSuccessJSON(map[string]interface{}{
  9148. "msg": "添加成功",
  9149. "additional_charges": additionalCharges,
  9150. })
  9151. }
  9152. func (this *HisApiController) DeleteAddition() {
  9153. id, _ := this.GetInt64("id")
  9154. //TODO 需要判断是否已经结算
  9155. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  9156. if err == nil {
  9157. this.ServeSuccessJSON(map[string]interface{}{
  9158. "msg": "删除成功",
  9159. })
  9160. return
  9161. } else {
  9162. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9163. return
  9164. }
  9165. }
  9166. func (this *HisApiController) GetAdminUsers() {
  9167. adminUser := this.GetAdminUserInfo()
  9168. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  9169. this.ServeSuccessJSON(map[string]interface{}{
  9170. "doctors": doctors,
  9171. })
  9172. }
  9173. func (this *HisApiController) GetLastOrNextHisPrescription() {
  9174. change_type, _ := this.GetInt64("type", 0)
  9175. record_date := this.GetString("record_time")
  9176. patient_id, _ := this.GetInt64("patient_id", 0)
  9177. p_type, _ := this.GetInt64("p_type", 0)
  9178. timeLayout := "2006-01-02"
  9179. loc, _ := time.LoadLocation("Local")
  9180. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  9181. record_time := theAdviceRecordTime.Unix()
  9182. adminUserInfo := this.GetAdminUserInfo()
  9183. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  9184. if adminUserInfo.CurrentOrgId == 10265 {
  9185. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9186. if config.ID > 0 && config.IsOpen == 1 {
  9187. for _, subitems := range prescriptions {
  9188. for _, item := range subitems.VMHisPrescription {
  9189. for _, subItem := range item.HisDoctorAdviceInfo {
  9190. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9191. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9192. if info.RetailPrice > 0 {
  9193. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9194. subItem.Drug.RetailPrice = drug.RetailPrice
  9195. }
  9196. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9197. subItem.Drug.MinPrice = info.RetailPrice
  9198. subItem.Drug.RetailPrice = info.RetailPrice
  9199. }
  9200. }
  9201. }
  9202. }
  9203. }
  9204. }
  9205. if config.ID > 0 && config.IsOpen == 1 {
  9206. for _, subitems := range prescriptions {
  9207. for _, item := range subitems.VMHisPrescription {
  9208. for _, subItem := range item.HisPrescriptionProject {
  9209. if subItem.Type == 3 {
  9210. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9211. if info.Price > 0 {
  9212. subItem.GoodInfo.PackingPrice = info.Price
  9213. }
  9214. }
  9215. }
  9216. }
  9217. }
  9218. }
  9219. }
  9220. if err == nil {
  9221. if len(prescriptions) == 0 {
  9222. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  9223. return
  9224. } else {
  9225. this.ServeSuccessJSON(map[string]interface{}{
  9226. "prescriptions": prescriptions,
  9227. })
  9228. return
  9229. }
  9230. } else {
  9231. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9232. return
  9233. }
  9234. }
  9235. func (this *HisApiController) GetCallHisPrescription() {
  9236. patient_id, _ := this.GetInt64("patient_id", 0)
  9237. timeLayout := "2006-01-02"
  9238. loc, _ := time.LoadLocation("Local")
  9239. start_time := this.GetString("start_time")
  9240. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9241. end_time := this.GetString("end_time")
  9242. p_type, _ := this.GetInt64("p_type")
  9243. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9244. adminUserInfo := this.GetAdminUserInfo()
  9245. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  9246. //if
  9247. //storeConfig, _ := service.GetAllStoreHouseConfig(adminUserInfo.CurrentOrgId)
  9248. //
  9249. //lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  9250. if adminUserInfo.CurrentOrgId == 10265 {
  9251. _, config := service.FindHisStockPriceRecordByOrgId(adminUserInfo.CurrentOrgId)
  9252. if config.ID > 0 && config.IsOpen == 1 {
  9253. for _, subitems := range prescriptions {
  9254. for _, item := range subitems.VMHisPrescription {
  9255. for _, subItem := range item.HisDoctorAdviceInfo {
  9256. drug, _ := service.GetDrugByGoodId(subItem.DrugId)
  9257. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, adminUserInfo.CurrentOrgId)
  9258. if info.RetailPrice > 0 {
  9259. if subItem.PrescribingNumberUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  9260. subItem.Drug.RetailPrice = drug.RetailPrice
  9261. }
  9262. if subItem.PrescribingNumberUnit == drug.MinUnit {
  9263. subItem.Drug.MinPrice = info.RetailPrice
  9264. subItem.Drug.RetailPrice = info.RetailPrice
  9265. }
  9266. }
  9267. }
  9268. }
  9269. }
  9270. }
  9271. if config.ID > 0 && config.IsOpen == 1 {
  9272. for _, subitems := range prescriptions {
  9273. for _, item := range subitems.VMHisPrescription {
  9274. for _, subItem := range item.HisPrescriptionProject {
  9275. if subItem.Type == 3 {
  9276. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, adminUserInfo.CurrentOrgId)
  9277. if info.Price > 0 {
  9278. subItem.GoodInfo.PackingPrice = info.Price
  9279. }
  9280. }
  9281. }
  9282. }
  9283. }
  9284. }
  9285. }
  9286. if err == nil {
  9287. this.ServeSuccessJSON(map[string]interface{}{
  9288. "prescriptions": prescriptions,
  9289. })
  9290. return
  9291. } else {
  9292. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9293. return
  9294. }
  9295. }
  9296. func (this *HisApiController) GetHisDayPrescription() {
  9297. timeLayout := "2006-01-02"
  9298. loc, _ := time.LoadLocation("Local")
  9299. start_time := this.GetString("start_time")
  9300. patient_id, _ := this.GetInt64("patient_id", 0)
  9301. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9302. end_time := this.GetString("end_time")
  9303. p_type, _ := this.GetInt64("p_type")
  9304. order_status, _ := this.GetInt64("type")
  9305. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9306. adminUserInfo := this.GetAdminUserInfo()
  9307. var dayHisPrescription []*models.HisPrescription
  9308. var err error
  9309. if order_status == 1 || order_status == 0 {
  9310. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9311. } else if order_status == 2 {
  9312. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  9313. }
  9314. var settle_total float64
  9315. for _, item := range dayHisPrescription {
  9316. if len(item.HisPrescriptionProject) > 0 {
  9317. for _, subItem := range item.HisPrescriptionProject {
  9318. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9319. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9320. settle_total = settle_total + total
  9321. }
  9322. }
  9323. if len(item.HisDoctorAdviceInfo) > 0 {
  9324. for _, subItem := range item.HisDoctorAdviceInfo {
  9325. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9326. settle_total = settle_total + total
  9327. }
  9328. }
  9329. }
  9330. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9331. if err == nil {
  9332. this.ServeSuccessJSON(map[string]interface{}{
  9333. "day_prescription": dayHisPrescription,
  9334. "settle_total": settle_total,
  9335. })
  9336. return
  9337. } else {
  9338. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9339. return
  9340. }
  9341. }
  9342. func (c *HisApiController) GetHisChargePatientList() {
  9343. record_date := c.GetString("record_date")
  9344. order_status, _ := c.GetInt64("type")
  9345. sch_type, _ := c.GetInt64("sch_type")
  9346. timeLayout := "2006-01-02"
  9347. loc, _ := time.LoadLocation("Local")
  9348. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9349. if err != nil {
  9350. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9351. return
  9352. }
  9353. recordDateTime := theTime.Unix()
  9354. adminInfo := c.GetAdminUserInfo()
  9355. var tempPatients []*service.NewTempPatients
  9356. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  9357. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  9358. if order_status != 2 {
  9359. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9360. } else {
  9361. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9362. }
  9363. } else {
  9364. if order_status != 2 {
  9365. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9366. } else {
  9367. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  9368. }
  9369. }
  9370. var patients []*service.NewTempPatients
  9371. var patients_two []*service.NewTempPatients
  9372. for _, item := range tempPatients {
  9373. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  9374. //过滤掉没挂号的和没开处方的
  9375. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  9376. patients = append(patients, item)
  9377. }
  9378. //过滤掉没挂号的
  9379. if len(item.HisPatient) > 0 {
  9380. patients_two = append(patients_two, item)
  9381. }
  9382. } else {
  9383. if len(item.HisPrescription) > 0 {
  9384. patients = append(patients, item)
  9385. }
  9386. }
  9387. }
  9388. c.ServeSuccessJSON(map[string]interface{}{
  9389. "list": patients,
  9390. "list_two": patients_two,
  9391. })
  9392. }
  9393. func (c *HisApiController) GetHisUnRegisterPatientList() {
  9394. record_date := c.GetString("record_date")
  9395. timeLayout := "2006-01-02"
  9396. loc, _ := time.LoadLocation("Local")
  9397. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9398. if err != nil {
  9399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9400. return
  9401. }
  9402. recordDateTime := theTime.Unix()
  9403. adminUser := c.GetAdminUserInfo()
  9404. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  9405. var patients []*service.Patients
  9406. for _, item := range tempPatients {
  9407. if item.HisPatient.ID == 0 {
  9408. patients = append(patients, item)
  9409. }
  9410. }
  9411. c.ServeSuccessJSON(map[string]interface{}{
  9412. "list": patients,
  9413. //"list_two": patients_two,
  9414. })
  9415. }
  9416. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  9417. newArr = make([]*service.Patients, 0)
  9418. for i := 0; i < len(patient); i++ {
  9419. repeat := false
  9420. for j := i + 1; j < len(patient); j++ {
  9421. if patient[i].ID == patient[j].ID {
  9422. repeat = true
  9423. break
  9424. }
  9425. }
  9426. if !repeat {
  9427. newArr = append(newArr, patient[i])
  9428. }
  9429. }
  9430. return
  9431. }
  9432. func (c *HisApiController) GetHisChargePatientInfo() {
  9433. patient_id, _ := c.GetInt64("patient_id")
  9434. his_patient_id, _ := c.GetInt64("his_patient_id")
  9435. record_date := c.GetString("record_date")
  9436. //start_time := c.GetString("start_time")
  9437. //end_time := c.GetString("end_time")
  9438. order_status, _ := c.GetInt64("type", 0)
  9439. p_type, _ := c.GetInt64("p_type", 0)
  9440. order_id, _ := c.GetInt64("order_id", 0)
  9441. timeLayout := "2006-01-02"
  9442. loc, _ := time.LoadLocation("Local")
  9443. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9444. if err != nil {
  9445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9446. return
  9447. }
  9448. recordDateTime := theTime.Unix()
  9449. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9450. //if err != nil {
  9451. //
  9452. //}
  9453. //startRecordDateTime := startTime.Unix()
  9454. //
  9455. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9456. //if err != nil {
  9457. //
  9458. //}
  9459. //endRecordDateTime := endTime.Unix()
  9460. admin := c.GetAdminUserInfo()
  9461. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9462. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9463. var prescriptions []*models.HisPrescription
  9464. //var unChargeMonthPrescriptions []*models.HisPrescription
  9465. order, _ := service.GetHisOrderByID(order_id)
  9466. if order_status == 1 || order_status == 0 {
  9467. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  9468. } else if order_status == 2 {
  9469. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9470. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9471. }
  9472. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9473. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9474. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9475. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9476. //获取所有科室信息
  9477. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9478. sch, _ := service.GetScheduleByDate(c.GetAdminUserInfo().CurrentOrgId, recordDateTime, patient_id)
  9479. c.ServeSuccessJSON(map[string]interface{}{
  9480. "his_info": his_patient_info,
  9481. "xt_info": xt_patient_info,
  9482. "prescription": prescriptions,
  9483. "case_history": case_history,
  9484. "info": patientPrescriptionInfo,
  9485. "last_info": lastPatientPrescriptionInfo,
  9486. "order": order,
  9487. "doctors": doctors,
  9488. "department": department,
  9489. "sch": sch,
  9490. })
  9491. return
  9492. }
  9493. func (c *HisApiController) GetAllOrderDetail() {
  9494. order_id, _ := c.GetInt64("id", 0)
  9495. order, _ := service.GetHisOrderByID(order_id)
  9496. if order.ID == 0 {
  9497. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9498. return
  9499. }
  9500. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9501. org_id := c.GetAdminUserInfo().CurrentOrgId
  9502. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9503. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9504. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9505. c.ServeSuccessJSON(map[string]interface{}{
  9506. "order": order,
  9507. "order_info": order_info,
  9508. "patient": patient,
  9509. "admin_info": adminInfo,
  9510. "hospital_record": record,
  9511. })
  9512. return
  9513. }
  9514. func (c *HisApiController) GetAllOrderDetailCollect() {
  9515. order_id, _ := c.GetInt64("id", 0)
  9516. order, _ := service.GetHisOrderByID(order_id)
  9517. if order.ID == 0 {
  9518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9519. return
  9520. }
  9521. org_id := c.GetAdminUserInfo().CurrentOrgId
  9522. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9523. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9524. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9525. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  9526. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  9527. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9528. var bedCostTotal float64 = 0 //床位总费
  9529. //var bedCostSelfTotal float64 = 0 //床位自费
  9530. var operationCostTotal float64 = 0 //手术费
  9531. //var operationCostSelfTotal float64 = 0 //手术费
  9532. var otherCostTotal float64 = 0 //其他费用
  9533. //var otherCostSelfTotal float64 = 0 //其他费用
  9534. var materialCostTotal float64 = 0 //材料费
  9535. //var materialCostSelfTotal float64 = 0 //材料费
  9536. var westernMedicineCostTotal float64 = 0 //西药费
  9537. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  9538. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9539. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9540. var checkCostTotal float64 = 0 //检查费
  9541. //var checkCostSelfTotal float64 = 0 //检查费
  9542. var laboratoryCostTotal float64 = 0 //化验费
  9543. //var laboratoryCostSelfTotal float64 = 0 //化验费
  9544. var treatCostTotal float64 = 0 //治疗费用
  9545. //var treatCostSelfTotal float64 = 0 //治疗费用
  9546. var zhenChaCostTotal float64 = 0 //其他费用
  9547. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9548. decimal.DivisionPrecision = 2
  9549. var BalanceAccountsType int64
  9550. if his.ID > 0 {
  9551. BalanceAccountsType = his.BalanceAccountsType
  9552. } else {
  9553. BalanceAccountsType = record.BalanceAccountsType
  9554. }
  9555. if BalanceAccountsType != 2 {
  9556. for _, item := range order_info {
  9557. if org_id == 10215 {
  9558. if item.MedChrgitmType == "01" { //床位费
  9559. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9560. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9561. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9562. }
  9563. if item.MedChrgitmType == "02" { //诊察费
  9564. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9565. //zhenChaCostSelfTotal = zhenChaCostTotal
  9566. }
  9567. if item.MedChrgitmType == "03" { //检查费
  9568. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9569. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9570. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9571. }
  9572. //if item.MedChrgitmType == "02" { //检查费
  9573. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9574. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9575. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9576. //}
  9577. if item.MedChrgitmType == "04" { //化验费
  9578. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9579. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9580. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9581. }
  9582. if item.MedChrgitmType == "05" { //治疗费
  9583. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9584. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9585. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9586. }
  9587. if item.MedChrgitmType == "06" { //手术费
  9588. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9589. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9590. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9591. }
  9592. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9593. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9594. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9595. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9596. }
  9597. if item.MedChrgitmType == "09" { //西药费
  9598. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9599. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9600. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9601. }
  9602. if item.MedChrgitmType == "11" { //中成费
  9603. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9604. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9605. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9606. }
  9607. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9608. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9609. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9610. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9611. }
  9612. } else if org_id == 10188 || org_id == 10217 {
  9613. if item.MedChrgitmType == "01" { //床位费
  9614. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9615. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9616. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9617. }
  9618. if item.MedChrgitmType == "02" { //诊察费
  9619. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9620. //zhenChaCostSelfTotal = zhenChaCostTotal
  9621. }
  9622. if item.MedChrgitmType == "03" { //检查费
  9623. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9624. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9625. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9626. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9627. }
  9628. //if item.MedChrgitmType == "02" { //检查费
  9629. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9630. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9631. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9632. //}
  9633. if item.MedChrgitmType == "04" { //化验费
  9634. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9635. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9636. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9637. }
  9638. if item.MedChrgitmType == "05" { //治疗费
  9639. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9640. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9641. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9642. }
  9643. if item.MedChrgitmType == "06" { //手术费
  9644. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9645. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9646. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9647. }
  9648. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9649. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9650. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9651. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9652. }
  9653. if item.MedChrgitmType == "09" { //西药费
  9654. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9655. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9656. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9657. }
  9658. if item.MedChrgitmType == "11" { //中成费
  9659. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9660. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9661. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9662. }
  9663. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9664. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9665. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9666. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9667. }
  9668. } else {
  9669. if item.MedChrgitmType == "01" { //床位费
  9670. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9671. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9672. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9673. }
  9674. //if item.MedChrgitmType == "02" { //诊察费
  9675. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9676. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9677. //}
  9678. if item.MedChrgitmType == "03" { //检查费
  9679. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9680. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9681. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9682. }
  9683. //if item.MedChrgitmType == "02" { //检查费
  9684. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9685. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9686. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9687. //}
  9688. if item.MedChrgitmType == "04" { //化验费
  9689. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9690. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9691. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9692. }
  9693. if item.MedChrgitmType == "05" { //治疗费
  9694. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9695. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9696. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9697. }
  9698. if item.MedChrgitmType == "06" { //手术费
  9699. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9700. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9701. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9702. }
  9703. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9704. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9705. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9706. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9707. }
  9708. if item.MedChrgitmType == "09" { //西药费
  9709. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9710. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9711. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9712. }
  9713. if item.MedChrgitmType == "11" { //中成费
  9714. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9715. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9716. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9717. }
  9718. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9719. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9720. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9721. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9722. }
  9723. }
  9724. }
  9725. c.ServeSuccessJSON(map[string]interface{}{
  9726. "order": order,
  9727. "order_info": order_info,
  9728. "patient": patient,
  9729. "admin_info": adminInfo,
  9730. "his_hospital": record,
  9731. "bedCostTotal": bedCostTotal,
  9732. "operationCostTotal": operationCostTotal,
  9733. "otherCostTotal": otherCostTotal,
  9734. "materialCostTotal": materialCostTotal,
  9735. "westernMedicineCostTotal": westernMedicineCostTotal,
  9736. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9737. "checkCostTotal": checkCostTotal,
  9738. "zhenChaCostTotal": zhenChaCostTotal,
  9739. "laboratoryCostTotal": laboratoryCostTotal,
  9740. "treatCostTotal": treatCostTotal,
  9741. })
  9742. } else {
  9743. for _, item := range order_info {
  9744. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9745. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9746. item.MedChrgitmType = "09"
  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. break
  9761. case 3:
  9762. item.MedChrgitmType = "03"
  9763. break
  9764. case 4:
  9765. item.MedChrgitmType = "03"
  9766. break
  9767. case 5:
  9768. item.MedChrgitmType = "08"
  9769. break
  9770. case 6:
  9771. item.MedChrgitmType = "14"
  9772. break
  9773. case 7:
  9774. item.MedChrgitmType = "14"
  9775. break
  9776. case 8:
  9777. item.MedChrgitmType = "03"
  9778. break
  9779. case 9:
  9780. item.MedChrgitmType = "14"
  9781. break
  9782. case 10:
  9783. item.MedChrgitmType = "14"
  9784. break
  9785. case 11:
  9786. item.MedChrgitmType = "06"
  9787. break
  9788. case 12:
  9789. item.MedChrgitmType = "12"
  9790. break
  9791. case 13:
  9792. item.MedChrgitmType = "01"
  9793. break
  9794. case 14:
  9795. item.MedChrgitmType = "04"
  9796. break
  9797. case 15:
  9798. item.MedChrgitmType = "14"
  9799. break
  9800. }
  9801. } else {
  9802. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9803. case 1:
  9804. item.MedChrgitmType = "14"
  9805. break
  9806. case 2:
  9807. item.MedChrgitmType = "05"
  9808. break
  9809. case 3:
  9810. item.MedChrgitmType = "04"
  9811. break
  9812. case 4:
  9813. item.MedChrgitmType = "14"
  9814. break
  9815. case 5:
  9816. item.MedChrgitmType = "08"
  9817. break
  9818. case 6:
  9819. item.MedChrgitmType = "14"
  9820. break
  9821. case 7:
  9822. item.MedChrgitmType = "14"
  9823. break
  9824. case 8:
  9825. item.MedChrgitmType = "03"
  9826. break
  9827. case 9:
  9828. item.MedChrgitmType = "14"
  9829. break
  9830. }
  9831. }
  9832. } else if item.HisPrescriptionProject.Type == 3 {
  9833. item.MedChrgitmType = "08"
  9834. }
  9835. }
  9836. }
  9837. for _, item := range order_info {
  9838. if org_id == 10215 {
  9839. if item.MedChrgitmType == "01" { //床位费
  9840. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9841. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9842. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9843. }
  9844. if item.MedChrgitmType == "02" { //诊察费
  9845. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9846. //zhenChaCostSelfTotal = zhenChaCostTotal
  9847. }
  9848. if item.MedChrgitmType == "03" { //检查费
  9849. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9850. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9851. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9852. }
  9853. //if item.MedChrgitmType == "02" { //检查费
  9854. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9855. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9856. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9857. //}
  9858. if item.MedChrgitmType == "04" { //化验费
  9859. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9860. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9861. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9862. }
  9863. if item.MedChrgitmType == "05" { //治疗费
  9864. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9865. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9866. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9867. }
  9868. if item.MedChrgitmType == "06" { //手术费
  9869. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9870. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9871. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9872. }
  9873. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9874. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9875. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9876. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9877. }
  9878. if item.MedChrgitmType == "09" { //西药费
  9879. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9880. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9881. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9882. }
  9883. if item.MedChrgitmType == "11" { //中成费
  9884. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9885. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9886. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9887. }
  9888. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9889. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9890. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9891. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9892. }
  9893. } else {
  9894. if item.MedChrgitmType == "01" { //床位费
  9895. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9896. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9897. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9898. }
  9899. //if item.MedChrgitmType == "02" { //诊察费
  9900. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9901. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9902. //}
  9903. if item.MedChrgitmType == "03" { //检查费
  9904. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9905. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9906. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9907. }
  9908. //if item.MedChrgitmType == "02" { //检查费
  9909. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9910. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9911. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9912. //}
  9913. if item.MedChrgitmType == "04" { //化验费
  9914. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9915. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9916. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9917. }
  9918. if item.MedChrgitmType == "05" { //治疗费
  9919. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9920. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9921. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9922. }
  9923. if item.MedChrgitmType == "06" { //手术费
  9924. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9925. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9926. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9927. }
  9928. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9929. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9930. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9931. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9932. }
  9933. if item.MedChrgitmType == "09" { //西药费
  9934. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9935. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9936. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9937. }
  9938. if item.MedChrgitmType == "11" { //中成费
  9939. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9940. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9941. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9942. }
  9943. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9944. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9945. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9946. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9947. }
  9948. }
  9949. }
  9950. c.ServeSuccessJSON(map[string]interface{}{
  9951. "order": order,
  9952. "order_info": order_info,
  9953. "patient": patient,
  9954. "admin_info": adminInfo,
  9955. "his_hospital": record,
  9956. "bedCostTotal": bedCostTotal,
  9957. "operationCostTotal": operationCostTotal,
  9958. "otherCostTotal": otherCostTotal,
  9959. "materialCostTotal": materialCostTotal,
  9960. "westernMedicineCostTotal": westernMedicineCostTotal,
  9961. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9962. "checkCostTotal": checkCostTotal,
  9963. "zhenChaCostTotal": zhenChaCostTotal,
  9964. "laboratoryCostTotal": laboratoryCostTotal,
  9965. "treatCostTotal": treatCostTotal,
  9966. })
  9967. }
  9968. }
  9969. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9970. page, _ := c.GetInt64("page")
  9971. limit, _ := c.GetInt64("limit")
  9972. keywords := c.GetString("keywords")
  9973. start_time := c.GetString("start_time")
  9974. end_time := c.GetString("end_time")
  9975. //clr_type := c.GetString("clr_type")
  9976. insutype := c.GetString("insutype")
  9977. timeLayout := "2006-01-02"
  9978. loc, _ := time.LoadLocation("Local")
  9979. var theStartTIme int64
  9980. if len(start_time) > 0 {
  9981. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9982. theStartTIme = theTime.Unix()
  9983. }
  9984. var theEndtTIme int64
  9985. if len(end_time) > 0 {
  9986. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9987. theEndtTIme = theTime.Unix()
  9988. }
  9989. if page <= 0 {
  9990. page = 1
  9991. }
  9992. if limit <= 0 {
  9993. limit = 10
  9994. }
  9995. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9996. c.ServeSuccessJSON(map[string]interface{}{
  9997. "total": total,
  9998. "list": list,
  9999. })
  10000. return
  10001. }
  10002. func (c *HisApiController) GetPutOnRecordList() {
  10003. page, _ := c.GetInt64("page")
  10004. limit, _ := c.GetInt64("limit")
  10005. keywords := c.GetString("keywords")
  10006. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  10007. if page <= 0 {
  10008. page = 1
  10009. }
  10010. if limit <= 0 {
  10011. limit = 10
  10012. }
  10013. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  10014. c.ServeSuccessJSON(map[string]interface{}{
  10015. "total": total,
  10016. "list": list,
  10017. })
  10018. return
  10019. }
  10020. func (c *HisApiController) GetCompareData() {
  10021. start_time := c.GetString("start_time")
  10022. end_time := c.GetString("end_time")
  10023. insutype := c.GetString("insutype")
  10024. clr_type := c.GetString("clr_type")
  10025. timeLayout := "2006-01-02"
  10026. loc, _ := time.LoadLocation("Local")
  10027. var theStartTIme int64
  10028. if len(start_time) > 0 {
  10029. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10030. if err != nil {
  10031. theStartTIme = 0
  10032. }
  10033. theStartTIme = theTime.Unix()
  10034. }
  10035. var theEndtTIme int64
  10036. if len(end_time) > 0 {
  10037. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10038. if err != nil {
  10039. theEndtTIme = 0
  10040. }
  10041. theEndtTIme = theTime.Unix()
  10042. }
  10043. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  10044. fmt.Println(err)
  10045. if err == nil {
  10046. c.ServeSuccessJSON(map[string]interface{}{
  10047. "list": formData,
  10048. })
  10049. } else {
  10050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  10051. return
  10052. }
  10053. }
  10054. func (c *HisApiController) GetFaPiaoData() {
  10055. order_id, _ := c.GetInt64("order_id")
  10056. patient_id, _ := c.GetInt64("patient_id")
  10057. //number := c.GetString("number")
  10058. adminUser := c.GetAdminUserInfo()
  10059. order, _ := service.GetHisOrderByID(order_id)
  10060. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10061. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10062. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10063. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10064. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  10065. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  10066. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10067. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10068. var bedCostTotal float64 = 0 //床位总费
  10069. var bedCostSelfTotal float64 = 0 //床位自费
  10070. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10071. var operationCostTotal float64 = 0 //手术费
  10072. var operationCostSelfTotal float64 = 0 //手术费
  10073. var operationCostPartSelfTotal float64 = 0 //手术费
  10074. var otherCostTotal float64 = 0 //其他费用
  10075. var otherCostSelfTotal float64 = 0 //其他费用
  10076. var otherCostPartSelfTotal float64 = 0 //其他费用
  10077. var materialCostTotal float64 = 0 //材料费
  10078. var materialCostSelfTotal float64 = 0 //材料费
  10079. var materialCostPartSelfTotal float64 = 0 //材料费
  10080. var westernMedicineCostTotal float64 = 0 //西药费
  10081. var westernMedicineCostSelfTotal float64 = 0 //西药费
  10082. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10083. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10084. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10085. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10086. var checkCostTotal float64 = 0 //检查费
  10087. var checkCostSelfTotal float64 = 0 //检查费
  10088. var checkCostPartSelfTotal float64 = 0 //检查费
  10089. var hiliCostTotal float64 = 0 //护理费
  10090. var hiliCostSelfTotal float64 = 0 //护理费
  10091. var hiliCostPartSelfTotal float64 = 0 //护理费
  10092. var laboratoryCostTotal float64 = 0 //化验费
  10093. var laboratoryCostSelfTotal float64 = 0 //化验费
  10094. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10095. var treatCostTotal float64 = 0 //治疗费用
  10096. var treatCostSelfTotal float64 = 0 //治疗费用
  10097. var treatCostPartSelfTotal float64 = 0 //治疗费用
  10098. var zhenChaCostTotal float64 = 0 //其他费用
  10099. var zhenChaCostSelfTotal float64 = 0 //其他费用
  10100. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10101. decimal.DivisionPrecision = 2
  10102. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10103. var balanceAccountsType int64
  10104. if his.ID > 0 {
  10105. balanceAccountsType = his.BalanceAccountsType
  10106. } else {
  10107. balanceAccountsType = his_hospital_record.BalanceAccountsType
  10108. }
  10109. if balanceAccountsType == 2 {
  10110. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10111. for _, item := range orderInfos_two {
  10112. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10113. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10114. item.MedChrgitmType = "09"
  10115. }
  10116. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10117. if item.HisPrescriptionProject.Type == 2 {
  10118. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10119. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10120. case 0:
  10121. item.MedChrgitmType = "0"
  10122. break
  10123. case 1:
  10124. item.MedChrgitmType = "14"
  10125. break
  10126. case 2:
  10127. item.MedChrgitmType = "05"
  10128. break
  10129. case 3:
  10130. item.MedChrgitmType = "03"
  10131. break
  10132. case 4:
  10133. item.MedChrgitmType = "03"
  10134. break
  10135. case 5:
  10136. item.MedChrgitmType = "08"
  10137. break
  10138. case 6:
  10139. item.MedChrgitmType = "14"
  10140. break
  10141. case 7:
  10142. item.MedChrgitmType = "14"
  10143. break
  10144. case 8:
  10145. item.MedChrgitmType = "03"
  10146. break
  10147. case 9:
  10148. item.MedChrgitmType = "14"
  10149. break
  10150. case 10:
  10151. item.MedChrgitmType = "14"
  10152. break
  10153. case 11:
  10154. item.MedChrgitmType = "06"
  10155. break
  10156. case 12:
  10157. item.MedChrgitmType = "12"
  10158. break
  10159. case 13:
  10160. item.MedChrgitmType = "01"
  10161. break
  10162. case 14:
  10163. item.MedChrgitmType = "04"
  10164. break
  10165. case 15:
  10166. item.MedChrgitmType = "02"
  10167. break
  10168. }
  10169. } else {
  10170. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10171. case 1:
  10172. item.MedChrgitmType = "14"
  10173. break
  10174. case 2:
  10175. item.MedChrgitmType = "05"
  10176. break
  10177. case 3:
  10178. item.MedChrgitmType = "04"
  10179. break
  10180. case 4:
  10181. item.MedChrgitmType = "03"
  10182. break
  10183. case 5:
  10184. item.MedChrgitmType = "08"
  10185. break
  10186. case 6:
  10187. item.MedChrgitmType = "14"
  10188. break
  10189. case 7:
  10190. item.MedChrgitmType = "14"
  10191. break
  10192. case 8:
  10193. item.MedChrgitmType = "03"
  10194. break
  10195. case 9:
  10196. item.MedChrgitmType = "14"
  10197. break
  10198. }
  10199. }
  10200. } else if item.HisPrescriptionProject.Type == 3 {
  10201. item.MedChrgitmType = "08"
  10202. }
  10203. }
  10204. }
  10205. for _, item := range orderInfos_two {
  10206. fmt.Println(item.MedChrgitmType)
  10207. if item.MedChrgitmType == "07" { //床位费
  10208. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10209. hiliCostSelfTotal = hiliCostTotal
  10210. }
  10211. if item.MedChrgitmType == "01" { //床位费
  10212. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10213. bedCostSelfTotal = bedCostTotal
  10214. }
  10215. if item.MedChrgitmType == "02" { //诊察费
  10216. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10217. zhenChaCostSelfTotal = zhenChaCostTotal
  10218. }
  10219. if item.MedChrgitmType == "03" { //检查费
  10220. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10221. checkCostSelfTotal = checkCostTotal
  10222. }
  10223. if item.MedChrgitmType == "04" { //化验费
  10224. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10225. laboratoryCostSelfTotal = laboratoryCostTotal
  10226. }
  10227. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10228. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10229. treatCostSelfTotal = treatCostTotal
  10230. }
  10231. if item.MedChrgitmType == "06" { //手术费
  10232. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10233. operationCostSelfTotal = treatCostTotal
  10234. }
  10235. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  10236. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10237. materialCostSelfTotal = materialCostTotal
  10238. }
  10239. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10240. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10241. westernMedicineCostSelfTotal = westernMedicineCostTotal
  10242. }
  10243. if item.MedChrgitmType == "11" { //中成费
  10244. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10245. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10246. }
  10247. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10248. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10249. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10250. otherCostSelfTotal = otherCostTotal
  10251. }
  10252. } else {
  10253. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10254. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10255. otherCostSelfTotal = otherCostTotal
  10256. }
  10257. }
  10258. }
  10259. } else {
  10260. for _, item := range orderInfos {
  10261. if item.MedChrgitmType == "01" { //床位费
  10262. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10263. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10264. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10265. }
  10266. if item.MedChrgitmType == "02" { //诊察费
  10267. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10268. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10269. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10270. }
  10271. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10272. if item.MedChrgitmType == "03" { //检查费
  10273. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10274. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10275. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10276. }
  10277. } else {
  10278. if item.MedChrgitmType == "03" { //检查费
  10279. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10280. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10281. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10282. }
  10283. }
  10284. if item.MedChrgitmType == "04" { //化验费
  10285. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10286. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10287. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10288. }
  10289. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  10290. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10291. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10292. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10293. }
  10294. if item.MedChrgitmType == "06" { //手术费
  10295. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10296. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10297. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10298. }
  10299. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  10300. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10301. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10302. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10303. }
  10304. if item.MedChrgitmType == "07" { //护理
  10305. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10306. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10307. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10308. }
  10309. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  10310. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10311. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10312. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10313. }
  10314. if item.MedChrgitmType == "11" { //中成费
  10315. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10316. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10317. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10318. }
  10319. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10320. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10321. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10322. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10323. }
  10324. }
  10325. }
  10326. timeLayout := "2006-01-02"
  10327. loc, _ := time.LoadLocation("Local")
  10328. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10329. if err != nil {
  10330. }
  10331. startRecordDateTime := startTime.Unix()
  10332. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10333. if err != nil {
  10334. }
  10335. endRecordDateTime := endTime.Unix()
  10336. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10337. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10338. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10339. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  10340. c.ServeSuccessJSON(map[string]interface{}{
  10341. "charge_admin_name": charge_admin.UserName,
  10342. "order_number": order.Number, //业务流水号
  10343. "id_card_no": his.IdCardNo, //社会保障号
  10344. "patient": patient,
  10345. "department_name": department.Name, //科室
  10346. "number": his.Number, //门诊号
  10347. "date": order.SettleAccountsDate, //结算日期
  10348. "name": order.PsnName, //姓名
  10349. "gender": patient.Gender, //性别
  10350. "psn_cash_money": order.PsnCashPay, //个人支付
  10351. "pay_way": "门诊", //结算方式
  10352. "medfee_sumamt": order.MedfeeSumamt, //总费用
  10353. "admin_user_name": admin.UserName, //收款员
  10354. "order": order,
  10355. "order_info": orderInfos_two,
  10356. "his": his,
  10357. "bedCostTotal": bedCostTotal,
  10358. "bedCostSelfTotal": bedCostSelfTotal,
  10359. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10360. "operationCostTotal": operationCostTotal,
  10361. "operationCostSelfTotal": operationCostSelfTotal,
  10362. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10363. "otherCostTotal": otherCostTotal,
  10364. "otherCostSelfTotal": otherCostSelfTotal,
  10365. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10366. "materialCostTotal": materialCostTotal,
  10367. "materialCostSelfTotal": materialCostSelfTotal,
  10368. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10369. "westernMedicineCostTotal": westernMedicineCostTotal,
  10370. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10371. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10372. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10373. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10374. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10375. "checkCostTotal": checkCostTotal,
  10376. "checkCostSelfTotal": checkCostSelfTotal,
  10377. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10378. "laboratoryCostTotal": laboratoryCostTotal,
  10379. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10380. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10381. "treatCostTotal": treatCostTotal,
  10382. "treatCostSelfTotal": treatCostSelfTotal,
  10383. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10384. "zhenChaCostTotal": zhenChaCostTotal,
  10385. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10386. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10387. "his_hospital_record": his_hospital_record,
  10388. "pre_pay_money": pre_pay_money,
  10389. "refund_sum": sum,
  10390. "doctor_info": doctor_info,
  10391. "hiliCostTotal": hiliCostTotal,
  10392. "hiliCostSelfTotal": hiliCostSelfTotal,
  10393. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  10394. })
  10395. }
  10396. //func (c *HisApiController) GetFaPiaoDatas() {
  10397. // order_ids := c.GetString("order_ids")
  10398. // patient_id, _ := c.GetInt64("patient_id")
  10399. // adminUser := c.GetAdminUserInfo()
  10400. //
  10401. // orders := strings.Split(order_ids, ",")
  10402. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  10403. //
  10404. // for _, item := range orders {
  10405. // order_id, _ := strconv.ParseInt(item, 10, 64)
  10406. // order, _ := service.GetHisOrderByID(order_id)
  10407. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  10408. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  10409. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  10410. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  10411. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  10412. //
  10413. // }
  10414. //
  10415. // var bedCostTotal float64 = 0 //床位总费
  10416. // var bedCostSelfTotal float64 = 0 //床位自费
  10417. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  10418. //
  10419. // var operationCostTotal float64 = 0 //手术费
  10420. // var operationCostSelfTotal float64 = 0 //手术费
  10421. // var operationCostPartSelfTotal float64 = 0 //手术费
  10422. //
  10423. // var otherCostTotal float64 = 0 //其他费用
  10424. // var otherCostSelfTotal float64 = 0 //其他费用
  10425. // var otherCostPartSelfTotal float64 = 0 //其他费用
  10426. //
  10427. // var materialCostTotal float64 = 0 //材料费
  10428. // var materialCostSelfTotal float64 = 0 //材料费
  10429. // var materialCostPartSelfTotal float64 = 0 //材料费
  10430. //
  10431. // var westernMedicineCostTotal float64 = 0 //西药费
  10432. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  10433. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  10434. //
  10435. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  10436. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  10437. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  10438. //
  10439. // var checkCostTotal float64 = 0 //检查费
  10440. // var checkCostSelfTotal float64 = 0 //检查费
  10441. // var checkCostPartSelfTotal float64 = 0 //检查费
  10442. //
  10443. // var laboratoryCostTotal float64 = 0 //化验费
  10444. // var laboratoryCostSelfTotal float64 = 0 //化验费
  10445. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  10446. //
  10447. // var treatCostTotal float64 = 0 //治疗费用
  10448. // var treatCostSelfTotal float64 = 0 //治疗费用
  10449. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  10450. //
  10451. // var zhenChaCostTotal float64 = 0 //其他费用
  10452. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  10453. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  10454. //
  10455. // decimal.DivisionPrecision = 2
  10456. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10457. //
  10458. // var balanceAccountsType int64
  10459. // if his.ID > 0 {
  10460. // balanceAccountsType = his.BalanceAccountsType
  10461. // } else {
  10462. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  10463. // }
  10464. // if balanceAccountsType == 2 {
  10465. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  10466. // for _, item := range orderInfos_two {
  10467. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  10468. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  10469. // item.MedChrgitmType = "09"
  10470. // }
  10471. //
  10472. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  10473. // if item.HisPrescriptionProject.Type == 2 {
  10474. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  10475. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10476. // case 0:
  10477. // item.MedChrgitmType = "0"
  10478. // break
  10479. // case 1:
  10480. // item.MedChrgitmType = "14"
  10481. // break
  10482. // case 2:
  10483. // item.MedChrgitmType = "05"
  10484. //
  10485. // break
  10486. // case 3:
  10487. // item.MedChrgitmType = "03"
  10488. //
  10489. // break
  10490. // case 4:
  10491. // item.MedChrgitmType = "03"
  10492. //
  10493. // break
  10494. // case 5:
  10495. // item.MedChrgitmType = "08"
  10496. //
  10497. // break
  10498. // case 6:
  10499. // item.MedChrgitmType = "14"
  10500. //
  10501. // break
  10502. // case 7:
  10503. // item.MedChrgitmType = "14"
  10504. //
  10505. // break
  10506. // case 8:
  10507. // item.MedChrgitmType = "03"
  10508. // break
  10509. // case 9:
  10510. // item.MedChrgitmType = "14"
  10511. // break
  10512. // case 10:
  10513. // item.MedChrgitmType = "14"
  10514. // break
  10515. // case 11:
  10516. // item.MedChrgitmType = "06"
  10517. // break
  10518. // case 12:
  10519. // item.MedChrgitmType = "12"
  10520. // break
  10521. // case 13:
  10522. // item.MedChrgitmType = "01"
  10523. // break
  10524. // case 14:
  10525. // item.MedChrgitmType = "04"
  10526. // break
  10527. // case 15:
  10528. // item.MedChrgitmType = "02"
  10529. // break
  10530. //
  10531. // }
  10532. //
  10533. // } else {
  10534. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  10535. //
  10536. // case 1:
  10537. // item.MedChrgitmType = "14"
  10538. // break
  10539. // case 2:
  10540. // item.MedChrgitmType = "05"
  10541. //
  10542. // break
  10543. // case 3:
  10544. // item.MedChrgitmType = "03"
  10545. //
  10546. // break
  10547. // case 4:
  10548. // item.MedChrgitmType = "03"
  10549. //
  10550. // break
  10551. // case 5:
  10552. // item.MedChrgitmType = "08"
  10553. //
  10554. // break
  10555. // case 6:
  10556. // item.MedChrgitmType = "14"
  10557. //
  10558. // break
  10559. // case 7:
  10560. // item.MedChrgitmType = "14"
  10561. //
  10562. // break
  10563. // case 8:
  10564. // item.MedChrgitmType = "03"
  10565. // break
  10566. // case 9:
  10567. // item.MedChrgitmType = "14"
  10568. // break
  10569. //
  10570. // }
  10571. //
  10572. // }
  10573. //
  10574. // } else if item.HisPrescriptionProject.Type == 3 {
  10575. // item.MedChrgitmType = "08"
  10576. // }
  10577. // }
  10578. // }
  10579. //
  10580. // for _, item := range orderInfos_two {
  10581. // fmt.Println(item.MedChrgitmType)
  10582. // if item.MedChrgitmType == "01" { //床位费
  10583. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10584. // bedCostSelfTotal = bedCostTotal
  10585. // }
  10586. //
  10587. // if item.MedChrgitmType == "02" { //诊察费
  10588. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10589. // zhenChaCostSelfTotal = zhenChaCostTotal
  10590. // }
  10591. //
  10592. // if item.MedChrgitmType == "03" { //检查费
  10593. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10594. // checkCostSelfTotal = checkCostTotal
  10595. // }
  10596. //
  10597. // if item.MedChrgitmType == "04" { //化验费
  10598. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10599. // laboratoryCostSelfTotal = laboratoryCostTotal
  10600. // }
  10601. //
  10602. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  10603. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10604. // treatCostSelfTotal = treatCostTotal
  10605. // }
  10606. //
  10607. // if item.MedChrgitmType == "06" { //手术费
  10608. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10609. // operationCostSelfTotal = treatCostTotal
  10610. // }
  10611. //
  10612. // if item.MedChrgitmType == "08" { //材料费
  10613. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10614. // materialCostSelfTotal = materialCostTotal
  10615. // }
  10616. //
  10617. // if item.MedChrgitmType == "09" { //西药费
  10618. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10619. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  10620. // }
  10621. //
  10622. // if item.MedChrgitmType == "11" { //中成费
  10623. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10624. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  10625. // }
  10626. //
  10627. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  10628. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  10629. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10630. // otherCostSelfTotal = otherCostTotal
  10631. // }
  10632. // } else {
  10633. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10634. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10635. // otherCostSelfTotal = otherCostTotal
  10636. // }
  10637. //
  10638. // }
  10639. //
  10640. // }
  10641. //
  10642. // } else {
  10643. // for _, item := range orderInfos {
  10644. // if item.MedChrgitmType == "01" { //床位费
  10645. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10646. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10647. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10648. // }
  10649. //
  10650. // if item.MedChrgitmType == "02" { //诊察费
  10651. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10652. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10653. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10654. // }
  10655. //
  10656. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  10657. // if item.MedChrgitmType == "03" { //检查费
  10658. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10659. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10660. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10661. //
  10662. // }
  10663. // } else {
  10664. // if item.MedChrgitmType == "03" { //检查费
  10665. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10666. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10667. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10668. // }
  10669. //
  10670. // }
  10671. //
  10672. // if item.MedChrgitmType == "04" { //化验费
  10673. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10674. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10675. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10676. //
  10677. // }
  10678. //
  10679. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  10680. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10681. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10682. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10683. //
  10684. // }
  10685. //
  10686. // if item.MedChrgitmType == "06" { //手术费
  10687. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10688. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10689. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10690. // }
  10691. //
  10692. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  10693. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10694. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10695. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10696. // }
  10697. //
  10698. // if item.MedChrgitmType == "09" { //西药费
  10699. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10700. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10701. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10702. // }
  10703. //
  10704. // if item.MedChrgitmType == "11" { //中成费
  10705. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10706. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10707. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10708. // }
  10709. //
  10710. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  10711. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  10712. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  10713. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  10714. // }
  10715. //
  10716. // }
  10717. // }
  10718. // timeLayout := "2006-01-02"
  10719. // loc, _ := time.LoadLocation("Local")
  10720. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  10721. // if err != nil {
  10722. // }
  10723. // startRecordDateTime := startTime.Unix()
  10724. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  10725. // if err != nil {
  10726. // }
  10727. // endRecordDateTime := endTime.Unix()
  10728. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  10729. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  10730. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  10731. //
  10732. // c.ServeSuccessJSON(map[string]interface{}{
  10733. // "order_number": order.Number, //业务流水号
  10734. // "id_card_no": his.IdCardNo, //社会保障号
  10735. // "department_name": department.Name, //科室
  10736. // "number": his.Number, //门诊号
  10737. // "date": order.SettleAccountsDate, //结算日期
  10738. // "name": order.PsnName, //姓名
  10739. // "gender": patient.Gender, //性别
  10740. // "psn_cash_money": order.PsnCashPay, //个人支付
  10741. // "pay_way": "门诊", //结算方式
  10742. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  10743. // "admin_user_name": admin.UserName, //收款员
  10744. // "order": order,
  10745. // "order_info": orderInfos_two,
  10746. // "his": his,
  10747. // "bedCostTotal": bedCostTotal,
  10748. // "bedCostSelfTotal": bedCostSelfTotal,
  10749. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  10750. // "operationCostTotal": operationCostTotal,
  10751. // "operationCostSelfTotal": operationCostSelfTotal,
  10752. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  10753. // "otherCostTotal": otherCostTotal,
  10754. // "otherCostSelfTotal": otherCostSelfTotal,
  10755. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  10756. // "materialCostTotal": materialCostTotal,
  10757. // "materialCostSelfTotal": materialCostSelfTotal,
  10758. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  10759. // "westernMedicineCostTotal": westernMedicineCostTotal,
  10760. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  10761. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  10762. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  10763. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  10764. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  10765. // "checkCostTotal": checkCostTotal,
  10766. // "checkCostSelfTotal": checkCostSelfTotal,
  10767. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  10768. // "laboratoryCostTotal": laboratoryCostTotal,
  10769. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  10770. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  10771. // "treatCostTotal": treatCostTotal,
  10772. // "treatCostSelfTotal": treatCostSelfTotal,
  10773. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  10774. // "zhenChaCostTotal": zhenChaCostTotal,
  10775. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  10776. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  10777. // "his_hospital_record": his_hospital_record,
  10778. // "pre_pay_money": pre_pay_money,
  10779. // "refund_sum": sum,
  10780. // })
  10781. //
  10782. //}
  10783. func (this *HisApiController) GetIncomeStatisticsData() {
  10784. start_time := this.GetString("start_time")
  10785. end_time := this.GetString("end_time")
  10786. key_words := this.GetString("key_words")
  10787. limit, _ := this.GetInt64("limit")
  10788. page, _ := this.GetInt64("page")
  10789. if page <= 0 {
  10790. page = 1
  10791. }
  10792. if limit <= 0 {
  10793. limit = 10
  10794. }
  10795. statistics_type, _ := this.GetInt64("statistics_type")
  10796. admin := this.GetAdminUserInfo()
  10797. timeLayout := "2006-01-02"
  10798. loc, _ := time.LoadLocation("Local")
  10799. var theStartTIme int64
  10800. if len(start_time) > 0 {
  10801. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10802. if err != nil {
  10803. theStartTIme = 0
  10804. }
  10805. theStartTIme = theTime.Unix()
  10806. }
  10807. var theEndtTIme int64
  10808. if len(end_time) > 0 {
  10809. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10810. if err != nil {
  10811. theEndtTIme = 0
  10812. }
  10813. theEndtTIme = theTime.Unix()
  10814. }
  10815. if statistics_type == 1 {
  10816. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10817. this.ServeSuccessJSON(map[string]interface{}{
  10818. "list": list,
  10819. "total": total,
  10820. })
  10821. } else {
  10822. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  10823. this.ServeSuccessJSON(map[string]interface{}{
  10824. "list": list,
  10825. "total": total,
  10826. })
  10827. }
  10828. }
  10829. func (c *HisApiController) PostProjectInformation() {
  10830. adminUser := c.GetAdminUserInfo()
  10831. orgId := adminUser.CurrentOrgId
  10832. dataBody := make(map[string]interface{}, 0)
  10833. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10834. if err != nil {
  10835. utils.ErrorLog(err.Error())
  10836. return
  10837. }
  10838. utils.ErrorLog("%v", dataBody)
  10839. var projectList []*models.HisProject
  10840. var total_goods []interface{}
  10841. tempProjects := dataBody["projects"].([]interface{})
  10842. total_goods = tempProjects
  10843. for index, projectMap := range tempProjects {
  10844. projectM := projectMap.(map[string]interface{})
  10845. var project models.HisProject
  10846. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  10847. utils.ErrorLog("project_name")
  10848. return
  10849. }
  10850. project_name, _ := projectM["project_name"].(string)
  10851. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10852. err_log := models.ExportErrLog{
  10853. LogType: 6,
  10854. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10855. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10856. Status: 1,
  10857. CreateTime: time.Now().Unix(),
  10858. UpdateTime: time.Now().Unix(),
  10859. ExportTime: time.Now().Unix(),
  10860. }
  10861. service.CreateExportErrLog(&err_log)
  10862. continue
  10863. }
  10864. project.ProjectName = project_name
  10865. prices := projectM["price"].(string)
  10866. price, _ := strconv.ParseFloat(prices, 64)
  10867. if price <= 0 { //名字为空则生成一条导入错误日志
  10868. err_log := models.ExportErrLog{
  10869. LogType: 6,
  10870. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10871. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10872. Status: 1,
  10873. CreateTime: time.Now().Unix(),
  10874. UpdateTime: time.Now().Unix(),
  10875. ExportTime: time.Now().Unix(),
  10876. }
  10877. service.CreateExportErrLog(&err_log)
  10878. continue
  10879. }
  10880. project.Price = price
  10881. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10882. utils.ErrorLog("unit_id")
  10883. return
  10884. }
  10885. unit := projectM["unit"].(string)
  10886. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10887. err_log := models.ExportErrLog{
  10888. LogType: 6,
  10889. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10890. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10891. Status: 1,
  10892. CreateTime: time.Now().Unix(),
  10893. UpdateTime: time.Now().Unix(),
  10894. ExportTime: time.Now().Unix(),
  10895. }
  10896. service.CreateExportErrLog(&err_log)
  10897. continue
  10898. }
  10899. project.Unit = unit
  10900. cost_classify := projectM["cost_classify"].(string)
  10901. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10902. err_log := models.ExportErrLog{
  10903. LogType: 6,
  10904. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10905. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10906. Status: 1,
  10907. CreateTime: time.Now().Unix(),
  10908. UpdateTime: time.Now().Unix(),
  10909. ExportTime: time.Now().Unix(),
  10910. }
  10911. service.CreateExportErrLog(&err_log)
  10912. continue
  10913. }
  10914. var costClassify = "费用类别"
  10915. var cost_classify_id int64
  10916. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10917. if len(cost_classify) != 0 {
  10918. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10919. if errcode == gorm.ErrRecordNotFound {
  10920. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10921. dataconfig := models.DictDataconfig{
  10922. ParentId: costClassifyConfig.ID,
  10923. Module: "system",
  10924. OrgId: orgId,
  10925. Name: cost_classify,
  10926. FieldName: "",
  10927. Value: costConfig.Value + 1,
  10928. CreatedTime: "",
  10929. UpdatedTime: "",
  10930. CreateUserId: adminUser.AdminUser.Id,
  10931. Status: 1,
  10932. Remark: "",
  10933. DeleteIdSystem: 0,
  10934. Title: "",
  10935. Content: "",
  10936. Order: 0,
  10937. Code: "",
  10938. }
  10939. service.CreatedDicConfig(&dataconfig)
  10940. }
  10941. }
  10942. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10943. for _, it := range costClassList {
  10944. if cost_classify == it.Name {
  10945. cost_classify_id = int64(it.Value)
  10946. }
  10947. }
  10948. project.CostClassify = cost_classify_id
  10949. executive_section := projectM["executive_section"].(string)
  10950. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10951. err_log := models.ExportErrLog{
  10952. LogType: 6,
  10953. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10954. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10955. Status: 1,
  10956. CreateTime: time.Now().Unix(),
  10957. UpdateTime: time.Now().Unix(),
  10958. ExportTime: time.Now().Unix(),
  10959. }
  10960. service.CreateExportErrLog(&err_log)
  10961. continue
  10962. }
  10963. if len(executive_section) != 0 {
  10964. //查找科室是否有内容
  10965. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10966. if errcodedepart == gorm.ErrRecordNotFound {
  10967. department := models.XtHisDepartment{
  10968. Name: executive_section,
  10969. Status: 1,
  10970. UserOrgId: adminUser.CurrentOrgId,
  10971. CreatedTime: time.Now().Unix(),
  10972. }
  10973. service.CreateDePartment(&department)
  10974. }
  10975. }
  10976. var executive_section_id int64
  10977. departMentList, _ := service.GetAllDepartMent(orgId)
  10978. for _, it := range departMentList {
  10979. if executive_section == it.Name {
  10980. executive_section_id = it.ID
  10981. }
  10982. }
  10983. project.ExecutiveSection = executive_section_id
  10984. medical_coverage := projectM["medical_coverage"].(string)
  10985. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10986. err_log := models.ExportErrLog{
  10987. LogType: 6,
  10988. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10989. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10990. Status: 1,
  10991. CreateTime: time.Now().Unix(),
  10992. UpdateTime: time.Now().Unix(),
  10993. ExportTime: time.Now().Unix(),
  10994. }
  10995. service.CreateExportErrLog(&err_log)
  10996. continue
  10997. }
  10998. var medicalCoverage = "医保等级"
  10999. var medical_coverage_id int64
  11000. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  11001. if len(medical_coverage) != 0 {
  11002. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  11003. if errormedicalcoverage == gorm.ErrRecordNotFound {
  11004. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  11005. dataconfig := models.DictDataconfig{
  11006. ParentId: medicalCoverageConfig.ID,
  11007. Module: "system",
  11008. OrgId: orgId,
  11009. Name: medical_coverage,
  11010. FieldName: "",
  11011. Value: medicalCoverageConfig.Value + 1,
  11012. CreatedTime: "",
  11013. UpdatedTime: "",
  11014. CreateUserId: adminUser.AdminUser.Id,
  11015. Status: 1,
  11016. Remark: "",
  11017. DeleteIdSystem: 0,
  11018. Title: "",
  11019. Content: "",
  11020. Order: 0,
  11021. Code: "",
  11022. }
  11023. service.CreatedDicConfig(&dataconfig)
  11024. }
  11025. }
  11026. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  11027. for _, it := range medicalCoverageList {
  11028. if medical_coverage == it.Name {
  11029. medical_coverage_id = int64(it.Value)
  11030. }
  11031. }
  11032. project.MedicalCoverage = medical_coverage_id
  11033. pinyin := projectM["pinyin"].(string)
  11034. project.Pinyin = pinyin
  11035. wubi := projectM["wubi"].(string)
  11036. project.Wubi = wubi
  11037. statistical_classification := projectM["statistical_classification"].(string)
  11038. var statisticalClassification = "统计分类"
  11039. var statistical_classification_id int64
  11040. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  11041. if len(statistical_classification) != 0 {
  11042. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  11043. if classificationerrcodes == gorm.ErrRecordNotFound {
  11044. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  11045. dataconfig := models.DictDataconfig{
  11046. ParentId: classiFication.ID,
  11047. Module: "system",
  11048. OrgId: orgId,
  11049. Name: statistical_classification,
  11050. FieldName: "",
  11051. Value: classiFicationConfig.Value + 1,
  11052. CreatedTime: "",
  11053. UpdatedTime: "",
  11054. CreateUserId: adminUser.AdminUser.Id,
  11055. Status: 1,
  11056. Remark: "",
  11057. DeleteIdSystem: 0,
  11058. Title: "",
  11059. Content: "",
  11060. Order: 0,
  11061. Code: "",
  11062. }
  11063. service.CreatedDicConfig(&dataconfig)
  11064. }
  11065. }
  11066. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  11067. for _, it := range classiFicationList {
  11068. if statistical_classification == it.Name {
  11069. statistical_classification_id = int64(it.Value)
  11070. }
  11071. }
  11072. project.StatisticalClassification = statistical_classification_id
  11073. disease_directory := int64(projectM["disease_directory"].(float64))
  11074. project.DiseaseDirectory = disease_directory
  11075. is_record := int64(projectM["is_record"].(float64))
  11076. project.IsRecord = is_record
  11077. medical_code := projectM["medical_code"].(string)
  11078. project.MedicalCode = medical_code
  11079. tube_color := projectM["tube_color"].(string)
  11080. var tubeColor = "试管颜色"
  11081. var tube_color_id int64
  11082. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  11083. if len(tube_color) != 0 {
  11084. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  11085. if errcodetube == gorm.ErrRecordNotFound {
  11086. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  11087. dataconfig := models.DictDataconfig{
  11088. ParentId: tubeColorConfig.ID,
  11089. Module: "system",
  11090. OrgId: orgId,
  11091. Name: tube_color,
  11092. FieldName: "",
  11093. Value: tubeConfig.Value + 1,
  11094. CreatedTime: "",
  11095. UpdatedTime: "",
  11096. CreateUserId: adminUser.AdminUser.Id,
  11097. Status: 1,
  11098. Remark: "",
  11099. DeleteIdSystem: 0,
  11100. Title: "",
  11101. Content: "",
  11102. Order: 0,
  11103. Code: "",
  11104. }
  11105. service.CreatedDicConfig(&dataconfig)
  11106. }
  11107. }
  11108. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  11109. for _, it := range tubeColorList {
  11110. if tube_color == it.Name {
  11111. tube_color_id = int64(it.Value)
  11112. }
  11113. }
  11114. project.TubeColor = tube_color_id
  11115. single_dose := projectM["single_dose"].(string)
  11116. project.SingleDose = single_dose
  11117. execution_frequency := projectM["execution_frequency"].(string)
  11118. project.ExecutionFrequency = execution_frequency
  11119. delivery_way := projectM["delivery_way"].(string)
  11120. project.DeliveryWay = delivery_way
  11121. number_days := projectM["number_days"].(string)
  11122. project.NumberDays = number_days
  11123. total := projectM["total"].(string)
  11124. project.Total = total
  11125. medical_status := int64(projectM["medical_status"].(float64))
  11126. project.MedicalStatus = medical_status
  11127. category := int64(projectM["category"].(float64))
  11128. project.Category = category
  11129. specail_project := int64(projectM["specail_project"].(float64))
  11130. project.SpecailProject = specail_project
  11131. social_security_directory_code := projectM["social_security_directory_code"].(string)
  11132. project.SocialSecurityDirectoryCode = social_security_directory_code
  11133. remark := projectM["remark"].(string)
  11134. project.Remark = remark
  11135. record_date := projectM["record_date"].(string)
  11136. timeLayout := "2006-01-02"
  11137. loc, _ := time.LoadLocation("Local")
  11138. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11139. project.RecordDate = theTime.Unix()
  11140. projectList = append(projectList, &project)
  11141. }
  11142. export_time := time.Now().Unix()
  11143. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  11144. if len(projectList) > 0 {
  11145. for _, item := range projectList {
  11146. hans := item.ProjectName // 要转换的汉字字符串
  11147. // 创建一个拼音转换器
  11148. p := pinyin.NewArgs()
  11149. // 将汉字转为拼音
  11150. pinyinSlice := pinyin.Pinyin(hans, p)
  11151. // 输出拼音
  11152. fmt.Println("Pinyin:", pinyinSlice)
  11153. // 获取首字母
  11154. firstLetter := ""
  11155. for _, py := range pinyinSlice {
  11156. if len(py) > 0 {
  11157. firstLetter += string(py[0][0])
  11158. }
  11159. }
  11160. item.FirstLetter = firstLetter
  11161. project := models.HisProject{
  11162. ProjectName: item.ProjectName,
  11163. Price: item.Price,
  11164. Unit: item.Unit,
  11165. CostClassify: item.CostClassify,
  11166. ExecutiveSection: item.ExecutiveSection,
  11167. MedicalCoverage: item.MedicalCoverage,
  11168. UserOrgId: orgId,
  11169. Status: 1,
  11170. CreatedTime: time.Now().Unix(),
  11171. Pinyin: item.Pinyin,
  11172. Wubi: item.Wubi,
  11173. StatisticalClassification: item.StatisticalClassification,
  11174. DiseaseDirectory: item.DiseaseDirectory,
  11175. IsRecord: item.IsRecord,
  11176. MedicalCode: item.MedicalCode,
  11177. TubeColor: item.TubeColor,
  11178. SingleDose: item.SingleDose,
  11179. DeliveryWay: item.DeliveryWay,
  11180. NumberDays: item.NumberDays,
  11181. Total: item.Total,
  11182. Category: item.Category,
  11183. MedicalStatus: item.MedicalStatus,
  11184. SpecailProject: item.SpecailProject,
  11185. RecordDate: item.RecordDate,
  11186. Remark: item.Remark,
  11187. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  11188. ExecutionFrequency: item.ExecutionFrequency,
  11189. FirstLetter: item.FirstLetter,
  11190. }
  11191. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  11192. if errcodeproject == gorm.ErrRecordNotFound {
  11193. service.CreateProjectInfomation(&project)
  11194. } else if errcodeproject == nil {
  11195. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  11196. }
  11197. log := models.ExportLog{
  11198. LogType: 6,
  11199. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11200. TotalNum: int64(len(total_goods)),
  11201. FailNum: int64(len(errLogs)),
  11202. SuccessNum: int64(len(projectList)),
  11203. CreateTime: time.Now().Unix(),
  11204. UpdateTime: time.Now().Unix(),
  11205. ExportTime: export_time,
  11206. Status: 1,
  11207. }
  11208. service.CreateExportLog(&log)
  11209. c.ServeSuccessJSON(map[string]interface{}{
  11210. "msg": "导入成功",
  11211. "total_num": len(total_goods),
  11212. "success_num": len(projectList),
  11213. "fail_num": int64(len(errLogs)),
  11214. })
  11215. }
  11216. } else {
  11217. log := models.ExportLog{
  11218. LogType: 6,
  11219. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11220. TotalNum: int64(len(total_goods)),
  11221. FailNum: int64(len(errLogs)),
  11222. SuccessNum: int64(len(projectList)),
  11223. CreateTime: time.Now().Unix(),
  11224. UpdateTime: time.Now().Unix(),
  11225. ExportTime: export_time,
  11226. Status: 1,
  11227. }
  11228. service.CreateExportLog(&log)
  11229. c.ServeSuccessJSON(map[string]interface{}{
  11230. "msg": "导入成功",
  11231. "total_num": len(total_goods),
  11232. "success_num": len(projectList),
  11233. "fail_num": int64(len(errLogs)),
  11234. })
  11235. }
  11236. }
  11237. //func (this *HisApiController) EditProjectInformation(){
  11238. //
  11239. // id, _ := this.GetInt64("id")
  11240. // project_team := this.GetString("project_team")
  11241. // price := this.GetString("price")
  11242. // price_float, _ := strconv.ParseFloat(price, 64)
  11243. // pinyin := this.GetString("pinyin")
  11244. // wubi := this.GetString("wubi")
  11245. // tube_color, _ := this.GetInt64("tube_color")
  11246. // team_type, _ := this.GetInt64("team_type")
  11247. // remark := this.GetString("remark")
  11248. // ids := this.GetString("ids")
  11249. // item_id := this.GetString("item_id")
  11250. // projectTeam := models.XtHisProjectTeam{
  11251. // ProjectTeam: project_team,
  11252. // Price: price_float,
  11253. // Pinyin: pinyin,
  11254. // Wubi: wubi,
  11255. // TubeColor: tube_color,
  11256. // TeamType: team_type,
  11257. // Remark: remark,
  11258. // ProjectId: ids,
  11259. // ItemId: item_id,
  11260. // }
  11261. //
  11262. //
  11263. // dataBody := make(map[string]interface{}, 0)
  11264. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  11265. // if err != nil {
  11266. // utils.ErrorLog(err.Error())
  11267. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11268. // return
  11269. // }
  11270. //
  11271. // err = service.UpdatedProjectTeam(id, &projectTeam)
  11272. //
  11273. //
  11274. // if err != nil {
  11275. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  11276. // return
  11277. // }
  11278. //
  11279. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  11280. // infos, _ := dataBody["info"].([]interface{})
  11281. // if len(infos) > 0 {
  11282. // var ids []string
  11283. //
  11284. // for _, item := range infos {
  11285. // items := item.(map[string]interface{})
  11286. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  11287. // utils.ErrorLog("id")
  11288. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11289. // return
  11290. // }
  11291. // id := int64(items["id"].(float64))
  11292. //
  11293. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11294. // utils.ErrorLog("type")
  11295. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11296. // return
  11297. // }
  11298. // types := int64(items["type"].(float64))
  11299. //
  11300. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  11301. // utils.ErrorLog("number")
  11302. // }
  11303. //
  11304. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  11305. //
  11306. // projectList := models.XtHisProjectList{
  11307. // Number: number,
  11308. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  11309. // ProjectId: id,
  11310. // Status: 1,
  11311. // CreatedTime: time.Now().Unix(),
  11312. // UpdatedTime: time.Now().Unix(),
  11313. // TeamId: projectTeam.ID,
  11314. // Type: types,
  11315. // }
  11316. // list := projectList
  11317. //
  11318. // service.CreateProjectList(&list)
  11319. //
  11320. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  11321. //
  11322. // }
  11323. // ids_str := strings.Join(ids, ",")
  11324. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  11325. // service.SaveProjectTeam(&projectTeam)
  11326. // this.ServeSuccessJSON(map[string]interface{}{
  11327. // "projectTeam": projectTeam,
  11328. // })
  11329. // }
  11330. // }
  11331. //}
  11332. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  11333. name := c.GetString("name")
  11334. mode_id, _ := c.GetInt64("mode", 0)
  11335. types, _ := c.GetInt64("type", 0)
  11336. patient_id, _ := c.GetInt64("patient_id", 0)
  11337. types = 1
  11338. adminInfo := c.GetAdminUserInfo()
  11339. template := &models.HisPrescriptionTemplate{
  11340. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  11341. PatientId: patient_id,
  11342. Type: types,
  11343. Status: 1,
  11344. Ctime: time.Now().Unix(),
  11345. Mtime: time.Now().Unix(),
  11346. Name: name,
  11347. Mode: mode_id,
  11348. }
  11349. dataBody := make(map[string]interface{}, 0)
  11350. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  11351. if err != nil {
  11352. utils.ErrorLog(err.Error())
  11353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11354. return
  11355. }
  11356. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  11357. //如果已经存在记录则删除处方
  11358. if template_one.ID > 0 {
  11359. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  11360. var ids []int64
  11361. var org_id int64
  11362. for _, item := range ps {
  11363. org_id = c.GetAdminUserInfo().CurrentOrgId
  11364. ids = append(ids, item.ID)
  11365. }
  11366. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  11367. if err2 == nil {
  11368. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11369. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11370. if len(prescriptions) > 0 {
  11371. for _, item := range prescriptions {
  11372. items := item.(map[string]interface{})
  11373. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11374. utils.ErrorLog("type")
  11375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11376. return
  11377. }
  11378. types := int64(items["type"].(float64))
  11379. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11380. utils.ErrorLog("med_type")
  11381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11382. return
  11383. }
  11384. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11385. ctime := time.Now().Unix()
  11386. prescription := &models.HisPrescriptionInfoTemplate{
  11387. PatientId: patient_id,
  11388. UserOrgId: adminInfo.CurrentOrgId,
  11389. Ctime: ctime,
  11390. Mtime: ctime,
  11391. Type: types,
  11392. Modifier: adminInfo.AdminUser.Id,
  11393. Creator: adminInfo.AdminUser.Id,
  11394. Status: 1,
  11395. PTemplateId: template_one.ID,
  11396. MedType: med_type,
  11397. }
  11398. service.CreateHisPrescriptionInfoTemplate(prescription)
  11399. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11400. advices := items["advices"].([]interface{})
  11401. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11402. ctime := time.Now().Unix()
  11403. mtime := ctime
  11404. if len(advices) > 0 {
  11405. for _, advice := range advices {
  11406. var s models.HisPrescriptionAdviceTemplate
  11407. s.PrescriptionId = prescription.ID
  11408. s.AdviceType = 2
  11409. s.StopState = 2
  11410. s.ExecutionState = 2
  11411. s.Status = 1
  11412. s.UserOrgId = adminInfo.CurrentOrgId
  11413. s.CreatedTime = ctime
  11414. s.UpdatedTime = mtime
  11415. s.PatientId = patient_id
  11416. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11417. if errcode > 0 {
  11418. c.ServeFailJSONWithSGJErrorCode(errcode)
  11419. return
  11420. }
  11421. service.CreateHisPrescriptionAdviceTemplate(&s)
  11422. }
  11423. }
  11424. }
  11425. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11426. projects := items["project"].([]interface{})
  11427. if len(projects) > 0 {
  11428. for _, project := range projects {
  11429. var p models.HisPrescriptionProjectTemplate
  11430. p.PrescriptionId = prescription.ID
  11431. p.Ctime = time.Now().Unix()
  11432. p.Mtime = time.Now().Unix()
  11433. p.PatientId = patient_id
  11434. p.UserOrgId = adminInfo.CurrentOrgId
  11435. p.Status = 1
  11436. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11437. if errcode > 0 {
  11438. c.ServeFailJSONWithSGJErrorCode(errcode)
  11439. return
  11440. }
  11441. service.CreateHisPrescriptionProjectTemplate(&p)
  11442. }
  11443. }
  11444. }
  11445. }
  11446. c.ServeSuccessJSON(map[string]interface{}{
  11447. "msg": "创建成功",
  11448. })
  11449. }
  11450. }
  11451. } else {
  11452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11453. return
  11454. }
  11455. } else {
  11456. err3 := service.CreateHisPrescriptionTemplate(template)
  11457. if err3 == nil {
  11458. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11459. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11460. if len(prescriptions) > 0 {
  11461. for _, item := range prescriptions {
  11462. items := item.(map[string]interface{})
  11463. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  11464. utils.ErrorLog("type")
  11465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11466. return
  11467. }
  11468. types := int64(items["type"].(float64))
  11469. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  11470. utils.ErrorLog("med_type")
  11471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11472. return
  11473. }
  11474. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  11475. ctime := time.Now().Unix()
  11476. prescription := &models.HisPrescriptionInfoTemplate{
  11477. PatientId: patient_id,
  11478. UserOrgId: adminInfo.CurrentOrgId,
  11479. Ctime: ctime,
  11480. Mtime: ctime,
  11481. Type: types,
  11482. Modifier: adminInfo.AdminUser.Id,
  11483. Creator: adminInfo.AdminUser.Id,
  11484. Status: 1,
  11485. PTemplateId: template.ID,
  11486. MedType: med_type,
  11487. }
  11488. service.CreateHisPrescriptionInfoTemplate(prescription)
  11489. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11490. advices := items["advices"].([]interface{})
  11491. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11492. ctime := time.Now().Unix()
  11493. mtime := ctime
  11494. if len(advices) > 0 {
  11495. for _, advice := range advices {
  11496. var s models.HisPrescriptionAdviceTemplate
  11497. s.PrescriptionId = prescription.ID
  11498. s.AdviceType = 2
  11499. s.StopState = 2
  11500. s.ExecutionState = 2
  11501. s.Status = 1
  11502. s.UserOrgId = adminInfo.CurrentOrgId
  11503. s.CreatedTime = ctime
  11504. s.UpdatedTime = mtime
  11505. s.PatientId = patient_id
  11506. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  11507. if errcode > 0 {
  11508. c.ServeFailJSONWithSGJErrorCode(errcode)
  11509. return
  11510. }
  11511. service.CreateHisPrescriptionAdviceTemplate(&s)
  11512. }
  11513. }
  11514. }
  11515. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11516. projects := items["project"].([]interface{})
  11517. if len(projects) > 0 {
  11518. for _, project := range projects {
  11519. var p models.HisPrescriptionProjectTemplate
  11520. p.PrescriptionId = prescription.ID
  11521. p.Ctime = time.Now().Unix()
  11522. p.Mtime = time.Now().Unix()
  11523. p.PatientId = patient_id
  11524. p.UserOrgId = adminInfo.CurrentOrgId
  11525. p.Status = 1
  11526. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  11527. if errcode > 0 {
  11528. c.ServeFailJSONWithSGJErrorCode(errcode)
  11529. return
  11530. }
  11531. service.CreateHisPrescriptionProjectTemplate(&p)
  11532. }
  11533. }
  11534. }
  11535. }
  11536. c.ServeSuccessJSON(map[string]interface{}{
  11537. "msg": "创建成功",
  11538. })
  11539. }
  11540. }
  11541. } else {
  11542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11543. return
  11544. }
  11545. }
  11546. }
  11547. func (c *HisApiController) PreSettle() {
  11548. id, _ := c.GetInt64("id")
  11549. record_time := c.GetString("record_time")
  11550. his_patient_id, _ := c.GetInt64("his_patient_id")
  11551. timeLayout := "2006-01-02"
  11552. loc, _ := time.LoadLocation("Local")
  11553. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  11554. diagnosis_id := c.GetString("diagnosis")
  11555. sick_type, _ := c.GetInt64("sick_type")
  11556. reg_type, _ := c.GetInt64("p_type")
  11557. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11558. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  11559. if err != nil {
  11560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11561. return
  11562. }
  11563. recordDateTime := theTime.Unix()
  11564. adminUser := c.GetAdminUserInfo()
  11565. var prescriptions []*models.HisPrescription
  11566. var start_time int64
  11567. var end_time int64
  11568. ids_str := c.GetString("ids")
  11569. ids_arr := strings.Split(ids_str, ",")
  11570. fmt.Println(reg_type)
  11571. if settle_accounts_type == 1 { //日结
  11572. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  11573. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  11574. } else {
  11575. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  11576. }
  11577. fmt.Println(prescriptions)
  11578. } else { //月结
  11579. start_time_str := c.GetString("start_time")
  11580. end_time_str := c.GetString("end_time")
  11581. timeLayout := "2006-01-02"
  11582. loc, _ := time.LoadLocation("Local")
  11583. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  11584. if err != nil {
  11585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11586. return
  11587. }
  11588. recordStartTime := theStartTime.Unix()
  11589. start_time = recordStartTime
  11590. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  11591. if err != nil {
  11592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11593. return
  11594. }
  11595. recordEndTime := theEndTime.Unix()
  11596. end_time = recordEndTime
  11597. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  11598. }
  11599. if reg_type == 1111 || reg_type == 1112 {
  11600. reg_type = 11
  11601. }
  11602. timestamp := time.Now().Unix()
  11603. tempTime := time.Unix(timestamp, 0)
  11604. timeFormat := tempTime.Format("20060102150405")
  11605. chrgBchno := rand.Intn(100000) + 10000
  11606. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  11607. strconv.FormatInt(his.PatientId, 10)
  11608. var ids []int64
  11609. for _, item := range prescriptions {
  11610. ids = append(ids, item.ID)
  11611. }
  11612. fmt.Println(ids)
  11613. var total float64
  11614. for _, item := range prescriptions {
  11615. fmt.Println(item)
  11616. if item.Type == 1 { //药品
  11617. for _, subItem := range item.HisDoctorAdviceInfo {
  11618. total = total + (subItem.Price * subItem.PrescribingNumber)
  11619. }
  11620. }
  11621. if item.Type == 2 { //项目
  11622. for _, subItem := range item.HisPrescriptionProject {
  11623. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11624. total = total + (subItem.Price * cnt)
  11625. }
  11626. }
  11627. for _, subItem := range item.HisAdditionalCharge {
  11628. total = total + (subItem.Price * float64(subItem.Count))
  11629. }
  11630. }
  11631. allTotal := fmt.Sprintf("%.2f", total)
  11632. totals, _ := strconv.ParseFloat(allTotal, 64)
  11633. order := &models.HisOrder{
  11634. UserOrgId: adminUser.CurrentOrgId,
  11635. HisPatientId: his.ID,
  11636. PatientId: id,
  11637. SettleAccountsDate: recordDateTime,
  11638. Ctime: time.Now().Unix(),
  11639. Mtime: time.Now().Unix(),
  11640. Status: 1,
  11641. OrderStatus: 1,
  11642. MdtrtId: his.Number,
  11643. Number: chrg_bchno,
  11644. MedfeeSumamt: totals,
  11645. SettleEndTime: end_time,
  11646. SettleStartTime: start_time,
  11647. SettleType: settle_accounts_type,
  11648. PsnPartAmt: totals,
  11649. PsnCashPay: totals,
  11650. PType: 2,
  11651. IsPre: 1,
  11652. MedType: strconv.Itoa(int(reg_type)),
  11653. Diagnosis: diagnosis_id,
  11654. }
  11655. err = service.CreateOrder(order)
  11656. if err != nil {
  11657. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  11658. return
  11659. }
  11660. var customs []*Custom
  11661. for _, item := range prescriptions {
  11662. fmt.Println(item.Type)
  11663. if item.Type == 1 { //药品
  11664. for _, subItem := range item.HisDoctorAdviceInfo {
  11665. cus := &Custom{
  11666. AdviceId: subItem.ID,
  11667. ProjectId: 0,
  11668. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  11669. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  11670. FeedetlSn: subItem.FeedetlSn,
  11671. Price: fmt.Sprintf("%.2f", subItem.Price),
  11672. MedListCodg: subItem.MedListCodg,
  11673. Type: 1,
  11674. }
  11675. customs = append(customs, cus)
  11676. }
  11677. }
  11678. if item.Type == 2 { //项目
  11679. for _, subItem := range item.HisPrescriptionProject {
  11680. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  11681. cus := &Custom{
  11682. AdviceId: 0,
  11683. ProjectId: subItem.ID,
  11684. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  11685. Cut: fmt.Sprintf("%.2f", cnt),
  11686. FeedetlSn: subItem.FeedetlSn,
  11687. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  11688. MedListCodg: subItem.MedListCodg,
  11689. Type: 2,
  11690. }
  11691. customs = append(customs, cus)
  11692. }
  11693. }
  11694. for _, item := range item.HisAdditionalCharge {
  11695. cus := &Custom{
  11696. ItemId: item.ID,
  11697. AdviceId: 0,
  11698. ProjectId: 0,
  11699. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  11700. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  11701. FeedetlSn: item.FeedetlSn,
  11702. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  11703. MedListCodg: item.XtHisAddtionConfig.Code,
  11704. Type: 3,
  11705. }
  11706. customs = append(customs, cus)
  11707. }
  11708. }
  11709. fmt.Println(customs)
  11710. for _, item := range customs {
  11711. var advice_id int64 = 0
  11712. var project_id int64 = 0
  11713. var item_id int64 = 0
  11714. var types int64 = 0
  11715. if item.Type == 1 {
  11716. advice_id = item.AdviceId
  11717. project_id = 0
  11718. item_id = 0
  11719. } else if item.Type == 2 {
  11720. advice_id = 0
  11721. item_id = 0
  11722. project_id = item.ProjectId
  11723. } else if item.Type == 3 {
  11724. advice_id = 0
  11725. item_id = item.ItemId
  11726. project_id = 0
  11727. }
  11728. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  11729. cut, _ := strconv.ParseFloat(item.Cut, 32)
  11730. pric, _ := strconv.ParseFloat(item.Price, 32)
  11731. info := &models.HisOrderInfo{
  11732. OrderNumber: order.Number,
  11733. UploadDate: time.Now().Unix(),
  11734. AdviceId: advice_id,
  11735. DetItemFeeSumamt: detItemFeeSumamt,
  11736. Cnt: cut,
  11737. Pric: pric,
  11738. PatientId: id,
  11739. Status: 1,
  11740. Mtime: time.Now().Unix(),
  11741. Ctime: time.Now().Unix(),
  11742. UserOrgId: adminUser.CurrentOrgId,
  11743. HisPatientId: his.ID,
  11744. OrderId: order.ID,
  11745. ProjectId: project_id,
  11746. Type: types,
  11747. ItemId: item_id,
  11748. }
  11749. service.CreateOrderInfo(info)
  11750. }
  11751. his.SickType = sick_type
  11752. service.UpdataHisPateint(&his)
  11753. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  11754. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  11755. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  11756. if err == nil {
  11757. c.ServeSuccessJSON(map[string]interface{}{
  11758. "msg": "结算成功",
  11759. })
  11760. }
  11761. }
  11762. type CustomOrderInfo struct {
  11763. Name string
  11764. Spec string
  11765. Unit string
  11766. Count float64
  11767. Price float64
  11768. Total float64
  11769. }
  11770. func (c *HisApiController) GetPrivateExpensesInfo() {
  11771. order_id, _ := c.GetInt64("id", 0)
  11772. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  11773. order, _ := service.GetHisOrderByID(order_id)
  11774. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  11775. if order.ID == 0 {
  11776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  11777. return
  11778. }
  11779. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  11780. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  11781. org_id := c.GetAdminUserInfo().CurrentOrgId
  11782. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  11783. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  11784. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  11785. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  11786. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  11787. //var orderInfos_four []*models.HisOrderInfoTwo
  11788. //for _, item := range orderInfos_three {
  11789. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  11790. // item.HisPrescriptionProject.IsCheckTeam = 1
  11791. // orderInfos_four = append(orderInfos_four, item)
  11792. //
  11793. // }
  11794. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  11795. // item.HisPrescriptionProject.IsCheckTeam = 2
  11796. // orderInfos_two = append(orderInfos_two, item)
  11797. // }
  11798. //}
  11799. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  11800. //var cus_slice []CustomOrderInfo
  11801. //for _, item := range new_order_info {
  11802. // var cus CustomOrderInfo
  11803. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  11804. // cus.Unit = ""
  11805. // cus.Spec = ""
  11806. // var total float64
  11807. // for _, subItem := range orderInfos_four {
  11808. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  11809. // total = total + subItem.DetItemFeeSumamt
  11810. // fmt.Println(subItem.DetItemFeeSumamt)
  11811. // }
  11812. // }
  11813. // cus.Count = 1
  11814. // cus.Total = total
  11815. // cus_slice = append(cus_slice, cus)
  11816. //}
  11817. orderInfos = append(orderInfos, orderInfos_two...)
  11818. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  11819. //orderInfos = append(orderInfos, orderInfos_three...)
  11820. //}/**/
  11821. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  11822. c.ServeSuccessJSON(map[string]interface{}{
  11823. "order": order,
  11824. "order_info": orderInfos,
  11825. "patient": patient,
  11826. "admin_info": adminInfo,
  11827. "his": his,
  11828. "current_admin": role,
  11829. "org_config": miConfig,
  11830. //"new_order_info": cus_slice,
  11831. })
  11832. }
  11833. func (this *HisApiController) ChangeMedType() {
  11834. med_type := this.GetString("med_type")
  11835. old_med_type := this.GetString("old_med_type")
  11836. ids := this.GetString("ids")
  11837. settle_type, _ := this.GetInt64("settle_type")
  11838. start_time := this.GetString("start_time")
  11839. end_time := this.GetString("end_time")
  11840. ids_arr := strings.Split(ids, ",")
  11841. if settle_type == 1 { //日结
  11842. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  11843. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  11844. prescription.MedType = med_type
  11845. err := service.SaveHisPrescriptionTwo(&prescription)
  11846. if err == nil {
  11847. this.ServeSuccessJSON(map[string]interface{}{
  11848. "msg": "修改成功",
  11849. })
  11850. } else {
  11851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11852. return
  11853. }
  11854. } else if settle_type == 2 {
  11855. timeLayout := "2006-01-02"
  11856. loc, _ := time.LoadLocation("Local")
  11857. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11858. if err != nil {
  11859. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11860. return
  11861. }
  11862. recordStartTime := theStartTime.Unix()
  11863. start_time_timestamp := recordStartTime
  11864. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11865. if err != nil {
  11866. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11867. return
  11868. }
  11869. recordEndTime := theEndTime.Unix()
  11870. end_time_timestamp := recordEndTime
  11871. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11872. if updateErr == nil {
  11873. this.ServeSuccessJSON(map[string]interface{}{
  11874. "msg": "修改成功",
  11875. })
  11876. } else {
  11877. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11878. return
  11879. }
  11880. }
  11881. }
  11882. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11883. patient_id, _ := c.GetInt64("patient_id")
  11884. his_patient_id, _ := c.GetInt64("his_patient_id")
  11885. record_date := c.GetString("record_date")
  11886. start_time := c.GetString("start_time")
  11887. end_time := c.GetString("end_time")
  11888. order_status, _ := c.GetInt64("type", 0)
  11889. p_type, _ := c.GetInt64("p_type", 0)
  11890. order_id, _ := c.GetInt64("order_id", 0)
  11891. timeLayout := "2006-01-02"
  11892. loc, _ := time.LoadLocation("Local")
  11893. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11894. if err != nil {
  11895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11896. return
  11897. }
  11898. recordDateTime := theTime.Unix()
  11899. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11900. if err != nil {
  11901. }
  11902. startRecordDateTime := startTime.Unix()
  11903. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11904. if err != nil {
  11905. }
  11906. endRecordDateTime := endTime.Unix()
  11907. admin := c.GetAdminUserInfo()
  11908. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11909. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11910. order, _ := service.GetHisOrderByID(order_id)
  11911. var monthPrescriptions []*models.HisPrescription
  11912. if order_status == 1 || order_status == 0 {
  11913. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11914. } else if order_status == 2 {
  11915. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11916. }
  11917. var settle_total float64
  11918. for _, item := range monthPrescriptions {
  11919. if len(item.HisPrescriptionProject) > 0 {
  11920. for _, subItem := range item.HisPrescriptionProject {
  11921. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11922. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11923. settle_total = settle_total + total
  11924. }
  11925. }
  11926. if len(item.HisDoctorAdviceInfo) > 0 {
  11927. for _, subItem := range item.HisDoctorAdviceInfo {
  11928. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11929. settle_total = settle_total + total
  11930. }
  11931. }
  11932. }
  11933. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11934. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11935. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11936. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11937. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11938. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11939. //获取所有科室信息
  11940. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11941. var dia string
  11942. for _, item := range month_p_info {
  11943. if len(dia) == 0 {
  11944. dia = item.Diagnosis
  11945. } else {
  11946. dia = dia + "," + item.Diagnosis
  11947. }
  11948. }
  11949. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11950. dia_arr = removeEmptyStrings(dia_arr)
  11951. c.ServeSuccessJSON(map[string]interface{}{
  11952. "his_info": his_patient_info,
  11953. "xt_info": xt_patient_info,
  11954. "case_history": case_history,
  11955. "info": patientPrescriptionInfo,
  11956. "last_info": lastPatientPrescriptionInfo,
  11957. "month_prescriptions": monthPrescriptions,
  11958. "order": order,
  11959. "doctors": doctors,
  11960. "department": department,
  11961. "settle_total": settle_total,
  11962. "dia_arr": dia_arr,
  11963. })
  11964. return
  11965. }
  11966. func removeEmptyStrings(input []string) []string {
  11967. var output []string
  11968. for _, s := range input {
  11969. if s != "" {
  11970. output = append(output, s)
  11971. }
  11972. }
  11973. return output
  11974. }
  11975. func removeDuplicates(input []string) []string {
  11976. seen := make(map[string]bool)
  11977. output := []string{}
  11978. for _, s := range input {
  11979. if _, exists := seen[s]; !exists {
  11980. seen[s] = true
  11981. output = append(output, s)
  11982. }
  11983. }
  11984. return output
  11985. }
  11986. func (c *HisApiController) GetHisMonthPatientInfo() {
  11987. patient_id, _ := c.GetInt64("patient_id")
  11988. his_patient_id, _ := c.GetInt64("his_patient_id")
  11989. record_date := c.GetString("record_date")
  11990. number := c.GetString("number")
  11991. start_time := c.GetString("start_time")
  11992. end_time := c.GetString("end_time")
  11993. p_type, _ := c.GetInt64("p_type")
  11994. timeLayout := "2006-01-02"
  11995. loc, _ := time.LoadLocation("Local")
  11996. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11997. if err != nil {
  11998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11999. return
  12000. }
  12001. recordDateTime := theTime.Unix()
  12002. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12003. if err != nil {
  12004. }
  12005. startRecordDateTime := startTime.Unix()
  12006. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12007. if err != nil {
  12008. }
  12009. endRecordDateTime := endTime.Unix()
  12010. admin := c.GetAdminUserInfo()
  12011. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  12012. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  12013. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  12014. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  12015. var settle_total float64
  12016. for _, item := range monthPrescriptions {
  12017. if len(item.HisPrescriptionProject) > 0 {
  12018. for _, subItem := range item.HisPrescriptionProject {
  12019. count, _ := strconv.ParseFloat(subItem.Count, 64)
  12020. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  12021. settle_total = settle_total + total
  12022. }
  12023. }
  12024. if len(item.HisDoctorAdviceInfo) > 0 {
  12025. for _, subItem := range item.HisDoctorAdviceInfo {
  12026. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  12027. settle_total = settle_total + total
  12028. }
  12029. }
  12030. }
  12031. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  12032. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  12033. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  12034. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  12035. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  12036. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  12037. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  12038. //获取所有科室信息
  12039. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  12040. c.ServeSuccessJSON(map[string]interface{}{
  12041. "his_info": his_patient_info,
  12042. "xt_info": xt_patient_info,
  12043. "case_history": case_history,
  12044. "info": patientPrescriptionInfo,
  12045. "month_prescriptions": monthPrescriptions,
  12046. "order": order,
  12047. "doctors": doctors,
  12048. "department": department,
  12049. "count": count,
  12050. "drugStockConfig": drugStockConfig,
  12051. "last_info": lastPatientPrescriptionInfo,
  12052. "settle_total": settle_total,
  12053. })
  12054. return
  12055. }
  12056. func (c *HisApiController) GetAllOrder() {
  12057. org_id := c.GetAdminUserInfo().CurrentOrgId
  12058. orders, _ := service.GetNewHisOrderList(org_id)
  12059. c.ServeSuccessJSON(map[string]interface{}{
  12060. "order": orders,
  12061. })
  12062. return
  12063. }
  12064. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  12065. newArr = make([]*models.HisOrderInfoTwo, 0)
  12066. for i := 0; i < len(arr); i++ {
  12067. repeat := false
  12068. for j := i + 1; j < len(arr); j++ {
  12069. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  12070. repeat = true
  12071. break
  12072. }
  12073. }
  12074. if !repeat {
  12075. newArr = append(newArr, arr[i])
  12076. }
  12077. }
  12078. return
  12079. }
  12080. // 修改处方退库操作 参数传修改之前的处方数据
  12081. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  12082. if advice.ExecutionState == 1 {
  12083. //查询该病人该药品是否有库存记录
  12084. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  12085. if errcode == gorm.ErrRecordNotFound {
  12086. } else {
  12087. //退库
  12088. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  12089. if advice.PrescribingNumberUnit == drug.MinUnit {
  12090. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12091. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12092. //退库
  12093. warehouseInfo := models.DrugWarehouseInfo{
  12094. StockMinNumber: prescribingNumber,
  12095. }
  12096. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  12097. operation_time := time.Now().Unix()
  12098. creater := advice.AdviceDoctor
  12099. ctime := time.Now().Unix()
  12100. timeStr := time.Now().Format("2006-01-02")
  12101. timeArr := strings.Split(timeStr, "-")
  12102. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12103. total = total + 1
  12104. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12105. cancelStock := models.DrugCancelStock{
  12106. OrderNumber: orderNumber,
  12107. OperaTime: operation_time,
  12108. OrgId: advice.UserOrgId,
  12109. Creater: creater,
  12110. Ctime: ctime,
  12111. Status: 1,
  12112. ReturnTime: advice.AdviceDate,
  12113. Dealer: info.Dealer,
  12114. Manufacturer: info.Manufacturer,
  12115. Type: 1,
  12116. }
  12117. service.AddSigleDrugCancelStock(&cancelStock)
  12118. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12119. dealer, _ := service.GetDealerById(info.Dealer)
  12120. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12121. cancelStockInfo := models.DrugCancelStockInfo{
  12122. OrderNumber: cancelInfo.OrderNumber,
  12123. CancelStockId: cancelInfo.ID,
  12124. DrugId: info.DrugId,
  12125. Count: info.Count,
  12126. Status: 1,
  12127. Ctime: ctime,
  12128. OrgId: advice.UserOrgId,
  12129. Type: 1,
  12130. Manufacturer: manufactureName.ManufacturerName,
  12131. Dealer: dealer.DealerName,
  12132. Total: 0,
  12133. RetailPrice: info.RetailPrice,
  12134. RetailTotalPrice: info.RetailTotalPrice,
  12135. Price: info.Price,
  12136. RegisterAccount: "",
  12137. Remark: info.Remark,
  12138. BatchNumber: info.BatchNumber,
  12139. MaxUnit: info.CountUnit,
  12140. ProductDate: info.ProductDate,
  12141. ExpiryDate: info.ExpiryDate,
  12142. BatchNumberId: info.WarehouseInfoId,
  12143. }
  12144. flow := models.DrugFlow{
  12145. WarehousingId: 0,
  12146. DrugId: info.DrugId,
  12147. Number: "",
  12148. BatchNumber: info.BatchNumber,
  12149. Count: info.Count,
  12150. UserOrgId: advice.UserOrgId,
  12151. PatientId: 0,
  12152. SystemTime: ctime,
  12153. ConsumableType: 4,
  12154. IsSys: 0,
  12155. WarehousingOrder: "",
  12156. WarehouseOutId: 0,
  12157. WarehouseOutOrderNumber: "",
  12158. IsEdit: 0,
  12159. CancelStockId: cancelStock.ID,
  12160. CancelOrderNumber: cancelStock.OrderNumber,
  12161. Manufacturer: info.Manufacturer,
  12162. Dealer: info.Dealer,
  12163. Creator: advice.UserOrgId,
  12164. UpdateCreator: 0,
  12165. Status: 1,
  12166. Ctime: time.Now().Unix(),
  12167. Mtime: 0,
  12168. Price: info.Price,
  12169. WarehousingDetailId: 0,
  12170. WarehouseOutDetailId: 0,
  12171. CancelOutDetailId: 0,
  12172. ExpireDate: info.ExpiryDate,
  12173. ProductDate: info.ProductDate,
  12174. MaxUnit: info.CountUnit,
  12175. MinUnit: "",
  12176. }
  12177. service.CreatedCancelStock(cancelStockInfo)
  12178. service.CreateDrugFlowOne(flow)
  12179. } else {
  12180. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  12181. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  12182. if advice.PrescribingNumberUnit == drug.MaxUnit {
  12183. warehouseInfo := models.DrugWarehouseInfo{
  12184. StockMinNumber: prescribingNumber,
  12185. }
  12186. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  12187. }
  12188. operation_time := time.Now().Unix()
  12189. creater := advice.AdviceDoctor
  12190. ctime := time.Now().Unix()
  12191. timeStr := time.Now().Format("2006-01-02")
  12192. timeArr := strings.Split(timeStr, "-")
  12193. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  12194. total = total + 1
  12195. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  12196. cancelStock := models.DrugCancelStock{
  12197. OrderNumber: orderNumber,
  12198. OperaTime: operation_time,
  12199. OrgId: advice.UserOrgId,
  12200. Creater: creater,
  12201. Ctime: ctime,
  12202. Status: 1,
  12203. ReturnTime: advice.AdviceDate,
  12204. Dealer: info.Dealer,
  12205. Manufacturer: info.Manufacturer,
  12206. Type: 1,
  12207. }
  12208. service.AddSigleDrugCancelStock(&cancelStock)
  12209. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  12210. dealer, _ := service.GetDealerById(info.Dealer)
  12211. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  12212. cancelStockInfo := models.DrugCancelStockInfo{
  12213. OrderNumber: cancelInfo.OrderNumber,
  12214. CancelStockId: cancelInfo.ID,
  12215. DrugId: info.DrugId,
  12216. Count: info.Count,
  12217. Status: 1,
  12218. Ctime: ctime,
  12219. OrgId: advice.UserOrgId,
  12220. Type: 1,
  12221. Manufacturer: manufactureName.ManufacturerName,
  12222. Dealer: dealer.DealerName,
  12223. Total: 0,
  12224. RetailPrice: info.RetailPrice,
  12225. RetailTotalPrice: info.RetailTotalPrice,
  12226. Price: info.Price,
  12227. RegisterAccount: "",
  12228. Remark: info.Remark,
  12229. BatchNumber: info.BatchNumber,
  12230. MaxUnit: info.CountUnit,
  12231. ProductDate: info.ProductDate,
  12232. ExpiryDate: info.ExpiryDate,
  12233. BatchNumberId: info.WarehouseInfoId,
  12234. }
  12235. flow := models.DrugFlow{
  12236. WarehousingId: 0,
  12237. DrugId: info.DrugId,
  12238. Number: "",
  12239. BatchNumber: info.BatchNumber,
  12240. Count: info.Count,
  12241. UserOrgId: advice.UserOrgId,
  12242. PatientId: 0,
  12243. SystemTime: ctime,
  12244. ConsumableType: 4,
  12245. IsSys: 0,
  12246. WarehousingOrder: "",
  12247. WarehouseOutId: 0,
  12248. WarehouseOutOrderNumber: "",
  12249. IsEdit: 0,
  12250. CancelStockId: cancelStock.ID,
  12251. CancelOrderNumber: cancelStock.OrderNumber,
  12252. Manufacturer: info.Manufacturer,
  12253. Dealer: info.Dealer,
  12254. Creator: advice.AdviceDoctor,
  12255. UpdateCreator: 0,
  12256. Status: 1,
  12257. Ctime: time.Now().Unix(),
  12258. Mtime: 0,
  12259. Price: info.Price,
  12260. WarehousingDetailId: 0,
  12261. WarehouseOutDetailId: 0,
  12262. CancelOutDetailId: 0,
  12263. ExpireDate: info.ExpiryDate,
  12264. ProductDate: info.ProductDate,
  12265. MaxUnit: info.CountUnit,
  12266. MinUnit: "",
  12267. }
  12268. service.CreatedCancelStock(cancelStockInfo)
  12269. service.CreateDrugFlowOne(flow)
  12270. }
  12271. }
  12272. }
  12273. return err
  12274. }
  12275. func (this *HisApiController) DeleteNCDS() {
  12276. id, _ := this.GetInt64("id", 0)
  12277. if id > 0 {
  12278. service.DeletePsnNCDSRecordById(id)
  12279. this.ServeSuccessJSON(map[string]interface{}{
  12280. "msg": "删除成功",
  12281. })
  12282. } else {
  12283. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  12284. return
  12285. }
  12286. }
  12287. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  12288. id, _ := c.GetInt64("id")
  12289. advice, _ := service.GetHisDoctorAdviceInfo(id)
  12290. c.ServeSuccessJSON(map[string]interface{}{
  12291. "advice": advice,
  12292. })
  12293. return
  12294. }
  12295. func (c *HisApiController) GetHisMonthChargePatientList() {
  12296. record_date := c.GetString("record_date")
  12297. start_time := c.GetString("start_time")
  12298. end_time := c.GetString("end_time")
  12299. timeLayout := "2006-01-02"
  12300. loc, _ := time.LoadLocation("Local")
  12301. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  12302. if err != nil {
  12303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12304. return
  12305. }
  12306. if err != nil {
  12307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  12308. return
  12309. }
  12310. recordDateTime := theTime.Unix()
  12311. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  12312. if err != nil {
  12313. }
  12314. startRecordDateTime := startTime.Unix()
  12315. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  12316. if err != nil {
  12317. }
  12318. endRecordDateTime := endTime.Unix()
  12319. adminInfo := c.GetAdminUserInfo()
  12320. var tempMonthChargePatients []*service.MonthChargePatients
  12321. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  12322. for _, item := range tempPatients {
  12323. //过滤没有处方的
  12324. if len(item.HisPrescription) == 0 {
  12325. tempMonthChargePatients = append(tempMonthChargePatients, item)
  12326. }
  12327. }
  12328. c.ServeSuccessJSON(map[string]interface{}{
  12329. "list": tempMonthChargePatients,
  12330. })
  12331. }
  12332. // PrescriptionDifference 医嘱数量差值结构体
  12333. type PrescriptionDrugDifference struct {
  12334. DrugID int64 //基础库药品id
  12335. ID int64 //医嘱id
  12336. Difference float64 //差值
  12337. Unit string //单位
  12338. }
  12339. type PrescriptionGoodDifference struct {
  12340. GoodID int64 //基础库项目耗材id
  12341. ID int64 //医嘱id
  12342. Difference int64 //差值
  12343. Unit string //单位
  12344. Type int64 //类型
  12345. }
  12346. type EditCustomData struct {
  12347. adviceList []*models.HisDoctorAdviceInfo
  12348. projectList []*models.HisPrescriptionProject
  12349. }
  12350. type SrcCustomData struct {
  12351. adviceList []*models.HisDoctorAdviceInfo
  12352. projectList []*models.HisPrescriptionProject
  12353. }
  12354. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  12355. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  12356. differences := make([]*PrescriptionDrugDifference, 0)
  12357. // 创建一个 map 来存储第一个切片中的药品信息
  12358. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  12359. for _, advice := range firstPrescription {
  12360. firstMap[advice.DrugId] = advice
  12361. }
  12362. // 遍历第二个切片中的药品信息,并比较数量差值
  12363. for _, advice := range secondPrescription {
  12364. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  12365. diff := &PrescriptionDrugDifference{
  12366. DrugID: advice.DrugId,
  12367. ID: firstAdvice.ID,
  12368. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  12369. Unit: firstAdvice.PrescribingNumberUnit,
  12370. }
  12371. differences = append(differences, diff)
  12372. }
  12373. }
  12374. return differences
  12375. }
  12376. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  12377. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  12378. differences := make([]*PrescriptionGoodDifference, 0)
  12379. // 创建一个 map 来存储第一个切片中的耗材信息
  12380. firstMap := make(map[int64]*models.HisPrescriptionProject)
  12381. for _, good := range firstPrescription {
  12382. firstMap[good.ProjectId] = good
  12383. }
  12384. // 遍历第二个切片中的耗材信息,并比较数量差值
  12385. for _, good := range secondPrescription {
  12386. if firstGood, ok := firstMap[good.ProjectId]; ok {
  12387. count, _ := strconv.ParseInt(good.Count, 10, 64)
  12388. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  12389. diff := &PrescriptionGoodDifference{
  12390. GoodID: good.ProjectId,
  12391. ID: firstGood.ID,
  12392. Difference: count - firstCount,
  12393. Unit: firstGood.Unit,
  12394. Type: firstGood.Type,
  12395. }
  12396. differences = append(differences, diff)
  12397. }
  12398. }
  12399. return differences
  12400. }
  12401. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  12402. var adviceList []*models.HisDoctorAdviceInfo
  12403. var projectList []*models.HisPrescriptionProject
  12404. var advice_ids []int64
  12405. var project_ids []int64
  12406. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  12407. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  12408. //var tempPrescription *models.HisPrescriptionProjectscription
  12409. if len(prescriptions) > 0 {
  12410. for _, item := range prescriptions {
  12411. items := item.(map[string]interface{})
  12412. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  12413. advices := items["advices"].([]interface{})
  12414. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  12415. groupNo := int64(0)
  12416. ctime := time.Now().Unix()
  12417. mtime := ctime
  12418. if len(advices) > 0 {
  12419. for _, advice := range advices {
  12420. var s models.HisDoctorAdviceInfo
  12421. s.AdviceType = 2
  12422. s.StopState = 2
  12423. s.ExecutionState = 2
  12424. s.Status = 1
  12425. s.Groupno = groupNo
  12426. s.CreatedTime = ctime
  12427. s.UpdatedTime = mtime
  12428. s.IsSettle = 2
  12429. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  12430. //存储切片中
  12431. if s.ID > 0 {
  12432. advice_ids = append(advice_ids, s.ID)
  12433. adviceList = append(adviceList, &s)
  12434. }
  12435. }
  12436. }
  12437. }
  12438. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  12439. projects := items["project"].([]interface{})
  12440. if len(projects) > 0 {
  12441. for _, project := range projects {
  12442. var p models.HisPrescriptionProject
  12443. p.Ctime = time.Now().Unix()
  12444. p.Mtime = time.Now().Unix()
  12445. p.Status = 1
  12446. SetProjectWithJSON(&p, project.(map[string]interface{}))
  12447. if p.ID > 0 {
  12448. project_ids = append(project_ids, p.ID)
  12449. projectList = append(projectList, &p)
  12450. }
  12451. }
  12452. }
  12453. }
  12454. }
  12455. }
  12456. }
  12457. editCustomData.projectList = projectList
  12458. editCustomData.adviceList = adviceList
  12459. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  12460. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  12461. srcCustomData.adviceList = list
  12462. srcCustomData.projectList = list2
  12463. return
  12464. }