his_api_controller.go 506KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. }
  92. func (c *HisApiController) CheckHisPatient() {
  93. record_date := c.GetString("record_date")
  94. patient_id, _ := c.GetInt64("patient_id")
  95. timeLayout := "2006-01-02"
  96. loc, _ := time.LoadLocation("Local")
  97. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  98. if err != nil {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. recordDateTime := theTime.Unix()
  103. adminInfo := c.GetAdminUserInfo()
  104. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  105. if len(patients) > 1 {
  106. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  107. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  108. c.ServeSuccessJSON(map[string]interface{}{
  109. "status": 1,
  110. "msg": "关联",
  111. "ps": ps,
  112. "his_patient_id": patients[len(patients)-1].ID,
  113. "patient_id": patients[len(patients)-1].PatientId,
  114. })
  115. } else {
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "status": 0,
  118. "msg": "无需关联",
  119. })
  120. }
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. return
  127. }
  128. }
  129. func (c *HisApiController) AssociationHisPrescription() {
  130. record_date := c.GetString("record_date")
  131. his_patient_id, _ := c.GetInt64("his_patient_id")
  132. patient_id, _ := c.GetInt64("patient_id")
  133. p_ids := c.GetString("p_ids")
  134. p_ids_arr := strings.Split(p_ids, ",")
  135. timeLayout := "2006-01-02"
  136. loc, _ := time.LoadLocation("Local")
  137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  138. if err != nil {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. recordDateTime := theTime.Unix()
  143. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  144. if his_patient_id == 0 || his_patient.ID == 0 {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  149. if err == nil {
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "msg": "关联处方成功",
  152. })
  153. return
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. return
  157. }
  158. }
  159. //func (c *HisApiController) AssociationHisPrescription() {
  160. // record_date, _ := c.GetInt64("record_date")
  161. // his_patient_id, _ := c.GetInt64("his_patient_id")
  162. // patient_id, _ := c.GetInt64("patient_id")
  163. // p_ids := c.GetString("p_ids")
  164. // p_ids_arr := strings.Split(p_ids, ",")
  165. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  166. // if his_patient_id == 0 || his_patient.ID == 0 {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. // return
  169. // }
  170. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  171. // if err == nil {
  172. // c.ServeSuccessJSON(map[string]interface{}{
  173. // "msg": "关联处方成功",
  174. // })
  175. // return
  176. // } else {
  177. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  178. // return
  179. // }
  180. //}
  181. func (c *HisApiController) GetFaPiaoNumber() {
  182. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  183. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  184. fmt.Println(count)
  185. var zero string
  186. number := count + 1
  187. if number >= 1000 {
  188. zero = "0000" + strconv.FormatInt(number, 10)
  189. } else if number >= 10000 {
  190. zero = "000" + strconv.FormatInt(number, 10)
  191. } else if number >= 100000 {
  192. zero = "00" + strconv.FormatInt(number, 10)
  193. } else if number >= 1000000 {
  194. zero = "0" + strconv.FormatInt(number, 10)
  195. } else {
  196. zero = strconv.FormatInt(number, 10)
  197. }
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "fapiao_number": zero,
  200. })
  201. return
  202. }
  203. func (c *HisApiController) ChangeOrderDesc() {
  204. id, _ := c.GetInt64("id")
  205. desc := c.GetString("desc")
  206. change_type := c.GetString("change_type")
  207. order, _ := service.GetHisOrderByID(id)
  208. if order.ID == 0 {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. switch change_type {
  213. case "oth_desc":
  214. order.OthDesc = desc
  215. break
  216. case "cash_pay":
  217. order.CashPay = desc
  218. break
  219. case "jifen_pay":
  220. order.JifenPay = desc
  221. break
  222. case "band_card_pay":
  223. order.BandCardPay = desc
  224. break
  225. case "ali_pay":
  226. order.AliPay = desc
  227. break
  228. case "wechat_pay":
  229. order.WechatPay = desc
  230. break
  231. case "fa_piao_number":
  232. order.FaPiaoNumber = desc
  233. break
  234. case "fa_piao_code":
  235. order.FaPiaoCode = desc
  236. break
  237. }
  238. err := service.SaveHisOrder(&order)
  239. if err == nil {
  240. c.ServeSuccessJSON(map[string]interface{}{
  241. "msg": "修改成功",
  242. })
  243. return
  244. } else {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  246. return
  247. }
  248. }
  249. func (c *HisApiController) GetMonthHisPatient() {
  250. record_date := c.GetString("record_date")
  251. //order_status, _ := c.GetInt64("type")
  252. timeLayout := "2006-01-02"
  253. loc, _ := time.LoadLocation("Local")
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  255. if err != nil {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. return
  258. }
  259. recordDateTime := theTime.Unix()
  260. adminInfo := c.GetAdminUserInfo()
  261. var tempPatients []service.NewTempPatients
  262. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  263. // 获取当前时间
  264. now := time.Now()
  265. // 获取本月的第一天
  266. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  267. // 获取下个月的第一天
  268. nextMonth := firstDay.AddDate(0, 1, 0)
  269. // 获取本月的最后一天
  270. lastDay := nextMonth.Add(-time.Nanosecond)
  271. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  272. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  273. var patients []service.NewTempPatients
  274. var patients_two []service.NewTempPatients
  275. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. patients_two = append(patients_two, item)
  281. }
  282. ////过滤掉没挂号的
  283. //if len(item.HisPatient) > 0 {
  284. //}
  285. }
  286. } else {
  287. for _, item := range tempPatients {
  288. //过滤掉没挂号的和没开处方的
  289. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  290. patients = append(patients, item)
  291. }
  292. ////过滤掉没挂号的
  293. //if len(item.HisPatient) > 0 {
  294. // patients_two = append(patients_two, item)
  295. //}
  296. }
  297. }
  298. c.ServeSuccessJSON(map[string]interface{}{
  299. "list": patients,
  300. "list_two": patients_two,
  301. "chargePatients": chargePatients,
  302. })
  303. }
  304. func (c *HisApiController) GetBatchSettleAccounts() {
  305. order_ids := c.GetString("order_ids")
  306. admin_user_id, _ := c.GetInt64("admin_user_id")
  307. adminUser := c.GetAdminUserInfo()
  308. orders := strings.Split(order_ids, ",")
  309. var newOrders []models.Orders
  310. for _, item := range orders {
  311. order, _ := service.GetHisOrderByIDTenOne(item)
  312. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  313. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  314. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  315. orderInfos = append(orderInfos, orderInfos_two...)
  316. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  317. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  318. var diagnosis_ids []string
  319. if his.ID > 0 {
  320. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  321. } else {
  322. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  323. }
  324. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  325. var dia_config []*models.HisXtDiagnoseConfig
  326. var name string
  327. for _, item := range diagnosis_ids {
  328. id, _ := strconv.ParseInt(item, 10, 64)
  329. diagnosisConfig, _ := service.FindDiagnoseById(id)
  330. dia_config = append(dia_config, diagnosisConfig)
  331. if len(name) == 0 {
  332. name = diagnosisConfig.ClassName
  333. } else {
  334. name = name + "," + diagnosisConfig.ClassName
  335. }
  336. }
  337. var bedCostTotal float64 = 0 //床位总费
  338. var bedCostSelfTotal float64 = 0 //床位自费
  339. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  340. var bedSelfTotal float64 = 0 //床位部分项目自费
  341. var bedInscpTotal float64 = 0 //床位部分项目自费
  342. var operationCostTotal float64 = 0 //手术费
  343. var operationCostSelfTotal float64 = 0 //手术费
  344. var operationCostPartSelfTotal float64 = 0 //手术费
  345. var operationSelfTotal float64 = 0 //床位部分项目自费
  346. var operationInscpTotal float64 = 0 //床位部分项目自费
  347. var otherCostTotal float64 = 0 //其他费用
  348. var otherCostSelfTotal float64 = 0 //其他费用
  349. var otherCostPartSelfTotal float64 = 0 //其他费用
  350. var otherSelfTotal float64 = 0 //床位部分项目自费
  351. var otherInscpTotal float64 = 0 //床位部分项目自费
  352. var materialCostTotal float64 = 0 //材料费
  353. var materialCostSelfTotal float64 = 0 //材料费
  354. var materialCostPartSelfTotal float64 = 0 //材料费
  355. var materialSelfTotal float64 = 0 //床位部分项目自费
  356. var materialInscpTotal float64 = 0 //床位部分项目自费
  357. var westernMedicineCostTotal float64 = 0 //西药费
  358. var westernMedicineCostSelfTotal float64 = 0 //西药费
  359. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  360. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  361. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  362. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  365. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  366. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  367. var checkCostTotal float64 = 0 //检查费
  368. var checkCostSelfTotal float64 = 0 //检查费
  369. var checkCostPartSelfTotal float64 = 0 //检查费
  370. var checkSelfTotal float64 = 0 //床位部分项目自费
  371. var checkInscpTotal float64 = 0 //床位部分项目自费
  372. var laboratoryCostTotal float64 = 0 //化验费
  373. var laboratoryCostSelfTotal float64 = 0 //化验费
  374. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  375. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  376. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  377. var treatCostTotal float64 = 0 //治疗费用
  378. var treatCostSelfTotal float64 = 0 //治疗费用
  379. var treatCostPartSelfTotal float64 = 0 //治疗费用
  380. var treatSelfTotal float64 = 0 //床位部分项目自费
  381. var treatInscpTotal float64 = 0 //床位部分项目自费
  382. decimal.DivisionPrecision = 2
  383. for _, item := range orderInfos {
  384. if item.MedChrgitmType == "01" { //床位费
  385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  386. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  387. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  388. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  389. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  390. }
  391. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  392. if item.MedChrgitmType == "03" { //检查费
  393. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  394. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  395. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  396. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  397. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  398. }
  399. } else {
  400. if item.MedChrgitmType == "03" { //检查费
  401. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  402. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  403. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  404. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  405. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  406. }
  407. }
  408. if item.MedChrgitmType == "04" { //化验费
  409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  410. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  411. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  412. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  413. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  414. }
  415. if item.MedChrgitmType == "05" { //治疗费
  416. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. if item.MedChrgitmType == "06" { //手术费
  423. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  424. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  425. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  426. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  427. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  428. }
  429. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  431. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  432. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  433. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  434. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  435. }
  436. if item.MedChrgitmType == "09" { //西药费
  437. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  438. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  439. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  440. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  441. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  442. }
  443. if item.MedChrgitmType == "11" { //中成费
  444. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  445. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  446. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  447. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  448. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  449. }
  450. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  454. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  455. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  456. }
  457. }
  458. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  459. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  460. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  461. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  462. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  463. var doctor_name string
  464. if roles.ID == 0 {
  465. doctor_name = "管理员"
  466. } else {
  467. doctor_name = roles.UserName
  468. }
  469. yiliao_leibie := ""
  470. switch order.MedType {
  471. case "11":
  472. yiliao_leibie = "普通门诊"
  473. break
  474. case "12":
  475. yiliao_leibie = "门诊挂号"
  476. break
  477. case "13":
  478. yiliao_leibie = "急诊"
  479. break
  480. case "14":
  481. yiliao_leibie = "门诊特殊病"
  482. break
  483. case "15":
  484. yiliao_leibie = "门诊统筹"
  485. break
  486. case "16":
  487. yiliao_leibie = "门诊慢性病"
  488. break
  489. case "21":
  490. yiliao_leibie = "普通住院"
  491. break
  492. }
  493. var newOrder models.Orders
  494. newOrder.Diagnosis = name
  495. newOrder.OrderInfos = orderInfos
  496. newOrder.Number = order.MdtrtId
  497. newOrder.Date = order.SettleAccountsDate
  498. newOrder.ChargeAdmin = charge_admin
  499. newOrder.PrintorAdmin = printor_admin
  500. newOrder.Order = order
  501. newOrder.BedCostTotal = bedCostTotal
  502. newOrder.BedCostSelfTotal = bedCostSelfTotal
  503. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  504. newOrder.BedSelfTotal = bedSelfTotal
  505. newOrder.BedInscpTotal = bedInscpTotal
  506. newOrder.OperationCostTotal = operationCostTotal
  507. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  508. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  509. newOrder.OperationSelfTotal = operationSelfTotal
  510. newOrder.OperationInscpTotal = operationInscpTotal
  511. newOrder.OtherCostTotal = otherCostTotal
  512. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  513. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  514. newOrder.OtherSelfTotal = otherSelfTotal
  515. newOrder.OtherInscpTotal = otherInscpTotal
  516. newOrder.MaterialCostTotal = materialCostTotal
  517. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  518. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  519. newOrder.MaterialSelfTotal = materialSelfTotal
  520. newOrder.MaterialInscpTotal = materialInscpTotal
  521. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  522. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  523. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  524. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  525. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  526. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  527. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  528. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  529. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  530. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  531. newOrder.CheckCostTotal = checkCostTotal
  532. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  533. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  534. newOrder.CheckSelfTotal = checkSelfTotal
  535. newOrder.CheckInscpTotal = checkInscpTotal
  536. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  537. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  538. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  539. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  540. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  541. newOrder.TreatCostTotal = treatCostTotal
  542. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  543. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  544. newOrder.TreatSelfTotal = treatSelfTotal
  545. newOrder.TreatInscpTotal = treatInscpTotal
  546. newOrder.DoctorInfo = doctor_info
  547. newOrder.DoctorName = doctor_name
  548. newOrder.HealthCardNo = order.PsnNo
  549. newOrder.YiliaoLeibie = yiliao_leibie
  550. newOrder.Patient = patient
  551. newOrder.OrgName = miConfig.OrgName
  552. newOrder.OrgCode = miConfig.Code
  553. newOrder.OrderNumber = order.Number
  554. newOrder.HisPatient = his
  555. newOrder.DiaConfig = dia_config
  556. newOrders = append(newOrders, newOrder)
  557. }
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "orders": newOrders,
  560. })
  561. }
  562. func (c *HisApiController) GetTestOrder() {
  563. order_id, _ := c.GetInt64("order_id")
  564. admin_user_id, _ := c.GetInt64("admin_user_id")
  565. adminUser := c.GetAdminUserInfo()
  566. order, _ := service.GetHisOrderByID(order_id)
  567. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  568. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  569. orderInfos = append(orderInfos, orderInfos_two...)
  570. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  571. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  572. var dia_config []*models.HisXtDiagnoseConfig
  573. var name string
  574. var bedCostTotal float64 = 0 //床位总费
  575. var bedCostSelfTotal float64 = 0 //床位自费
  576. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  577. var bedSelfTotal float64 = 0 //床位部分项目自费
  578. var bedInscpTotal float64 = 0 //床位部分项目自费
  579. var operationCostTotal float64 = 0 //手术费
  580. var operationCostSelfTotal float64 = 0 //手术费
  581. var operationCostPartSelfTotal float64 = 0 //手术费
  582. var operationSelfTotal float64 = 0 //床位部分项目自费
  583. var operationInscpTotal float64 = 0 //床位部分项目自费
  584. var otherCostTotal float64 = 0 //其他费用
  585. var otherCostSelfTotal float64 = 0 //其他费用
  586. var otherCostPartSelfTotal float64 = 0 //其他费用
  587. var otherSelfTotal float64 = 0 //床位部分项目自费
  588. var otherInscpTotal float64 = 0 //床位部分项目自费
  589. var materialCostTotal float64 = 0 //材料费
  590. var materialCostSelfTotal float64 = 0 //材料费
  591. var materialCostPartSelfTotal float64 = 0 //材料费
  592. var materialSelfTotal float64 = 0 //床位部分项目自费
  593. var materialInscpTotal float64 = 0 //床位部分项目自费
  594. var westernMedicineCostTotal float64 = 0 //西药费
  595. var westernMedicineCostSelfTotal float64 = 0 //西药费
  596. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  597. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  598. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  602. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  603. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  604. var checkCostTotal float64 = 0 //检查费
  605. var checkCostSelfTotal float64 = 0 //检查费
  606. var checkCostPartSelfTotal float64 = 0 //检查费
  607. var checkSelfTotal float64 = 0 //床位部分项目自费
  608. var checkInscpTotal float64 = 0 //床位部分项目自费
  609. var laboratoryCostTotal float64 = 0 //化验费
  610. var laboratoryCostSelfTotal float64 = 0 //化验费
  611. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  612. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  613. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  614. var treatCostTotal float64 = 0 //治疗费用
  615. var treatCostSelfTotal float64 = 0 //治疗费用
  616. var treatCostPartSelfTotal float64 = 0 //治疗费用
  617. var treatSelfTotal float64 = 0 //床位部分项目自费
  618. var treatInscpTotal float64 = 0 //床位部分项目自费
  619. decimal.DivisionPrecision = 2
  620. for _, item := range orderInfos {
  621. if item.MedChrgitmType == "01" { //床位费
  622. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  623. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  624. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  625. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  626. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  627. }
  628. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  629. if item.MedChrgitmType == "03" { //检查费
  630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  631. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  632. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  633. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  634. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  635. }
  636. } else {
  637. if item.MedChrgitmType == "03" { //检查费
  638. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  639. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  640. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  641. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  642. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  643. }
  644. }
  645. if item.MedChrgitmType == "04" { //化验费
  646. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  647. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  648. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  649. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  650. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  651. }
  652. if item.MedChrgitmType == "05" { //治疗费
  653. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. if item.MedChrgitmType == "06" { //手术费
  660. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  661. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  662. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  663. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  664. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  665. }
  666. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  668. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  669. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  670. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  671. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  672. }
  673. if item.MedChrgitmType == "09" { //西药费
  674. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  675. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  676. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  677. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  678. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  679. }
  680. if item.MedChrgitmType == "11" { //中成费
  681. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  682. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  683. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  684. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  685. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  686. }
  687. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  688. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  689. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  690. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  691. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  692. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  693. }
  694. }
  695. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  696. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  697. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  698. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  699. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  700. var doctor_name string
  701. if roles.ID == 0 {
  702. doctor_name = "管理员"
  703. } else {
  704. doctor_name = roles.UserName
  705. }
  706. yiliao_leibie := ""
  707. switch order.MedType {
  708. case "11":
  709. yiliao_leibie = "普通门诊"
  710. break
  711. case "12":
  712. yiliao_leibie = "门诊挂号"
  713. break
  714. case "13":
  715. yiliao_leibie = "急诊"
  716. break
  717. case "14":
  718. yiliao_leibie = "门诊特殊病"
  719. break
  720. case "15":
  721. yiliao_leibie = "门诊统筹"
  722. break
  723. case "16":
  724. yiliao_leibie = "门诊慢性病"
  725. break
  726. case "21":
  727. yiliao_leibie = "普通住院"
  728. break
  729. }
  730. c.ServeSuccessJSON(map[string]interface{}{
  731. "diagnosis": name,
  732. "order_infos": orderInfos,
  733. "number": order.MdtrtId,
  734. "date": order.SettleAccountsDate,
  735. "charge_admin": charge_admin,
  736. "printor_admin": printor_admin,
  737. "info": order,
  738. "order": order,
  739. "bedCostTotal": bedCostTotal,
  740. "bedCostSelfTotal": bedCostSelfTotal,
  741. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  742. "bedSelfTotal": bedSelfTotal,
  743. "bedInscpTotal": bedInscpTotal,
  744. "operationCostTotal": operationCostTotal,
  745. "operationCostSelfTotal": operationCostSelfTotal,
  746. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  747. "operationSelfTotal": operationSelfTotal,
  748. "operationInscpTotal": operationInscpTotal,
  749. "otherCostTotal": otherCostTotal,
  750. "otherCostSelfTotal": otherCostSelfTotal,
  751. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  752. "otherSelfTotal": otherSelfTotal,
  753. "otherInscpTotal": otherInscpTotal,
  754. "materialCostTotal": materialCostTotal,
  755. "materialCostSelfTotal": materialCostSelfTotal,
  756. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  757. "materialSelfTotal": materialSelfTotal,
  758. "materialInscpTotal": materialInscpTotal,
  759. "westernMedicineCostTotal": westernMedicineCostTotal,
  760. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  761. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  762. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  763. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  764. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  765. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  766. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  767. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  768. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  769. "checkCostTotal": checkCostTotal,
  770. "checkCostSelfTotal": checkCostSelfTotal,
  771. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  772. "checkSelfTotal": checkSelfTotal,
  773. "checkInscpTotal": checkInscpTotal,
  774. "laboratoryCostTotal": laboratoryCostTotal,
  775. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  776. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  777. "laboratorySelfTotal": laboratorySelfTotal,
  778. "laboratoryInscpTotal": laboratoryInscpTotal,
  779. "treatCostTotal": treatCostTotal,
  780. "treatCostSelfTotal": treatCostSelfTotal,
  781. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  782. "treatSelfTotal": treatSelfTotal,
  783. "treatInscpTotal": treatInscpTotal,
  784. "doctor_info": doctor_info,
  785. "doctor_name": doctor_name,
  786. "health_card_no": order.PsnNo,
  787. "yiliao_leibie": yiliao_leibie,
  788. "patient": patient,
  789. "org_name": miConfig.OrgName,
  790. "org_code": miConfig.Code,
  791. "order_number": order.Number,
  792. "his_hospital": his_hospital,
  793. "dia_config": dia_config,
  794. })
  795. }
  796. type CustomFundPay struct {
  797. FundPayType string `json:"fund_pay_type"`
  798. FundPayamt float64 `json:"fund_payamt"`
  799. InscpScpAmt float64 `json:"inscp_scp_amt"`
  800. }
  801. func (c *PublicApiController) GetBaiLinExportData() {
  802. data := service.GetBaiLinOrderData()
  803. fmt.Println(len(data))
  804. var new_data []*models.NewCustomHisOrder
  805. for _, item := range data {
  806. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  807. new_data = append(new_data, item)
  808. }
  809. }
  810. fmt.Println(len(new_data))
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "list": new_data,
  813. })
  814. }
  815. func (c *HisApiController) GetHisUnChargePatientList() {
  816. record_date := c.GetString("record_date")
  817. sch_type, _ := c.GetInt64("sch_type")
  818. timeLayout := "2006-01-02"
  819. loc, _ := time.LoadLocation("Local")
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. recordDateTime := theTime.Unix()
  826. adminInfo := c.GetAdminUserInfo()
  827. var tempPatients []*service.NewTempPatients
  828. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  829. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  830. var patients []*service.NewTempPatients
  831. var patients_two []*service.NewTempPatients
  832. for _, item := range tempPatients {
  833. //过滤掉没挂号的和没开处方的
  834. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  835. patients = append(patients, item)
  836. }
  837. //过滤掉没挂号的
  838. if len(item.HisPatient) > 0 {
  839. patients_two = append(patients_two, item)
  840. }
  841. }
  842. c.ServeSuccessJSON(map[string]interface{}{
  843. "list": patients,
  844. "list_two": patients_two,
  845. })
  846. }
  847. func (c *HisApiController) GetPrivateExpensesOrder() {
  848. //id, _ := c.GetInt64("id")
  849. //record_time := c.GetString("record_time")
  850. order_id, _ := c.GetInt64("order_id")
  851. admin_user_id, _ := c.GetInt64("admin_user_id")
  852. //timeLayout := "2006-01-02"
  853. //loc, _ := time.LoadLocation("Local")
  854. //
  855. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  856. //if err != nil {
  857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. // return
  859. //}
  860. //recordDateTime := theTime.Unix()
  861. adminUser := c.GetAdminUserInfo()
  862. order, _ := service.GetHisOrderByID(order_id)
  863. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  864. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  865. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  866. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  867. //var config []*models.HisXtDiagnoseConfig
  868. var name string
  869. if order.PType == 1 {
  870. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  871. for _, item := range diagnosis_ids {
  872. id, _ := strconv.ParseInt(item, 10, 64)
  873. diagnosisConfig, _ := service.FindDiagnoseById(id)
  874. if len(name) == 0 {
  875. name = diagnosisConfig.ClassName
  876. } else {
  877. name = name + "," + diagnosisConfig.ClassName
  878. }
  879. }
  880. } else {
  881. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  882. for _, item := range diagnosis_ids {
  883. id, _ := strconv.ParseInt(item, 10, 64)
  884. diagnosisConfig, _ := service.FindDiagnoseById(id)
  885. if len(name) == 0 {
  886. name = diagnosisConfig.ClassName
  887. } else {
  888. name = name + "," + diagnosisConfig.ClassName
  889. }
  890. }
  891. }
  892. var bedCostTotal float64 = 0 //床位总费
  893. //var bedCostSelfTotal float64 = 0 //床位自费
  894. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  895. var operationCostTotal float64 = 0 //手术费
  896. //var operationCostSelfTotal float64 = 0 //手术费
  897. var operationCostPartSelfTotal float64 = 0 //手术费
  898. var otherCostTotal float64 = 0 //其他费用
  899. //var otherCostSelfTotal float64 = 0 //其他费用
  900. var otherCostPartSelfTotal float64 = 0 //其他费用
  901. var materialCostTotal float64 = 0 //材料费
  902. //var materialCostSelfTotal float64 = 0 //材料费
  903. var materialCostPartSelfTotal float64 = 0 //材料费
  904. var westernMedicineCostTotal float64 = 0 //西药费
  905. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  906. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  907. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  908. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  909. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  910. var checkCostTotal float64 = 0 //检查费
  911. //var checkCostSelfTotal float64 = 0 //检查费
  912. var checkCostPartSelfTotal float64 = 0 //检查费
  913. var laboratoryCostTotal float64 = 0 //化验费
  914. //var laboratoryCostSelfTotal float64 = 0 //化验费
  915. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  916. var treatCostTotal float64 = 0 //治疗费用
  917. //var treatCostSelfTotal float64 = 0 //治疗费用
  918. var treatCostPartSelfTotal float64 = 0 //治疗费用
  919. var zhenChaCostTotal float64 = 0 //其他费用
  920. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  921. decimal.DivisionPrecision = 2
  922. for _, item := range orderInfos {
  923. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  924. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  925. item.MedChrgitmType = "09"
  926. }
  927. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  928. if item.HisPrescriptionProject.Type == 2 {
  929. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  930. fmt.Println("CostClassify")
  931. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  932. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  933. case 0:
  934. item.MedChrgitmType = "0"
  935. break
  936. case 1:
  937. item.MedChrgitmType = "14"
  938. break
  939. case 2:
  940. item.MedChrgitmType = "05"
  941. break
  942. case 3:
  943. item.MedChrgitmType = "03"
  944. break
  945. case 4:
  946. item.MedChrgitmType = "03"
  947. break
  948. case 5:
  949. item.MedChrgitmType = "08"
  950. break
  951. case 6:
  952. item.MedChrgitmType = "14"
  953. break
  954. case 7:
  955. item.MedChrgitmType = "14"
  956. break
  957. case 8:
  958. item.MedChrgitmType = "03"
  959. break
  960. case 9:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 10:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 11:
  967. item.MedChrgitmType = "06"
  968. break
  969. case 12:
  970. item.MedChrgitmType = "12"
  971. break
  972. case 13:
  973. item.MedChrgitmType = "01"
  974. break
  975. case 14:
  976. item.MedChrgitmType = "04"
  977. break
  978. case 15:
  979. item.MedChrgitmType = "14"
  980. break
  981. }
  982. } else {
  983. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  984. case 1:
  985. item.MedChrgitmType = "14"
  986. break
  987. case 2:
  988. item.MedChrgitmType = "05"
  989. break
  990. case 3:
  991. item.MedChrgitmType = "04"
  992. break
  993. case 4:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 5:
  997. item.MedChrgitmType = "08"
  998. break
  999. case 6:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 7:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 8:
  1006. item.MedChrgitmType = "03"
  1007. break
  1008. case 9:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. default:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. }
  1015. }
  1016. } else if item.HisPrescriptionProject.Type == 3 {
  1017. item.MedChrgitmType = "08"
  1018. }
  1019. }
  1020. }
  1021. order.PsnCashPay = order.MedfeeSumamt
  1022. for _, item := range orderInfos {
  1023. if item.MedChrgitmType == "01" { //床位费
  1024. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1025. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1026. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1027. }
  1028. if item.MedChrgitmType == "02" { //诊察费
  1029. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1030. //zhenChaCostSelfTotal = zhenChaCostTotal
  1031. }
  1032. if item.MedChrgitmType == "03" { //检查费
  1033. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1034. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1035. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1036. }
  1037. if item.MedChrgitmType == "02" { //检查费
  1038. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1039. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1040. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1041. }
  1042. if item.MedChrgitmType == "04" { //化验费
  1043. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1044. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1045. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1046. }
  1047. if item.MedChrgitmType == "05" { //治疗费
  1048. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1049. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1050. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1051. }
  1052. if item.MedChrgitmType == "06" { //手术费
  1053. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1054. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1055. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1056. }
  1057. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1058. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1059. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1060. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1061. }
  1062. if item.MedChrgitmType == "09" { //西药费
  1063. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1064. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1065. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1066. }
  1067. if item.MedChrgitmType == "11" { //中成费
  1068. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1069. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1070. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1071. }
  1072. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1073. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1074. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1075. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1076. }
  1077. }
  1078. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1079. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1080. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1081. var dia_config []*models.HisXtDiagnoseConfig
  1082. var diagnosis_ids []string
  1083. if his.ID > 0 {
  1084. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1085. } else {
  1086. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1087. }
  1088. for _, item := range diagnosis_ids {
  1089. id, _ := strconv.ParseInt(item, 10, 64)
  1090. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1091. dia_config = append(dia_config, diagnosisConfig)
  1092. }
  1093. var rf []CustomFundPay
  1094. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1095. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1096. c.ServeSuccessJSON(map[string]interface{}{
  1097. "patient": patient,
  1098. "order_infos": orderInfos,
  1099. "diagnosis": name,
  1100. "bedCostTotal": bedCostTotal,
  1101. "bedCostSelfTotal": bedCostTotal,
  1102. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1103. "operationCostTotal": operationCostTotal,
  1104. "operationCostSelfTotal": operationCostTotal,
  1105. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1106. "otherCostTotal": otherCostTotal,
  1107. "otherCostSelfTotal": otherCostTotal,
  1108. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1109. "materialCostTotal": materialCostTotal,
  1110. "materialCostSelfTotal": materialCostTotal,
  1111. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1112. "westernMedicineCostTotal": westernMedicineCostTotal,
  1113. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1114. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1115. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1116. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1117. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1118. "checkCostTotal": checkCostTotal,
  1119. "checkCostSelfTotal": checkCostTotal,
  1120. "zhenChaCostTotal": zhenChaCostTotal,
  1121. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1122. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1123. "laboratoryCostTotal": laboratoryCostTotal,
  1124. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1125. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1126. "treatCostTotal": treatCostTotal,
  1127. "treatCostSelfTotal": treatCostTotal,
  1128. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1129. "charge_admin": charge_admin,
  1130. "printor_admin": printor_admin,
  1131. "org_name": org.OrgName,
  1132. "org_code": miConfig.Code,
  1133. "name": patient.Name,
  1134. "number": order.MdtrtId,
  1135. "date": order.SettleAccountsDate,
  1136. "info": order,
  1137. "new_order": order,
  1138. "his_hospital": his_hospital,
  1139. "his": his,
  1140. "funds": rf,
  1141. "dia_config": dia_config,
  1142. })
  1143. }
  1144. func (c *HisApiController) RefudDetail() {
  1145. order_id, _ := c.GetInt64("order_id")
  1146. order, _ := service.GetHisOrderByID(order_id)
  1147. adminUser := c.GetAdminUserInfo()
  1148. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1149. c.ServeSuccessJSON(map[string]interface{}{
  1150. "msg": "撤销成功",
  1151. })
  1152. }
  1153. func (c *HisApiController) Sscard() {
  1154. //r := CardInit()
  1155. //if r == 0 {
  1156. // GetBaseInfo()
  1157. //}
  1158. //c.ServeSuccessJSON(map[string]interface{}{
  1159. // "list": "11",
  1160. //})
  1161. }
  1162. func GetBaseInfo() error {
  1163. //handle := syscall.MustLoadDLL("SSCard.dll")
  1164. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1165. //
  1166. //str := make([]byte, 256)
  1167. //str1 := make([]byte, 256)
  1168. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1169. //if ferr != nil {
  1170. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1171. // return ferr
  1172. //}
  1173. //
  1174. //fmt.Println(string(str))
  1175. //
  1176. //fmt.Println(r)
  1177. return nil
  1178. }
  1179. func CardInit() int {
  1180. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1181. //add := DllTestDef.MustFindProc("Init")
  1182. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1183. //if err != nil {
  1184. // fmt.Println("SSCard的运算结果为:", ret)
  1185. //}
  1186. //result := int(ret)
  1187. return 0
  1188. }
  1189. func IntPtr(n int) uintptr {
  1190. return uintptr(n)
  1191. }
  1192. func StrPtr(s string) uintptr {
  1193. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1194. }
  1195. func (c *HisApiController) GetHisPatientList() {
  1196. //types, _ := c.GetInt64("type", 0)
  1197. record_date := c.GetString("record_date")
  1198. sch_type, _ := c.GetInt64("sch_type")
  1199. timeLayout := "2006-01-02"
  1200. loc, _ := time.LoadLocation("Local")
  1201. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1202. if err != nil {
  1203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1204. return
  1205. }
  1206. recordDateTime := theTime.Unix()
  1207. adminInfo := c.GetAdminUserInfo()
  1208. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1209. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1210. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1211. //获取当前用户的信息
  1212. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1213. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1214. //获取所有科室信息
  1215. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1216. c.ServeSuccessJSON(map[string]interface{}{
  1217. "list": patients,
  1218. "list_two": patients_two,
  1219. "info": adminUserInfo,
  1220. "doctors": doctors,
  1221. "department": department,
  1222. })
  1223. }
  1224. type CustomTemplate struct {
  1225. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1226. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1227. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1228. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1229. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1230. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1231. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1232. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1233. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1234. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1235. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1236. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1237. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1238. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1239. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1240. }
  1241. func (c *HisApiController) GetHisPatientInfo() {
  1242. patient_id, _ := c.GetInt64("patient_id")
  1243. his_patient_id, _ := c.GetInt64("his_patient_id")
  1244. record_date := c.GetString("record_date")
  1245. number := c.GetString("number")
  1246. //start_time := c.GetString("start_time")
  1247. //end_time := c.GetString("end_time")
  1248. p_type, _ := c.GetInt64("p_type")
  1249. timeLayout := "2006-01-02"
  1250. loc, _ := time.LoadLocation("Local")
  1251. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1252. if err != nil {
  1253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1254. return
  1255. }
  1256. recordDateTime := theTime.Unix()
  1257. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1258. //if err != nil {
  1259. //
  1260. //}
  1261. //startRecordDateTime := startTime.Unix()
  1262. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1263. //if err != nil {
  1264. //
  1265. //}
  1266. //endRecordDateTime := endTime.Unix()
  1267. admin := c.GetAdminUserInfo()
  1268. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1269. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1270. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1271. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1272. var prescriptions []*models.HisPrescription
  1273. var last_prescriptions []*models.HisPrescription
  1274. var sch_prescriptions []CustomTemplate
  1275. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1276. if p_type == 1 { //住院
  1277. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1278. for _, item := range prescriptions {
  1279. for _, subItem := range item.HisDoctorAdviceInfo {
  1280. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1281. if info.RetailPrice > 0 {
  1282. subItem.Drug.MinPrice = info.RetailPrice
  1283. }
  1284. }
  1285. }
  1286. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1287. } else { //门诊
  1288. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1289. for _, item := range prescriptions {
  1290. for _, subItem := range item.HisDoctorAdviceInfo {
  1291. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1292. if info.RetailPrice > 0 {
  1293. subItem.Drug.MinPrice = info.RetailPrice
  1294. }
  1295. }
  1296. }
  1297. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1298. }
  1299. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1300. if sch.ID > 0 {
  1301. var week string
  1302. t := time.Now()
  1303. switch t.Weekday().String() {
  1304. case "Monday":
  1305. week = "周一"
  1306. break
  1307. case "Tuesday":
  1308. week = "周二"
  1309. break
  1310. case "Wednesday":
  1311. week = "周三"
  1312. break
  1313. case "Thursday":
  1314. week = "周四"
  1315. break
  1316. case "Friday":
  1317. week = "周五"
  1318. break
  1319. case "Saturday":
  1320. week = "周六"
  1321. break
  1322. case "Sunday":
  1323. week = "周日"
  1324. break
  1325. }
  1326. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1327. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1328. //根据推送频率组装新的数组
  1329. for _, item := range temp_sch_prescriptions {
  1330. var cus CustomTemplate
  1331. cus.ID = item.ID
  1332. cus.UserOrgId = item.UserOrgId
  1333. cus.PatientId = item.PatientId
  1334. cus.MedType = item.MedType
  1335. cus.RecordDate = item.RecordDate
  1336. cus.Type = item.Type
  1337. cus.PType = item.PType
  1338. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1339. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1340. if subItem.FrequencyType == 1 { //每次必推
  1341. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1342. }
  1343. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1344. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1345. }
  1346. if subItem.FrequencyType == 2 { //按照天数频率
  1347. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1348. now := p.Unix()
  1349. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1350. dayStr2 := "-" + dayStr
  1351. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1352. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1353. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1354. if len(advices) == 0 {
  1355. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1356. }
  1357. }
  1358. }
  1359. }
  1360. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1361. if subItem.Type == 2 {
  1362. if subItem.XtHisProject.MedicalStatus != 1 {
  1363. if subItem.FrequencyType == 1 {
  1364. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1365. }
  1366. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1367. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1368. }
  1369. if subItem.FrequencyType == 2 {
  1370. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1371. now := p.Unix()
  1372. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1373. dayStr2 := "-" + dayStr
  1374. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1375. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1376. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1377. if len(projects) == 0 {
  1378. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1379. }
  1380. }
  1381. }
  1382. } else if subItem.Type == 3 {
  1383. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1384. if subItem.FrequencyType == 1 {
  1385. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1386. }
  1387. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1388. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1389. }
  1390. if subItem.FrequencyType == 2 {
  1391. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1392. now := p.Unix()
  1393. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1394. dayStr2 := "-" + dayStr
  1395. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1396. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1397. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1398. if len(projects) == 0 {
  1399. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1400. }
  1401. }
  1402. }
  1403. }
  1404. }
  1405. sch_prescriptions = append(sch_prescriptions, cus)
  1406. }
  1407. for _, item := range sch_prescriptions {
  1408. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1409. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1410. }
  1411. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1412. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1413. }
  1414. }
  1415. }
  1416. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1417. if config.ID > 0 && config.IsOpen == 1 {
  1418. for _, item := range sch_prescriptions {
  1419. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1420. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1421. if info.RetailPrice > 0 {
  1422. subItem.Drug.MinPrice = info.RetailPrice
  1423. }
  1424. }
  1425. }
  1426. }
  1427. if config.ID > 0 && config.IsOpen == 1 {
  1428. for _, item := range sch_prescriptions {
  1429. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1430. if subItem.Type == 3 {
  1431. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1432. if info.Price > 0 {
  1433. subItem.GoodInfo.PackingPrice = info.Price
  1434. }
  1435. }
  1436. }
  1437. }
  1438. }
  1439. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1440. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1441. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1442. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1443. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1444. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1445. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1446. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1447. //获取所有科室信息
  1448. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1449. c.ServeSuccessJSON(map[string]interface{}{
  1450. "his_info": his_patient_info,
  1451. "xt_info": xt_patient_info,
  1452. "prescription": prescriptions,
  1453. "case_history": case_history,
  1454. "info": patientPrescriptionInfo,
  1455. //"month_prescriptions": monthPrescriptions,
  1456. "order": order,
  1457. "doctors": doctors,
  1458. "department": department,
  1459. "sch_prescriptions": sch_prescriptions,
  1460. "last_prescriptions": last_prescriptions,
  1461. "schedule": sch,
  1462. "count": count,
  1463. "drugStockConfig": drugStockConfig,
  1464. "last_info": lastPatientPrescriptionInfo,
  1465. })
  1466. return
  1467. }
  1468. func (c *HisApiController) GetHisPrescriptionConfig() {
  1469. adminInfo := c.GetAdminUserInfo()
  1470. //获取医嘱模版
  1471. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1472. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1473. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1474. //获取所有基础药
  1475. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1476. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1477. if config.ID > 0 && config.IsOpen == 1 {
  1478. for _, item := range drugs {
  1479. var index = 0
  1480. for _, subItem := range item.OtherDrugWarehouseInfo {
  1481. if index == 0 {
  1482. index = index + 1
  1483. if subItem.RetailPrice > 0 {
  1484. item.MinPrice = subItem.RetailPrice
  1485. }
  1486. }
  1487. }
  1488. }
  1489. }
  1490. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1491. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1492. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1493. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1494. //获取所有科室信息
  1495. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1496. //获取诊断信息
  1497. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1498. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1499. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1500. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1501. //获取是否开启保存耗材出库的开关
  1502. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1503. c.ServeSuccessJSON(map[string]interface{}{
  1504. "drugs": drugs,
  1505. "advices_template": advices,
  1506. "drugways": drugways,
  1507. "efs": efs,
  1508. "doctors": doctors,
  1509. "department": department,
  1510. "sick": sick,
  1511. "additions": additions,
  1512. "diagnose": diagnose,
  1513. "manufacturers": manufacturers,
  1514. "goodOutOpen": goodOutOpen,
  1515. "patientDiagnose": patientDiagnose,
  1516. })
  1517. }
  1518. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1519. //获取所有基础药
  1520. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1521. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1522. if config.ID > 0 && config.IsOpen == 1 {
  1523. for _, item := range drugs {
  1524. var index = 0
  1525. for _, subItem := range item.OtherDrugWarehouseInfo {
  1526. if index == 0 {
  1527. index = index + 1
  1528. if subItem.RetailPrice > 0 {
  1529. item.MinPrice = subItem.RetailPrice
  1530. }
  1531. }
  1532. }
  1533. }
  1534. }
  1535. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1536. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1537. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1538. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1539. //获取所有科室信息
  1540. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1541. //获取诊断信息
  1542. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1543. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1544. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1545. //获取是否开启保存耗材出库的开关
  1546. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1547. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1548. c.ServeSuccessJSON(map[string]interface{}{
  1549. "drugs": drugs,
  1550. "advices_template": advices,
  1551. "drugways": drugways,
  1552. "efs": efs,
  1553. "doctors": doctors,
  1554. "department": department,
  1555. "sick": sick,
  1556. "additions": additions,
  1557. "diagnose": diagnose,
  1558. "manufacturers": manufacturers,
  1559. "goodOutOpen": goodOutOpen,
  1560. "patientDiagnose": patientDiagnose,
  1561. })
  1562. }
  1563. }
  1564. func (c *HisApiController) CreateHisPrescription() {
  1565. record_date := c.GetString("record_date")
  1566. patient_id, _ := c.GetInt64("patient_id")
  1567. reg_type, _ := c.GetInt64("reg_type")
  1568. diagnose := c.GetString("diagnose")
  1569. sick_type, _ := c.GetInt64("sick_type")
  1570. sick_history := c.GetString("sick_history")
  1571. doctor_id, _ := c.GetInt64("doctor", 0)
  1572. department, _ := c.GetInt64("department", 0)
  1573. his_patient_id, _ := c.GetInt64("his_patient_id")
  1574. p_type, _ := c.GetInt64("p_type")
  1575. patient_diagnose := c.GetString("patient_diagnose")
  1576. dataBody := make(map[string]interface{}, 0)
  1577. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1578. if err != nil {
  1579. utils.ErrorLog(err.Error())
  1580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1581. return
  1582. }
  1583. //edit, src := GetCompareData(dataBody)
  1584. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1585. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1586. //fmt.Println(drugResult)
  1587. //fmt.Println(goodResult)
  1588. timeLayout := "2006-01-02"
  1589. loc, _ := time.LoadLocation("Local")
  1590. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1591. if err != nil {
  1592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1593. return
  1594. }
  1595. adminInfo := c.GetAdminUserInfo()
  1596. recordDateTime := theTime.Unix()
  1597. //查询默认出库仓库库存
  1598. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1599. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1600. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1601. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1602. if len(lists) == 1 {
  1603. his_patient_id = lists[0].ID
  1604. }
  1605. }
  1606. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1607. //保存处方出库
  1608. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1609. //自动出库
  1610. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1611. //耗材保存处方出库
  1612. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1613. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1614. //已发药和已收费限制逻辑
  1615. isMidicine := false
  1616. isCharge := false
  1617. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1618. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1619. if len(prescriptions) > 0 {
  1620. for _, item := range prescriptions {
  1621. items := item.(map[string]interface{})
  1622. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1623. utils.ErrorLog("id")
  1624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1625. return
  1626. }
  1627. id := int64(items["id"].(float64))
  1628. if id > 0 {
  1629. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1630. if err != nil {
  1631. if new_prescription.OrderStatus == 4 {
  1632. isCharge = true
  1633. }
  1634. }
  1635. }
  1636. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1637. advices := items["advices"].([]interface{})
  1638. if len(advices) > 0 {
  1639. for _, advice := range advices {
  1640. var adviceId int64
  1641. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1642. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1643. }
  1644. if adviceId > 0 {
  1645. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1646. if err == nil {
  1647. if his_advice_info.IsMedicine == 1 {
  1648. isMidicine = true
  1649. }
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. if isMidicine == true {
  1659. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1660. return
  1661. }
  1662. if isCharge == true {
  1663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1664. return
  1665. }
  1666. // 开始主事务
  1667. db := service.XTWriteDB()
  1668. tx := db.Begin()
  1669. // 在函数结束时处理事务回滚
  1670. defer func() {
  1671. if r := recover(); r != nil {
  1672. tx.Rollback()
  1673. }
  1674. }()
  1675. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1676. //药品发药出库
  1677. if pharmacyConfig.IsOpen == 1 {
  1678. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1679. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1680. if len(prescriptions) > 0 {
  1681. for _, item := range prescriptions {
  1682. items := item.(map[string]interface{})
  1683. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1684. advices := items["advices"].([]interface{})
  1685. if len(advices) > 0 {
  1686. for _, advice := range advices {
  1687. var drug_id int64
  1688. var prescribing_number float64
  1689. var prescribingNumberUnit string
  1690. var adviceId int64
  1691. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1692. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1693. }
  1694. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1695. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1696. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1697. }
  1698. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1699. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1700. }
  1701. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1702. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1703. }
  1704. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1705. if drug.ID == 0 {
  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. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1726. return
  1727. }
  1728. if prescribing_number > all_count {
  1729. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1730. return
  1731. }
  1732. }
  1733. }
  1734. }
  1735. if prescribingNumberUnit == drug.MaxUnit {
  1736. num := prescribing_number * float64(drug.MinNumber)
  1737. if drug.IsUse != 1 {
  1738. if drug.IsProject == 0 || drug.IsProject == 2 {
  1739. if all_count == 0 {
  1740. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1741. return
  1742. }
  1743. if num > all_count {
  1744. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1745. return
  1746. }
  1747. }
  1748. }
  1749. }
  1750. }
  1751. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1752. if drugOutConfig.IsOpen != 1 {
  1753. //修改处方
  1754. for _, advice := range advices {
  1755. var drug_id int64
  1756. var prescribing_number float64
  1757. var prescribingNumberUnit string
  1758. var prescribingNumber string
  1759. var adviceId int64
  1760. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1761. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1762. }
  1763. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1764. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1765. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1766. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1767. }
  1768. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1769. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1770. }
  1771. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1772. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1773. }
  1774. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1775. if drug.ID == 0 {
  1776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1777. return
  1778. }
  1779. //查询药品的所有库存
  1780. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1781. var total_count int64
  1782. for _, it := range list {
  1783. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1784. }
  1785. totals := strconv.FormatInt(total_count, 10)
  1786. //查询该药品是否存在开药记录
  1787. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1788. //新增处方
  1789. if advicelist.ID == 0 {
  1790. all_count, _ := strconv.ParseFloat(totals, 64)
  1791. if prescribingNumberUnit == drug.MinUnit {
  1792. if drug.IsUse != 1 {
  1793. if drug.IsProject == 0 || drug.IsProject == 2 {
  1794. if all_count == 0 {
  1795. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1796. return
  1797. }
  1798. if prescribing_number > all_count {
  1799. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1800. return
  1801. }
  1802. }
  1803. }
  1804. } else {
  1805. if prescribingNumberUnit == drug.MaxUnit {
  1806. num := prescribing_number * float64(drug.MinNumber)
  1807. if drug.IsUse != 1 {
  1808. if drug.IsProject == 0 || drug.IsProject == 2 {
  1809. if all_count == 0 {
  1810. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1811. return
  1812. }
  1813. if num > all_count {
  1814. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1815. return
  1816. }
  1817. }
  1818. }
  1819. }
  1820. }
  1821. }
  1822. //修改处方
  1823. if advicelist.ID > 0 {
  1824. var device_number int64
  1825. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1826. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1827. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1828. device_number = prescribingNumberInt * drug.MinNumber
  1829. }
  1830. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1831. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1832. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1833. device_number = prescribingNumberInt
  1834. }
  1835. var number_count int64
  1836. if prescribingNumberUnit == drug.MaxUnit {
  1837. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1838. number_count = prescribingNumberInt * drug.MinNumber
  1839. }
  1840. if prescribingNumberUnit == drug.MinUnit {
  1841. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1842. number_count = prescribingNumberInt
  1843. }
  1844. //如果修改的数量大于之前修改的数量
  1845. if (number_count - device_number) > 0 {
  1846. //如果修改的差数量 大于库存数量
  1847. if drug.IsUse != 1 {
  1848. if (number_count - device_number) > total_count {
  1849. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1850. return
  1851. }
  1852. }
  1853. }
  1854. }
  1855. }
  1856. }
  1857. }
  1858. }
  1859. }
  1860. }
  1861. }
  1862. }
  1863. }
  1864. //已发药和已收费限制逻辑
  1865. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1866. //校验库存总量
  1867. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1868. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1869. if len(prescriptions) > 0 {
  1870. for _, item := range prescriptions {
  1871. items := item.(map[string]interface{})
  1872. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1873. advices := items["advices"].([]interface{})
  1874. if len(advices) > 0 {
  1875. for _, advice := range advices {
  1876. var drug_id int64
  1877. var prescribing_number float64
  1878. var prescribingNumberUnit string
  1879. var adviceId int64
  1880. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1881. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1882. }
  1883. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1884. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1885. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1886. }
  1887. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1888. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1889. }
  1890. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1891. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1892. }
  1893. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1894. if drug.ID == 0 {
  1895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1896. return
  1897. }
  1898. //查询药品的所有库存
  1899. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1900. var total_count int64
  1901. for _, it := range list {
  1902. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1903. }
  1904. totals := strconv.FormatInt(total_count, 10)
  1905. //查询该药品是否存在开药记录
  1906. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1907. //查询最新批次库存
  1908. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1909. var batch_number_count int64
  1910. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1911. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1912. //新增处方
  1913. if advicelist.ID == 0 {
  1914. all_count, _ := strconv.ParseFloat(totals, 64)
  1915. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1916. if prescribingNumberUnit == drug.MinUnit {
  1917. if drug.IsUse != 1 {
  1918. if drug.IsProject == 0 || drug.IsProject == 2 {
  1919. if all_count == 0 {
  1920. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1921. return
  1922. }
  1923. if prescribing_number > all_count {
  1924. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1925. return
  1926. }
  1927. }
  1928. if adminInfo.CurrentOrgId == 10215 {
  1929. if prescribing_number > batch_number_all_count {
  1930. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1931. return
  1932. }
  1933. }
  1934. }
  1935. }
  1936. if prescribingNumberUnit == drug.MaxUnit {
  1937. num := prescribing_number * float64(drug.MinNumber)
  1938. if drug.IsUse != 1 {
  1939. if drug.IsProject == 0 || drug.IsProject == 2 {
  1940. if all_count == 0 {
  1941. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1942. return
  1943. }
  1944. if num > all_count {
  1945. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1946. return
  1947. }
  1948. }
  1949. if adminInfo.CurrentOrgId == 10215 {
  1950. if num > batch_number_all_count {
  1951. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1952. return
  1953. }
  1954. }
  1955. }
  1956. }
  1957. }
  1958. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1959. if drugOutConfig.IsOpen != 1 {
  1960. //修改处方
  1961. for _, advice := range advices {
  1962. var drug_id int64
  1963. var prescribing_number float64
  1964. var prescribingNumberUnit string
  1965. var prescribingNumber string
  1966. var adviceId int64
  1967. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1968. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1969. }
  1970. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1971. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1972. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1973. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1974. }
  1975. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1976. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1977. }
  1978. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1979. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1980. }
  1981. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1982. if drug.ID == 0 {
  1983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1984. return
  1985. }
  1986. //查询药品的所有库存
  1987. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1988. var total_count int64
  1989. for _, it := range list {
  1990. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1991. }
  1992. totals := strconv.FormatInt(total_count, 10)
  1993. //查询该药品是否存在开药记录
  1994. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1995. //新增处方
  1996. if advicelist.ID == 0 {
  1997. //查询最新批次库存
  1998. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1999. var batch_number_count int64
  2000. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2001. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2002. all_count, _ := strconv.ParseFloat(totals, 64)
  2003. if prescribingNumberUnit == drug.MinUnit {
  2004. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2005. if drug.IsUse != 1 {
  2006. if drug.IsProject == 0 || drug.IsProject == 2 {
  2007. if all_count == 0 {
  2008. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2009. return
  2010. }
  2011. if prescribing_number > all_count {
  2012. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2013. return
  2014. }
  2015. }
  2016. if adminInfo.CurrentOrgId == 10215 {
  2017. if prescribing_number > batch_number_all_count {
  2018. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2019. return
  2020. }
  2021. }
  2022. }
  2023. } else {
  2024. if prescribingNumberUnit == drug.MaxUnit {
  2025. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2026. num := prescribing_number * float64(drug.MinNumber)
  2027. if drug.IsUse != 1 {
  2028. if drug.IsProject == 0 || drug.IsProject == 2 {
  2029. if all_count == 0 {
  2030. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2031. return
  2032. }
  2033. if num > all_count {
  2034. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2035. return
  2036. }
  2037. }
  2038. if adminInfo.CurrentOrgId == 10215 {
  2039. if prescribing_number > batch_number_all_count {
  2040. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2041. return
  2042. }
  2043. }
  2044. }
  2045. }
  2046. }
  2047. }
  2048. //修改处方
  2049. if advicelist.ID > 0 {
  2050. //查询最新批次库存
  2051. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2052. var batch_number_count int64
  2053. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2054. var device_number int64
  2055. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2056. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2057. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2058. device_number = prescribingNumberInt * drug.MinNumber
  2059. }
  2060. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2061. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2062. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2063. device_number = prescribingNumberInt
  2064. }
  2065. var number_count int64
  2066. if prescribingNumberUnit == drug.MaxUnit {
  2067. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2068. number_count = prescribingNumberInt * drug.MinNumber
  2069. }
  2070. if prescribingNumberUnit == drug.MinUnit {
  2071. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2072. number_count = prescribingNumberInt
  2073. }
  2074. //如果修改的数量大于之前修改的数量
  2075. if (number_count - device_number) > 0 {
  2076. //如果修改的差数量 大于库存数量
  2077. if drug.IsUse != 1 {
  2078. if drug.IsProject == 0 || drug.IsProject == 2 {
  2079. if total_count == 0 {
  2080. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2081. return
  2082. }
  2083. if (number_count - device_number) > total_count {
  2084. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2085. return
  2086. }
  2087. if (number_count - device_number) > batch_number_count {
  2088. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2089. return
  2090. }
  2091. }
  2092. if adminInfo.CurrentOrgId == 10215 {
  2093. // 查询该药品最后一次出库记录
  2094. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2095. var out_count int64
  2096. var in_count int64
  2097. var stock_max_number int64
  2098. var stock_min_number int64
  2099. for _, it := range outInfo {
  2100. if it.CountUnit == drug.MaxUnit {
  2101. it.Count = it.Count * drug.MinNumber
  2102. }
  2103. out_count += it.Count
  2104. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2105. stock_max_number = warehouseInfoList.StockMaxNumber
  2106. stock_min_number = warehouseInfoList.StockMinNumber
  2107. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2108. }
  2109. if out_count > 0 {
  2110. if (number_count - device_number) > in_count {
  2111. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2112. return
  2113. }
  2114. }
  2115. // 未出库
  2116. if out_count == 0 {
  2117. var sum_in_count int64
  2118. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2119. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2120. fmt.Println("sum_in_count", sum_in_count)
  2121. //如果修改的数量大于有库存的第一个批次
  2122. if number_count > sum_in_count {
  2123. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2124. return
  2125. }
  2126. }
  2127. }
  2128. }
  2129. }
  2130. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2131. if pharmacyConfig.IsOpen != 1 {
  2132. if device_number != number_count {
  2133. // 查询该药品最后一次出库记录
  2134. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2135. //回退库存
  2136. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2137. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2138. }
  2139. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2140. var stock_max_number int64
  2141. var stock_min_number int64
  2142. if number_count >= drug.MinNumber {
  2143. stock_max_number = device_number / drug.MinNumber
  2144. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2145. stock_min_number = device_number % drug.MinNumber
  2146. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2147. } else {
  2148. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2149. }
  2150. }
  2151. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2152. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2153. }
  2154. //删除记录
  2155. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2156. //查询默认仓库剩余多少库存
  2157. var sum_count int64
  2158. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2159. for _, its := range stockInfo {
  2160. if its.MaxUnit == drug.MaxUnit {
  2161. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2162. }
  2163. sum_count += its.StockMaxNumber + its.StockMinNumber
  2164. }
  2165. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. //保存处方开药
  2172. if drugOutConfig.IsOpen == 1 {
  2173. //修改处方
  2174. for _, advice := range advices {
  2175. var drug_id int64
  2176. var prescribing_number float64
  2177. var prescribingNumberUnit string
  2178. var prescribingNumber string
  2179. var adviceId int64
  2180. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2181. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2182. }
  2183. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2184. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2185. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2186. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2187. }
  2188. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2189. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2190. }
  2191. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2192. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2193. }
  2194. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2195. if drug.ID == 0 {
  2196. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2197. return
  2198. }
  2199. //查询药品的所有库存
  2200. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2201. var total_count int64
  2202. for _, it := range list {
  2203. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2204. }
  2205. totals := strconv.FormatInt(total_count, 10)
  2206. //查询该药品是否存在开药记录
  2207. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2208. //新增处方
  2209. if advicelist.ID == 0 {
  2210. //查询最新批次库存
  2211. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2212. var batch_number_count int64
  2213. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2214. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2215. all_count, _ := strconv.ParseFloat(totals, 64)
  2216. if prescribingNumberUnit == drug.MinUnit {
  2217. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2218. if drug.IsUse != 1 {
  2219. if drug.IsProject == 0 || drug.IsProject == 2 {
  2220. if all_count == 0 {
  2221. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2222. return
  2223. }
  2224. if prescribing_number > all_count {
  2225. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2226. return
  2227. }
  2228. }
  2229. if adminInfo.CurrentOrgId == 10215 {
  2230. if prescribing_number > batch_number_all_count {
  2231. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2232. return
  2233. }
  2234. }
  2235. }
  2236. } else {
  2237. if prescribingNumberUnit == drug.MaxUnit {
  2238. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2239. num := prescribing_number * float64(drug.MinNumber)
  2240. if drug.IsUse != 1 {
  2241. if drug.IsProject == 0 || drug.IsProject == 2 {
  2242. if all_count == 0 {
  2243. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2244. return
  2245. }
  2246. if num > all_count {
  2247. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2248. return
  2249. }
  2250. }
  2251. if adminInfo.CurrentOrgId == 10215 {
  2252. if prescribing_number > batch_number_all_count {
  2253. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2254. return
  2255. }
  2256. }
  2257. }
  2258. }
  2259. }
  2260. }
  2261. //修改处方
  2262. if advicelist.ID > 0 {
  2263. //查询最新批次库存
  2264. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2265. var batch_number_count int64
  2266. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2267. var device_number int64
  2268. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2269. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2270. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2271. device_number = prescribingNumberInt * drug.MinNumber
  2272. }
  2273. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2274. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2275. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2276. device_number = prescribingNumberInt
  2277. }
  2278. var number_count int64
  2279. if prescribingNumberUnit == drug.MaxUnit {
  2280. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2281. number_count = prescribingNumberInt * drug.MinNumber
  2282. }
  2283. if prescribingNumberUnit == drug.MinUnit {
  2284. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2285. number_count = prescribingNumberInt
  2286. }
  2287. //如果修改的数量大于之前修改的数量
  2288. if (number_count - device_number) > 0 {
  2289. //如果修改的差数量 大于库存数量
  2290. if drug.IsUse != 1 {
  2291. if drug.IsProject == 0 || drug.IsProject == 2 {
  2292. if total_count == 0 {
  2293. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2294. return
  2295. }
  2296. if (number_count - device_number) > total_count {
  2297. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2298. return
  2299. }
  2300. }
  2301. if adminInfo.CurrentOrgId == 10215 {
  2302. if (number_count - device_number) > batch_number_count {
  2303. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2304. return
  2305. }
  2306. }
  2307. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2308. //查询历史出库数据总批次
  2309. // 查询该药品最后一次出库记录
  2310. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2311. var out_count int64
  2312. var in_count int64
  2313. var stock_max_number int64
  2314. var stock_min_number int64
  2315. for _, it := range outInfo {
  2316. if it.CountUnit == drug.MaxUnit {
  2317. it.Count = it.Count * drug.MinNumber
  2318. }
  2319. out_count += it.Count
  2320. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2321. stock_max_number = warehouseInfoList.StockMaxNumber
  2322. stock_min_number = warehouseInfoList.StockMinNumber
  2323. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2324. }
  2325. if out_count > 0 {
  2326. if (number_count - device_number) > in_count {
  2327. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2328. return
  2329. }
  2330. }
  2331. // 未出库
  2332. if out_count == 0 {
  2333. var sum_in_count int64
  2334. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2335. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2336. if sum_in_count == 0 {
  2337. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2338. return
  2339. }
  2340. //如果修改的数量大于有库存的第一个批次
  2341. if number_count > sum_in_count {
  2342. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2343. return
  2344. }
  2345. }
  2346. }
  2347. }
  2348. }
  2349. }
  2350. }
  2351. }
  2352. }
  2353. }
  2354. }
  2355. }
  2356. }
  2357. }
  2358. }
  2359. //校验耗材库存
  2360. if goodOutConfig.IsOpen == 1 {
  2361. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2362. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2363. if len(prescriptions) > 0 {
  2364. for _, item := range prescriptions {
  2365. items := item.(map[string]interface{})
  2366. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2367. projects := items["project"].([]interface{})
  2368. if len(projects) > 0 {
  2369. for _, project := range projects {
  2370. var project_id int64
  2371. var project_type int64
  2372. var totals float64
  2373. var project_name string
  2374. var parsetotal int64
  2375. var id int64
  2376. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2377. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2378. }
  2379. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2380. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2381. }
  2382. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2383. total, _ := project.(map[string]interface{})["total"].(string)
  2384. totals, _ = strconv.ParseFloat(total, 64)
  2385. }
  2386. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2387. project_name = project.(map[string]interface{})["project_name"].(string)
  2388. }
  2389. if project_type == 3 {
  2390. //查找该耗材的出库记录
  2391. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2392. if len(goodWarehouseInfo) == 0 {
  2393. //查询耗材库存
  2394. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2395. var stock_count int64
  2396. for _, it := range list {
  2397. stock_count += it.StockCount
  2398. }
  2399. stock_counts := strconv.FormatInt(stock_count, 10)
  2400. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2401. if stock_total_count == 0 {
  2402. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2403. return
  2404. }
  2405. if totals > stock_total_count {
  2406. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2407. return
  2408. }
  2409. }
  2410. if len(goodWarehouseInfo) > 0 {
  2411. //查询该患者耗材的历史数据
  2412. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2413. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2414. //数量发生改变
  2415. if parsetotal != count {
  2416. //如果现在的数量大于历史数量,就要看库存是否足够
  2417. if parsetotal > count {
  2418. //查询耗材所有库存
  2419. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2420. var stock_count int64
  2421. for _, it := range list {
  2422. stock_count += it.StockCount
  2423. }
  2424. //库存不足
  2425. if stock_count == 0 {
  2426. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2427. return
  2428. }
  2429. if (parsetotal - count) > stock_count {
  2430. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2431. return
  2432. }
  2433. }
  2434. }
  2435. }
  2436. }
  2437. }
  2438. }
  2439. }
  2440. }
  2441. }
  2442. }
  2443. }
  2444. //不使用耗材保存处方出库
  2445. if goodOutConfig.IsOpen != 1 {
  2446. if stockConfig.IsOpen == 1 {
  2447. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2448. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2449. if len(prescriptions) > 0 {
  2450. for _, item := range prescriptions {
  2451. items := item.(map[string]interface{})
  2452. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2453. projects := items["project"].([]interface{})
  2454. if len(projects) > 0 {
  2455. for _, project := range projects {
  2456. var project_id int64
  2457. var project_type int64
  2458. var totals float64
  2459. var project_name string
  2460. var parsetotal int64
  2461. var id int64
  2462. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2463. id = int64(project.(map[string]interface{})["id"].(float64))
  2464. }
  2465. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2466. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2467. }
  2468. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2469. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2470. }
  2471. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2472. total, _ := project.(map[string]interface{})["total"].(string)
  2473. totals, _ = strconv.ParseFloat(total, 64)
  2474. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2475. }
  2476. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2477. project_name = project.(map[string]interface{})["project_name"].(string)
  2478. }
  2479. if project_type == 3 {
  2480. //查找该耗材的出库记录
  2481. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2482. //没有出库记录
  2483. if len(goodWarehouseInfo) == 0 {
  2484. //查询耗材库存
  2485. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2486. var stock_count int64
  2487. for _, it := range list {
  2488. stock_count += it.StockCount
  2489. }
  2490. stock_counts := strconv.FormatInt(stock_count, 10)
  2491. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2492. if stock_total_count == 0 {
  2493. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2494. return
  2495. }
  2496. if totals > stock_total_count {
  2497. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2498. return
  2499. }
  2500. //查找今日该患者已经出库的所有耗材
  2501. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2502. for _, item := range goodList {
  2503. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2504. var flush_count int64
  2505. for _, it := range goodListSix {
  2506. flush_count += it.StockCount
  2507. }
  2508. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2509. creater := adminInfo.AdminUser.Id
  2510. if errs != nil {
  2511. goodErrcode := models.XtGoodErrcode{
  2512. UserOrgId: item.OrgId,
  2513. Errcode: "手动出库更新剩余出库失败",
  2514. GoodId: item.GoodId,
  2515. Status: 1,
  2516. Ctime: time.Now().Unix(),
  2517. Mtime: 0,
  2518. Count: 0,
  2519. StockCount: 0,
  2520. Creater: creater,
  2521. BatchNumberId: 0,
  2522. WarehouseOutId: 0,
  2523. }
  2524. service.CreateGoodErrcode(goodErrcode)
  2525. }
  2526. }
  2527. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2528. }
  2529. //有出库记录
  2530. if len(goodWarehouseInfo) > 0 {
  2531. //查询该患者耗材的历史数据
  2532. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2533. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2534. //数量发生改变
  2535. if parsetotal != count {
  2536. //查找今日该患者已经出库的所有耗材
  2537. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2538. for _, item := range goodList {
  2539. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2540. var flush_count int64
  2541. for _, it := range goodListSix {
  2542. flush_count += it.StockCount
  2543. }
  2544. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2545. //减少出库数量
  2546. creater := adminInfo.AdminUser.Id
  2547. if errs != nil {
  2548. goodErrcode := models.XtGoodErrcode{
  2549. UserOrgId: item.OrgId,
  2550. Errcode: "手动出库更新剩余出库失败",
  2551. GoodId: item.GoodId,
  2552. Status: 1,
  2553. Ctime: time.Now().Unix(),
  2554. Mtime: 0,
  2555. Count: 0,
  2556. StockCount: 0,
  2557. Creater: creater,
  2558. BatchNumberId: 0,
  2559. WarehouseOutId: 0,
  2560. }
  2561. service.CreateGoodErrcode(goodErrcode)
  2562. }
  2563. //查询默认仓库
  2564. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2565. var total_count int64
  2566. for _, it := range stockList {
  2567. total_count += it.StockCount
  2568. }
  2569. //基础库插入数据
  2570. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2571. }
  2572. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2573. }
  2574. }
  2575. }
  2576. }
  2577. }
  2578. }
  2579. }
  2580. }
  2581. }
  2582. }
  2583. }
  2584. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2585. var hpInfo models.HisPrescriptionInfo
  2586. if info.ID == 0 {
  2587. var randNum int
  2588. randNum = rand.Intn(10000) + 1000
  2589. timestamp := time.Now().Unix()
  2590. tempTime := time.Unix(timestamp, 0)
  2591. timeFormat := tempTime.Format("20060102150405")
  2592. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2593. hpInfo = models.HisPrescriptionInfo{
  2594. HisPatientId: his_patient_id,
  2595. UserOrgId: adminInfo.CurrentOrgId,
  2596. RecordDate: theTime.Unix(),
  2597. PatientId: patient_id,
  2598. Status: 1,
  2599. Ctime: time.Now().Unix(),
  2600. Mtime: time.Now().Unix(),
  2601. Creator: adminInfo.AdminUser.Id,
  2602. Modifier: adminInfo.AdminUser.Id,
  2603. Diagnosis: diagnose,
  2604. SickHistory: sick_history,
  2605. Departments: department,
  2606. RegisterType: reg_type,
  2607. PrescriptionNumber: p_number,
  2608. PrescriptionStatus: 1,
  2609. Doctor: role.UserName,
  2610. DoctorId: doctor_id,
  2611. SickType: sick_type,
  2612. PType: p_type,
  2613. PatientDiagnosis: patient_diagnose,
  2614. }
  2615. service.SavePatientPrescriptionInfo(hpInfo)
  2616. //创建步骤表
  2617. finish := models.XtDialysisFinish{
  2618. IsFinish: 1,
  2619. UserOrgId: adminInfo.CurrentOrgId,
  2620. Status: 1,
  2621. Ctime: time.Now().Unix(),
  2622. Mtime: 0,
  2623. Module: 4,
  2624. RecordDate: theTime.Unix(),
  2625. Sourse: 1,
  2626. PatientId: patient_id,
  2627. }
  2628. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2629. if dialysisFinish.ID == 0 {
  2630. service.CreateDialysisFinish(finish)
  2631. }
  2632. redis := service.RedisClient()
  2633. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2634. redis.Set(key, "", time.Second)
  2635. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2636. redis.Set(keyOne, "", time.Second)
  2637. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2638. redis.Set(keySeven, "", time.Second)
  2639. defer redis.Close()
  2640. } else {
  2641. hpInfo = models.HisPrescriptionInfo{
  2642. ID: info.ID,
  2643. UserOrgId: adminInfo.CurrentOrgId,
  2644. RecordDate: info.RecordDate,
  2645. PatientId: info.PatientId,
  2646. Status: 1,
  2647. Ctime: info.Ctime,
  2648. Mtime: time.Now().Unix(),
  2649. Creator: info.Creator,
  2650. Modifier: adminInfo.AdminUser.Id,
  2651. Diagnosis: diagnose,
  2652. SickHistory: sick_history,
  2653. Departments: department,
  2654. RegisterType: reg_type,
  2655. PrescriptionNumber: info.PrescriptionNumber,
  2656. Doctor: role.UserName,
  2657. PrescriptionStatus: info.PrescriptionStatus,
  2658. DoctorId: doctor_id,
  2659. SickType: sick_type,
  2660. PType: info.PType,
  2661. HisPatientId: info.HisPatientId,
  2662. PatientDiagnosis: patient_diagnose,
  2663. }
  2664. service.SavePatientPrescriptionInfo(hpInfo)
  2665. //创建步骤表
  2666. finish := models.XtDialysisFinish{
  2667. IsFinish: 1,
  2668. UserOrgId: adminInfo.CurrentOrgId,
  2669. Status: 1,
  2670. Ctime: time.Now().Unix(),
  2671. Mtime: 0,
  2672. Module: 4,
  2673. RecordDate: info.RecordDate,
  2674. Sourse: 1,
  2675. PatientId: info.PatientId,
  2676. }
  2677. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2678. if dialysisFinish.ID == 0 {
  2679. service.CreateDialysisFinish(finish)
  2680. }
  2681. redis := service.RedisClient()
  2682. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2683. redis.Set(key, "", time.Second)
  2684. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2685. redis.Set(keyOne, "", time.Second)
  2686. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2687. redis.Set(keySeven, "", time.Second)
  2688. defer redis.Close()
  2689. }
  2690. //定义切片
  2691. var adviceList []models.HisDoctorAdviceInfo
  2692. var projectList []models.HisPrescriptionProject
  2693. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 {
  2694. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2695. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2696. var tempPrescription *models.HisPrescription
  2697. if len(prescriptions) > 0 {
  2698. for _, item := range prescriptions {
  2699. // 开始外部循环的事务
  2700. tx := db.Begin()
  2701. // 在函数结束时处理事务回滚
  2702. defer func() {
  2703. if r := recover(); r != nil {
  2704. tx.Rollback()
  2705. }
  2706. }()
  2707. items := item.(map[string]interface{})
  2708. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2709. utils.ErrorLog("id")
  2710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2711. return
  2712. }
  2713. id := int64(items["id"].(float64))
  2714. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2715. tempPrescription = &new_prescription
  2716. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2717. utils.ErrorLog("type")
  2718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2719. return
  2720. }
  2721. types := int64(items["type"].(float64))
  2722. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2723. utils.ErrorLog("med_type")
  2724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2725. return
  2726. }
  2727. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2728. if med_type == "0" {
  2729. med_type = "14"
  2730. }
  2731. //if order_status == 0 {
  2732. // order_status = 1
  2733. //}
  2734. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2735. utils.ErrorLog("pre_time")
  2736. }
  2737. preTime, _ := items["pre_time"].(string)
  2738. fmt.Println("preTime", preTime)
  2739. timeLayout := "2006-01-02"
  2740. loc, _ := time.LoadLocation("Local")
  2741. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2742. result := strings.Split(preTime, " ")
  2743. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2744. if err != nil {
  2745. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2746. return
  2747. }
  2748. pTime := theTime2.Unix()
  2749. ctime := time.Now().Unix()
  2750. if tempPrescription.ID == 0 {
  2751. prescription := &models.HisPrescription{
  2752. ID: 0,
  2753. PatientId: patient_id,
  2754. UserOrgId: adminInfo.CurrentOrgId,
  2755. RecordDate: recordDateTime,
  2756. Ctime: ctime,
  2757. Mtime: ctime,
  2758. Type: types,
  2759. Modifier: adminInfo.AdminUser.Id,
  2760. Creator: adminInfo.AdminUser.Id,
  2761. Status: 1,
  2762. Doctor: role.UserName,
  2763. HisPatientId: his_patient_id,
  2764. OrderStatus: 1,
  2765. BatchNumber: "",
  2766. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2767. PreTime: pTime,
  2768. PType: p_type,
  2769. MedType: med_type,
  2770. }
  2771. tempPrescription = prescription
  2772. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2773. redis := service.RedisClient()
  2774. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2775. redis.Set(key, "", time.Second)
  2776. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2777. redis.Set(keyOne, "", time.Second)
  2778. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2779. redis.Set(keySeven, "", time.Second)
  2780. defer redis.Close()
  2781. } else {
  2782. tempPrescription.ID = id
  2783. tempPrescription.Type = types
  2784. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2785. tempPrescription.Mtime = time.Now().Unix()
  2786. tempPrescription.Doctor = role.UserName
  2787. //tempPrescription.OrderStatus = order_status
  2788. tempPrescription.PreTime = pTime
  2789. tempPrescription.MedType = med_type
  2790. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2791. redis := service.RedisClient()
  2792. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2793. redis.Set(key, "", time.Second)
  2794. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2795. redis.Set(keyOne, "", time.Second)
  2796. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2797. redis.Set(keySeven, "", time.Second)
  2798. defer redis.Close()
  2799. }
  2800. //service.SaveHisPrescription(prescription)
  2801. //更改患者挂号状态
  2802. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2803. fmt.Println("更改失败", err2)
  2804. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2805. advices := items["advices"].([]interface{})
  2806. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2807. groupNo := int64(0)
  2808. ctime := time.Now().Unix()
  2809. mtime := ctime
  2810. if len(advices) > 0 {
  2811. for _, advice := range advices {
  2812. tx := db.Begin()
  2813. // 在函数结束时处理事务回滚
  2814. defer func() {
  2815. if r := recover(); r != nil {
  2816. tx.Rollback()
  2817. }
  2818. }()
  2819. var s models.HisDoctorAdviceInfo
  2820. s.PrescriptionId = tempPrescription.ID
  2821. s.AdviceType = 2
  2822. s.AdviceDoctor = doctor_id
  2823. s.StopState = 2
  2824. s.ExecutionState = 2
  2825. s.AdviceDate = theTime3.Unix()
  2826. s.Status = 1
  2827. s.UserOrgId = adminInfo.CurrentOrgId
  2828. s.RecordDate = theTime3.Unix()
  2829. s.StartTime = tempPrescription.PreTime
  2830. s.Groupno = groupNo
  2831. s.CreatedTime = ctime
  2832. s.UpdatedTime = mtime
  2833. s.PatientId = patient_id
  2834. s.HisPatientId = his_patient_id
  2835. s.StartTime = pTime
  2836. s.IsSettle = 2
  2837. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2838. if errcode > 0 {
  2839. c.ServeFailJSONWithSGJErrorCode(errcode)
  2840. return
  2841. }
  2842. s.StartTime = pTime
  2843. var total_count int64 //处方总库存
  2844. //查询改药品信息
  2845. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2846. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2847. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2848. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2849. total_count += prescribingNumberSeven * medical.MinNumber
  2850. }
  2851. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2852. total_count += prescribingNumberSeven
  2853. }
  2854. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2855. total_count += prescribingNumberSeven
  2856. }
  2857. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2858. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2859. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2860. if s.Price != lastWarehouse.RetailPrice {
  2861. s.Price = lastWarehouse.RetailPrice
  2862. }
  2863. if s.Price == 0 {
  2864. s.Price = lastWarehouse.RetailPrice
  2865. }
  2866. }
  2867. //查询保存处方出库开关是否打开
  2868. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2869. if drugOutConfig.IsOpen == 1 {
  2870. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2871. // 查询该药品最后一次出库记录
  2872. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2873. if len(druginfo) > 0 {
  2874. //回退库存
  2875. for _, it := range druginfo {
  2876. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2877. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2878. }
  2879. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2880. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2881. }
  2882. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2883. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2884. }
  2885. }
  2886. //删除记录
  2887. service.DeleteDrugAutoWarehouseSeven(s.DrugId, patient_id, recordDateTime, s.ID)
  2888. }
  2889. service.CreateHisDoctorAdviceOne(&s, tx)
  2890. advicelast, _ := service.GetLastHisAdvicesList(s.PatientId, s.AdviceDate, s.UserOrgId, tx)
  2891. //出库
  2892. if drug.IsUse == 2 {
  2893. creater := adminInfo.AdminUser.Id
  2894. newadviceInfo := &models.HisDoctorAdviceInfo{
  2895. ID: advicelast.ID,
  2896. UserOrgId: s.UserOrgId,
  2897. PatientId: s.PatientId,
  2898. HisPatientId: s.HisPatientId,
  2899. AdviceType: s.AdviceType,
  2900. AdviceDate: s.AdviceDate,
  2901. StartTime: s.StartTime,
  2902. AdviceName: s.AdviceName,
  2903. AdviceDesc: s.AdviceDesc,
  2904. ReminderDate: s.ReminderDate,
  2905. SingleDose: s.SingleDose,
  2906. SingleDoseUnit: s.SingleDoseUnit,
  2907. PrescribingNumber: s.PrescribingNumber,
  2908. PrescribingNumberUnit: s.PrescribingNumberUnit,
  2909. DeliveryWay: s.DeliveryWay,
  2910. ExecutionFrequency: s.ExecutionFrequency,
  2911. AdviceDoctor: s.AdviceDoctor,
  2912. Status: s.Status,
  2913. CreatedTime: s.CreatedTime,
  2914. UpdatedTime: s.UpdatedTime,
  2915. AdviceAffirm: s.AdviceAffirm,
  2916. Remark: s.Remark,
  2917. StopTime: s.StopTime,
  2918. StopReason: s.StopReason,
  2919. StopDoctor: s.StopDoctor,
  2920. StopState: s.StopState,
  2921. ParentId: s.ParentId,
  2922. ExecutionTime: s.ExecutionTime,
  2923. ExecutionStaff: s.ExecutionStaff,
  2924. ExecutionState: s.ExecutionState,
  2925. Checker: s.Checker,
  2926. RecordDate: s.RecordDate,
  2927. DialysisOrderId: s.DialysisOrderId,
  2928. CheckTime: s.CheckTime,
  2929. CheckState: s.CheckState,
  2930. DrugSpec: s.DrugSpec,
  2931. DrugSpecUnit: s.DrugSpecUnit,
  2932. Groupno: s.Groupno,
  2933. RemindType: s.RemindType,
  2934. FrequencyType: s.FrequencyType,
  2935. DayCount: s.DayCount,
  2936. WeekDay: s.WeekDay,
  2937. TemplateId: s.TemplateId,
  2938. Modifier: s.Modifier,
  2939. DrugId: s.DrugId,
  2940. Price: s.Price,
  2941. PrescriptionId: s.PrescriptionId,
  2942. MedListCodg: s.MedListCodg,
  2943. FeedetlSn: s.FeedetlSn,
  2944. Day: s.DayCount,
  2945. ChildDoctorAdvice: nil,
  2946. Drug: models.Drug{},
  2947. Diagnosis: s.Diagnosis,
  2948. Way: s.Way,
  2949. HospApprFlag: s.HospApprFlag,
  2950. LmtUsedFlag: s.LmtUsedFlag,
  2951. HisOrderInfo: models.HisOrderInfo{},
  2952. IsMedicine: s.IsMedicine,
  2953. ExecutionFrequencyId: s.ExecutionFrequencyId,
  2954. Child: nil,
  2955. IsSettle: s.IsSettle,
  2956. IsMobile: s.IsMobile,
  2957. IsSelfDrug: s.IsSelfDrug,
  2958. DrugWayCount: s.DrugWayCount,
  2959. }
  2960. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  2961. }
  2962. //更新字典里面的库存
  2963. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  2964. var sum_count int64
  2965. for _, its := range stockInfo {
  2966. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  2967. if its.MaxUnit == baseDrug.MaxUnit {
  2968. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2969. }
  2970. sum_count += its.StockMaxNumber + its.StockMinNumber
  2971. }
  2972. //更新基础库存
  2973. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  2974. //剩余库存
  2975. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  2976. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  2977. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  2978. }
  2979. //记录日志
  2980. byterequest, _ := json.Marshal(s)
  2981. adviceLog := models.XtDoctorAdviceLog{
  2982. UserOrgId: s.UserOrgId,
  2983. PatientId: s.PatientId,
  2984. AdminUserId: adminInfo.AdminUser.Id,
  2985. Module: 1,
  2986. ErrLog: string(byterequest),
  2987. Status: 1,
  2988. Ctime: time.Now().Unix(),
  2989. Mtime: 0,
  2990. Source: "电脑端新建his医嘱",
  2991. RecordDate: s.AdviceDate,
  2992. }
  2993. service.CreateDoctorAdviceLog(adviceLog)
  2994. //存储切片中
  2995. adviceList = append(adviceList, s)
  2996. redis := service.RedisClient()
  2997. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2998. redis.Set(key, "", time.Second)
  2999. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3000. redis.Set(keyOne, "", time.Second)
  3001. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3002. redis.Set(keySeven, "", time.Second)
  3003. var randNum int
  3004. randNum = rand.Intn(10000) + 1000
  3005. timestamp := time.Now().Unix()
  3006. tempTime := time.Unix(timestamp, 0)
  3007. timeFormat := tempTime.Format("20060102150405")
  3008. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3009. service.CreateHisDoctorAdviceOne(&s, tx)
  3010. tx.Commit()
  3011. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3012. redis.Set(keySix, "", time.Second)
  3013. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3014. redis.Set(keyFive, "", time.Second)
  3015. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3016. redis.Set(keyEight, "", time.Second)
  3017. defer redis.Close()
  3018. }
  3019. }
  3020. }
  3021. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3022. projects := items["project"].([]interface{})
  3023. if len(projects) > 0 {
  3024. for _, project := range projects {
  3025. tx := db.Begin()
  3026. // 在函数结束时处理事务回滚
  3027. defer func() {
  3028. if r := recover(); r != nil {
  3029. tx.Rollback()
  3030. }
  3031. }()
  3032. var p models.HisPrescriptionProject
  3033. p.PrescriptionId = tempPrescription.ID
  3034. p.Ctime = time.Now().Unix()
  3035. p.Mtime = p.Ctime
  3036. p.PatientId = patient_id
  3037. p.RecordDate = theTime3.Unix()
  3038. p.Doctor = doctor_id
  3039. p.UserOrgId = adminInfo.CurrentOrgId
  3040. p.HisPatientId = his_patient_id
  3041. p.Status = 1
  3042. p.StartTime = pTime
  3043. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3044. if errcode > 0 {
  3045. c.ServeFailJSONWithSGJErrorCode(errcode)
  3046. return
  3047. }
  3048. if p.ID == 0 {
  3049. p.IsOut = 2
  3050. }
  3051. if p.ID > 0 {
  3052. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3053. p.IsOut = projectDetail.IsOut
  3054. }
  3055. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3056. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3057. if p.Type == 3 {
  3058. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3059. if p.Price != lastWarehouse.PackingPrice {
  3060. p.Price = lastWarehouse.PackingPrice
  3061. }
  3062. if p.Unit == "" {
  3063. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3064. p.Unit = goodInfoOne.PackingUnit
  3065. }
  3066. }
  3067. }
  3068. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3069. //
  3070. // if p.Type == 3 {
  3071. // //查询该耗材是否停用
  3072. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3073. // //表示该耗材已经停用,不能保存
  3074. // if goodInfoSeven.ID == 0 {
  3075. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3076. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3077. // return
  3078. // }
  3079. // }
  3080. //
  3081. //}
  3082. service.CreateNewHisProjectTwo(&p, tx)
  3083. //查询保存耗材出库开关是否打开
  3084. if goodOutConfig.IsOpen == 1 {
  3085. //耗材出库
  3086. if p.Type == 3 {
  3087. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3088. //查询历史出库数据
  3089. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3090. var out_count_five int64
  3091. for _, item := range flowGood {
  3092. out_count_five += item.Count
  3093. }
  3094. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3095. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3096. if out_count_five != parseIntCount {
  3097. //查询耗材最后一次出库记录
  3098. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3099. //查询默认出库仓库库存
  3100. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3101. if len(wareOut) > 0 {
  3102. for _, it := range wareOut {
  3103. //回退库存
  3104. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3105. //删除出库记录
  3106. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3107. }
  3108. }
  3109. timeStr := time.Now().Format("2006-01-02")
  3110. timeArr := strings.Split(timeStr, "-")
  3111. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3112. total = total + 1
  3113. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3114. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3115. number = number + total
  3116. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3117. operation_time := time.Now().Unix()
  3118. creater := c.GetAdminUserInfo().AdminUser.Id
  3119. recordDateStr := time.Now().Format("2006-01-02")
  3120. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3121. nowtime := recordDate.Unix()
  3122. warehouseOut := models.WarehouseOut{
  3123. WarehouseOutOrderNumber: warehousing_out_order,
  3124. OperationTime: operation_time,
  3125. OrgId: adminInfo.CurrentOrgId,
  3126. Creater: creater,
  3127. Ctime: time.Now().Unix(),
  3128. Status: 1,
  3129. WarehouseOutTime: nowtime,
  3130. Type: 1,
  3131. StorehouseId: storeConfig.StorehouseOutInfo,
  3132. IsCheck: 1,
  3133. IsSys: 1,
  3134. }
  3135. //查询是否生成出库单
  3136. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3137. if out.ID == 0 {
  3138. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3139. }
  3140. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3141. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3142. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3143. dialyPrepareOne := models.DialysisBeforePrepare{
  3144. GoodTypeId: goodObj.GoodTypeId,
  3145. GoodId: p.ProjectId,
  3146. PatientId: p.PatientId,
  3147. RecordDate: p.RecordDate,
  3148. UserOrgId: adminInfo.CurrentOrgId,
  3149. Count: parseIntCount,
  3150. Ctime: time.Now().Unix(),
  3151. Creater: creater,
  3152. Status: 1,
  3153. StorehouseId: houseConfig.StorehouseOutInfo,
  3154. ProjectId: lastHisProject.ID,
  3155. }
  3156. //判断是否是零用耗材(非零用)
  3157. if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3158. //查询历史出库数据
  3159. flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3160. var out_count int64
  3161. for _, item := range flowGood {
  3162. out_count += item.Count
  3163. }
  3164. //如果历史数和当前数据不想等才进行退库出库
  3165. if out_count != parseIntCount {
  3166. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3167. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3168. detail := models.AutomaticReduceDetail{
  3169. WarehouseOutId: 0,
  3170. WarehouseOutOrderNumber: "",
  3171. PatientId: p.PatientId,
  3172. Ctime: time.Now().Unix(),
  3173. Mtime: 0,
  3174. Status: 1,
  3175. RecordTime: p.RecordDate,
  3176. OrgId: p.UserOrgId,
  3177. GoodId: p.ProjectId,
  3178. GoodTypeId: 0,
  3179. Count: parseIntCount,
  3180. Type: 0,
  3181. ProjectId: lastHisProject.ID,
  3182. StorehouseId: 0,
  3183. }
  3184. service.CreateNewAutoDetail(detail, tx)
  3185. //查询剩余库存
  3186. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3187. var sum_count int64
  3188. for _, item := range goodList {
  3189. sum_count += item.StockCount
  3190. }
  3191. //更新剩余库存
  3192. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3193. //耗材
  3194. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3195. }
  3196. //判断是否是零用耗材(零用但是是出库耗材)
  3197. if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3198. //查询历史出库数据
  3199. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3200. var out_count int64
  3201. for _, item := range flowGood {
  3202. out_count += item.Count
  3203. }
  3204. //如果历史数和当前数据不想等才进行退库出库
  3205. if out_count != parseIntCount {
  3206. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3207. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3208. detail := models.AutomaticReduceDetail{
  3209. WarehouseOutId: 0,
  3210. WarehouseOutOrderNumber: "",
  3211. PatientId: p.PatientId,
  3212. Ctime: time.Now().Unix(),
  3213. Mtime: 0,
  3214. Status: 1,
  3215. RecordTime: p.RecordDate,
  3216. OrgId: p.UserOrgId,
  3217. GoodId: p.ProjectId,
  3218. GoodTypeId: 0,
  3219. Count: parseIntCount,
  3220. Type: 0,
  3221. ProjectId: p.ID,
  3222. StorehouseId: 0,
  3223. }
  3224. service.CreateNewAutoDetail(detail, tx)
  3225. //查询剩余库存
  3226. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3227. var sum_count int64
  3228. for _, item := range goodList {
  3229. sum_count += item.StockCount
  3230. }
  3231. //更新剩余库存
  3232. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3233. //耗材
  3234. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3235. }
  3236. }
  3237. }
  3238. }
  3239. //记录日志
  3240. byterequest, _ := json.Marshal(p)
  3241. adviceLog := models.XtDoctorAdviceLog{
  3242. UserOrgId: p.UserOrgId,
  3243. PatientId: p.PatientId,
  3244. AdminUserId: adminInfo.AdminUser.Id,
  3245. Module: 1,
  3246. ErrLog: string(byterequest),
  3247. Status: 1,
  3248. Ctime: time.Now().Unix(),
  3249. Mtime: 0,
  3250. Source: "电脑端新建his项目",
  3251. RecordDate: p.RecordDate,
  3252. }
  3253. service.CreateDoctorAdviceLog(adviceLog)
  3254. projectList = append(projectList, p)
  3255. var randNum int
  3256. randNum = rand.Intn(10000) + 1000
  3257. timestamp := time.Now().Unix()
  3258. tempTime := time.Unix(timestamp, 0)
  3259. timeFormat := tempTime.Format("20060102150405")
  3260. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3261. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3262. //新增或者编辑项目,修改对应的标签数据
  3263. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3264. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3265. var label models.HisLabelPrintInfo
  3266. project, _ := service.GetProjectDetail(p.ProjectId)
  3267. if project.CostClassify == 3 { //类别为检验检查
  3268. if p.TeamId > 0 { //检验检查组套
  3269. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3270. if tempLabel.ID == 0 {
  3271. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3272. label.Number = tempPrescription.PrescriptionNumber
  3273. label.ProjectId = project.ID
  3274. label.Status = 1
  3275. label.IsPrint = 2
  3276. label.DoctorId = info.DoctorId
  3277. label.UserOrgId = p.UserOrgId
  3278. label.PatientId = patient_id
  3279. label.RecordDate = recordDateTime
  3280. label.Ctime = time.Now().Unix()
  3281. label.Mtime = time.Now().Unix()
  3282. label.ItemId = p.TeamId
  3283. label.FeedetlSn = p.FeedetlSn
  3284. label.PProjectId = p.ID
  3285. label.ProjectName = team.ProjectTeam
  3286. label.PatientName = patient.Name
  3287. service.CreateNewHisLabelRecord(&label, tx)
  3288. }
  3289. } else { //单条检验检查项目
  3290. label.Number = tempPrescription.PrescriptionNumber
  3291. label.ProjectId = project.ID
  3292. label.Status = 1
  3293. label.DoctorId = info.DoctorId
  3294. label.UserOrgId = p.UserOrgId
  3295. label.PatientId = patient_id
  3296. label.RecordDate = recordDateTime
  3297. label.IsPrint = 2
  3298. label.Ctime = time.Now().Unix()
  3299. label.Mtime = time.Now().Unix()
  3300. label.FeedetlSn = p.FeedetlSn
  3301. label.PProjectId = p.ID
  3302. label.ItemId = p.TeamId
  3303. label.ProjectName = project.ProjectName
  3304. label.PatientName = patient.Name
  3305. service.CreateNewHisLabelRecord(&label, tx)
  3306. }
  3307. }
  3308. }
  3309. }
  3310. service.SaveNewHisProjectTwo(&p, tx)
  3311. }
  3312. }
  3313. tx.Commit()
  3314. }
  3315. }
  3316. }
  3317. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3318. // addition := items["addition"].([]interface{})
  3319. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3320. // ctime := time.Now().Unix()
  3321. // mtime := ctime
  3322. // if len(addition) > 0 {
  3323. // for _, item := range addition {
  3324. // var s models.HisAdditionalCharge
  3325. // s.PrescriptionId = tempPrescription.ID
  3326. // s.Status = 1
  3327. // s.UserOrgId = adminInfo.CurrentOrgId
  3328. // s.RecordDate = recordDateTime
  3329. // s.CreatedTime = ctime
  3330. // s.UpdatedTime = mtime
  3331. // s.PatientId = patient_id
  3332. // s.HisPatientId = his_patient_id
  3333. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3334. // if errcode > 0 {
  3335. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3336. // return
  3337. // }
  3338. // service.CreateAdditionalCharge(&s)
  3339. // var randNum int
  3340. // randNum = rand.Intn(10000) + 1000
  3341. // timestamp := time.Now().Unix()
  3342. // tempTime := time.Unix(timestamp, 0)
  3343. // timeFormat := tempTime.Format("20060102150405")
  3344. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3345. // service.CreateAdditionalCharge(&s)
  3346. //
  3347. // }
  3348. // }
  3349. //}
  3350. }
  3351. }
  3352. //查询今日该患者开的药品处方
  3353. //hisdoctorlist, _ := service.GetNewHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId, tx)
  3354. //drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3355. //药品出库
  3356. //if drugOutConfig.IsOpen == 1 {
  3357. // for _, item := range hisdoctorlist {
  3358. // drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3359. //
  3360. // // 查询该药品最后一次出库记录
  3361. // druginfo, _ := service.GetLastNewDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3362. //
  3363. // if len(druginfo) > 0 {
  3364. // //回退库存
  3365. // for _, it := range druginfo {
  3366. //
  3367. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3368. //
  3369. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3370. //
  3371. // }
  3372. // if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3373. //
  3374. // service.ModifyNewDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3375. //
  3376. // }
  3377. // if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3378. //
  3379. // service.ModifyNewDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId, tx)
  3380. //
  3381. // }
  3382. // }
  3383. // }
  3384. //
  3385. // //删除记录
  3386. // service.DeleteNewDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID, tx)
  3387. // //查询最后一次数据
  3388. // if drugOutConfig.IsOpen == 1 {
  3389. // //出库
  3390. // if drug.IsUse == 2 {
  3391. // creater := adminInfo.AdminUser.Id
  3392. //
  3393. // service.NewHisDrugsDelivery(item.UserOrgId, creater, item, tx)
  3394. //
  3395. // }
  3396. //
  3397. // //更新字典里面的库存
  3398. // stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId, tx)
  3399. // var sum_count int64
  3400. // for _, its := range stockInfo {
  3401. // baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3402. // if its.MaxUnit == baseDrug.MaxUnit {
  3403. // its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3404. // }
  3405. // sum_count += its.StockMaxNumber + its.StockMinNumber
  3406. // }
  3407. // //更新基础库存
  3408. // service.UpdateNewBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId, tx)
  3409. // //剩余库存
  3410. // service.UpdateNewDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3411. //
  3412. // over, _ := service.FindNewOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3413. // service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3414. //
  3415. // }
  3416. // }
  3417. //}
  3418. //耗材保存处方出库
  3419. //if goodOutConfig.IsOpen == 1 {
  3420. //
  3421. // //查询今日耗材出库数量
  3422. // hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3423. //
  3424. // for _, item := range hisgoodlist {
  3425. //
  3426. // //查询历史出库数据
  3427. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3428. // var out_count_five int64
  3429. // for _, item := range flowGood {
  3430. // out_count_five += item.Count
  3431. // }
  3432. //
  3433. // parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3434. //
  3435. // if out_count_five != parseIntCount {
  3436. //
  3437. // //查询耗材最后一次出库记录
  3438. // wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3439. // //查询默认出库仓库库存
  3440. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3441. // if len(wareOut) > 0 {
  3442. //
  3443. // for _, it := range wareOut {
  3444. // //回退库存
  3445. // service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3446. //
  3447. // //删除出库记录
  3448. // service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3449. //
  3450. // }
  3451. // }
  3452. //
  3453. // timeStr := time.Now().Format("2006-01-02")
  3454. // timeArr := strings.Split(timeStr, "-")
  3455. // total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3456. //
  3457. // total = total + 1
  3458. // warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3459. // number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3460. // number = number + total
  3461. // warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3462. //
  3463. // operation_time := time.Now().Unix()
  3464. // creater := c.GetAdminUserInfo().AdminUser.Id
  3465. //
  3466. // recordDateStr := time.Now().Format("2006-01-02")
  3467. // recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3468. // nowtime := recordDate.Unix()
  3469. // warehouseOut := models.WarehouseOut{
  3470. // WarehouseOutOrderNumber: warehousing_out_order,
  3471. // OperationTime: operation_time,
  3472. // OrgId: adminInfo.CurrentOrgId,
  3473. // Creater: creater,
  3474. // Ctime: time.Now().Unix(),
  3475. // Status: 1,
  3476. // WarehouseOutTime: nowtime,
  3477. // Type: 1,
  3478. // StorehouseId: storeConfig.StorehouseOutInfo,
  3479. // IsCheck: 1,
  3480. // IsSys: 1,
  3481. // }
  3482. // //查询是否生成出库单
  3483. // out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3484. //
  3485. // if out.ID == 0 {
  3486. // service.AddSigleWarehouseOut(&warehouseOut)
  3487. // }
  3488. //
  3489. // lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3490. //
  3491. // goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3492. // houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3493. //
  3494. // dialyPrepareOne := models.DialysisBeforePrepare{
  3495. // GoodTypeId: goodObj.GoodTypeId,
  3496. // GoodId: item.ProjectId,
  3497. // PatientId: item.PatientId,
  3498. // RecordDate: item.RecordDate,
  3499. // UserOrgId: adminInfo.CurrentOrgId,
  3500. // Count: parseIntCount,
  3501. // Ctime: time.Now().Unix(),
  3502. // Creater: creater,
  3503. // Status: 1,
  3504. // StorehouseId: houseConfig.StorehouseOutInfo,
  3505. // ProjectId: item.ID,
  3506. // }
  3507. // goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3508. // if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3509. //
  3510. // //查询历史出库数据
  3511. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3512. // var out_count int64
  3513. // for _, item := range flowGood {
  3514. // out_count += item.Count
  3515. // }
  3516. //
  3517. // //如果历史数和当前数据不想等才进行退库出库
  3518. // if out_count != parseIntCount {
  3519. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3520. //
  3521. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3522. // detail := models.AutomaticReduceDetail{
  3523. // WarehouseOutId: 0,
  3524. // WarehouseOutOrderNumber: "",
  3525. // PatientId: item.PatientId,
  3526. // Ctime: time.Now().Unix(),
  3527. // Mtime: 0,
  3528. // Status: 1,
  3529. // RecordTime: item.RecordDate,
  3530. // OrgId: item.UserOrgId,
  3531. // GoodId: item.ProjectId,
  3532. // GoodTypeId: 0,
  3533. // Count: parseIntCount,
  3534. // Type: 0,
  3535. // ProjectId: item.ID,
  3536. // StorehouseId: 0,
  3537. // }
  3538. //
  3539. // service.CreateAutoDetail(detail)
  3540. //
  3541. // //查询剩余库存
  3542. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3543. // var sum_count int64
  3544. // for _, item := range goodList {
  3545. // sum_count += item.StockCount
  3546. // }
  3547. //
  3548. // //更新剩余库存
  3549. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3550. //
  3551. // //耗材
  3552. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3553. // }
  3554. //
  3555. // }
  3556. //
  3557. // if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3558. // //查询历史出库数据
  3559. // flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3560. // var out_count int64
  3561. // for _, item := range flowGood {
  3562. // out_count += item.Count
  3563. // }
  3564. // //如果历史数和当前数据不想等才进行退库出库
  3565. // if out_count != parseIntCount {
  3566. // service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3567. //
  3568. // service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3569. // detail := models.AutomaticReduceDetail{
  3570. // WarehouseOutId: 0,
  3571. // WarehouseOutOrderNumber: "",
  3572. // PatientId: item.PatientId,
  3573. // Ctime: time.Now().Unix(),
  3574. // Mtime: 0,
  3575. // Status: 1,
  3576. // RecordTime: item.RecordDate,
  3577. // OrgId: item.UserOrgId,
  3578. // GoodId: item.ProjectId,
  3579. // GoodTypeId: 0,
  3580. // Count: parseIntCount,
  3581. // Type: 0,
  3582. // ProjectId: item.ID,
  3583. // StorehouseId: 0,
  3584. // }
  3585. //
  3586. // service.CreateAutoDetail(detail)
  3587. //
  3588. // //查询剩余库存
  3589. // goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3590. // var sum_count int64
  3591. // for _, item := range goodList {
  3592. // sum_count += item.StockCount
  3593. // }
  3594. //
  3595. // //更新剩余库存
  3596. // service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3597. //
  3598. // //耗材
  3599. // service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3600. // }
  3601. //
  3602. // }
  3603. //
  3604. // }
  3605. // }
  3606. //}
  3607. }
  3608. tx.Commit()
  3609. if err == nil {
  3610. c.ServeSuccessJSON(map[string]interface{}{
  3611. "msg": "保存成功",
  3612. })
  3613. return
  3614. } else {
  3615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3616. return
  3617. }
  3618. } else {
  3619. // 开始主事务
  3620. db := service.XTWriteDB()
  3621. tx := db.Begin()
  3622. // 在函数结束时处理事务回滚
  3623. defer func() {
  3624. if r := recover(); r != nil {
  3625. tx.Rollback()
  3626. }
  3627. }()
  3628. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3629. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3630. var tempPrescription *models.HisPrescription
  3631. if len(prescriptions) > 0 {
  3632. for _, item := range prescriptions {
  3633. items := item.(map[string]interface{})
  3634. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3635. utils.ErrorLog("id")
  3636. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3637. return
  3638. }
  3639. id := int64(items["id"].(float64))
  3640. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3641. tempPrescription = &new_prescription
  3642. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3643. utils.ErrorLog("type")
  3644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3645. return
  3646. }
  3647. types := int64(items["type"].(float64))
  3648. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3649. utils.ErrorLog("med_type")
  3650. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3651. return
  3652. }
  3653. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3654. if med_type == "0" {
  3655. med_type = "14"
  3656. }
  3657. //if order_status == 0 {
  3658. // order_status = 1
  3659. //}
  3660. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3661. utils.ErrorLog("pre_time")
  3662. }
  3663. preTime, _ := items["pre_time"].(string)
  3664. timeLayout := "2006-01-02"
  3665. loc, _ := time.LoadLocation("Local")
  3666. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3667. result := strings.Split(preTime, " ")
  3668. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3669. if err != nil {
  3670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3671. return
  3672. }
  3673. pTime := theTime2.Unix()
  3674. ctime := time.Now().Unix()
  3675. if tempPrescription.ID == 0 {
  3676. prescription := &models.HisPrescription{
  3677. ID: 0,
  3678. PatientId: patient_id,
  3679. UserOrgId: adminInfo.CurrentOrgId,
  3680. RecordDate: recordDateTime,
  3681. Ctime: ctime,
  3682. Mtime: ctime,
  3683. Type: types,
  3684. Modifier: adminInfo.AdminUser.Id,
  3685. Creator: adminInfo.AdminUser.Id,
  3686. Status: 1,
  3687. Doctor: role.UserName,
  3688. HisPatientId: his_patient_id,
  3689. OrderStatus: 1,
  3690. BatchNumber: "",
  3691. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3692. PreTime: pTime,
  3693. PType: p_type,
  3694. MedType: med_type,
  3695. }
  3696. tempPrescription = prescription
  3697. service.SaveHisPrescription(tempPrescription)
  3698. redis := service.RedisClient()
  3699. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3700. redis.Set(key, "", time.Second)
  3701. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3702. redis.Set(keyOne, "", time.Second)
  3703. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3704. redis.Set(keySeven, "", time.Second)
  3705. defer redis.Close()
  3706. } else {
  3707. tempPrescription.ID = id
  3708. tempPrescription.Type = types
  3709. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3710. tempPrescription.Mtime = time.Now().Unix()
  3711. tempPrescription.Doctor = role.UserName
  3712. //tempPrescription.OrderStatus = order_status
  3713. tempPrescription.PreTime = pTime
  3714. tempPrescription.MedType = med_type
  3715. service.SaveHisPrescription(tempPrescription)
  3716. redis := service.RedisClient()
  3717. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3718. redis.Set(key, "", time.Second)
  3719. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3720. redis.Set(keyOne, "", time.Second)
  3721. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3722. redis.Set(keySeven, "", time.Second)
  3723. defer redis.Close()
  3724. }
  3725. //service.SaveHisPrescription(prescription)
  3726. //更改患者挂号状态
  3727. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3728. fmt.Println("更改失败", err2)
  3729. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3730. advices := items["advices"].([]interface{})
  3731. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3732. groupNo := int64(0)
  3733. ctime := time.Now().Unix()
  3734. mtime := ctime
  3735. if len(advices) > 0 {
  3736. for _, advice := range advices {
  3737. var s models.HisDoctorAdviceInfo
  3738. s.PrescriptionId = tempPrescription.ID
  3739. s.AdviceType = 2
  3740. s.AdviceDoctor = doctor_id
  3741. s.StopState = 2
  3742. s.ExecutionState = 2
  3743. s.AdviceDate = theTime3.Unix()
  3744. s.Status = 1
  3745. s.UserOrgId = adminInfo.CurrentOrgId
  3746. s.RecordDate = theTime3.Unix()
  3747. s.StartTime = tempPrescription.PreTime
  3748. s.Groupno = groupNo
  3749. s.CreatedTime = ctime
  3750. s.UpdatedTime = mtime
  3751. s.PatientId = patient_id
  3752. s.HisPatientId = his_patient_id
  3753. s.StartTime = pTime
  3754. s.IsSettle = 2
  3755. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3756. if errcode > 0 {
  3757. c.ServeFailJSONWithSGJErrorCode(errcode)
  3758. return
  3759. }
  3760. s.StartTime = pTime
  3761. var total_count int64 //处方总库存
  3762. //查询改药品信息
  3763. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3764. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3765. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3766. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3767. total_count += prescribingNumberSeven * medical.MinNumber
  3768. }
  3769. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3770. total_count += prescribingNumberSeven
  3771. }
  3772. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3773. total_count += prescribingNumberSeven
  3774. }
  3775. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3776. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3777. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3778. if s.Price != lastWarehouse.RetailPrice {
  3779. s.Price = lastWarehouse.RetailPrice
  3780. }
  3781. if s.Price == 0 {
  3782. s.Price = lastWarehouse.RetailPrice
  3783. }
  3784. }
  3785. service.CreateHisDoctorAdvice(&s)
  3786. //记录日志
  3787. byterequest, _ := json.Marshal(s)
  3788. adviceLog := models.XtDoctorAdviceLog{
  3789. UserOrgId: s.UserOrgId,
  3790. PatientId: s.PatientId,
  3791. AdminUserId: adminInfo.AdminUser.Id,
  3792. Module: 1,
  3793. ErrLog: string(byterequest),
  3794. Status: 1,
  3795. Ctime: time.Now().Unix(),
  3796. Mtime: 0,
  3797. Source: "电脑端新建his医嘱",
  3798. RecordDate: s.AdviceDate,
  3799. }
  3800. service.CreateDoctorAdviceLog(adviceLog)
  3801. //存储切片中
  3802. adviceList = append(adviceList, s)
  3803. redis := service.RedisClient()
  3804. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3805. redis.Set(key, "", time.Second)
  3806. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3807. redis.Set(keyOne, "", time.Second)
  3808. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3809. redis.Set(keySeven, "", time.Second)
  3810. var randNum int
  3811. randNum = rand.Intn(10000) + 1000
  3812. timestamp := time.Now().Unix()
  3813. tempTime := time.Unix(timestamp, 0)
  3814. timeFormat := tempTime.Format("20060102150405")
  3815. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3816. service.CreateHisDoctorAdvice(&s)
  3817. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3818. redis.Set(keySix, "", time.Second)
  3819. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3820. redis.Set(keyFive, "", time.Second)
  3821. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3822. redis.Set(keyEight, "", time.Second)
  3823. defer redis.Close()
  3824. }
  3825. }
  3826. }
  3827. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3828. projects := items["project"].([]interface{})
  3829. if len(projects) > 0 {
  3830. for _, project := range projects {
  3831. var p models.HisPrescriptionProject
  3832. p.PrescriptionId = tempPrescription.ID
  3833. p.Ctime = time.Now().Unix()
  3834. p.Mtime = time.Now().Unix()
  3835. p.PatientId = patient_id
  3836. p.RecordDate = theTime3.Unix()
  3837. p.Doctor = doctor_id
  3838. p.UserOrgId = adminInfo.CurrentOrgId
  3839. p.HisPatientId = his_patient_id
  3840. p.Status = 1
  3841. p.StartTime = pTime
  3842. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3843. if errcode > 0 {
  3844. c.ServeFailJSONWithSGJErrorCode(errcode)
  3845. return
  3846. }
  3847. if p.ID == 0 {
  3848. p.IsOut = 2
  3849. }
  3850. if p.ID > 0 {
  3851. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3852. p.IsOut = projectDetail.IsOut
  3853. }
  3854. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3855. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3856. if p.Type == 3 {
  3857. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3858. if p.Price != lastWarehouse.PackingPrice {
  3859. p.Price = lastWarehouse.PackingPrice
  3860. }
  3861. if p.Unit == "" {
  3862. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3863. p.Unit = goodInfoOne.PackingUnit
  3864. }
  3865. }
  3866. }
  3867. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3868. //
  3869. // if p.Type == 3 {
  3870. // //查询该耗材是否停用
  3871. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3872. // //表示该耗材已经停用,不能保存
  3873. // if goodInfoSeven.ID == 0 {
  3874. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3875. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3876. // return
  3877. // }
  3878. // }
  3879. //
  3880. //}
  3881. service.CreateHisProjectTwo(&p)
  3882. //记录日志
  3883. byterequest, _ := json.Marshal(p)
  3884. adviceLog := models.XtDoctorAdviceLog{
  3885. UserOrgId: p.UserOrgId,
  3886. PatientId: p.PatientId,
  3887. AdminUserId: adminInfo.AdminUser.Id,
  3888. Module: 1,
  3889. ErrLog: string(byterequest),
  3890. Status: 1,
  3891. Ctime: time.Now().Unix(),
  3892. Mtime: 0,
  3893. Source: "电脑端新建his项目",
  3894. RecordDate: p.RecordDate,
  3895. }
  3896. service.CreateDoctorAdviceLog(adviceLog)
  3897. projectList = append(projectList, p)
  3898. var randNum int
  3899. randNum = rand.Intn(10000) + 1000
  3900. timestamp := time.Now().Unix()
  3901. tempTime := time.Unix(timestamp, 0)
  3902. timeFormat := tempTime.Format("20060102150405")
  3903. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3904. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3905. //新增或者编辑项目,修改对应的标签数据
  3906. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3907. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3908. var label models.HisLabelPrintInfo
  3909. project, _ := service.GetProjectDetail(p.ProjectId)
  3910. if project.CostClassify == 3 { //类别为检验检查
  3911. if p.TeamId > 0 { //检验检查组套
  3912. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3913. if tempLabel.ID == 0 {
  3914. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3915. label.Number = tempPrescription.PrescriptionNumber
  3916. label.ProjectId = project.ID
  3917. label.Status = 1
  3918. label.IsPrint = 2
  3919. label.DoctorId = info.DoctorId
  3920. label.UserOrgId = p.UserOrgId
  3921. label.PatientId = patient_id
  3922. label.RecordDate = recordDateTime
  3923. label.Ctime = time.Now().Unix()
  3924. label.Mtime = time.Now().Unix()
  3925. label.ItemId = p.TeamId
  3926. label.FeedetlSn = p.FeedetlSn
  3927. label.PProjectId = p.ID
  3928. label.ProjectName = team.ProjectTeam
  3929. label.PatientName = patient.Name
  3930. service.CreateHisLabelRecord(&label)
  3931. }
  3932. } else { //单条检验检查项目
  3933. label.Number = tempPrescription.PrescriptionNumber
  3934. label.ProjectId = project.ID
  3935. label.Status = 1
  3936. label.DoctorId = info.DoctorId
  3937. label.UserOrgId = p.UserOrgId
  3938. label.PatientId = patient_id
  3939. label.RecordDate = recordDateTime
  3940. label.IsPrint = 2
  3941. label.Ctime = time.Now().Unix()
  3942. label.Mtime = time.Now().Unix()
  3943. label.FeedetlSn = p.FeedetlSn
  3944. label.PProjectId = p.ID
  3945. label.ItemId = p.TeamId
  3946. label.ProjectName = project.ProjectName
  3947. label.PatientName = patient.Name
  3948. service.CreateHisLabelRecord(&label)
  3949. }
  3950. }
  3951. }
  3952. }
  3953. service.SaveHisProjectTwo(&p)
  3954. }
  3955. }
  3956. }
  3957. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3958. // addition := items["addition"].([]interface{})
  3959. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3960. // ctime := time.Now().Unix()
  3961. // mtime := ctime
  3962. // if len(addition) > 0 {
  3963. // for _, item := range addition {
  3964. // var s models.HisAdditionalCharge
  3965. // s.PrescriptionId = tempPrescription.ID
  3966. // s.Status = 1
  3967. // s.UserOrgId = adminInfo.CurrentOrgId
  3968. // s.RecordDate = recordDateTime
  3969. // s.CreatedTime = ctime
  3970. // s.UpdatedTime = mtime
  3971. // s.PatientId = patient_id
  3972. // s.HisPatientId = his_patient_id
  3973. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3974. // if errcode > 0 {
  3975. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3976. // return
  3977. // }
  3978. // service.CreateAdditionalCharge(&s)
  3979. // var randNum int
  3980. // randNum = rand.Intn(10000) + 1000
  3981. // timestamp := time.Now().Unix()
  3982. // tempTime := time.Unix(timestamp, 0)
  3983. // timeFormat := tempTime.Format("20060102150405")
  3984. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3985. // service.CreateAdditionalCharge(&s)
  3986. //
  3987. // }
  3988. // }
  3989. //}
  3990. }
  3991. }
  3992. //查询今日该患者开的药品处方
  3993. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3994. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3995. //药品出库
  3996. if drugOutConfig.IsOpen == 1 {
  3997. for _, item := range hisdoctorlist {
  3998. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3999. // 查询该药品最后一次出库记录
  4000. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  4001. if len(druginfo) > 0 {
  4002. //回退库存
  4003. for _, it := range druginfo {
  4004. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  4005. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4006. }
  4007. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4008. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4009. }
  4010. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4011. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4012. }
  4013. }
  4014. }
  4015. //删除记录
  4016. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4017. //查询最后一次数据
  4018. if drugOutConfig.IsOpen == 1 {
  4019. //出库
  4020. if drug.IsUse == 2 {
  4021. creater := adminInfo.AdminUser.Id
  4022. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4023. }
  4024. //更新字典里面的库存
  4025. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4026. var sum_count int64
  4027. for _, its := range stockInfo {
  4028. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4029. if its.MaxUnit == baseDrug.MaxUnit {
  4030. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4031. }
  4032. sum_count += its.StockMaxNumber + its.StockMinNumber
  4033. }
  4034. //更新基础库存
  4035. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4036. //剩余库存
  4037. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4038. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4039. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4040. }
  4041. }
  4042. }
  4043. //耗材保存处方出库
  4044. if goodOutConfig.IsOpen == 1 {
  4045. //查询今日耗材出库数量
  4046. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4047. for _, item := range hisgoodlist {
  4048. //查询历史出库数据
  4049. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4050. var out_count_five int64
  4051. for _, item := range flowGood {
  4052. out_count_five += item.Count
  4053. }
  4054. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4055. if out_count_five != parseIntCount {
  4056. //查询耗材最后一次出库记录
  4057. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4058. //查询默认出库仓库库存
  4059. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4060. if len(wareOut) > 0 {
  4061. for _, it := range wareOut {
  4062. //回退库存
  4063. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4064. //删除出库记录
  4065. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4066. }
  4067. }
  4068. timeStr := time.Now().Format("2006-01-02")
  4069. timeArr := strings.Split(timeStr, "-")
  4070. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4071. total = total + 1
  4072. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4073. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4074. number = number + total
  4075. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4076. operation_time := time.Now().Unix()
  4077. creater := c.GetAdminUserInfo().AdminUser.Id
  4078. recordDateStr := time.Now().Format("2006-01-02")
  4079. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4080. nowtime := recordDate.Unix()
  4081. warehouseOut := models.WarehouseOut{
  4082. WarehouseOutOrderNumber: warehousing_out_order,
  4083. OperationTime: operation_time,
  4084. OrgId: adminInfo.CurrentOrgId,
  4085. Creater: creater,
  4086. Ctime: time.Now().Unix(),
  4087. Status: 1,
  4088. WarehouseOutTime: nowtime,
  4089. Type: 1,
  4090. StorehouseId: storeConfig.StorehouseOutInfo,
  4091. IsCheck: 1,
  4092. IsSys: 1,
  4093. }
  4094. //查询是否生成出库单
  4095. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4096. if out.ID == 0 {
  4097. service.AddSigleWarehouseOut(&warehouseOut)
  4098. }
  4099. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4100. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4101. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4102. dialyPrepareOne := models.DialysisBeforePrepare{
  4103. GoodTypeId: goodObj.GoodTypeId,
  4104. GoodId: item.ProjectId,
  4105. PatientId: item.PatientId,
  4106. RecordDate: item.RecordDate,
  4107. UserOrgId: adminInfo.CurrentOrgId,
  4108. Count: parseIntCount,
  4109. Ctime: time.Now().Unix(),
  4110. Creater: creater,
  4111. Status: 1,
  4112. StorehouseId: houseConfig.StorehouseOutInfo,
  4113. ProjectId: item.ID,
  4114. }
  4115. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4116. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4117. //查询历史出库数据
  4118. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4119. var out_count int64
  4120. for _, item := range flowGood {
  4121. out_count += item.Count
  4122. }
  4123. //如果历史数和当前数据不想等才进行退库出库
  4124. if out_count != parseIntCount {
  4125. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4126. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4127. detail := models.AutomaticReduceDetail{
  4128. WarehouseOutId: 0,
  4129. WarehouseOutOrderNumber: "",
  4130. PatientId: item.PatientId,
  4131. Ctime: time.Now().Unix(),
  4132. Mtime: 0,
  4133. Status: 1,
  4134. RecordTime: item.RecordDate,
  4135. OrgId: item.UserOrgId,
  4136. GoodId: item.ProjectId,
  4137. GoodTypeId: 0,
  4138. Count: parseIntCount,
  4139. Type: 0,
  4140. ProjectId: item.ID,
  4141. StorehouseId: 0,
  4142. }
  4143. service.CreateAutoDetail(detail)
  4144. //查询剩余库存
  4145. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4146. var sum_count int64
  4147. for _, item := range goodList {
  4148. sum_count += item.StockCount
  4149. }
  4150. //更新剩余库存
  4151. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4152. //耗材
  4153. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4154. }
  4155. }
  4156. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4157. //查询历史出库数据
  4158. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4159. var out_count int64
  4160. for _, item := range flowGood {
  4161. out_count += item.Count
  4162. }
  4163. //如果历史数和当前数据不想等才进行退库出库
  4164. if out_count != parseIntCount {
  4165. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4166. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4167. detail := models.AutomaticReduceDetail{
  4168. WarehouseOutId: 0,
  4169. WarehouseOutOrderNumber: "",
  4170. PatientId: item.PatientId,
  4171. Ctime: time.Now().Unix(),
  4172. Mtime: 0,
  4173. Status: 1,
  4174. RecordTime: item.RecordDate,
  4175. OrgId: item.UserOrgId,
  4176. GoodId: item.ProjectId,
  4177. GoodTypeId: 0,
  4178. Count: parseIntCount,
  4179. Type: 0,
  4180. ProjectId: item.ID,
  4181. StorehouseId: 0,
  4182. }
  4183. service.CreateAutoDetail(detail)
  4184. //查询剩余库存
  4185. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4186. var sum_count int64
  4187. for _, item := range goodList {
  4188. sum_count += item.StockCount
  4189. }
  4190. //更新剩余库存
  4191. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4192. //耗材
  4193. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4194. }
  4195. }
  4196. }
  4197. }
  4198. }
  4199. }
  4200. tx.Commit()
  4201. if err == nil {
  4202. c.ServeSuccessJSON(map[string]interface{}{
  4203. "msg": "保存成功",
  4204. })
  4205. return
  4206. } else {
  4207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4208. return
  4209. }
  4210. }
  4211. }
  4212. //func (c *HisApiController) EditHisPrescription() {
  4213. // record_date := c.GetString("record_date")
  4214. // patient_id, _ := c.GetInt64("patient_id")
  4215. // reg_type, _ := c.GetInt64("reg_type")
  4216. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4217. // diagnose := c.GetString("diagnose")
  4218. // sick_type, _ := c.GetInt64("sick_type")
  4219. // sick_history := c.GetString("sick_history")
  4220. // doctor_id, _ := c.GetInt64("doctor", 0)
  4221. // department, _ := c.GetInt64("department", 0)
  4222. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4223. // p_type, _ := c.GetInt64("p_type")
  4224. //
  4225. // dataBody := make(map[string]interface{}, 0)
  4226. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4227. // if err != nil {
  4228. // utils.ErrorLog(err.Error())
  4229. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4230. // return
  4231. // }
  4232. //
  4233. // timeLayout := "2006-01-02"
  4234. // loc, _ := time.LoadLocation("Local")
  4235. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4236. // if err != nil {
  4237. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4238. // return
  4239. // }
  4240. // adminInfo := c.GetAdminUserInfo()
  4241. // recordDateTime := theTime.Unix()
  4242. //
  4243. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4244. //
  4245. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4246. // var hpInfo models.HisPrescriptionInfo
  4247. // if info.ID == 0 {
  4248. // var randNum int
  4249. // randNum = rand.Intn(10000) + 1000
  4250. // timestamp := time.Now().Unix()
  4251. // tempTime := time.Unix(timestamp, 0)
  4252. // timeFormat := tempTime.Format("20060102150405")
  4253. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4254. //
  4255. // hpInfo = models.HisPrescriptionInfo{
  4256. // UserOrgId: adminInfo.CurrentOrgId,
  4257. // RecordDate: theTime.Unix(),
  4258. // PatientId: patient_id,
  4259. // Status: 1,
  4260. // Ctime: time.Now().Unix(),
  4261. // Mtime: time.Now().Unix(),
  4262. // Creator: adminInfo.AdminUser.Id,
  4263. // Modifier: adminInfo.AdminUser.Id,
  4264. // Diagnosis: diagnose,
  4265. // SickHistory: sick_history,
  4266. // Departments: department,
  4267. // RegisterType: reg_type,
  4268. // PrescriptionNumber: p_number,
  4269. // PrescriptionStatus: 1,
  4270. // Doctor: role.UserName,
  4271. // DoctorId: doctor_id,
  4272. // SickType: sick_type,
  4273. // PType: p_type,
  4274. // }
  4275. // service.SavePatientPrescriptionInfo(hpInfo)
  4276. //
  4277. // } else {
  4278. // hpInfo = models.HisPrescriptionInfo{
  4279. // ID: info.ID,
  4280. // UserOrgId: adminInfo.CurrentOrgId,
  4281. // RecordDate: info.RecordDate,
  4282. // PatientId: info.PatientId,
  4283. // Status: 1,
  4284. // Ctime: info.Ctime,
  4285. // Mtime: time.Now().Unix(),
  4286. // Creator: info.Creator,
  4287. // Modifier: adminInfo.AdminUser.Id,
  4288. // Diagnosis: diagnose,
  4289. // SickHistory: sick_history,
  4290. // Departments: department,
  4291. // RegisterType: reg_type,
  4292. // PrescriptionNumber: info.PrescriptionNumber,
  4293. // Doctor: role.UserName,
  4294. // PrescriptionStatus: info.PrescriptionStatus,
  4295. // DoctorId: doctor_id,
  4296. // SickType: sick_type,
  4297. // PType: info.PType,
  4298. // }
  4299. // service.SavePatientPrescriptionInfo(hpInfo)
  4300. // }
  4301. //
  4302. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4303. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4304. //
  4305. // if len(prescriptions) > 0 {
  4306. // for _, item := range prescriptions {
  4307. // items := item.(map[string]interface{})
  4308. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4309. // utils.ErrorLog("id")
  4310. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4311. // return
  4312. // }
  4313. // id := int64(items["id"].(float64))
  4314. //
  4315. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4316. // utils.ErrorLog("type")
  4317. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4318. // return
  4319. // }
  4320. // types := int64(items["type"].(float64))
  4321. //
  4322. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4323. // utils.ErrorLog("med_type")
  4324. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4325. // return
  4326. // }
  4327. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4328. //
  4329. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4330. //
  4331. // ctime := time.Now().Unix()
  4332. //
  4333. // prescription := &models.HisPrescription{
  4334. // ID: id,
  4335. // PatientId: patient_id,
  4336. // UserOrgId: adminInfo.CurrentOrgId,
  4337. // RecordDate: recordDateTime,
  4338. // Ctime: ctime,
  4339. // Mtime: ctime,
  4340. // Type: types,
  4341. // Modifier: adminInfo.AdminUser.Id,
  4342. // Creator: adminInfo.AdminUser.Id,
  4343. // Status: 1,
  4344. // Doctor: role.UserName,
  4345. // HisPatientId: his_patient_id,
  4346. // OrderStatus: 1,
  4347. // BatchNumber: "",
  4348. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4349. // PType: hpInfo.PType,
  4350. // MedType: med_type,
  4351. // }
  4352. //
  4353. // if historyPrescription.ID > 0 {
  4354. // prescription.PreTime = historyPrescription.PreTime
  4355. //
  4356. // }
  4357. //
  4358. // service.SaveHisPrescription(prescription)
  4359. //
  4360. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4361. // advices := items["advices"].([]interface{})
  4362. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4363. // groupNo := int64(0)
  4364. // ctime := time.Now().Unix()
  4365. // mtime := ctime
  4366. // if len(advices) > 0 {
  4367. // for _, advice := range advices {
  4368. // var s models.HisDoctorAdviceInfo
  4369. // s.PrescriptionId = prescription.ID
  4370. // s.AdviceType = 2
  4371. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4372. // s.StopState = 2
  4373. // s.ExecutionState = 2
  4374. // s.AdviceDate = recordDateTime
  4375. // s.Status = 1
  4376. // s.UserOrgId = adminInfo.CurrentOrgId
  4377. // s.RecordDate = recordDateTime
  4378. // s.StartTime = prescription.PreTime
  4379. // s.Groupno = groupNo
  4380. // s.CreatedTime = ctime
  4381. // s.UpdatedTime = mtime
  4382. // s.PatientId = patient_id
  4383. // s.HisPatientId = his_patient_id
  4384. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4385. // if errcode > 0 {
  4386. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4387. // return
  4388. // }
  4389. //
  4390. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4391. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4392. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4393. // if s.Price == 0 {
  4394. // s.Price = lastWarehouse.RetailPrice
  4395. // }
  4396. // }
  4397. //
  4398. // service.CreateHisDoctorAdvice(&s)
  4399. // //记录日志
  4400. // byterequest, _ := json.Marshal(s)
  4401. // adviceLog := models.XtDoctorAdviceLog{
  4402. // UserOrgId: s.UserOrgId,
  4403. // PatientId: s.PatientId,
  4404. // AdminUserId: adminInfo.AdminUser.Id,
  4405. // Module: 1,
  4406. // ErrLog: string(byterequest),
  4407. // Status: 1,
  4408. // Ctime: time.Now().Unix(),
  4409. // Mtime: 0,
  4410. // Source: "电脑端his医嘱修改",
  4411. // RecordDate: s.AdviceDate,
  4412. // }
  4413. // service.CreateDoctorAdviceLog(adviceLog)
  4414. // redis := service.RedisClient()
  4415. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4416. // redis.Set(key, "", time.Second)
  4417. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4418. // fmt.Println("keyOne", keyOne)
  4419. // redis.Set(keyOne, "", time.Second)
  4420. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4421. // redis.Set(keySeven, "", time.Second)
  4422. // redis.Close()
  4423. //
  4424. // }
  4425. // }
  4426. // }
  4427. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4428. // projects := items["project"].([]interface{})
  4429. // if len(projects) > 0 {
  4430. // for _, project := range projects {
  4431. // var p models.HisPrescriptionProject
  4432. // p.PrescriptionId = prescription.ID
  4433. // p.Ctime = time.Now().Unix()
  4434. // p.Mtime = time.Now().Unix()
  4435. // p.PatientId = patient_id
  4436. // p.RecordDate = recordDateTime
  4437. // p.UserOrgId = adminInfo.CurrentOrgId
  4438. // p.HisPatientId = his_patient_id
  4439. // p.Status = 1
  4440. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4441. // if errcode > 0 {
  4442. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4443. // return
  4444. // }
  4445. // service.CreateHisProjectTwo(&p)
  4446. //
  4447. // //记录日志
  4448. // byterequest, _ := json.Marshal(p)
  4449. // adviceLog := models.XtDoctorAdviceLog{
  4450. // UserOrgId: p.UserOrgId,
  4451. // PatientId: p.PatientId,
  4452. // AdminUserId: adminInfo.AdminUser.Id,
  4453. // Module: 1,
  4454. // ErrLog: string(byterequest),
  4455. // Status: 1,
  4456. // Ctime: time.Now().Unix(),
  4457. // Mtime: 0,
  4458. // Source: "电脑端his项目修改",
  4459. // RecordDate: p.RecordDate,
  4460. // }
  4461. // service.CreateDoctorAdviceLog(adviceLog)
  4462. // }
  4463. // }
  4464. // }
  4465. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4466. // addition := items["addition"].([]interface{})
  4467. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4468. // ctime := time.Now().Unix()
  4469. // mtime := ctime
  4470. // if len(addition) > 0 {
  4471. // for _, item := range addition {
  4472. // var s models.HisAdditionalCharge
  4473. // s.PrescriptionId = prescription.ID
  4474. // s.Status = 1
  4475. // s.UserOrgId = adminInfo.CurrentOrgId
  4476. // s.RecordDate = recordDateTime
  4477. // s.CreatedTime = ctime
  4478. // s.UpdatedTime = mtime
  4479. // s.PatientId = patient_id
  4480. // s.HisPatientId = his_patient_id
  4481. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4482. // if errcode > 0 {
  4483. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4484. // return
  4485. // }
  4486. // service.CreateAdditionalCharge(&s)
  4487. // }
  4488. // }
  4489. // }
  4490. //
  4491. // }
  4492. // }
  4493. // }
  4494. // if err == nil {
  4495. // c.ServeSuccessJSON(map[string]interface{}{
  4496. // "msg": "保存成功",
  4497. // })
  4498. // return
  4499. //
  4500. // } else {
  4501. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4502. // return
  4503. // }
  4504. //}
  4505. func (c *HisApiController) DeletePrescription() {
  4506. prescription_id, _ := c.GetInt64("id")
  4507. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4508. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4509. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4510. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4511. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4512. //耗材保存处方出库
  4513. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4514. //已收费和已发药限制逻辑
  4515. isCharge := false
  4516. isMedicine := false
  4517. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4518. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4519. for _, item := range new_prescriptions {
  4520. if item.IsMedicine == 1 {
  4521. isMedicine = true
  4522. }
  4523. }
  4524. for _, item := range new_prescriptions {
  4525. if item.OrderStatus == 4 {
  4526. isCharge = true
  4527. }
  4528. }
  4529. if p_err != nil {
  4530. if new_prescription.ID > 0 {
  4531. if new_prescription.OrderStatus == 2 {
  4532. isCharge = true
  4533. }
  4534. }
  4535. }
  4536. for _, item := range advices {
  4537. if item.IsMedicine == 1 {
  4538. isMedicine = true
  4539. }
  4540. }
  4541. if isCharge {
  4542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4543. return
  4544. }
  4545. if isMedicine {
  4546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4547. return
  4548. }
  4549. //已收费和已发药限制逻辑
  4550. if len(projects) > 0 {
  4551. for _, item := range projects {
  4552. service.DeletePrintInfo(item.ID) //删除打印信息
  4553. if goodOutConfig.IsOpen != 1 {
  4554. if stockConfig.IsOpen == 1 {
  4555. if item.Type == 3 && item.IsOut == 1 {
  4556. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4557. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4558. good.Total = good.Total + f_count
  4559. service.UpdateGoodInfo(&good)
  4560. operation_time := time.Now().Unix()
  4561. creater := c.GetAdminUserInfo().AdminUser.Id
  4562. //创建退库单
  4563. timeStr := time.Now().Format("2006-01-02")
  4564. timeArr := strings.Split(timeStr, "-")
  4565. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4566. total = total + 1
  4567. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4568. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4569. cancelStock := models.CancelStock{
  4570. OrderNumber: orderNumber,
  4571. OperaTime: operation_time,
  4572. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4573. Creater: creater,
  4574. Ctime: time.Now().Unix(),
  4575. Status: 1,
  4576. ReturnTime: item.RecordDate,
  4577. Type: 1,
  4578. StorehouseId: houseConfig.StorehouseOutInfo,
  4579. IsCheck: 1,
  4580. }
  4581. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4582. if msgerrkonde == gorm.ErrRecordNotFound {
  4583. service.AddSigleCancelStock(&cancelStock)
  4584. }
  4585. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4586. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4587. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4588. //查询该耗材是否出库
  4589. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4590. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4591. deaerler, _ := service.GetDealerById(info.Dealer)
  4592. var total_count int64
  4593. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4594. total_count += count
  4595. if info.ID > 0 {
  4596. if info.Count >= total_count {
  4597. //回退库存
  4598. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4599. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4600. var flush_count int64
  4601. for _, it := range goodList {
  4602. flush_count += it.StockCount
  4603. }
  4604. cancelStockInfo := models.CancelStockInfo{
  4605. GoodId: item.ProjectId,
  4606. CancelStockId: cancel.ID,
  4607. GoodTypeId: good.GoodTypeId,
  4608. Count: prescribingNumber,
  4609. Price: info.Price,
  4610. Total: 0,
  4611. ProductDate: info.ProductDate,
  4612. ExpiryDate: info.ExpiryDate,
  4613. Ctime: time.Now().Unix(),
  4614. Status: 1,
  4615. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4616. OrderNumber: cancel.OrderNumber,
  4617. Type: 0,
  4618. Dealer: deaerler.DealerName,
  4619. Manufacturer: manufacturer.ManufacturerName,
  4620. Number: info.Number,
  4621. RegisterAccount: "",
  4622. Remark: "",
  4623. WarehouseInfoId: info.WarehouseInfotId,
  4624. PatientId: info.PatientId,
  4625. RecordDate: info.SysRecordTime,
  4626. StorehouseId: houseConfig.StorehouseOutInfo,
  4627. IsCheck: 1,
  4628. }
  4629. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4630. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4631. flow := models.VmStockFlow{
  4632. WarehousingId: info.WarehouseInfotId,
  4633. GoodId: item.ProjectId,
  4634. Number: info.Number,
  4635. LicenseNumber: info.LicenseNumber,
  4636. Count: prescribingNumber,
  4637. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4638. PatientId: item.PatientId,
  4639. SystemTime: info.SysRecordTime,
  4640. ConsumableType: 7,
  4641. IsSys: 0,
  4642. WarehousingOrder: "",
  4643. WarehouseOutId: info.WarehouseOutId,
  4644. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4645. IsEdit: 0,
  4646. CancelStockId: cancel.ID,
  4647. CancelOrderNumber: cancel.OrderNumber,
  4648. Manufacturer: manufacturer.ID,
  4649. Dealer: 0,
  4650. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4651. UpdateCreator: 0,
  4652. Status: 1,
  4653. Ctime: time.Now().Unix(),
  4654. Mtime: 0,
  4655. Price: info.Price,
  4656. WarehousingDetailId: info.WarehouseInfotId,
  4657. WarehouseOutDetailId: info.ID,
  4658. CancelOutDetailId: cancelInfo.ID,
  4659. ProductDate: info.ProductDate,
  4660. ExpireDate: info.ExpiryDate,
  4661. StorehouseId: houseConfig.StorehouseOutInfo,
  4662. OverCount: flush_count,
  4663. }
  4664. service.CreateStockFlowOne(flow)
  4665. //退库数量增加
  4666. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4667. //出库数量减少
  4668. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4669. }
  4670. if info.Count < total_count {
  4671. //回退库存
  4672. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4673. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4674. var flush_count int64
  4675. for _, it := range goodList {
  4676. flush_count += it.StockCount
  4677. }
  4678. cancelStockInfo := models.CancelStockInfo{
  4679. GoodId: item.ProjectId,
  4680. CancelStockId: cancel.ID,
  4681. GoodTypeId: good.GoodTypeId,
  4682. Count: info.Count,
  4683. Price: info.Price,
  4684. Total: 0,
  4685. ProductDate: info.ProductDate,
  4686. ExpiryDate: info.ExpiryDate,
  4687. Ctime: time.Now().Unix(),
  4688. Status: 1,
  4689. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4690. OrderNumber: cancel.OrderNumber,
  4691. Type: 0,
  4692. Dealer: deaerler.DealerName,
  4693. Manufacturer: manufacturer.ManufacturerName,
  4694. Number: info.Number,
  4695. RegisterAccount: "",
  4696. Remark: "",
  4697. WarehouseInfoId: info.WarehouseInfotId,
  4698. PatientId: info.PatientId,
  4699. RecordDate: info.SysRecordTime,
  4700. StorehouseId: houseConfig.StorehouseOutInfo,
  4701. IsCheck: 1,
  4702. }
  4703. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4704. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4705. flow := models.VmStockFlow{
  4706. WarehousingId: info.WarehouseInfotId,
  4707. GoodId: item.ProjectId,
  4708. Number: info.Number,
  4709. LicenseNumber: info.LicenseNumber,
  4710. Count: info.Count,
  4711. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4712. PatientId: item.PatientId,
  4713. SystemTime: info.SysRecordTime,
  4714. ConsumableType: 7,
  4715. IsSys: 0,
  4716. WarehousingOrder: "",
  4717. WarehouseOutId: info.WarehouseOutId,
  4718. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4719. IsEdit: 0,
  4720. CancelStockId: cancel.ID,
  4721. CancelOrderNumber: cancel.OrderNumber,
  4722. Manufacturer: manufacturer.ID,
  4723. Dealer: 0,
  4724. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4725. UpdateCreator: 0,
  4726. Status: 1,
  4727. Ctime: time.Now().Unix(),
  4728. Mtime: 0,
  4729. Price: info.Price,
  4730. WarehousingDetailId: info.WarehouseInfotId,
  4731. WarehouseOutDetailId: info.ID,
  4732. CancelOutDetailId: cancelInfo.ID,
  4733. ProductDate: info.ProductDate,
  4734. ExpireDate: info.ExpiryDate,
  4735. StorehouseId: houseConfig.StorehouseOutInfo,
  4736. OverCount: flush_count,
  4737. }
  4738. service.CreateStockFlowOne(flow)
  4739. //退库数量增加
  4740. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4741. //出库数量减少
  4742. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4743. }
  4744. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4745. var flush_count int64
  4746. for _, it := range goodList {
  4747. flush_count += it.StockCount
  4748. }
  4749. //查询已出库数量
  4750. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4751. if prescribingNumber < dialysisInfo.Count {
  4752. //改变数量
  4753. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4754. }
  4755. if prescribingNumber >= dialysisInfo.Count {
  4756. //删除出库表
  4757. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4758. }
  4759. //更新库存
  4760. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4761. //更新基础库库存
  4762. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4763. }
  4764. }
  4765. }
  4766. }
  4767. //保存耗材出库
  4768. if goodOutConfig.IsOpen == 1 {
  4769. if item.Type == 3 {
  4770. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4771. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4772. good.Total = good.Total + f_count
  4773. service.UpdateGoodInfo(&good)
  4774. operation_time := time.Now().Unix()
  4775. creater := c.GetAdminUserInfo().AdminUser.Id
  4776. //创建退库单
  4777. timeStr := time.Now().Format("2006-01-02")
  4778. timeArr := strings.Split(timeStr, "-")
  4779. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4780. total = total + 1
  4781. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4782. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4783. cancelStock := models.CancelStock{
  4784. OrderNumber: orderNumber,
  4785. OperaTime: operation_time,
  4786. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4787. Creater: creater,
  4788. Ctime: time.Now().Unix(),
  4789. Status: 1,
  4790. ReturnTime: item.RecordDate,
  4791. Type: 1,
  4792. StorehouseId: houseConfig.StorehouseOutInfo,
  4793. IsCheck: 1,
  4794. }
  4795. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4796. if msgerrkonde == gorm.ErrRecordNotFound {
  4797. service.AddSigleCancelStock(&cancelStock)
  4798. }
  4799. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4800. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4801. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4802. //查询该耗材是否出库
  4803. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4804. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4805. deaerler, _ := service.GetDealerById(info.Dealer)
  4806. var total_count int64
  4807. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4808. total_count += count
  4809. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4810. var flush_count int64
  4811. for _, it := range goodList {
  4812. flush_count += it.StockCount
  4813. }
  4814. fmt.Println("历史出库数据", info.Count)
  4815. fmt.Println("出库数量", total_count)
  4816. if info.ID > 0 {
  4817. cancelStockInfo := models.CancelStockInfo{
  4818. GoodId: item.ProjectId,
  4819. CancelStockId: cancel.ID,
  4820. GoodTypeId: good.GoodTypeId,
  4821. Count: prescribingNumber,
  4822. Price: info.Price,
  4823. Total: 0,
  4824. ProductDate: info.ProductDate,
  4825. ExpiryDate: info.ExpiryDate,
  4826. Ctime: time.Now().Unix(),
  4827. Status: 1,
  4828. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4829. OrderNumber: cancel.OrderNumber,
  4830. Type: 0,
  4831. Dealer: deaerler.DealerName,
  4832. Manufacturer: manufacturer.ManufacturerName,
  4833. Number: info.Number,
  4834. RegisterAccount: "",
  4835. Remark: "",
  4836. WarehouseInfoId: info.WarehouseInfotId,
  4837. PatientId: info.PatientId,
  4838. RecordDate: info.SysRecordTime,
  4839. StorehouseId: houseConfig.StorehouseOutInfo,
  4840. IsCheck: 1,
  4841. }
  4842. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4843. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4844. //查询出库数量
  4845. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4846. //出库数据 大于 退库数量
  4847. if len(list) > 0 {
  4848. for _, it := range list {
  4849. //回退库存
  4850. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4851. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4852. var flush_count_one int64
  4853. for _, it := range goodList {
  4854. flush_count_one += it.StockCount
  4855. }
  4856. //查询该批次是否有退库数据
  4857. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4858. creater := c.GetAdminUserInfo().AdminUser.Id
  4859. flow := models.VmStockFlow{
  4860. WarehousingId: it.WarehouseInfotId,
  4861. GoodId: it.GoodId,
  4862. Number: it.Number,
  4863. LicenseNumber: it.LicenseNumber,
  4864. Count: it.Count,
  4865. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4866. PatientId: it.PatientId,
  4867. SystemTime: it.SysRecordTime,
  4868. ConsumableType: 7,
  4869. IsSys: 0,
  4870. WarehousingOrder: "",
  4871. WarehouseOutId: it.WarehouseOutId,
  4872. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4873. IsEdit: 0,
  4874. CancelStockId: cancel.ID,
  4875. CancelOrderNumber: cancel.OrderNumber,
  4876. Manufacturer: manufacturer.ID,
  4877. Dealer: 0,
  4878. Creator: creater,
  4879. UpdateCreator: 0,
  4880. Status: 1,
  4881. Ctime: time.Now().Unix(),
  4882. Mtime: 0,
  4883. Price: it.Price,
  4884. WarehousingDetailId: it.WarehouseInfotId,
  4885. WarehouseOutDetailId: it.ID,
  4886. CancelOutDetailId: cancelInfo.ID,
  4887. ProductDate: it.ProductDate,
  4888. ExpireDate: it.ExpiryDate,
  4889. StorehouseId: houseConfig.StorehouseOutInfo,
  4890. OverCount: flush_count_one,
  4891. }
  4892. service.CreateStockFlowOne(flow)
  4893. //if flow.ID > 0 {
  4894. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  4895. //}
  4896. }
  4897. }
  4898. //flow := models.VmStockFlow{
  4899. // WarehousingId: info.WarehouseInfotId,
  4900. // GoodId: item.ProjectId,
  4901. // Number: info.Number,
  4902. // LicenseNumber: info.LicenseNumber,
  4903. // Count: prescribingNumber,
  4904. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4905. // PatientId: item.PatientId,
  4906. // SystemTime: info.SysRecordTime,
  4907. // ConsumableType: 7,
  4908. // IsSys: 0,
  4909. // WarehousingOrder: "",
  4910. // WarehouseOutId: info.WarehouseOutId,
  4911. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4912. // IsEdit: 0,
  4913. // CancelStockId: cancel.ID,
  4914. // CancelOrderNumber: cancel.OrderNumber,
  4915. // Manufacturer: manufacturer.ID,
  4916. // Dealer: 0,
  4917. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  4918. // UpdateCreator: 0,
  4919. // Status: 1,
  4920. // Ctime: time.Now().Unix(),
  4921. // Mtime: 0,
  4922. // Price: info.Price,
  4923. // WarehousingDetailId: info.WarehouseInfotId,
  4924. // WarehouseOutDetailId: info.ID,
  4925. // CancelOutDetailId: cancelInfo.ID,
  4926. // ProductDate: info.ProductDate,
  4927. // ExpireDate: info.ExpiryDate,
  4928. // StorehouseId: houseConfig.StorehouseOutInfo,
  4929. // OverCount: flush_count,
  4930. //}
  4931. //service.CreateStockFlowOne(flow)
  4932. //退库数量增加
  4933. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4934. //出库数量减少
  4935. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4936. //查询已出库数量
  4937. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4938. if prescribingNumber < dialysisInfo.Count {
  4939. //改变数量
  4940. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4941. }
  4942. if prescribingNumber >= dialysisInfo.Count {
  4943. //删除出库表
  4944. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4945. }
  4946. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4947. var flush_count_one int64
  4948. for _, it := range goodList {
  4949. flush_count_one += it.StockCount
  4950. }
  4951. //更新库存
  4952. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4953. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4954. //更新基础库库存
  4955. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4956. }
  4957. }
  4958. }
  4959. }
  4960. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4961. fmt.Println(err)
  4962. }
  4963. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4964. fmt.Println(err)
  4965. if len(advices) > 0 {
  4966. for _, item := range advices {
  4967. redis := service.RedisClient()
  4968. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4969. redis.Set(keyFive, "", time.Second)
  4970. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4971. redis.Set(keyOne, "", time.Second)
  4972. redis.Close()
  4973. }
  4974. }
  4975. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4976. if len(advices) > 0 {
  4977. for _, item := range advices {
  4978. creater := c.GetAdminUserInfo().AdminUser.Id
  4979. service.DrugAutoAddCancelInfo(item, creater)
  4980. }
  4981. }
  4982. } else {
  4983. if drugOutConfig.IsOpen == 1 {
  4984. if len(advices) > 0 {
  4985. for _, item := range advices {
  4986. creater := c.GetAdminUserInfo().AdminUser.Id
  4987. service.DrugAutoAddCancelInfo(item, creater)
  4988. }
  4989. }
  4990. } else {
  4991. if len(advices) > 0 {
  4992. for _, item := range advices {
  4993. creater := c.GetAdminUserInfo().AdminUser.Id
  4994. service.DrugAutoAddCancelInfo(item, creater)
  4995. }
  4996. }
  4997. }
  4998. }
  4999. c.ServeSuccessJSON(map[string]interface{}{
  5000. "msg": "删除成功",
  5001. })
  5002. return
  5003. }
  5004. func (c *HisApiController) DeleteDoctorAdvice() {
  5005. id, _ := c.GetInt64("id")
  5006. advice, _ := service.GetHisDoctorAdvicesById(id)
  5007. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5008. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5009. //已收费和已发药的限制逻辑
  5010. isCharge := false
  5011. isMedicine := false
  5012. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5013. //获取今天该患者所有处方,判断是否发药或者收费
  5014. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5015. for _, item := range new_prescriptions {
  5016. if item.IsMedicine == 1 {
  5017. isMedicine = true
  5018. }
  5019. }
  5020. for _, item := range new_prescriptions {
  5021. if item.OrderStatus == 4 {
  5022. isCharge = true
  5023. }
  5024. }
  5025. if isMedicine {
  5026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5027. return
  5028. }
  5029. if isCharge {
  5030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5031. return
  5032. }
  5033. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5034. for _, item := range advices {
  5035. if item.IsMedicine == 1 {
  5036. isMedicine = true
  5037. }
  5038. }
  5039. if isMedicine {
  5040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5041. return
  5042. }
  5043. if new_prescription.ID > 0 {
  5044. if new_prescription.OrderStatus == 2 {
  5045. isCharge = true
  5046. }
  5047. }
  5048. if isCharge {
  5049. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5050. return
  5051. }
  5052. //已收费和已发药的限制逻辑
  5053. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5054. redis := service.RedisClient()
  5055. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5056. redis.Set(keyFive, "", time.Second)
  5057. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5058. redis.Set(keyOne, "", time.Second)
  5059. defer redis.Close()
  5060. if err == nil {
  5061. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5062. //查询是否在处方中出库
  5063. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5064. if openConfig.IsOpen != 1 {
  5065. //判断该医嘱是否执行了
  5066. if advice.ExecutionState == 1 {
  5067. creater := c.GetAdminUserInfo().AdminUser.Id
  5068. service.DrugAutoAddCancelInfo(&advice, creater)
  5069. }
  5070. }
  5071. //开启保存处方扣减功能
  5072. if openConfig.IsOpen == 1 {
  5073. creater := c.GetAdminUserInfo().AdminUser.Id
  5074. service.DrugAutoAddCancelInfo(&advice, creater)
  5075. }
  5076. } else {
  5077. if drugOutConfig.IsOpen == 1 {
  5078. //查询是否在处方中出库
  5079. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5080. if openConfig.IsOpen != 1 {
  5081. //判断该医嘱是否执行了
  5082. if advice.ExecutionState == 1 {
  5083. creater := c.GetAdminUserInfo().AdminUser.Id
  5084. service.DrugAutoAddCancelInfo(&advice, creater)
  5085. }
  5086. }
  5087. //开启保存处方扣减功能
  5088. if openConfig.IsOpen == 1 {
  5089. creater := c.GetAdminUserInfo().AdminUser.Id
  5090. service.DrugAutoAddCancelInfo(&advice, creater)
  5091. }
  5092. } else {
  5093. //判断该医嘱是否执行了
  5094. if advice.ExecutionState == 1 {
  5095. creater := c.GetAdminUserInfo().AdminUser.Id
  5096. service.DrugAutoAddCancelInfo(&advice, creater)
  5097. }
  5098. }
  5099. }
  5100. c.ServeSuccessJSON(map[string]interface{}{
  5101. "msg": "删除成功",
  5102. })
  5103. return
  5104. } else {
  5105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5106. return
  5107. }
  5108. }
  5109. func (c *HisApiController) DeleteProject() {
  5110. id, _ := c.GetInt64("id")
  5111. adminInfo := c.GetAdminUserInfo()
  5112. project, _ := service.GetHisProjectByID(id)
  5113. // var consumable models.DialysisBeforePrepare
  5114. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5115. //耗材保存处方出库
  5116. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5117. isCharge := false
  5118. isMedicine := false
  5119. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5120. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5121. for _, item := range new_prescriptions {
  5122. if item.IsMedicine == 1 {
  5123. isMedicine = true
  5124. }
  5125. }
  5126. for _, item := range new_prescriptions {
  5127. if item.OrderStatus == 4 {
  5128. isCharge = true
  5129. }
  5130. }
  5131. if isMedicine {
  5132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5133. return
  5134. }
  5135. if isCharge {
  5136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5137. return
  5138. }
  5139. if new_prescription.ID > 0 {
  5140. if new_prescription.OrderStatus == 2 {
  5141. isCharge = true
  5142. }
  5143. }
  5144. if isCharge {
  5145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5146. return
  5147. }
  5148. service.DeletePrintInfo(id)
  5149. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5150. label.Status = 0
  5151. service.CreateHisLabelRecordTwo(&label)
  5152. fmt.Println(goodOutConfig.IsOpen)
  5153. if goodOutConfig.IsOpen != 1 {
  5154. if stockConfig.IsOpen == 1 {
  5155. if project.Type == 2 {
  5156. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5157. fmt.Println(err)
  5158. }
  5159. if project.Type == 3 && project.IsOut == 1 {
  5160. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5161. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5162. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5163. operation_time := time.Now().Unix()
  5164. creater := adminInfo.AdminUser.Id
  5165. //创建退库单
  5166. timeStr := time.Now().Format("2006-01-02")
  5167. timeArr := strings.Split(timeStr, "-")
  5168. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5169. total = total + 1
  5170. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5171. cancelStock := models.CancelStock{
  5172. OrderNumber: orderNumber,
  5173. OperaTime: operation_time,
  5174. OrgId: adminInfo.CurrentOrgId,
  5175. Creater: creater,
  5176. Ctime: time.Now().Unix(),
  5177. Status: 1,
  5178. ReturnTime: project.RecordDate,
  5179. Type: 1,
  5180. StorehouseId: houseConfig.StorehouseOutInfo,
  5181. IsCheck: 1,
  5182. }
  5183. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5184. if msgerrkonde == gorm.ErrRecordNotFound {
  5185. service.AddSigleCancelStock(&cancelStock)
  5186. }
  5187. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5188. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5189. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5190. //查询是否有出库
  5191. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5192. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5193. deaerler, _ := service.GetDealerById(info.Dealer)
  5194. if info.ID > 0 {
  5195. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5196. if info.Count >= prescribingNumber {
  5197. cancelStockInfo := models.CancelStockInfo{
  5198. GoodId: project.ProjectId,
  5199. CancelStockId: cancel.ID,
  5200. GoodTypeId: good.GoodTypeId,
  5201. Count: prescribingNumber,
  5202. Price: info.Price,
  5203. Total: 0,
  5204. ProductDate: info.ProductDate,
  5205. ExpiryDate: info.ExpiryDate,
  5206. Ctime: time.Now().Unix(),
  5207. Status: 1,
  5208. OrgId: adminInfo.CurrentOrgId,
  5209. OrderNumber: cancel.OrderNumber,
  5210. Type: 0,
  5211. Dealer: deaerler.DealerName,
  5212. Manufacturer: manufacturer.ManufacturerName,
  5213. Number: info.Number,
  5214. RegisterAccount: "",
  5215. Remark: "",
  5216. WarehouseInfoId: info.WarehouseInfotId,
  5217. PatientId: info.PatientId,
  5218. RecordDate: info.SysRecordTime,
  5219. StorehouseId: houseConfig.StorehouseOutInfo,
  5220. IsCheck: 1,
  5221. }
  5222. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5223. //回退库存
  5224. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5225. //退库数量增加
  5226. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5227. //出库数量减少
  5228. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5229. }
  5230. if info.Count < prescribingNumber {
  5231. cancelStockInfo := models.CancelStockInfo{
  5232. GoodId: project.ProjectId,
  5233. CancelStockId: cancel.ID,
  5234. GoodTypeId: good.GoodTypeId,
  5235. Count: info.Count,
  5236. Price: info.Price,
  5237. Total: 0,
  5238. ProductDate: info.ProductDate,
  5239. ExpiryDate: info.ExpiryDate,
  5240. Ctime: time.Now().Unix(),
  5241. Status: 1,
  5242. OrgId: adminInfo.CurrentOrgId,
  5243. OrderNumber: cancel.OrderNumber,
  5244. Type: 0,
  5245. Dealer: deaerler.DealerName,
  5246. Manufacturer: manufacturer.ManufacturerName,
  5247. Number: info.Number,
  5248. RegisterAccount: "",
  5249. Remark: "",
  5250. WarehouseInfoId: info.WarehouseInfotId,
  5251. PatientId: info.PatientId,
  5252. RecordDate: info.SysRecordTime,
  5253. StorehouseId: houseConfig.StorehouseOutInfo,
  5254. IsCheck: 1,
  5255. }
  5256. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5257. //回退库存
  5258. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5259. //退库数量增加
  5260. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5261. //出库数量减少
  5262. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5263. }
  5264. //查询剩余库存
  5265. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5266. var over_count int64
  5267. for _, it := range goodList {
  5268. over_count += it.StockCount
  5269. }
  5270. //出库数据 大于 退库数量
  5271. if info.Count >= prescribingNumber {
  5272. flow := models.VmStockFlow{
  5273. WarehousingId: info.WarehouseInfotId,
  5274. GoodId: project.ProjectId,
  5275. Number: info.Number,
  5276. LicenseNumber: info.LicenseNumber,
  5277. Count: prescribingNumber,
  5278. UserOrgId: adminInfo.CurrentOrgId,
  5279. PatientId: project.PatientId,
  5280. SystemTime: info.SysRecordTime,
  5281. ConsumableType: 7,
  5282. IsSys: 0,
  5283. WarehousingOrder: "",
  5284. WarehouseOutId: info.WarehouseOutId,
  5285. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5286. IsEdit: 0,
  5287. CancelStockId: cancel.ID,
  5288. CancelOrderNumber: cancel.OrderNumber,
  5289. Manufacturer: manufacturer.ID,
  5290. Dealer: 0,
  5291. Creator: adminInfo.AdminUser.Id,
  5292. UpdateCreator: 0,
  5293. Status: 1,
  5294. Ctime: time.Now().Unix(),
  5295. Mtime: 0,
  5296. Price: info.Price,
  5297. WarehousingDetailId: info.WarehouseInfotId,
  5298. WarehouseOutDetailId: info.ID,
  5299. CancelOutDetailId: cancelInfo.ID,
  5300. ProductDate: info.ProductDate,
  5301. ExpireDate: info.ExpiryDate,
  5302. StorehouseId: houseConfig.StorehouseOutInfo,
  5303. OverCount: over_count,
  5304. }
  5305. service.CreateStockFlowOne(flow)
  5306. }
  5307. //出库数据小于退库数据
  5308. if info.Count < prescribingNumber {
  5309. flow := models.VmStockFlow{
  5310. WarehousingId: info.WarehouseInfotId,
  5311. GoodId: project.ProjectId,
  5312. Number: info.Number,
  5313. LicenseNumber: info.LicenseNumber,
  5314. Count: info.Count,
  5315. UserOrgId: adminInfo.CurrentOrgId,
  5316. PatientId: project.PatientId,
  5317. SystemTime: info.SysRecordTime,
  5318. ConsumableType: 7,
  5319. IsSys: 0,
  5320. WarehousingOrder: "",
  5321. WarehouseOutId: info.WarehouseOutId,
  5322. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5323. IsEdit: 0,
  5324. CancelStockId: cancel.ID,
  5325. CancelOrderNumber: cancel.OrderNumber,
  5326. Manufacturer: manufacturer.ID,
  5327. Dealer: 0,
  5328. Creator: adminInfo.AdminUser.Id,
  5329. UpdateCreator: 0,
  5330. Status: 1,
  5331. Ctime: time.Now().Unix(),
  5332. Mtime: 0,
  5333. Price: info.Price,
  5334. WarehousingDetailId: info.WarehouseInfotId,
  5335. WarehouseOutDetailId: info.ID,
  5336. CancelOutDetailId: cancelInfo.ID,
  5337. ProductDate: info.ProductDate,
  5338. ExpireDate: info.ExpiryDate,
  5339. StorehouseId: houseConfig.StorehouseOutInfo,
  5340. OverCount: over_count,
  5341. }
  5342. service.CreateStockFlowOne(flow)
  5343. }
  5344. //查询已出库数量
  5345. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5346. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  5347. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  5348. if prescribingNumber < dialysisInfo.Count {
  5349. //改变数量
  5350. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5351. }
  5352. if prescribingNumber >= dialysisInfo.Count {
  5353. //删除出库表
  5354. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5355. }
  5356. //更新剩余库存
  5357. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5358. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5359. var total_count_one int64
  5360. for _, it := range stockList {
  5361. total_count_one += it.StockCount
  5362. }
  5363. //基础库插入数据
  5364. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5365. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5366. var flush_count int64
  5367. for _, it := range goodListOne {
  5368. flush_count += it.StockCount
  5369. }
  5370. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5371. if errs != nil {
  5372. goodErrcode := models.XtGoodErrcode{
  5373. UserOrgId: project.UserOrgId,
  5374. Errcode: "手动出库更新剩余出库失败",
  5375. GoodId: project.ProjectId,
  5376. Status: 1,
  5377. Ctime: time.Now().Unix(),
  5378. Mtime: 0,
  5379. Count: 0,
  5380. StockCount: 0,
  5381. Creater: creater,
  5382. BatchNumberId: 0,
  5383. WarehouseOutId: 0,
  5384. }
  5385. service.CreateGoodErrcode(goodErrcode)
  5386. }
  5387. }
  5388. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5389. fmt.Println(err)
  5390. } else {
  5391. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5392. fmt.Println(err)
  5393. }
  5394. } else {
  5395. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5396. fmt.Println(err)
  5397. }
  5398. }
  5399. //保存处方出库
  5400. if goodOutConfig.IsOpen == 1 {
  5401. if project.Type == 3 {
  5402. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5403. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5404. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5405. operation_time := time.Now().Unix()
  5406. creater := adminInfo.AdminUser.Id
  5407. //创建退库单
  5408. timeStr := time.Now().Format("2006-01-02")
  5409. timeArr := strings.Split(timeStr, "-")
  5410. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5411. total = total + 1
  5412. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5413. cancelStock := models.CancelStock{
  5414. OrderNumber: orderNumber,
  5415. OperaTime: operation_time,
  5416. OrgId: adminInfo.CurrentOrgId,
  5417. Creater: creater,
  5418. Ctime: time.Now().Unix(),
  5419. Status: 1,
  5420. ReturnTime: project.RecordDate,
  5421. Type: 1,
  5422. StorehouseId: houseConfig.StorehouseOutInfo,
  5423. IsCheck: 1,
  5424. }
  5425. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5426. if msgerrkonde == gorm.ErrRecordNotFound {
  5427. service.AddSigleCancelStock(&cancelStock)
  5428. }
  5429. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5430. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5431. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5432. //获取出库数据
  5433. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5434. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5435. deaerler, _ := service.GetDealerById(info.Dealer)
  5436. if info.ID > 0 {
  5437. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5438. if info.Count >= prescribingNumber {
  5439. cancelStockInfo := models.CancelStockInfo{
  5440. GoodId: project.ProjectId,
  5441. CancelStockId: cancel.ID,
  5442. GoodTypeId: good.GoodTypeId,
  5443. Count: prescribingNumber,
  5444. Price: info.Price,
  5445. Total: 0,
  5446. ProductDate: info.ProductDate,
  5447. ExpiryDate: info.ExpiryDate,
  5448. Ctime: time.Now().Unix(),
  5449. Status: 1,
  5450. OrgId: adminInfo.CurrentOrgId,
  5451. OrderNumber: cancel.OrderNumber,
  5452. Type: 0,
  5453. Dealer: deaerler.DealerName,
  5454. Manufacturer: manufacturer.ManufacturerName,
  5455. Number: info.Number,
  5456. RegisterAccount: "",
  5457. Remark: "",
  5458. WarehouseInfoId: info.WarehouseInfotId,
  5459. PatientId: info.PatientId,
  5460. RecordDate: info.SysRecordTime,
  5461. StorehouseId: houseConfig.StorehouseOutInfo,
  5462. IsCheck: 1,
  5463. }
  5464. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5465. //退库数量增加
  5466. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5467. //出库数量减少
  5468. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5469. }
  5470. if info.Count < prescribingNumber {
  5471. cancelStockInfo := models.CancelStockInfo{
  5472. GoodId: project.ProjectId,
  5473. CancelStockId: cancel.ID,
  5474. GoodTypeId: good.GoodTypeId,
  5475. Count: prescribingNumber,
  5476. Price: info.Price,
  5477. Total: 0,
  5478. ProductDate: info.ProductDate,
  5479. ExpiryDate: info.ExpiryDate,
  5480. Ctime: time.Now().Unix(),
  5481. Status: 1,
  5482. OrgId: adminInfo.CurrentOrgId,
  5483. OrderNumber: cancel.OrderNumber,
  5484. Type: 0,
  5485. Dealer: deaerler.DealerName,
  5486. Manufacturer: manufacturer.ManufacturerName,
  5487. Number: info.Number,
  5488. RegisterAccount: "",
  5489. Remark: "",
  5490. WarehouseInfoId: info.WarehouseInfotId,
  5491. PatientId: info.PatientId,
  5492. RecordDate: info.SysRecordTime,
  5493. StorehouseId: houseConfig.StorehouseOutInfo,
  5494. IsCheck: 1,
  5495. }
  5496. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5497. //回退库存
  5498. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5499. }
  5500. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5501. var over_count int64
  5502. for _, it := range goodList {
  5503. over_count += it.StockCount
  5504. }
  5505. //查询出库数量
  5506. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  5507. //出库数据 大于 退库数量
  5508. if len(list) > 0 {
  5509. for _, it := range list {
  5510. //回退库存
  5511. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5512. //退库数量增加
  5513. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  5514. //出库数量减少
  5515. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  5516. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5517. var over_count_one int64
  5518. for _, it := range goodList {
  5519. over_count_one += it.StockCount
  5520. }
  5521. //查询该批次是否有退库数据
  5522. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  5523. flow := models.VmStockFlow{
  5524. WarehousingId: it.WarehouseInfotId,
  5525. GoodId: it.GoodId,
  5526. Number: it.Number,
  5527. LicenseNumber: it.LicenseNumber,
  5528. Count: it.Count,
  5529. UserOrgId: adminInfo.CurrentOrgId,
  5530. PatientId: it.PatientId,
  5531. SystemTime: it.SysRecordTime,
  5532. ConsumableType: 7,
  5533. IsSys: 0,
  5534. WarehousingOrder: "",
  5535. WarehouseOutId: it.WarehouseOutId,
  5536. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5537. IsEdit: 0,
  5538. CancelStockId: cancel.ID,
  5539. CancelOrderNumber: cancel.OrderNumber,
  5540. Manufacturer: manufacturer.ID,
  5541. Dealer: 0,
  5542. Creator: adminInfo.AdminUser.Id,
  5543. UpdateCreator: 0,
  5544. Status: 1,
  5545. Ctime: time.Now().Unix(),
  5546. Mtime: 0,
  5547. Price: it.Price,
  5548. WarehousingDetailId: it.WarehouseInfotId,
  5549. WarehouseOutDetailId: it.ID,
  5550. CancelOutDetailId: cancelInfo.ID,
  5551. ProductDate: it.ProductDate,
  5552. ExpireDate: it.ExpiryDate,
  5553. StorehouseId: houseConfig.StorehouseOutInfo,
  5554. OverCount: over_count_one,
  5555. }
  5556. service.CreateStockFlowOne(flow)
  5557. }
  5558. }
  5559. //查询已出库数量
  5560. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5561. if prescribingNumber < dialysisInfo.Count {
  5562. //改变数量
  5563. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5564. }
  5565. if prescribingNumber >= dialysisInfo.Count {
  5566. //删除出库表
  5567. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5568. }
  5569. //更新剩余库存
  5570. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5571. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5572. var total_count_one int64
  5573. for _, it := range stockList {
  5574. total_count_one += it.StockCount
  5575. }
  5576. //基础库插入数据
  5577. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5578. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5579. var flush_count int64
  5580. for _, it := range goodListOne {
  5581. flush_count += it.StockCount
  5582. }
  5583. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5584. if errs != nil {
  5585. goodErrcode := models.XtGoodErrcode{
  5586. UserOrgId: project.UserOrgId,
  5587. Errcode: "手动出库更新剩余出库失败",
  5588. GoodId: project.ProjectId,
  5589. Status: 1,
  5590. Ctime: time.Now().Unix(),
  5591. Mtime: 0,
  5592. Count: 0,
  5593. StockCount: 0,
  5594. Creater: creater,
  5595. BatchNumberId: 0,
  5596. WarehouseOutId: 0,
  5597. }
  5598. service.CreateGoodErrcode(goodErrcode)
  5599. }
  5600. }
  5601. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5602. fmt.Println(err)
  5603. } else {
  5604. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5605. fmt.Println(err)
  5606. }
  5607. }
  5608. c.ServeSuccessJSON(map[string]interface{}{
  5609. "msg": "删除成功",
  5610. })
  5611. return
  5612. }
  5613. func (c *HisApiController) CreateHisAdditionalCharge() {
  5614. his_patient_id, _ := c.GetInt64("his_patient_id")
  5615. patient_id, _ := c.GetInt64("patient_id")
  5616. record_date := c.GetString("record_date")
  5617. timeLayout := "2006-01-02"
  5618. loc, _ := time.LoadLocation("Local")
  5619. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5620. if err != nil {
  5621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5622. return
  5623. }
  5624. adminInfo := c.GetAdminUserInfo()
  5625. recordDateTime := theTime.Unix()
  5626. dataBody := make(map[string]interface{}, 0)
  5627. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5628. if err != nil {
  5629. utils.ErrorLog(err.Error())
  5630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5631. return
  5632. }
  5633. var additions []*models.HisAdditionalCharge
  5634. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5635. additions, _ := dataBody["addition"].([]interface{})
  5636. if len(additions) > 0 {
  5637. for _, item := range additions {
  5638. items := item.(map[string]interface{})
  5639. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5640. utils.ErrorLog("item_id")
  5641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5642. return
  5643. }
  5644. item_id := int64(items["item_id"].(float64))
  5645. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5646. utils.ErrorLog("item_name")
  5647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5648. return
  5649. }
  5650. item_name := items["item_name"].(string)
  5651. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5652. utils.ErrorLog("price")
  5653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5654. return
  5655. }
  5656. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5657. ctime := time.Now().Unix()
  5658. additional := &models.HisAdditionalCharge{
  5659. PatientId: patient_id,
  5660. HisPatientId: his_patient_id,
  5661. UserOrgId: adminInfo.CurrentOrgId,
  5662. RecordDate: recordDateTime,
  5663. CreatedTime: ctime,
  5664. UpdatedTime: ctime,
  5665. Modifier: adminInfo.AdminUser.Id,
  5666. Creator: adminInfo.AdminUser.Id,
  5667. Price: price,
  5668. ItemName: item_name,
  5669. ItemId: item_id,
  5670. Status: 1,
  5671. }
  5672. additions = append(additions, additional)
  5673. }
  5674. }
  5675. }
  5676. for _, item := range additions {
  5677. service.CreateAddtionalCharge(item)
  5678. }
  5679. c.ServeSuccessJSON(map[string]interface{}{
  5680. "msg": "创建成功",
  5681. })
  5682. }
  5683. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5684. blood_fat := c.GetString("blood_fat")
  5685. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5686. blood_sugar := c.GetString("blood_sugar")
  5687. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5688. chief_conplaint := c.GetString("chief_conplaint")
  5689. dbp := c.GetString("dbp")
  5690. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5691. delivery_way, _ := c.GetInt64("delivery_way")
  5692. diagnostic := c.GetString("diagnostic")
  5693. family_history := c.GetString("family_history")
  5694. height := c.GetString("height")
  5695. history_of_present_illness := c.GetString("history_of_present_illness")
  5696. is_infect, _ := c.GetInt64("is_infect")
  5697. past_history := c.GetString("past_history")
  5698. patient_id, _ := c.GetInt64("patient_id")
  5699. his_patient_id, _ := c.GetInt64("his_patient_id")
  5700. personal_history := c.GetString("personal_history")
  5701. pulse := c.GetString("pulse")
  5702. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5703. sbp := c.GetString("sbp")
  5704. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5705. heightfloat, _ := strconv.ParseFloat(height, 64)
  5706. sicktype := c.GetString("sick_type")
  5707. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5708. symptom := c.GetString("symptom")
  5709. sick_date := c.GetString("sick_date")
  5710. temperatures := c.GetString("temperature")
  5711. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5712. record_date := c.GetString("record_date")
  5713. breathing := c.GetString("breathing")
  5714. doctor_advice := c.GetString("doctor_advice")
  5715. remark := c.GetString("remark")
  5716. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5717. sick, _ := c.GetInt64("sick")
  5718. diagnose, _ := c.GetInt64("diagnose")
  5719. //id, _ := c.GetInt64("id")
  5720. timeLayout := "2006-01-02"
  5721. loc, _ := time.LoadLocation("Local")
  5722. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5723. allergic_history := c.GetString("allergic_history")
  5724. if err != nil {
  5725. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5726. return
  5727. }
  5728. recordDateTime := theTime.Unix()
  5729. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5730. if err != nil {
  5731. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5732. return
  5733. }
  5734. sickTimes := sickTime.Unix()
  5735. ctime := time.Now().Unix()
  5736. primary_disease := c.GetString("primary_disease")
  5737. confirm_failure_date := c.GetString("confirm_failure_date")
  5738. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5739. drug_allergy_history := c.GetString("drug_allergy_history")
  5740. physical_examination := c.GetString("physical_examination")
  5741. special_inspection := c.GetString("special_inspection")
  5742. lab_apparatus := c.GetString("lab_apparatus")
  5743. caseHistory := models.HisPatientCaseHistory{
  5744. HisPatientId: his_patient_id,
  5745. PatientId: patient_id,
  5746. Temperature: temperature,
  5747. BloodSugar: bloodsugarfloat,
  5748. Pulse: pulsefloat,
  5749. Sbp: sbpfloat,
  5750. Dbp: dbpfloat,
  5751. Height: heightfloat,
  5752. BloodFat: bloodfatfloat,
  5753. SickType: sick_type,
  5754. Symptom: symptom,
  5755. SickDate: sickTimes,
  5756. IsInfect: is_infect,
  5757. HistoryOfPresentIllness: history_of_present_illness,
  5758. PastHistory: past_history,
  5759. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5760. ChiefConplaint: chief_conplaint,
  5761. PersonalHistory: personal_history,
  5762. FamilyHistory: family_history,
  5763. Diagnostic: diagnostic,
  5764. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5765. Status: 1,
  5766. Ctime: ctime,
  5767. Mtime: ctime,
  5768. RecordDate: recordDateTime,
  5769. DeliveryWay: delivery_way,
  5770. Breathing: breathingfloat,
  5771. DoctorAdvice: doctor_advice,
  5772. Remark: remark,
  5773. Sick: sick,
  5774. Diagnose: diagnose,
  5775. AllergicHistory: allergic_history,
  5776. PrimaryDisease: primary_disease,
  5777. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5778. DrugAllergyHistory: drug_allergy_history,
  5779. PhysicalExamination: physical_examination,
  5780. SpecialInspection: special_inspection,
  5781. LabApparatus: lab_apparatus,
  5782. }
  5783. //查询该患者是否有病历
  5784. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5785. if errcodes == gorm.ErrRecordNotFound {
  5786. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5787. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5788. if err != nil {
  5789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5790. return
  5791. }
  5792. c.ServeSuccessJSON(map[string]interface{}{
  5793. "caseHistory": caseHistory,
  5794. "historyInfo": historyInfo,
  5795. })
  5796. return
  5797. } else if errcodes == nil {
  5798. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5799. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5800. if err != nil {
  5801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5802. return
  5803. }
  5804. c.ServeSuccessJSON(map[string]interface{}{
  5805. "caseHistory": caseHistory,
  5806. "historyInfo": historyInfo,
  5807. })
  5808. }
  5809. //查询该患者是否有病历
  5810. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5811. //if errcode == gorm.ErrRecordNotFound {
  5812. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5813. // if err != nil {
  5814. // c.ServeSuccessJSON(map[string]interface{}{
  5815. // "msg": "保存成功",
  5816. // })
  5817. // }
  5818. //} else if errcode == nil {
  5819. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5820. // return
  5821. //}
  5822. }
  5823. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5824. patient_id, _ := c.GetInt64("patient_id", 0)
  5825. adminUser := c.GetAdminUserInfo()
  5826. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5827. c.ServeSuccessJSON(map[string]interface{}{
  5828. "list": caseHistorys,
  5829. })
  5830. }
  5831. func (c *HisApiController) GetHisPatientCaseHistory() {
  5832. record_date, _ := c.GetInt64("record_date", 0)
  5833. patient_id, _ := c.GetInt64("patient_id", 0)
  5834. admin := c.GetAdminUserInfo()
  5835. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5836. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5837. c.ServeSuccessJSON(map[string]interface{}{
  5838. "info": info,
  5839. "case_history": case_history,
  5840. })
  5841. }
  5842. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5843. template_name := c.GetString("template_name")
  5844. template_remark := c.GetString("template_remark")
  5845. doctor := c.GetAdminUserInfo().AdminUser.Id
  5846. diagnostic := c.GetString("diagnostic")
  5847. chief_conplaint := c.GetString("chief_conplain")
  5848. history_of_present_illness := c.GetString("history_of_present_illness")
  5849. past_history := c.GetString("past_history")
  5850. personal_history := c.GetString("personal_history")
  5851. family_history := c.GetString("family_history")
  5852. user_name := c.GetString("user_name")
  5853. doctor_advice := c.GetString("doctor_advice")
  5854. remark := c.GetString("remark")
  5855. //record_date := c.GetString("record_date")
  5856. //fmt.Println("record_date--------",record_date)
  5857. //timeLayout := "2006-01-02"
  5858. //loc, _ := time.LoadLocation("Local")
  5859. //
  5860. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5861. //if err != nil {
  5862. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5863. // return
  5864. //}
  5865. //recordDateTime := theTime.Unix()
  5866. ctime := time.Now().Unix()
  5867. template := models.HisCaseHistoryTemplate{
  5868. HistoryOfPresentIllness: history_of_present_illness,
  5869. PastHistory: past_history,
  5870. ChiefConplaint: chief_conplaint,
  5871. PersonalHistory: personal_history,
  5872. FamilyHistory: family_history,
  5873. Diagnostic: diagnostic,
  5874. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5875. Status: 1,
  5876. Ctime: ctime,
  5877. Mtime: ctime,
  5878. RecordDate: time.Now().Unix(),
  5879. TemplateName: template_name,
  5880. TemplateRemark: template_remark,
  5881. Creator: doctor,
  5882. Modifier: doctor,
  5883. UserName: user_name,
  5884. DoctorAdvice: doctor_advice,
  5885. Remark: remark,
  5886. }
  5887. err := service.SaveHisPatientCaseHistoryTemplate(template)
  5888. if err == nil {
  5889. c.ServeSuccessJSON(map[string]interface{}{
  5890. "msg": "保存成功",
  5891. })
  5892. } else {
  5893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5894. return
  5895. }
  5896. }
  5897. func (c *HisApiController) GetCaseHistoryTemplate() {
  5898. timeLayout := "2006-01-02"
  5899. loc, _ := time.LoadLocation("Local")
  5900. keyword := c.GetString("keyword")
  5901. start_time := c.GetString("start_time")
  5902. end_time := c.GetString("end_time")
  5903. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5904. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5905. admin := c.GetAdminUserInfo()
  5906. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  5907. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  5908. c.ServeSuccessJSON(map[string]interface{}{
  5909. "template": template,
  5910. //"history": history,
  5911. })
  5912. }
  5913. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5914. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5915. utils.ErrorLog("drug_name")
  5916. return enums.ErrorCodeParamWrong
  5917. }
  5918. adviceName, _ := json["drug_name"].(string)
  5919. if len(adviceName) == 0 {
  5920. utils.ErrorLog("len(advice_name) == 0")
  5921. return enums.ErrorCodeParamWrong
  5922. }
  5923. advice.AdviceName = adviceName
  5924. adviceDesc, _ := json["advice_desc"].(string)
  5925. advice.AdviceDesc = adviceDesc
  5926. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5927. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5928. advice.DrugSpec = drugSpec
  5929. }
  5930. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5931. remark, _ := json["remark"].(string)
  5932. advice.Remark = remark
  5933. }
  5934. if json["id"] == nil {
  5935. advice.DrugId = 0
  5936. } else {
  5937. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5938. drug_id := int64(json["id"].(float64))
  5939. advice.DrugId = drug_id
  5940. }
  5941. }
  5942. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5943. advice_id := int64(json["advice_id"].(float64))
  5944. advice.ID = advice_id
  5945. if advice.ID > 0 {
  5946. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5947. if err == nil {
  5948. if hisAdvice.ID > 0 {
  5949. advice.ExecutionTime = hisAdvice.ExecutionTime
  5950. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5951. advice.ExecutionState = hisAdvice.ExecutionState
  5952. advice.CheckTime = hisAdvice.CheckTime
  5953. advice.Checker = hisAdvice.Checker
  5954. advice.CheckState = hisAdvice.CheckState
  5955. advice.StartTime = hisAdvice.StartTime
  5956. advice.FeedetlSn = hisAdvice.FeedetlSn
  5957. }
  5958. }
  5959. }
  5960. }
  5961. //
  5962. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5963. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5964. // advice.ExecutionTime = execution_time
  5965. //}
  5966. //
  5967. //
  5968. //
  5969. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5970. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5971. // advice.ExecutionStaff = execution_staff
  5972. //}
  5973. //
  5974. //
  5975. //
  5976. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5977. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5978. // advice.ExecutionState = execution_state
  5979. //}
  5980. //
  5981. //
  5982. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5983. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5984. // advice.CheckTime = check_time
  5985. //}
  5986. //
  5987. //
  5988. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5989. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5990. // advice.CheckState = check_state
  5991. //}
  5992. //
  5993. //
  5994. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5995. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5996. // advice.Checker = checker
  5997. //}
  5998. //
  5999. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6000. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6001. // advice.StartTime = start_time
  6002. //}
  6003. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6004. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6005. advice.IsSelfDrug = is_self_drug
  6006. }
  6007. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6008. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6009. drug_way_count, _ := json["drug_way_count"].(string)
  6010. advice.DrugWayCount = drug_way_count
  6011. }
  6012. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6013. drugSpecUnit, _ := json["min_unit"].(string)
  6014. advice.DrugSpecUnit = drugSpecUnit
  6015. }
  6016. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6017. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6018. advice.SingleDose = singleDose
  6019. }
  6020. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6021. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6022. advice.SingleDoseUnit = singleDoseUnit
  6023. }
  6024. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6025. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6026. advice.PrescribingNumber = prescribingNumber
  6027. }
  6028. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6029. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6030. advice.PrescribingNumberUnit = prescribingNumberUnit
  6031. }
  6032. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6033. deliveryWay, _ := json["delivery_way"].(string)
  6034. advice.DeliveryWay = deliveryWay
  6035. }
  6036. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6037. executionFrequency, _ := json["execution_frequency"].(string)
  6038. advice.ExecutionFrequency = executionFrequency
  6039. }
  6040. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6041. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6042. advice.Price = price
  6043. }
  6044. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6045. med_list_codg, _ := json["medical_insurance_number"].(string)
  6046. advice.MedListCodg = med_list_codg
  6047. }
  6048. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6049. day := int64(json["day"].(float64))
  6050. advice.Day = day
  6051. }
  6052. return 0
  6053. }
  6054. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6055. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6056. id := int64(json["id"].(float64))
  6057. project.ID = id
  6058. historyProject, _ := service.GetHisProjectByID(id)
  6059. project.FeedetlSn = historyProject.FeedetlSn
  6060. }
  6061. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6062. project_id := int64(json["project_id"].(float64))
  6063. project.ProjectId = project_id
  6064. }
  6065. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6066. // price := int64(json["price"].(float64))
  6067. // formatInt_price := strconv.FormatInt(price, 10)
  6068. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6069. // project.Price = float_price
  6070. // }
  6071. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6072. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6073. project.Price = price
  6074. }
  6075. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6076. total, _ := json["total"].(string)
  6077. project.Count = total
  6078. }
  6079. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6080. medical_code, _ := json["medical_code"].(string)
  6081. project.MedListCodg = medical_code
  6082. }
  6083. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6084. single_dose, _ := json["single_dose"].(string)
  6085. project.SingleDose = single_dose
  6086. }
  6087. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6088. delivery_way, _ := json["delivery_way"].(string)
  6089. project.DeliveryWay = delivery_way
  6090. }
  6091. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6092. execution_frequency, _ := json["execution_frequency"].(string)
  6093. project.ExecutionFrequency = execution_frequency
  6094. }
  6095. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6096. remark, _ := json["remark"].(string)
  6097. project.Remark = remark
  6098. }
  6099. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6100. day, _ := json["number_days"].(string)
  6101. project.Day = day
  6102. }
  6103. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6104. unit, _ := json["unit"].(string)
  6105. project.Unit = unit
  6106. }
  6107. return 0
  6108. }
  6109. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6110. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6111. id := int64(json["id"].(float64))
  6112. historyAddtions, _ := service.GetHisAdditionByID(id)
  6113. additionalCharge.ID = id
  6114. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6115. }
  6116. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6117. item_id := int64(json["item_id"].(float64))
  6118. additionalCharge.ItemId = item_id
  6119. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6120. if config.ID > 0 {
  6121. if len(config.Code) > 0 {
  6122. additionalCharge.MedListCodg = config.Code
  6123. }
  6124. }
  6125. }
  6126. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6127. // price := int64(json["price"].(float64))
  6128. // formatInt_price := strconv.FormatInt(price, 10)
  6129. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6130. // additionalCharge.Price = float_price
  6131. // }
  6132. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6133. // price := int64(json["price"].(float64))
  6134. // formatInt_price := strconv.FormatInt(price, 10)
  6135. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6136. // additionalCharge.Price = float_price
  6137. //}
  6138. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6139. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6140. additionalCharge.Price = price
  6141. }
  6142. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6143. count, _ := json["count"].(string)
  6144. counts, _ := strconv.ParseInt(count, 10, 64)
  6145. additionalCharge.Count = counts
  6146. }
  6147. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6148. item_name, _ := json["item_name"].(string)
  6149. additionalCharge.ItemName = item_name
  6150. }
  6151. return 0
  6152. }
  6153. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6154. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6155. utils.ErrorLog("drug_name")
  6156. return enums.ErrorCodeParamWrong
  6157. }
  6158. adviceName, _ := json["drug_name"].(string)
  6159. if len(adviceName) == 0 {
  6160. utils.ErrorLog("len(advice_name) == 0")
  6161. return enums.ErrorCodeParamWrong
  6162. }
  6163. advice.AdviceName = adviceName
  6164. adviceDesc, _ := json["advice_desc"].(string)
  6165. advice.AdviceDesc = adviceDesc
  6166. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6167. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6168. advice.DrugSpec = drugSpec
  6169. }
  6170. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6171. remark, _ := json["remark"].(string)
  6172. advice.Remark = remark
  6173. }
  6174. if json["id"] == nil {
  6175. advice.DrugId = 0
  6176. } else {
  6177. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6178. drug_id := int64(json["id"].(float64))
  6179. advice.DrugId = drug_id
  6180. }
  6181. }
  6182. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6183. groupno := int64(json["groupno"].(float64))
  6184. advice.Groupno = groupno
  6185. }
  6186. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6187. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6188. advice.IsSelfDrug = is_self_drug
  6189. }
  6190. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6191. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6192. drug_way_count, _ := json["drug_way_count"].(string)
  6193. advice.DrugWayCount = drug_way_count
  6194. }
  6195. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6196. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6197. advice.HospApprFlag = hosp_appr_flag
  6198. }
  6199. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6200. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6201. advice.PrescribingNumber = prescribingNumber
  6202. }
  6203. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6204. // frequency_type := int64(json["frequency_type"].(float64))
  6205. // advice.FrequencyType = frequency_type
  6206. //}
  6207. //
  6208. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6209. // day_count := int64(json["day_count"].(float64))
  6210. // advice.DayCount = day_count
  6211. //}
  6212. //
  6213. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6214. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6215. // week_day, _ := json["week_day"].(string)
  6216. // advice.WeekDay = week_day
  6217. //}
  6218. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6219. drugSpecUnit, _ := json["min_unit"].(string)
  6220. advice.DrugSpecUnit = drugSpecUnit
  6221. }
  6222. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6223. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6224. advice.SingleDose = singleDose
  6225. }
  6226. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6227. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6228. advice.SingleDoseUnit = singleDoseUnit
  6229. }
  6230. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6231. deliveryWay, _ := json["delivery_way"].(string)
  6232. advice.DeliveryWay = deliveryWay
  6233. }
  6234. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6235. executionFrequency, _ := json["execution_frequency"].(string)
  6236. advice.ExecutionFrequency = executionFrequency
  6237. }
  6238. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6239. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6240. advice.Price = price
  6241. }
  6242. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6243. med_list_codg, _ := json["medical_insurance_number"].(string)
  6244. advice.MedListCodg = med_list_codg
  6245. }
  6246. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6247. day := int64(json["day"].(float64))
  6248. advice.Day = day
  6249. }
  6250. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6251. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6252. advice.PrescribingNumberUnit = prescribingNumberUnit
  6253. }
  6254. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6255. advice_id := int64(json["advice_id"].(float64))
  6256. advice.ID = advice_id
  6257. if advice.ID > 0 {
  6258. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6259. if err == nil {
  6260. if hisAdvice.ID > 0 {
  6261. advice.ExecutionTime = hisAdvice.ExecutionTime
  6262. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6263. advice.ExecutionState = hisAdvice.ExecutionState
  6264. advice.CheckTime = hisAdvice.CheckTime
  6265. advice.Checker = hisAdvice.Checker
  6266. advice.CheckState = hisAdvice.CheckState
  6267. advice.StartTime = hisAdvice.StartTime
  6268. advice.HospApprFlag = hisAdvice.HospApprFlag
  6269. advice.IsMedicine = hisAdvice.IsMedicine
  6270. if hisAdvice.UserOrgId == 10028 {
  6271. 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 {
  6272. advice.ExecutionTime = 0
  6273. advice.ExecutionStaff = 0
  6274. advice.ExecutionState = 2
  6275. advice.CheckTime = 0
  6276. advice.Checker = 0
  6277. advice.CheckState = 2
  6278. }
  6279. } else {
  6280. 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 {
  6281. advice.ExecutionTime = 0
  6282. advice.ExecutionStaff = 0
  6283. advice.ExecutionState = 2
  6284. advice.CheckTime = 0
  6285. advice.Checker = 0
  6286. advice.CheckState = 2
  6287. }
  6288. }
  6289. //advice.Groupno = hisAdvice.Groupno
  6290. }
  6291. }
  6292. }
  6293. }
  6294. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6295. //
  6296. //if drugStockConfig.IsOpen == 1 {
  6297. //
  6298. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6299. // if advice.ID == 0 { //医嘱不存在
  6300. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6301. // drug.Total = drug.Total - advice.PrescribingNumber
  6302. // service.UpdateBaseDrugLib(&drug)
  6303. //
  6304. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6305. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6306. // drug.Total = drug.Total - num
  6307. // service.UpdateBaseDrugLib(&drug)
  6308. // }
  6309. //
  6310. // } else if advice.ID > 0 { //医嘱存在
  6311. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6312. // var num float64
  6313. //
  6314. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6315. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6316. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6317. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6318. // drug.Total = drug.Total + num
  6319. // service.UpdateBaseDrugLib(&drug)
  6320. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6321. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6322. // drug.Total = drug.Total - num
  6323. // service.UpdateBaseDrugLib(&drug)
  6324. // }
  6325. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6326. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6327. // if num2 > advice.PrescribingNumber {
  6328. // num = num2 - advice.PrescribingNumber
  6329. // drug.Total = drug.Total + num
  6330. // service.UpdateBaseDrugLib(&drug)
  6331. // } else if num2 < advice.PrescribingNumber {
  6332. // num = advice.PrescribingNumber - num2
  6333. // drug.Total = drug.Total - num
  6334. // service.UpdateBaseDrugLib(&drug)
  6335. // }
  6336. //
  6337. // }
  6338. //
  6339. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6340. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6341. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6342. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6343. // if num1 > num2 {
  6344. // num = num1 - num2
  6345. // drug.Total = drug.Total + num
  6346. // service.UpdateBaseDrugLib(&drug)
  6347. // } else if num1 < num2 {
  6348. // num = num2 - num1
  6349. // drug.Total = drug.Total - num
  6350. // service.UpdateBaseDrugLib(&drug)
  6351. // }
  6352. //
  6353. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6354. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6355. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6356. // if hisAdvice.PrescribingNumber > num2 {
  6357. // num = hisAdvice.PrescribingNumber - num2
  6358. // drug.Total = drug.Total + num
  6359. // service.UpdateBaseDrugLib(&drug)
  6360. // } else if num2 < advice.PrescribingNumber {
  6361. // num = num2 - hisAdvice.PrescribingNumber
  6362. // drug.Total = drug.Total - num
  6363. // service.UpdateBaseDrugLib(&drug)
  6364. // }
  6365. //
  6366. // }
  6367. // }
  6368. // }
  6369. //}
  6370. //
  6371. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6372. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6373. // advice.ExecutionTime = execution_time
  6374. //}
  6375. //
  6376. //
  6377. //
  6378. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6379. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6380. // advice.ExecutionStaff = execution_staff
  6381. //}
  6382. //
  6383. //
  6384. //
  6385. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6386. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6387. // advice.ExecutionState = execution_state
  6388. //}
  6389. //
  6390. //
  6391. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6392. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6393. // advice.CheckTime = check_time
  6394. //}
  6395. //
  6396. //
  6397. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6398. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6399. // advice.CheckState = check_state
  6400. //}
  6401. //
  6402. //
  6403. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6404. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6405. // advice.Checker = checker
  6406. //}
  6407. //
  6408. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6409. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6410. // advice.StartTime = start_time
  6411. //}
  6412. return 0
  6413. }
  6414. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6415. project.ExecutionStaff = 0
  6416. project.ExecutionState = 2
  6417. project.ExecutionTime = 0
  6418. project.Checker = 0
  6419. project.CheckState = 2
  6420. project.CheckTime = 0
  6421. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6422. id := int64(json["id"].(float64))
  6423. project.ID = id
  6424. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6425. project.ExecutionStaff = temp_project.ExecutionStaff
  6426. project.ExecutionState = temp_project.ExecutionState
  6427. project.ExecutionTime = temp_project.ExecutionTime
  6428. project.Checker = temp_project.Checker
  6429. project.CheckState = temp_project.CheckState
  6430. project.CheckTime = temp_project.CheckTime
  6431. project.TeamId = temp_project.TeamId
  6432. }
  6433. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6434. types := int64(json["type"].(float64))
  6435. project.Type = types
  6436. }
  6437. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6438. project_id := int64(json["project_id"].(float64))
  6439. project.ProjectId = project_id
  6440. }
  6441. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6442. team_id := int64(json["team_id"].(float64))
  6443. project.TeamId = team_id
  6444. }
  6445. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6446. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6447. project.Price = price
  6448. }
  6449. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6450. total, _ := json["total"].(string)
  6451. //totals, _ := strconv.ParseInt(total, 10, 64)
  6452. project.Count = total
  6453. }
  6454. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6455. medical_code, _ := json["medical_code"].(string)
  6456. project.MedListCodg = medical_code
  6457. }
  6458. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6459. single_dose, _ := json["single_dose"].(string)
  6460. project.SingleDose = single_dose
  6461. }
  6462. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6463. delivery_way, _ := json["delivery_way"].(string)
  6464. project.DeliveryWay = delivery_way
  6465. }
  6466. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6467. execution_frequency, _ := json["execution_frequency"].(string)
  6468. project.ExecutionFrequency = execution_frequency
  6469. }
  6470. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6471. remark, _ := json["remark"].(string)
  6472. project.Remark = remark
  6473. }
  6474. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6475. day, _ := json["number_days"].(string)
  6476. project.Day = day
  6477. }
  6478. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6479. unit, _ := json["unit"].(string)
  6480. project.Unit = unit
  6481. }
  6482. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6483. // frequency_type := int64(json["frequency_type"].(float64))
  6484. // project.FrequencyType = frequency_type
  6485. //}
  6486. //
  6487. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6488. // day_count := int64(json["day_count"].(float64))
  6489. // project.DayCount = day_count
  6490. //}
  6491. //
  6492. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6493. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6494. // week_day, _ := json["week_day"].(string)
  6495. // project.WeekDay = week_day
  6496. //}
  6497. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6498. //
  6499. //if project.ID == 0 {
  6500. // if stockConfig.IsOpen == 1 {
  6501. // if project.Type == 3 {
  6502. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6503. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6504. // good.Total = good.Total - f_count
  6505. // service.UpdateGoodInfo(&good)
  6506. // }
  6507. // }
  6508. //
  6509. //} else {
  6510. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6511. //
  6512. // if stockConfig.IsOpen == 1 {
  6513. // if project.Type == 3 {
  6514. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6515. // if project.Count < temp_project.Count {
  6516. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6517. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6518. //
  6519. // other_count := f_count_two - f_count_one
  6520. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6521. // good.Total = good.Total + other_count_two
  6522. // service.UpdateGoodInfo(&good)
  6523. // } else if project.Count > temp_project.Count {
  6524. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6525. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6526. //
  6527. // other_count := f_count_one - f_count_two
  6528. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6529. // good.Total = good.Total - other_count_two
  6530. // service.UpdateGoodInfo(&good)
  6531. // }
  6532. //
  6533. // }
  6534. // }
  6535. //
  6536. //}
  6537. return 0
  6538. }
  6539. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6540. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6541. utils.ErrorLog("drug_name")
  6542. return enums.ErrorCodeParamWrong
  6543. }
  6544. adviceName, _ := json["drug_name"].(string)
  6545. if len(adviceName) == 0 {
  6546. utils.ErrorLog("len(advice_name) == 0")
  6547. return enums.ErrorCodeParamWrong
  6548. }
  6549. advice.AdviceName = adviceName
  6550. adviceDesc, _ := json["advice_desc"].(string)
  6551. advice.AdviceDesc = adviceDesc
  6552. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6553. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6554. advice.DrugSpec = drugSpec
  6555. }
  6556. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6557. remark, _ := json["remark"].(string)
  6558. advice.Remark = remark
  6559. }
  6560. if json["id"] == nil {
  6561. advice.DrugId = 0
  6562. } else {
  6563. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6564. drug_id := int64(json["id"].(float64))
  6565. advice.DrugId = drug_id
  6566. }
  6567. }
  6568. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6569. groupno := int64(json["groupno"].(float64))
  6570. advice.Groupno = groupno
  6571. }
  6572. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6573. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6574. advice.IsSelfDrug = is_self_drug
  6575. }
  6576. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6577. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6578. drug_way_count, _ := json["drug_way_count"].(string)
  6579. advice.DrugWayCount = drug_way_count
  6580. }
  6581. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6582. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6583. advice.HospApprFlag = hosp_appr_flag
  6584. }
  6585. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6586. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6587. advice.PrescribingNumber = prescribingNumber
  6588. }
  6589. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6590. // frequency_type := int64(json["frequency_type"].(float64))
  6591. // advice.FrequencyType = frequency_type
  6592. //}
  6593. //
  6594. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6595. // day_count := int64(json["day_count"].(float64))
  6596. // advice.DayCount = day_count
  6597. //}
  6598. //
  6599. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6600. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6601. // week_day, _ := json["week_day"].(string)
  6602. // advice.WeekDay = week_day
  6603. //}
  6604. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6605. drugSpecUnit, _ := json["min_unit"].(string)
  6606. advice.DrugSpecUnit = drugSpecUnit
  6607. }
  6608. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6609. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6610. advice.SingleDose = singleDose
  6611. }
  6612. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6613. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6614. advice.SingleDoseUnit = singleDoseUnit
  6615. }
  6616. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6617. deliveryWay, _ := json["delivery_way"].(string)
  6618. advice.DeliveryWay = deliveryWay
  6619. }
  6620. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6621. executionFrequency, _ := json["execution_frequency"].(string)
  6622. advice.ExecutionFrequency = executionFrequency
  6623. }
  6624. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6625. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6626. advice.Price = price
  6627. }
  6628. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6629. med_list_codg, _ := json["medical_insurance_number"].(string)
  6630. advice.MedListCodg = med_list_codg
  6631. }
  6632. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6633. day := int64(json["day"].(float64))
  6634. advice.Day = day
  6635. }
  6636. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6637. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6638. advice.PrescribingNumberUnit = prescribingNumberUnit
  6639. }
  6640. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6641. advice_id := int64(json["advice_id"].(float64))
  6642. advice.ID = advice_id
  6643. if advice.ID > 0 {
  6644. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6645. if err == nil {
  6646. if hisAdvice.ID > 0 {
  6647. if hisAdvice.YbSyncStatus == 1 {
  6648. advice.YbSyncStatus = 0
  6649. }
  6650. advice.UpdatedTime = time.Now().Unix()
  6651. advice.CreatedTime = hisAdvice.CreatedTime
  6652. advice.ExecutionTime = hisAdvice.ExecutionTime
  6653. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6654. advice.ExecutionState = hisAdvice.ExecutionState
  6655. advice.CheckTime = hisAdvice.CheckTime
  6656. advice.Checker = hisAdvice.Checker
  6657. advice.CheckState = hisAdvice.CheckState
  6658. advice.StartTime = hisAdvice.StartTime
  6659. advice.HospApprFlag = hisAdvice.HospApprFlag
  6660. advice.IsMedicine = hisAdvice.IsMedicine
  6661. if hisAdvice.UserOrgId == 10028 {
  6662. 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 {
  6663. advice.ExecutionTime = 0
  6664. advice.ExecutionStaff = 0
  6665. advice.ExecutionState = 2
  6666. advice.CheckTime = 0
  6667. advice.Checker = 0
  6668. advice.CheckState = 2
  6669. }
  6670. } else {
  6671. 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 {
  6672. advice.ExecutionTime = 0
  6673. advice.ExecutionStaff = 0
  6674. advice.ExecutionState = 2
  6675. advice.CheckTime = 0
  6676. advice.Checker = 0
  6677. advice.CheckState = 2
  6678. }
  6679. }
  6680. //advice.Groupno = hisAdvice.Groupno
  6681. }
  6682. }
  6683. }
  6684. }
  6685. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6686. //
  6687. //if drugStockConfig.IsOpen == 1 {
  6688. //
  6689. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6690. // if advice.ID == 0 { //医嘱不存在
  6691. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6692. // drug.Total = drug.Total - advice.PrescribingNumber
  6693. // service.UpdateBaseDrugLib(&drug)
  6694. //
  6695. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6696. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6697. // drug.Total = drug.Total - num
  6698. // service.UpdateBaseDrugLib(&drug)
  6699. // }
  6700. //
  6701. // } else if advice.ID > 0 { //医嘱存在
  6702. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6703. // var num float64
  6704. //
  6705. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6706. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6707. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6708. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6709. // drug.Total = drug.Total + num
  6710. // service.UpdateBaseDrugLib(&drug)
  6711. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6712. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6713. // drug.Total = drug.Total - num
  6714. // service.UpdateBaseDrugLib(&drug)
  6715. // }
  6716. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6717. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6718. // if num2 > advice.PrescribingNumber {
  6719. // num = num2 - advice.PrescribingNumber
  6720. // drug.Total = drug.Total + num
  6721. // service.UpdateBaseDrugLib(&drug)
  6722. // } else if num2 < advice.PrescribingNumber {
  6723. // num = advice.PrescribingNumber - num2
  6724. // drug.Total = drug.Total - num
  6725. // service.UpdateBaseDrugLib(&drug)
  6726. // }
  6727. //
  6728. // }
  6729. //
  6730. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6731. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6732. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6733. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6734. // if num1 > num2 {
  6735. // num = num1 - num2
  6736. // drug.Total = drug.Total + num
  6737. // service.UpdateBaseDrugLib(&drug)
  6738. // } else if num1 < num2 {
  6739. // num = num2 - num1
  6740. // drug.Total = drug.Total - num
  6741. // service.UpdateBaseDrugLib(&drug)
  6742. // }
  6743. //
  6744. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6745. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6746. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6747. // if hisAdvice.PrescribingNumber > num2 {
  6748. // num = hisAdvice.PrescribingNumber - num2
  6749. // drug.Total = drug.Total + num
  6750. // service.UpdateBaseDrugLib(&drug)
  6751. // } else if num2 < advice.PrescribingNumber {
  6752. // num = num2 - hisAdvice.PrescribingNumber
  6753. // drug.Total = drug.Total - num
  6754. // service.UpdateBaseDrugLib(&drug)
  6755. // }
  6756. //
  6757. // }
  6758. // }
  6759. // }
  6760. //}
  6761. //
  6762. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6763. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6764. // advice.ExecutionTime = execution_time
  6765. //}
  6766. //
  6767. //
  6768. //
  6769. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6770. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6771. // advice.ExecutionStaff = execution_staff
  6772. //}
  6773. //
  6774. //
  6775. //
  6776. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6777. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6778. // advice.ExecutionState = execution_state
  6779. //}
  6780. //
  6781. //
  6782. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6783. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6784. // advice.CheckTime = check_time
  6785. //}
  6786. //
  6787. //
  6788. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6789. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6790. // advice.CheckState = check_state
  6791. //}
  6792. //
  6793. //
  6794. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6795. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6796. // advice.Checker = checker
  6797. //}
  6798. //
  6799. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6800. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6801. // advice.StartTime = start_time
  6802. //}
  6803. return 0
  6804. }
  6805. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6806. project.ExecutionStaff = 0
  6807. project.ExecutionState = 2
  6808. project.ExecutionTime = 0
  6809. project.Checker = 0
  6810. project.CheckState = 2
  6811. project.CheckTime = 0
  6812. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6813. id := int64(json["id"].(float64))
  6814. project.ID = id
  6815. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6816. if temp_project.ID > 0 {
  6817. if temp_project.YbSyncStatus == 1 {
  6818. project.YbSyncStatus = 0
  6819. }
  6820. project.ExecutionStaff = temp_project.ExecutionStaff
  6821. project.ExecutionState = temp_project.ExecutionState
  6822. project.ExecutionTime = temp_project.ExecutionTime
  6823. project.Checker = temp_project.Checker
  6824. project.CheckState = temp_project.CheckState
  6825. project.CheckTime = temp_project.CheckTime
  6826. project.TeamId = temp_project.TeamId
  6827. project.Ctime = temp_project.Ctime
  6828. project.Mtime = time.Now().Unix()
  6829. }
  6830. }
  6831. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6832. types := int64(json["type"].(float64))
  6833. project.Type = types
  6834. }
  6835. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6836. project_id := int64(json["project_id"].(float64))
  6837. project.ProjectId = project_id
  6838. }
  6839. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6840. team_id := int64(json["team_id"].(float64))
  6841. project.TeamId = team_id
  6842. }
  6843. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6844. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6845. project.Price = price
  6846. }
  6847. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6848. total, _ := json["total"].(string)
  6849. //totals, _ := strconv.ParseInt(total, 10, 64)
  6850. project.Count = total
  6851. }
  6852. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6853. medical_code, _ := json["medical_code"].(string)
  6854. project.MedListCodg = medical_code
  6855. }
  6856. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6857. single_dose, _ := json["single_dose"].(string)
  6858. project.SingleDose = single_dose
  6859. }
  6860. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6861. delivery_way, _ := json["delivery_way"].(string)
  6862. project.DeliveryWay = delivery_way
  6863. }
  6864. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6865. execution_frequency, _ := json["execution_frequency"].(string)
  6866. project.ExecutionFrequency = execution_frequency
  6867. }
  6868. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6869. remark, _ := json["remark"].(string)
  6870. project.Remark = remark
  6871. }
  6872. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6873. day, _ := json["number_days"].(string)
  6874. project.Day = day
  6875. }
  6876. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6877. unit, _ := json["unit"].(string)
  6878. project.Unit = unit
  6879. }
  6880. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6881. // frequency_type := int64(json["frequency_type"].(float64))
  6882. // project.FrequencyType = frequency_type
  6883. //}
  6884. //
  6885. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6886. // day_count := int64(json["day_count"].(float64))
  6887. // project.DayCount = day_count
  6888. //}
  6889. //
  6890. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6891. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6892. // week_day, _ := json["week_day"].(string)
  6893. // project.WeekDay = week_day
  6894. //}
  6895. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6896. //
  6897. //if project.ID == 0 {
  6898. // if stockConfig.IsOpen == 1 {
  6899. // if project.Type == 3 {
  6900. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6901. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6902. // good.Total = good.Total - f_count
  6903. // service.UpdateGoodInfo(&good)
  6904. // }
  6905. // }
  6906. //
  6907. //} else {
  6908. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6909. //
  6910. // if stockConfig.IsOpen == 1 {
  6911. // if project.Type == 3 {
  6912. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6913. // if project.Count < temp_project.Count {
  6914. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6915. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6916. //
  6917. // other_count := f_count_two - f_count_one
  6918. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6919. // good.Total = good.Total + other_count_two
  6920. // service.UpdateGoodInfo(&good)
  6921. // } else if project.Count > temp_project.Count {
  6922. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6923. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6924. //
  6925. // other_count := f_count_one - f_count_two
  6926. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6927. // good.Total = good.Total - other_count_two
  6928. // service.UpdateGoodInfo(&good)
  6929. // }
  6930. //
  6931. // }
  6932. // }
  6933. //
  6934. //}
  6935. return 0
  6936. }
  6937. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6938. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6939. id := int64(json["id"].(float64))
  6940. additionalCharge.ID = id
  6941. }
  6942. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6943. item_id := int64(json["item_id"].(float64))
  6944. additionalCharge.ItemId = item_id
  6945. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6946. if config.ID > 0 {
  6947. if len(config.Code) > 0 {
  6948. additionalCharge.MedListCodg = config.Code
  6949. }
  6950. }
  6951. }
  6952. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6953. // price := int64(json["price"].(float64))
  6954. // formatInt_price := strconv.FormatInt(price, 10)
  6955. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6956. // additionalCharge.Price = float_price
  6957. // }
  6958. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6959. // price := int64(json["price"].(float64))
  6960. // formatInt_price := strconv.FormatInt(price, 10)
  6961. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6962. // additionalCharge.Price = float_price
  6963. //}
  6964. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6965. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6966. additionalCharge.Price = price
  6967. }
  6968. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6969. count, _ := json["count"].(string)
  6970. counts, _ := strconv.ParseInt(count, 10, 64)
  6971. additionalCharge.Count = counts
  6972. }
  6973. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6974. item_name, _ := json["item_name"].(string)
  6975. additionalCharge.ItemName = item_name
  6976. }
  6977. return 0
  6978. }
  6979. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  6980. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6981. utils.ErrorLog("drug_name")
  6982. return enums.ErrorCodeParamWrong
  6983. }
  6984. adviceName, _ := json["drug_name"].(string)
  6985. if len(adviceName) == 0 {
  6986. utils.ErrorLog("len(advice_name) == 0")
  6987. return enums.ErrorCodeParamWrong
  6988. }
  6989. advice.AdviceName = adviceName
  6990. adviceDesc, _ := json["advice_desc"].(string)
  6991. advice.AdviceDesc = adviceDesc
  6992. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6993. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6994. advice.DrugSpec = drugSpec
  6995. }
  6996. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6997. remark, _ := json["remark"].(string)
  6998. advice.Remark = remark
  6999. }
  7000. if json["id"] == nil {
  7001. advice.DrugId = 0
  7002. } else {
  7003. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  7004. drug_id := int64(json["id"].(float64))
  7005. advice.DrugId = drug_id
  7006. }
  7007. }
  7008. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  7009. groupno := int64(json["groupno"].(float64))
  7010. advice.Groupno = groupno
  7011. }
  7012. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  7013. drugSpecUnit, _ := json["min_unit"].(string)
  7014. advice.DrugSpecUnit = drugSpecUnit
  7015. }
  7016. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7017. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  7018. advice.SingleDose = singleDose
  7019. }
  7020. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7021. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7022. advice.SingleDoseUnit = singleDoseUnit
  7023. }
  7024. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7025. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7026. advice.PrescribingNumber = prescribingNumber
  7027. }
  7028. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7029. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7030. advice.PrescribingNumberUnit = prescribingNumberUnit
  7031. }
  7032. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7033. deliveryWay, _ := json["delivery_way"].(string)
  7034. advice.DeliveryWay = deliveryWay
  7035. }
  7036. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7037. executionFrequency, _ := json["execution_frequency"].(string)
  7038. advice.ExecutionFrequency = executionFrequency
  7039. }
  7040. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7041. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7042. advice.Price = price
  7043. }
  7044. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7045. med_list_codg, _ := json["medical_insurance_number"].(string)
  7046. advice.MedListCodg = med_list_codg
  7047. }
  7048. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7049. day := int64(json["day"].(float64))
  7050. advice.Day = day
  7051. }
  7052. advice.FrequencyType = 1
  7053. return 0
  7054. }
  7055. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7056. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7057. types := int64(json["type"].(float64))
  7058. project.Type = types
  7059. }
  7060. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7061. project_id := int64(json["project_id"].(float64))
  7062. project.ProjectId = project_id
  7063. }
  7064. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7065. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7066. project.Price = price
  7067. }
  7068. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7069. total, _ := json["total"].(string)
  7070. //totals, _ := strconv.ParseInt(total, 10, 64)
  7071. project.Count = total
  7072. }
  7073. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7074. medical_code, _ := json["medical_code"].(string)
  7075. project.MedListCodg = medical_code
  7076. }
  7077. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7078. single_dose, _ := json["single_dose"].(string)
  7079. project.SingleDose = single_dose
  7080. }
  7081. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7082. delivery_way, _ := json["delivery_way"].(string)
  7083. project.DeliveryWay = delivery_way
  7084. }
  7085. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7086. execution_frequency, _ := json["execution_frequency"].(string)
  7087. project.ExecutionFrequency = execution_frequency
  7088. }
  7089. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7090. remark, _ := json["remark"].(string)
  7091. project.Remark = remark
  7092. }
  7093. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7094. day, _ := json["number_days"].(string)
  7095. project.Day = day
  7096. }
  7097. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7098. unit, _ := json["unit"].(string)
  7099. project.Unit = unit
  7100. }
  7101. project.FrequencyType = 1
  7102. return 0
  7103. }
  7104. func (c *HisApiController) GetHisOrderListTwo() {
  7105. start_time := c.GetString("start_time")
  7106. end_time := c.GetString("end_time")
  7107. timeLayout := "2006-01-02"
  7108. loc, _ := time.LoadLocation("Local")
  7109. var startTime int64
  7110. if len(start_time) > 0 {
  7111. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7112. if err != nil {
  7113. //fmt.Println(err)
  7114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7115. return
  7116. }
  7117. startTime = theTime.Unix()
  7118. }
  7119. var endTime int64
  7120. if len(end_time) > 0 {
  7121. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7122. if err != nil {
  7123. utils.ErrorLog(err.Error())
  7124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7125. return
  7126. }
  7127. endTime = theTime.Unix()
  7128. }
  7129. adminUser := c.GetAdminUserInfo()
  7130. org_id := adminUser.CurrentOrgId
  7131. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7132. if err == nil {
  7133. c.ServeSuccessJSON(map[string]interface{}{
  7134. "order2": order,
  7135. })
  7136. } else {
  7137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7138. return
  7139. }
  7140. }
  7141. func (c *HisApiController) GetHisOrderList() {
  7142. page, _ := c.GetInt64("page", -1)
  7143. limit, _ := c.GetInt64("limit", -1)
  7144. start_time := c.GetString("start_time")
  7145. end_time := c.GetString("end_time")
  7146. types, _ := c.GetInt64("type", 0)
  7147. keywords := c.GetString("keywords")
  7148. p_type, _ := c.GetInt64("p_type", 0)
  7149. sort_type, _ := c.GetInt64("sort_type", 0)
  7150. charge_type, _ := c.GetInt64("charge_type", 0)
  7151. sch_type, _ := c.GetInt64("sch_type", 0)
  7152. zone_type, _ := c.GetInt64("zone_type", 0)
  7153. med_type, _ := c.GetInt64("med_type", 0)
  7154. timeLayout := "2006-01-02"
  7155. loc, _ := time.LoadLocation("Local")
  7156. var startTime int64
  7157. if len(start_time) > 0 {
  7158. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7159. if err != nil {
  7160. //fmt.Println(err)
  7161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7162. return
  7163. }
  7164. startTime = theTime.Unix()
  7165. }
  7166. var endTime int64
  7167. if len(end_time) > 0 {
  7168. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7169. if err != nil {
  7170. utils.ErrorLog(err.Error())
  7171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7172. return
  7173. }
  7174. endTime = theTime.Unix()
  7175. }
  7176. adminUser := c.GetAdminUserInfo()
  7177. org_id := adminUser.CurrentOrgId
  7178. 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)
  7179. for _, item := range order {
  7180. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7181. item.DoctorName = info.Doctor
  7182. item.DepartmentName = info.XtHisDepartment.Name
  7183. }
  7184. if err == nil {
  7185. c.ServeSuccessJSON(map[string]interface{}{
  7186. "order": order,
  7187. "total": total,
  7188. })
  7189. } else {
  7190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7191. return
  7192. }
  7193. }
  7194. func (c *HisApiController) GetHisOrder() {
  7195. patient_id, _ := c.GetInt64("patient_id", 0)
  7196. number := c.GetString("number")
  7197. adminInfo := c.GetAdminUserInfo()
  7198. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7199. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7200. if err == nil {
  7201. c.ServeSuccessJSON(map[string]interface{}{
  7202. "order": order,
  7203. "prescription": prescriptions,
  7204. })
  7205. } else {
  7206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7207. return
  7208. }
  7209. }
  7210. func (c *HisApiController) GetHisPrescriptionList() {
  7211. record_date := c.GetString("record_date")
  7212. keywords := c.GetString("keywords")
  7213. page, _ := c.GetInt64("page")
  7214. limit, _ := c.GetInt64("limit")
  7215. sch_type, _ := c.GetInt64("sch_type")
  7216. timeLayout := "2006-01-02"
  7217. loc, _ := time.LoadLocation("Local")
  7218. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7219. if err != nil {
  7220. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7221. return
  7222. }
  7223. recordDateTime := theTime.Unix()
  7224. adminInfo := c.GetAdminUserInfo()
  7225. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7226. //adminInfo := c.GetAdminUserInfo()
  7227. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7228. //fmt.Println(prescriptionOrder)
  7229. if err == nil {
  7230. c.ServeSuccessJSON(map[string]interface{}{
  7231. "order": prescriptionOrder,
  7232. "total": total,
  7233. })
  7234. } else {
  7235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7236. return
  7237. }
  7238. }
  7239. func (c *HisApiController) GetHisPrescriptionInfo() {
  7240. id, _ := c.GetInt64("id")
  7241. adminInfo := c.GetAdminUserInfo()
  7242. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7243. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7244. if err == nil {
  7245. c.ServeSuccessJSON(map[string]interface{}{
  7246. "order": prescriptionOrder,
  7247. "prescription": prescription,
  7248. })
  7249. } else {
  7250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7251. return
  7252. }
  7253. }
  7254. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7255. adminUser := c.GetAdminUserInfo()
  7256. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7257. c.ServeSuccessJSON(map[string]interface{}{
  7258. "config": config,
  7259. })
  7260. }
  7261. type ResultTwo struct {
  7262. ErrMsg interface{} `json:"err_msg"`
  7263. InfRefmsgid string `json:"inf_refmsgid"`
  7264. Infcode int64 `json:"infcode"`
  7265. Output struct {
  7266. Baseinfo struct {
  7267. Age float64 `json:"age"`
  7268. Brdy string `json:"brdy"`
  7269. Certno string `json:"certno"`
  7270. Gend string `json:"gend"`
  7271. Naty string `json:"naty"`
  7272. PsnCertType string `json:"psn_cert_type"`
  7273. PsnName string `json:"psn_name"`
  7274. PsnNo string `json:"psn_no"`
  7275. } `json:"baseinfo"`
  7276. Idetinfo []interface{} `json:"idetinfo"`
  7277. Iinfo []struct {
  7278. Balc float64 `json:"balc"`
  7279. CvlservFlag string `json:"cvlserv_flag"`
  7280. EmpName string `json:"emp_name"`
  7281. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7282. Insutype string `json:"insutype"`
  7283. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7284. PausInsuDate interface{} `json:"paus_insu_date"`
  7285. PsnInsuDate string `json:"psn_insu_date"`
  7286. PsnInsuStas string `json:"psn_insu_stas"`
  7287. PsnType string `json:"psn_type"`
  7288. } `json:"insuinfo"`
  7289. } `json:"output"`
  7290. RefmsgTime string `json:"refmsg_time"`
  7291. RespondTime string `json:"respond_time"`
  7292. Signtype interface{} `json:"signtype"`
  7293. WarnInfo interface{} `json:"warn_info"`
  7294. }
  7295. type ResultThree struct {
  7296. Cainfo interface{} `json:"cainfo"`
  7297. ErrMsg interface{} `json:"err_msg"`
  7298. InfRefmsgid string `json:"inf_refmsgid"`
  7299. Infcode int64 `json:"infcode"`
  7300. Output struct {
  7301. Data struct {
  7302. IptOtpNo string `json:"ipt_otp_no"`
  7303. MdtrtID string `json:"mdtrt_id"`
  7304. PsnNo string `json:"psn_no"`
  7305. } `json:"data"`
  7306. } `json:"output"`
  7307. RefmsgTime string `json:"refmsg_time"`
  7308. RespondTime string `json:"respond_time"`
  7309. Signtype interface{} `json:"signtype"`
  7310. WarnMsg interface{} `json:"warn_msg"`
  7311. }
  7312. type ResultFour struct {
  7313. Cainfo string `json:"cainfo"`
  7314. ErrMsg string `json:"err_msg"`
  7315. InfRefmsgid string `json:"inf_refmsgid"`
  7316. Infcode int64 `json:"infcode"`
  7317. Output struct {
  7318. Result []struct {
  7319. BasMednFlag string `json:"bas_medn_flag"`
  7320. ChldMedcFlag string `json:"chld_medc_flag"`
  7321. ChrgitmLv string `json:"chrgitm_lv"`
  7322. Cnt float64 `json:"cnt"`
  7323. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  7324. DrtReimFlag string `json:"drt_reim_flag"`
  7325. FeedetlSn string `json:"feedetl_sn"`
  7326. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7327. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  7328. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7329. ListSpItemFlag string `json:"list_sp_item_flag"`
  7330. LmtUsedFlag string `json:"lmt_used_flag"`
  7331. MedChrgitmType string `json:"med_chrgitm_type"`
  7332. Memo string `json:"memo"`
  7333. OverlmtAmt float64 `json:"overlmt_amt"`
  7334. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7335. Pric float64 `json:"pric"`
  7336. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  7337. SelfpayProp float64 `json:"selfpay_prop"`
  7338. } `json:"result"`
  7339. } `json:"output"`
  7340. RefmsgTime string `json:"refmsg_time"`
  7341. RespondTime string `json:"respond_time"`
  7342. Signtype string `json:"signtype"`
  7343. WarnMsg string `json:"warn_msg"`
  7344. }
  7345. type ResultFive struct {
  7346. Insutype string `json:"insutype"`
  7347. }
  7348. type ResultSix struct {
  7349. Cainfo interface{} `json:"cainfo"`
  7350. ErrMsg interface{} `json:"err_msg"`
  7351. InfRefmsgid string `json:"inf_refmsgid"`
  7352. Infcode int64 `json:"infcode"`
  7353. Output struct {
  7354. } `json:"output"`
  7355. RefmsgTime string `json:"refmsg_time"`
  7356. RespondTime string `json:"respond_time"`
  7357. Signtype interface{} `json:"signtype"`
  7358. WarnMsg interface{} `json:"warn_msg"`
  7359. }
  7360. type ResultSeven struct {
  7361. Cainfo string `json:"cainfo"`
  7362. ErrMsg string `json:"err_msg"`
  7363. InfRefmsgid string `json:"inf_refmsgid"`
  7364. Infcode int64 `json:"infcode"`
  7365. Output struct {
  7366. Setldetail []interface{} `json:"setldetail"`
  7367. Setlinfo struct {
  7368. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7369. AcctPay float64 `json:"acct_pay"`
  7370. ActPayDedc float64 `json:"act_pay_dedc"`
  7371. Age float64 `json:"age"`
  7372. Balc float64 `json:"balc"`
  7373. Brdy string `json:"brdy"`
  7374. Certno string `json:"certno"`
  7375. ClrOptins string `json:"clr_optins"`
  7376. ClrType string `json:"clr_type"`
  7377. ClrWay string `json:"clr_way"`
  7378. CvlservFlag string `json:"cvlserv_flag"`
  7379. CvlservPay float64 `json:"cvlserv_pay"`
  7380. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7381. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7382. Gend string `json:"gend"`
  7383. HifesPay float64 `json:"hifes_pay"`
  7384. HifmiPay float64 `json:"hifmi_pay"`
  7385. HifobPay float64 `json:"hifob_pay"`
  7386. HifpPay float64 `json:"hifp_pay"`
  7387. HospPartAmt float64 `json:"hosp_part_amt"`
  7388. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7389. Insutype string `json:"insutype"`
  7390. MafPay float64 `json:"maf_pay"`
  7391. MdtrtCertType string `json:"mdtrt_cert_type"`
  7392. MdtrtID string `json:"mdtrt_id"`
  7393. MedType string `json:"med_type"`
  7394. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7395. MedinsSetlID string `json:"medins_setl_id"`
  7396. Naty string `json:"naty"`
  7397. OthPay float64 `json:"oth_pay"`
  7398. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7399. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7400. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7401. PsnCashPay float64 `json:"psn_cash_pay"`
  7402. PsnCertType string `json:"psn_cert_type"`
  7403. PsnName string `json:"psn_name"`
  7404. PsnNo string `json:"psn_no"`
  7405. PsnPartAmt float64 `json:"psn_part_amt"`
  7406. PsnType string `json:"psn_type"`
  7407. SetlID string `json:"setl_id"`
  7408. SetlTime string `json:"setl_time"`
  7409. } `json:"setlinfo"`
  7410. } `json:"output"`
  7411. RefmsgTime string `json:"refmsg_time"`
  7412. RespondTime string `json:"respond_time"`
  7413. Signtype interface{} `json:"signtype"`
  7414. WarnMsg interface{} `json:"warn_msg"`
  7415. }
  7416. type ResultEight struct {
  7417. Cainfo string `json:"cainfo"`
  7418. ErrMsg string `json:"err_msg"`
  7419. InfRefmsgid string `json:"inf_refmsgid"`
  7420. Infcode int64 `json:"infcode"`
  7421. Output struct {
  7422. Stmtinfo struct {
  7423. SetlOptins string `json:"setl_optins"`
  7424. StmtRslt string `json:"stmt_rslt"`
  7425. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  7426. } `json:"stmtinfo"`
  7427. } `json:"output"`
  7428. RefmsgTime string `json:"refmsg_time"`
  7429. RespondTime string `json:"respond_time"`
  7430. Signtype interface{} `json:"signtype"`
  7431. WarnMsg interface{} `json:"warn_msg"`
  7432. }
  7433. type ResultNine struct {
  7434. Cainfo string `json:"cainfo"`
  7435. ErrMsg string `json:"err_msg"`
  7436. InfRefmsgid string `json:"inf_refmsgid"`
  7437. Infcode int64 `json:"infcode"`
  7438. Output struct {
  7439. FileQuryNo string `json:"file_qury_no"`
  7440. } `json:"output"`
  7441. RefmsgTime string `json:"refmsg_time"`
  7442. RespondTime string `json:"respond_time"`
  7443. Signtype interface{} `json:"signtype"`
  7444. WarnMsg interface{} `json:"warn_msg"`
  7445. }
  7446. type ResultTen struct {
  7447. Cainfo string `json:"cainfo"`
  7448. ErrMsg string `json:"err_msg"`
  7449. InfRefmsgid string `json:"inf_refmsgid"`
  7450. Infcode int64 `json:"infcode"`
  7451. Output struct {
  7452. DldEndtime string `json:"dld_endtime"`
  7453. FileQuryNo string `json:"file_qury_no"`
  7454. Filename string `json:"filename"`
  7455. } `json:"output"`
  7456. RefmsgTime string `json:"refmsg_time"`
  7457. RespondTime string `json:"respond_time"`
  7458. Signtype interface{} `json:"signtype"`
  7459. WarnMsg interface{} `json:"warn_msg"`
  7460. }
  7461. type ResultEleven struct {
  7462. Cainfo string `json:"cainfo"`
  7463. ErrMsg string `json:"err_msg"`
  7464. InfRefmsgid string `json:"inf_refmsgid"`
  7465. Infcode int64 `json:"infcode"`
  7466. Output struct {
  7467. Setlinfo struct {
  7468. FixmedinsName string `json:"fixmedins_name"`
  7469. FixmedinsCode string `json:"fixmedins_code"`
  7470. PsnNo string `json:"psn_no"`
  7471. PsnName string `json:"psn_name"`
  7472. HifobPay float64 `json:"hifob_pay"`
  7473. Gend string `json:"gend"`
  7474. Brdy string `json:"brdy"`
  7475. PsnCertType string `json:"psn_cert_type"`
  7476. PsnType string `json:"psn_type"`
  7477. EmpName string `json:"emp_name"`
  7478. Certno string `json:"certno"`
  7479. Insutype string `json:"insutype"`
  7480. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7481. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7482. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7483. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7484. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7485. ActPayDedc float64 `json:"act_pay_dedc"`
  7486. HifpPay float64 `json:"hifp_pay"`
  7487. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7488. CvlservPay float64 `json:"cvlserv_pay"`
  7489. HifesPay float64 `json:"hifes_pay"`
  7490. HifmiPay float64 `json:"hifmi_pay"`
  7491. MafPay float64 `json:"maf_pay"`
  7492. OthPay float64 `json:"oth_pay"`
  7493. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7494. PsnPay float64 `json:"psn_pay"`
  7495. AcctPay float64 `json:"acct_pay"`
  7496. CashPayamt float64 `json:"cash_payamt"`
  7497. Balc float64 `json:"balc"`
  7498. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7499. MedinsSetlId string `json:"medins_setl_id"`
  7500. RefdSetlFlag string `json:"refd_setl_flag"`
  7501. SetlTime string `json:"setl_time"`
  7502. MedType string `json:"med_type"`
  7503. } `json:"setlinfo"`
  7504. } `json:"output"`
  7505. RefmsgTime string `json:"refmsg_time"`
  7506. RespondTime string `json:"respond_time"`
  7507. Signtype interface{} `json:"signtype"`
  7508. WarnMsg interface{} `json:"warn_msg"`
  7509. }
  7510. type Custom struct {
  7511. DetItemFeeSumamt string
  7512. Cut string
  7513. FeedetlSn string
  7514. Price string
  7515. MedListCodg string
  7516. Type int64
  7517. AdviceId int64
  7518. ProjectId int64
  7519. ItemId int64
  7520. }
  7521. // 获取个人信息----挂号-----上传就诊信息
  7522. func (c *HisApiController) GetRegisterInfo() {
  7523. id, _ := c.GetInt64("id")
  7524. record_time := c.GetString("record_time")
  7525. settlementValue, _ := c.GetInt64("settlement_value")
  7526. medical_insurance_card := c.GetString("medical_insurance_card")
  7527. name := c.GetString("name")
  7528. id_card_type, _ := c.GetInt64("id_card_type")
  7529. certificates, _ := c.GetInt64("certificates")
  7530. medical_care, _ := c.GetInt64("medical_care")
  7531. birthday := c.GetString("birthday")
  7532. age, _ := c.GetInt64("age")
  7533. id_card := c.GetString("id_card")
  7534. register_type, _ := c.GetInt64("register")
  7535. doctor, _ := c.GetInt64("doctor")
  7536. department, _ := c.GetInt64("department")
  7537. gender, _ := c.GetInt64("sex")
  7538. phone := c.GetString("phone")
  7539. registration_fee, _ := c.GetFloat("registration_fee")
  7540. medical_expenses, _ := c.GetFloat("medical_expenses")
  7541. social_type, _ := c.GetInt64("social_type")
  7542. //diagnosis_id, _ := c.GetInt64("diagnosis")
  7543. diagnosis_ids := c.GetString("diagnosis")
  7544. sick_type, _ := c.GetInt64("sick_type")
  7545. reg_type := c.GetString("p_type")
  7546. timeLayout := "2006-01-02"
  7547. loc, _ := time.LoadLocation("Local")
  7548. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  7549. birthUnix := birthdays.Unix()
  7550. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7551. if err != nil {
  7552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7553. return
  7554. }
  7555. recordDateTime := theTime.Unix()
  7556. adminInfo := c.GetAdminUserInfo()
  7557. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  7558. if tempPatient.ID == 0 {
  7559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  7560. return
  7561. }
  7562. var patient service.Patients
  7563. if id == 0 {
  7564. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  7565. } else {
  7566. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  7567. }
  7568. if patient.ID == 0 {
  7569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7570. return
  7571. }
  7572. if len(patient.IdCardNo) == 0 {
  7573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  7574. return
  7575. }
  7576. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7577. if len(his) >= 1 {
  7578. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  7579. if len(his) >= 1 && order.ID == 0 {
  7580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  7581. return
  7582. }
  7583. }
  7584. timeStr := time.Now().Format("2006-01-02 15:04:05")
  7585. fmt.Println(timeStr)
  7586. timeArr := strings.Split(timeStr, " ")
  7587. fmt.Println(timeArr)
  7588. timeArrTwo := strings.Split(timeArr[0], "-")
  7589. timeArrThree := strings.Split(timeArr[1], ":")
  7590. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  7591. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7592. if len(lists) == 0 {
  7593. var hisPatient models.XtHisPatient
  7594. hisPatient = models.XtHisPatient{
  7595. Name: name,
  7596. Age: age,
  7597. Gender: gender,
  7598. Birthday: birthUnix,
  7599. Phone: phone,
  7600. MedicalTreatmentType: medical_care,
  7601. IdType: certificates,
  7602. IdCardNo: id_card,
  7603. BalanceAccountsType: settlementValue,
  7604. SocialType: social_type,
  7605. MedicalInsuranceNumber: medical_insurance_card,
  7606. RegisterType: register_type,
  7607. RegisterCost: registration_fee,
  7608. TreatmentCost: medical_expenses,
  7609. AdminUserId: adminInfo.AdminUser.Id,
  7610. UserOrgId: adminInfo.CurrentOrgId,
  7611. Status: 1,
  7612. RecordDate: recordDateTime,
  7613. IsReturn: 1,
  7614. PatientId: patient.ID,
  7615. Ctime: time.Now().Unix(),
  7616. Mtime: time.Now().Unix(),
  7617. Number: str,
  7618. IdCardType: id_card_type,
  7619. Departments: department,
  7620. Doctor: doctor,
  7621. PType: reg_type,
  7622. Diagnosis: diagnosis_ids,
  7623. SickType: sick_type,
  7624. }
  7625. service.CreateHisPatient(&hisPatient)
  7626. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7627. c.ServeSuccessJSON(map[string]interface{}{
  7628. "his_info": hisPatient,
  7629. })
  7630. } else {
  7631. //chrgBchno := rand.Intn(1000000) + 10000
  7632. var hisPatient models.XtHisPatient
  7633. hisPatient = models.XtHisPatient{
  7634. Name: name,
  7635. Age: age,
  7636. Gender: gender,
  7637. Birthday: birthUnix,
  7638. Phone: phone,
  7639. MedicalTreatmentType: medical_care,
  7640. IdType: certificates,
  7641. IdCardNo: id_card,
  7642. BalanceAccountsType: settlementValue,
  7643. SocialType: social_type,
  7644. MedicalInsuranceNumber: medical_insurance_card,
  7645. RegisterType: register_type,
  7646. RegisterCost: registration_fee,
  7647. TreatmentCost: medical_expenses,
  7648. AdminUserId: adminInfo.AdminUser.Id,
  7649. UserOrgId: adminInfo.CurrentOrgId,
  7650. Status: 1,
  7651. RecordDate: recordDateTime,
  7652. IsReturn: 1,
  7653. PatientId: patient.ID,
  7654. Ctime: time.Now().Unix(),
  7655. Mtime: time.Now().Unix(),
  7656. Number: str,
  7657. IdCardType: id_card_type,
  7658. Departments: department,
  7659. Doctor: doctor,
  7660. PType: reg_type,
  7661. Diagnosis: diagnosis_ids,
  7662. SickType: sick_type,
  7663. }
  7664. service.CreateHisPatient(&hisPatient)
  7665. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7666. c.ServeSuccessJSON(map[string]interface{}{
  7667. "his_info": hisPatient,
  7668. })
  7669. }
  7670. }
  7671. // 上传明细----结算
  7672. func (c *HisApiController) GetUploadInfo() {
  7673. id, _ := c.GetInt64("id")
  7674. record_time := c.GetString("record_time")
  7675. his_patient_id, _ := c.GetInt64("his_patient_id")
  7676. oth_desc := c.GetString("oth_desc")
  7677. pay_way, _ := c.GetInt64("pay_way")
  7678. pay_ways := c.GetString("pay_ways")
  7679. pay_price, _ := c.GetFloat("pay_price")
  7680. pay_card_no := c.GetString("pay_card_no")
  7681. discount_price, _ := c.GetFloat("discount_price")
  7682. preferential_price, _ := c.GetFloat("preferential_price")
  7683. reality_price, _ := c.GetFloat("reality_price")
  7684. found_price, _ := c.GetFloat("found_price")
  7685. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7686. private_price, _ := c.GetFloat("private_price")
  7687. timeLayout := "2006-01-02"
  7688. loc, _ := time.LoadLocation("Local")
  7689. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7690. fapiao_code := c.GetString("fapiao_code")
  7691. fapiao_number := c.GetString("fapiao_number")
  7692. diagnosis_id := c.GetString("diagnosis")
  7693. sick_type, _ := c.GetInt64("sick_type")
  7694. reg_type, _ := c.GetInt64("p_type")
  7695. order_id, _ := c.GetInt64("order_id")
  7696. cash_pay := c.GetString("cash_pay")
  7697. wechat_pay := c.GetString("wechat_pay")
  7698. ali_pay := c.GetString("ali_pay")
  7699. jifen_pay := c.GetString("jifen_pay")
  7700. band_card_pay := c.GetString("band_card_pay")
  7701. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7702. tmp_decimal := c.GetString("tmp_decimal")
  7703. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7704. var decimal float64 //本次使用的押金
  7705. var errmsg error
  7706. tx := service.XTWriteDB().Begin() //开了事务
  7707. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7708. defer func() {
  7709. if errmsg != nil {
  7710. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7711. tx.Rollback()
  7712. } else {
  7713. tx.Commit()
  7714. }
  7715. }()
  7716. fmt.Println("dec_way", dec_way)
  7717. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7718. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7719. return
  7720. }
  7721. if len(tmp_decimal) > 0 {
  7722. if tmp_decimal[0] == 45 {
  7723. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7724. return
  7725. }
  7726. }
  7727. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7728. fmt.Println(errs)
  7729. decimal = tt
  7730. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7731. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7732. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7733. if err != nil {
  7734. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7735. return
  7736. }
  7737. recordDateTime := theTime.Unix()
  7738. adminUser := c.GetAdminUserInfo()
  7739. var prescriptions []*models.HisPrescription
  7740. var prescriptionsOne []*models.HisPrescription
  7741. var start_time int64
  7742. var end_time int64
  7743. ids_str := c.GetString("ids")
  7744. ids_arr := strings.Split(ids_str, ",")
  7745. if tempOrder.ID == 0 {
  7746. if settle_accounts_type == 1 { //日结
  7747. fmt.Println(reg_type)
  7748. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7749. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7750. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7751. } else {
  7752. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7753. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7754. }
  7755. } else { //月结
  7756. start_time_str := c.GetString("start_time")
  7757. end_time_str := c.GetString("end_time")
  7758. timeLayout := "2006-01-02"
  7759. loc, _ := time.LoadLocation("Local")
  7760. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7761. if err != nil {
  7762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7763. return
  7764. }
  7765. recordStartTime := theStartTime.Unix()
  7766. start_time = recordStartTime
  7767. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7768. if err != nil {
  7769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7770. return
  7771. }
  7772. recordEndTime := theEndTime.Unix()
  7773. end_time = recordEndTime
  7774. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7775. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7776. }
  7777. var goods []*models.DialysisBeforePrepareGoods
  7778. var newGoods []*models.NewDialysisBeforePrepareGoods
  7779. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7780. var infos []*models.HisDoctorAdviceInfo
  7781. var infoList []*models.HisDoctorAdviceInfo
  7782. var hisAdvice []*models.HisDoctorAdviceInfo
  7783. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7784. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7785. //判断库存不足
  7786. //结算出库开关
  7787. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7788. if settConfig.IsOpen == 1 {
  7789. //判断库存的地方
  7790. for _, info := range prescriptions {
  7791. if info.Type == 1 {
  7792. infos = append(infos, info.HisDoctorAdviceInfo...)
  7793. }
  7794. if info.Type == 2 {
  7795. for _, sumItem := range info.HisPrescriptionProject {
  7796. if sumItem.Type == 3 {
  7797. var good models.DialysisBeforePrepareGoods
  7798. var newGood models.NewDialysisBeforePrepareGoods
  7799. good.GoodId = sumItem.GoodInfo.ID
  7800. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7801. count, _ := strconv.Atoi(sumItem.Count)
  7802. good.Count = int64(count)
  7803. good.StorehouseId = houseConfig.StorehouseOutInfo
  7804. good.ProjectId = sumItem.ID
  7805. goods = append(goods, &good)
  7806. newGood.GoodId = sumItem.GoodInfo.ID
  7807. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7808. count2, _ := strconv.Atoi(sumItem.Count)
  7809. newGood.Count = int64(count2)
  7810. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7811. newGood.ProjectId = sumItem.ID
  7812. newGoods = append(newGoods, &newGood)
  7813. }
  7814. }
  7815. }
  7816. }
  7817. for _, info := range prescriptionsOne {
  7818. if info.Type == 1 {
  7819. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7820. }
  7821. if info.Type == 2 {
  7822. for _, sumItem := range info.HisPrescriptionProject {
  7823. if sumItem.Type == 3 {
  7824. var newGood models.NewDialysisBeforePrepareGoods
  7825. newGood.GoodId = sumItem.GoodInfo.ID
  7826. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7827. count2, _ := strconv.Atoi(sumItem.Count)
  7828. newGood.Count = int64(count2)
  7829. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7830. newGood.ProjectId = sumItem.ID
  7831. newGoodOne = append(newGoodOne, &newGood)
  7832. }
  7833. }
  7834. }
  7835. }
  7836. //判断
  7837. for _, itemOne := range infos {
  7838. for _, itemTwo := range hisAdvice {
  7839. if itemOne.DrugId == itemTwo.DrugId {
  7840. itemTwo.Child = append(itemTwo.Child, itemOne)
  7841. }
  7842. }
  7843. }
  7844. for _, itemTwo := range hisAdvice {
  7845. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7846. var sum_out_count int64
  7847. for _, itemThree := range itemTwo.Child {
  7848. var prescribing_number int64
  7849. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7850. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7851. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7852. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7853. }
  7854. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7855. prescribing_number = parseIntPrescribingNumber
  7856. }
  7857. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7858. prescribing_number = parseIntPrescribingNumber
  7859. }
  7860. sum_out_count += prescribing_number
  7861. }
  7862. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  7863. if sum_out_count > drugStockOut.FlushCount {
  7864. c.ServeSuccessJSON(map[string]interface{}{
  7865. "msg": "2",
  7866. "drug": medical,
  7867. })
  7868. return
  7869. }
  7870. }
  7871. for _, itemOne := range newGoods {
  7872. for _, item := range newGoodOne {
  7873. if itemOne.GoodId == item.GoodId {
  7874. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  7875. }
  7876. }
  7877. }
  7878. for _, item := range newGoodOne {
  7879. var sum_out_count_one int64
  7880. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  7881. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  7882. sum_out_count_one += itemOne.Count
  7883. }
  7884. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7885. fmt.Println("sum_out_count_one", sum_out_count_one)
  7886. fmt.Println("list.FlushCount", list.FlushCount)
  7887. if sum_out_count_one > list.FlushCount {
  7888. c.ServeSuccessJSON(map[string]interface{}{
  7889. "msg": "3",
  7890. "good": good,
  7891. })
  7892. return
  7893. }
  7894. }
  7895. }
  7896. timestamp := time.Now().Unix()
  7897. tempTime := time.Unix(timestamp, 0)
  7898. timeFormat := tempTime.Format("20060102150405")
  7899. chrgBchno := rand.Intn(100000) + 10000
  7900. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7901. strconv.FormatInt(his.PatientId, 10)
  7902. var ids []int64
  7903. for _, item := range prescriptions {
  7904. ids = append(ids, item.ID)
  7905. }
  7906. var total float64
  7907. for _, item := range prescriptions {
  7908. fmt.Println(item)
  7909. if item.Type == 1 { //药品
  7910. for _, subItem := range item.HisDoctorAdviceInfo {
  7911. total = total + (subItem.Price * subItem.PrescribingNumber)
  7912. }
  7913. }
  7914. if item.Type == 2 { //项目
  7915. for _, subItem := range item.HisPrescriptionProject {
  7916. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7917. total = total + (subItem.Price * cnt)
  7918. }
  7919. }
  7920. for _, subItem := range item.HisAdditionalCharge {
  7921. total = total + (subItem.Price * float64(subItem.Count))
  7922. }
  7923. }
  7924. if reg_type == 1111 || reg_type == 1112 {
  7925. reg_type = 11
  7926. }
  7927. tm := time.Unix(time.Now().Unix(), 0)
  7928. allTotal := fmt.Sprintf("%.4f", total)
  7929. totals, _ := strconv.ParseFloat(allTotal, 64)
  7930. order := &models.HisOrder{
  7931. UserOrgId: adminUser.CurrentOrgId,
  7932. HisPatientId: his.ID,
  7933. PatientId: id,
  7934. SettleAccountsDate: recordDateTime,
  7935. Ctime: time.Now().Unix(),
  7936. Mtime: time.Now().Unix(),
  7937. Status: 1,
  7938. OrderStatus: 2,
  7939. MdtrtId: his.Number,
  7940. Number: chrg_bchno,
  7941. MedfeeSumamt: totals,
  7942. PayWay: pay_way,
  7943. PayWays: pay_ways,
  7944. PayPrice: pay_price,
  7945. MedType: strconv.Itoa(int(reg_type)),
  7946. PayCardNo: pay_card_no,
  7947. DiscountPrice: discount_price,
  7948. PreferentialPrice: preferential_price,
  7949. RealityPrice: reality_price,
  7950. FoundPrice: found_price,
  7951. MedicalInsurancePrice: medical_insurance_price,
  7952. PrivatePrice: private_price,
  7953. SettleEndTime: end_time,
  7954. SettleStartTime: start_time,
  7955. PsnPartAmt: totals,
  7956. PsnCashPay: totals,
  7957. SettleType: settle_accounts_type,
  7958. FaPiaoCode: fapiao_code,
  7959. FaPiaoNumber: fapiao_number,
  7960. Diagnosis: diagnosis_id,
  7961. PType: 2,
  7962. SetlTime: tm.Format("2006-01-02 15:04:05"),
  7963. Decimal: decimal,
  7964. OthDesc: oth_desc,
  7965. CashPay: cash_pay,
  7966. WechatPay: wechat_pay,
  7967. AliPay: ali_pay,
  7968. JifenPay: jifen_pay,
  7969. BandCardPay: band_card_pay,
  7970. Creator: adminUser.AdminUser.Id,
  7971. }
  7972. err = service.CreateOrderTX(order, tx)
  7973. if err != nil {
  7974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7975. return
  7976. }
  7977. var customs []*Custom
  7978. for _, item := range prescriptions {
  7979. if item.Type == 1 { //药品a
  7980. for _, subItem := range item.HisDoctorAdviceInfo {
  7981. cus := &Custom{
  7982. AdviceId: subItem.ID,
  7983. ProjectId: 0,
  7984. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  7985. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  7986. FeedetlSn: subItem.FeedetlSn,
  7987. Price: fmt.Sprintf("%.4f", subItem.Price),
  7988. MedListCodg: subItem.MedListCodg,
  7989. Type: 1,
  7990. }
  7991. customs = append(customs, cus)
  7992. }
  7993. }
  7994. if item.Type == 2 { //项目
  7995. for _, subItem := range item.HisPrescriptionProject {
  7996. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7997. cus := &Custom{
  7998. AdviceId: 0,
  7999. ProjectId: subItem.ID,
  8000. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  8001. Cut: fmt.Sprintf("%.4f", cnt),
  8002. FeedetlSn: subItem.FeedetlSn,
  8003. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  8004. MedListCodg: subItem.MedListCodg,
  8005. Type: 2,
  8006. }
  8007. customs = append(customs, cus)
  8008. }
  8009. }
  8010. for _, item := range item.HisAdditionalCharge {
  8011. cus := &Custom{
  8012. ItemId: item.ID,
  8013. AdviceId: 0,
  8014. ProjectId: 0,
  8015. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  8016. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  8017. FeedetlSn: item.FeedetlSn,
  8018. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  8019. MedListCodg: item.XtHisAddtionConfig.Code,
  8020. Type: 3,
  8021. }
  8022. customs = append(customs, cus)
  8023. }
  8024. }
  8025. for _, item := range customs {
  8026. var advice_id int64 = 0
  8027. var project_id int64 = 0
  8028. var item_id int64 = 0
  8029. var types int64 = 0
  8030. if item.Type == 1 {
  8031. advice_id = item.AdviceId
  8032. project_id = 0
  8033. item_id = 0
  8034. } else if item.Type == 2 {
  8035. advice_id = 0
  8036. item_id = 0
  8037. project_id = item.ProjectId
  8038. } else if item.Type == 3 {
  8039. advice_id = 0
  8040. item_id = item.ItemId
  8041. project_id = 0
  8042. }
  8043. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8044. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8045. pric, _ := strconv.ParseFloat(item.Price, 32)
  8046. info := &models.HisOrderInfo{
  8047. OrderNumber: order.Number,
  8048. UploadDate: time.Now().Unix(),
  8049. AdviceId: advice_id,
  8050. DetItemFeeSumamt: detItemFeeSumamt,
  8051. Cnt: cut,
  8052. Pric: pric,
  8053. PatientId: id,
  8054. Status: 1,
  8055. Mtime: time.Now().Unix(),
  8056. Ctime: time.Now().Unix(),
  8057. UserOrgId: adminUser.CurrentOrgId,
  8058. HisPatientId: his.ID,
  8059. OrderId: order.ID,
  8060. ProjectId: project_id,
  8061. Type: types,
  8062. ItemId: item_id,
  8063. }
  8064. service.CreateOrderInfoTX(info, tx)
  8065. }
  8066. his.Diagnosis = diagnosis_id
  8067. his.SickType = sick_type
  8068. his.RegisterType = reg_type
  8069. his.MedicalTreatmentType = reg_type
  8070. service.UpdataHisPateintTX(&his, tx)
  8071. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8072. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8073. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8074. //判断是否使用了押金
  8075. if dec_way == "true" {
  8076. tmpstring := strconv.FormatInt(order.ID, 10)
  8077. //扣押金
  8078. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8079. order.Decimal = decimal
  8080. service.UpDateOrderTwo(order, tx)
  8081. if errmsg != nil {
  8082. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8083. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8084. return
  8085. }
  8086. }
  8087. if err == nil {
  8088. for _, info := range prescriptions {
  8089. if info.Type == 1 {
  8090. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8091. }
  8092. if info.Type == 2 {
  8093. for _, sumItem := range info.HisPrescriptionProject {
  8094. if sumItem.Type == 3 {
  8095. var good models.DialysisBeforePrepareGoods
  8096. var newGood models.NewDialysisBeforePrepareGoods
  8097. var oldGood models.OldDialysisBeforePrepareGoods
  8098. good.GoodId = sumItem.GoodInfo.ID
  8099. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8100. count, _ := strconv.Atoi(sumItem.Count)
  8101. good.Count = int64(count)
  8102. good.StorehouseId = houseConfig.StorehouseOutInfo
  8103. good.ProjectId = sumItem.ID
  8104. good.PatientId = sumItem.PatientId
  8105. goods = append(goods, &good)
  8106. newGood.GoodId = sumItem.GoodInfo.ID
  8107. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8108. count2, _ := strconv.Atoi(sumItem.Count)
  8109. newGood.Count = int64(count2)
  8110. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8111. newGood.ProjectId = sumItem.ID
  8112. newGood.PatientId = sumItem.HisPatientId
  8113. newGoods = append(newGoods, &newGood)
  8114. oldGood.GoodId = sumItem.GoodInfo.ID
  8115. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8116. count3, _ := strconv.Atoi(sumItem.Count)
  8117. oldGood.Count = int64(count3)
  8118. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8119. oldGood.ProjectId = sumItem.ID
  8120. oldGood.RecordDate = sumItem.RecordDate
  8121. oldGood.PatientId = sumItem.HisPatientId
  8122. oldGoods = append(oldGoods, &oldGood)
  8123. }
  8124. }
  8125. }
  8126. }
  8127. if settConfig.IsOpen == 1 {
  8128. for _, item := range infoList {
  8129. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8130. if medical.IsUse == 2 {
  8131. //药品出库
  8132. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8133. //查询默认仓库
  8134. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8135. //查询默认仓库剩余多少库存
  8136. var sum_count int64
  8137. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8138. for _, its := range stockInfo {
  8139. if its.MaxUnit == medical.MaxUnit {
  8140. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8141. }
  8142. sum_count += its.StockMaxNumber + its.StockMinNumber
  8143. }
  8144. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8145. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8146. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8147. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8148. }
  8149. }
  8150. orgId := c.GetAdminUserInfo().CurrentOrgId
  8151. if len(oldGoods) > 0 {
  8152. timeStr := time.Now().Format("2006-01-02")
  8153. timeArr := strings.Split(timeStr, "-")
  8154. total, _ := service.FindAllWarehouseOut(orgId)
  8155. total = total + 1
  8156. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8157. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8158. number = number + total
  8159. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8160. operation_time := time.Now().Unix()
  8161. creater := c.GetAdminUserInfo().AdminUser.Id
  8162. //查询默认出库仓库库存
  8163. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8164. recordDateStr := time.Now().Format("2006-01-02")
  8165. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8166. nowtime := recordDate.Unix()
  8167. warehouseOut := models.WarehouseOut{
  8168. WarehouseOutOrderNumber: warehousing_out_order,
  8169. OperationTime: operation_time,
  8170. OrgId: orgId,
  8171. Creater: creater,
  8172. Ctime: time.Now().Unix(),
  8173. Status: 1,
  8174. WarehouseOutTime: nowtime,
  8175. Type: 1,
  8176. StorehouseId: storeConfig.StorehouseOutInfo,
  8177. IsCheck: 1,
  8178. OrderId: order.ID,
  8179. IsSys: 5,
  8180. }
  8181. //查询是否生成出库单
  8182. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8183. if out.ID == 0 {
  8184. service.AddSigleWarehouseOut(&warehouseOut)
  8185. }
  8186. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8187. for _, item := range oldGoods {
  8188. dialyPrepareOne := models.DialysisBeforePrepare{
  8189. GoodTypeId: item.GoodTypeId,
  8190. GoodId: item.GoodId,
  8191. PatientId: his.PatientId,
  8192. RecordDate: item.RecordDate,
  8193. UserOrgId: adminUser.CurrentOrgId,
  8194. Count: item.Count,
  8195. Ctime: time.Now().Unix(),
  8196. Creater: adminUser.AdminUser.Id,
  8197. CommdityCode: item.CommdityCode,
  8198. Status: 1,
  8199. StorehouseId: houseConfig.StorehouseOutInfo,
  8200. }
  8201. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8202. //非零用
  8203. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8204. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8205. //查询剩余库存
  8206. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8207. var sum_count int64
  8208. for _, item := range goodList {
  8209. sum_count += item.StockCount
  8210. }
  8211. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8212. //耗材
  8213. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8214. }
  8215. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8216. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8217. //查询剩余库存
  8218. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8219. var sum_count int64
  8220. for _, item := range goodList {
  8221. sum_count += item.StockCount
  8222. }
  8223. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8224. //耗材
  8225. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8226. }
  8227. }
  8228. }
  8229. }
  8230. c.ServeSuccessJSON(map[string]interface{}{
  8231. "msg": "结算成功",
  8232. })
  8233. }
  8234. }
  8235. }
  8236. // 退款
  8237. func (c *HisApiController) Refund() {
  8238. order_id, _ := c.GetInt64("order_id")
  8239. order, _ := service.GetHisOrderByID(order_id)
  8240. adminUser := c.GetAdminUserInfo()
  8241. orgid := c.GetAdminUserInfo().CurrentOrgId
  8242. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8243. if err != nil {
  8244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8245. return
  8246. }
  8247. tmp := strconv.FormatInt(order.ID, 10)
  8248. //当押金不为零时产生退费记录
  8249. if order.Decimal != 0 {
  8250. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8251. if err != nil {
  8252. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8253. return
  8254. }
  8255. }
  8256. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8257. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8258. var goods []*models.DialysisBeforePrepareGoods
  8259. var newGoods []*models.NewDialysisBeforePrepareGoods
  8260. var infos []*models.HisDoctorAdviceInfo
  8261. for _, info := range orders {
  8262. if info.AdviceId > 0 && info.ProjectId == 0 {
  8263. infos = append(infos, &info.HisDoctorAdviceInfo)
  8264. }
  8265. if info.ProjectId > 0 && info.AdviceId == 0 {
  8266. if info.HisPrescriptionProject.Type == 3 {
  8267. var good models.DialysisBeforePrepareGoods
  8268. var newGood models.NewDialysisBeforePrepareGoods
  8269. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8270. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8271. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8272. good.Count = int64(count)
  8273. good.StorehouseId = houseConfig.StorehouseOutInfo
  8274. good.ProjectId = info.HisPrescriptionProject.ID
  8275. good.PatientId = info.PatientId
  8276. good.OrderId = order_id
  8277. goods = append(goods, &good)
  8278. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8279. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8280. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8281. newGood.Count = int64(count2)
  8282. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8283. newGood.ProjectId = info.HisPrescriptionProject.ID
  8284. newGood.RecordDate = order.SettleAccountsDate
  8285. newGood.UserOrgId = order.UserOrgId
  8286. newGood.PatientId = info.PatientId
  8287. newGood.OrderId = order_id
  8288. newGoods = append(newGoods, &newGood)
  8289. }
  8290. }
  8291. }
  8292. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8293. if settConfig.IsOpen == 1 {
  8294. for _, item := range infos {
  8295. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8296. }
  8297. for _, item := range newGoods {
  8298. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8299. }
  8300. }
  8301. c.ServeSuccessJSON(map[string]interface{}{
  8302. "msg": "退费成功",
  8303. })
  8304. }
  8305. func (c *HisApiController) RefundNumber() {
  8306. his_patient_id, _ := c.GetInt64("id")
  8307. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8308. info.Status = 0
  8309. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  8310. if count > 0 {
  8311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  8312. return
  8313. }
  8314. err := service.SaveHisPatient(info)
  8315. if err == nil {
  8316. c.ServeSuccessJSON(map[string]interface{}{
  8317. "msg": "退号成功",
  8318. })
  8319. } else {
  8320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8321. return
  8322. }
  8323. }
  8324. func (this *HisApiController) AdditionalCharge() {
  8325. dataBody := make(map[string]interface{}, 0)
  8326. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8327. fmt.Println(err)
  8328. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  8329. patient_id := int64(dataBody["patient_id"].(float64))
  8330. medicineData, _ := dataBody["medicineData"].([]interface{})
  8331. adminUserInfo := this.GetAdminUserInfo()
  8332. orgId := adminUserInfo.CurrentOrgId
  8333. admin_user_id := adminUserInfo.AdminUser.Id
  8334. timeStr := time.Now().Format("2006-01-02")
  8335. timeLayout := "2006-01-02 15:04:05"
  8336. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8337. timenow := timeStringToTime.Unix()
  8338. var additionalCharges []*models.HisAdditionalCharge
  8339. for _, item := range medicineData {
  8340. var randNum int
  8341. randNum = rand.Intn(10000) + 1000
  8342. timestamp := time.Now().Unix()
  8343. tempTime := time.Unix(timestamp, 0)
  8344. timeFormat := tempTime.Format("20060102150405")
  8345. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  8346. items := item.(map[string]interface{})
  8347. money := items["price"].(string)
  8348. item_id_str := items["item_id"].(string)
  8349. name := items["name"].(string)
  8350. id_str := items["id"].(string)
  8351. moneys, _ := strconv.ParseInt(money, 10, 64)
  8352. monStr := strconv.FormatInt(moneys, 10)
  8353. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  8354. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  8355. id, _ := strconv.ParseInt(id_str, 10, 64)
  8356. additionalCharge := &models.HisAdditionalCharge{
  8357. ID: id,
  8358. HisPatientId: his_patient_id,
  8359. UserOrgId: orgId,
  8360. PatientId: patient_id,
  8361. RecordDate: timenow,
  8362. Price: monneyStr,
  8363. Status: 1,
  8364. ItemName: name,
  8365. ItemId: item_id,
  8366. AdminUserId: admin_user_id,
  8367. CreatedTime: time.Now().Unix(),
  8368. OrderStatus: 0,
  8369. PrescriptionNumber: "",
  8370. BatchNumber: "",
  8371. FeedetlSn: p_number,
  8372. }
  8373. service.CreateAdditionalCharge(additionalCharge)
  8374. additionalCharges = append(additionalCharges, additionalCharge)
  8375. }
  8376. this.ServeSuccessJSON(map[string]interface{}{
  8377. "msg": "添加成功",
  8378. "additional_charges": additionalCharges,
  8379. })
  8380. }
  8381. func (this *HisApiController) DeleteAddition() {
  8382. id, _ := this.GetInt64("id")
  8383. //TODO 需要判断是否已经结算
  8384. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  8385. if err == nil {
  8386. this.ServeSuccessJSON(map[string]interface{}{
  8387. "msg": "删除成功",
  8388. })
  8389. return
  8390. } else {
  8391. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8392. return
  8393. }
  8394. }
  8395. func (this *HisApiController) GetAdminUsers() {
  8396. adminUser := this.GetAdminUserInfo()
  8397. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  8398. this.ServeSuccessJSON(map[string]interface{}{
  8399. "doctors": doctors,
  8400. })
  8401. }
  8402. func (this *HisApiController) GetLastOrNextHisPrescription() {
  8403. change_type, _ := this.GetInt64("type", 0)
  8404. record_date := this.GetString("record_time")
  8405. patient_id, _ := this.GetInt64("patient_id", 0)
  8406. p_type, _ := this.GetInt64("p_type", 0)
  8407. timeLayout := "2006-01-02"
  8408. loc, _ := time.LoadLocation("Local")
  8409. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8410. record_time := theAdviceRecordTime.Unix()
  8411. adminUserInfo := this.GetAdminUserInfo()
  8412. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  8413. if err == nil {
  8414. if len(prescriptions) == 0 {
  8415. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  8416. return
  8417. } else {
  8418. this.ServeSuccessJSON(map[string]interface{}{
  8419. "prescriptions": prescriptions,
  8420. })
  8421. return
  8422. }
  8423. } else {
  8424. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8425. return
  8426. }
  8427. }
  8428. func (this *HisApiController) GetCallHisPrescription() {
  8429. patient_id, _ := this.GetInt64("patient_id", 0)
  8430. timeLayout := "2006-01-02"
  8431. loc, _ := time.LoadLocation("Local")
  8432. start_time := this.GetString("start_time")
  8433. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8434. end_time := this.GetString("end_time")
  8435. p_type, _ := this.GetInt64("p_type")
  8436. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8437. adminUserInfo := this.GetAdminUserInfo()
  8438. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  8439. if err == nil {
  8440. this.ServeSuccessJSON(map[string]interface{}{
  8441. "prescriptions": prescriptions,
  8442. })
  8443. return
  8444. } else {
  8445. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8446. return
  8447. }
  8448. }
  8449. func (this *HisApiController) GetHisDayPrescription() {
  8450. timeLayout := "2006-01-02"
  8451. loc, _ := time.LoadLocation("Local")
  8452. start_time := this.GetString("start_time")
  8453. patient_id, _ := this.GetInt64("patient_id", 0)
  8454. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8455. end_time := this.GetString("end_time")
  8456. p_type, _ := this.GetInt64("p_type")
  8457. order_status, _ := this.GetInt64("type")
  8458. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8459. adminUserInfo := this.GetAdminUserInfo()
  8460. var dayHisPrescription []*models.HisPrescription
  8461. var err error
  8462. if order_status == 1 || order_status == 0 {
  8463. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8464. } else if order_status == 2 {
  8465. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8466. }
  8467. var settle_total float64
  8468. for _, item := range dayHisPrescription {
  8469. if len(item.HisPrescriptionProject) > 0 {
  8470. for _, subItem := range item.HisPrescriptionProject {
  8471. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8472. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8473. settle_total = settle_total + total
  8474. }
  8475. }
  8476. if len(item.HisDoctorAdviceInfo) > 0 {
  8477. for _, subItem := range item.HisDoctorAdviceInfo {
  8478. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8479. settle_total = settle_total + total
  8480. }
  8481. }
  8482. }
  8483. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8484. if err == nil {
  8485. this.ServeSuccessJSON(map[string]interface{}{
  8486. "day_prescription": dayHisPrescription,
  8487. "settle_total": settle_total,
  8488. })
  8489. return
  8490. } else {
  8491. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8492. return
  8493. }
  8494. }
  8495. func (c *HisApiController) GetHisChargePatientList() {
  8496. record_date := c.GetString("record_date")
  8497. order_status, _ := c.GetInt64("type")
  8498. sch_type, _ := c.GetInt64("sch_type")
  8499. timeLayout := "2006-01-02"
  8500. loc, _ := time.LoadLocation("Local")
  8501. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8502. if err != nil {
  8503. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8504. return
  8505. }
  8506. recordDateTime := theTime.Unix()
  8507. adminInfo := c.GetAdminUserInfo()
  8508. var tempPatients []*service.NewTempPatients
  8509. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  8510. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  8511. if order_status != 2 {
  8512. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8513. } else {
  8514. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8515. }
  8516. } else {
  8517. if order_status != 2 {
  8518. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8519. } else {
  8520. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8521. }
  8522. }
  8523. var patients []*service.NewTempPatients
  8524. var patients_two []*service.NewTempPatients
  8525. for _, item := range tempPatients {
  8526. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  8527. //过滤掉没挂号的和没开处方的
  8528. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  8529. patients = append(patients, item)
  8530. }
  8531. //过滤掉没挂号的
  8532. if len(item.HisPatient) > 0 {
  8533. patients_two = append(patients_two, item)
  8534. }
  8535. } else {
  8536. if len(item.HisPrescription) > 0 {
  8537. patients = append(patients, item)
  8538. }
  8539. }
  8540. }
  8541. c.ServeSuccessJSON(map[string]interface{}{
  8542. "list": patients,
  8543. "list_two": patients_two,
  8544. })
  8545. }
  8546. func (c *HisApiController) GetHisUnRegisterPatientList() {
  8547. record_date := c.GetString("record_date")
  8548. timeLayout := "2006-01-02"
  8549. loc, _ := time.LoadLocation("Local")
  8550. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8551. if err != nil {
  8552. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8553. return
  8554. }
  8555. recordDateTime := theTime.Unix()
  8556. adminUser := c.GetAdminUserInfo()
  8557. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  8558. var patients []*service.Patients
  8559. for _, item := range tempPatients {
  8560. if item.HisPatient.ID == 0 {
  8561. patients = append(patients, item)
  8562. }
  8563. }
  8564. c.ServeSuccessJSON(map[string]interface{}{
  8565. "list": patients,
  8566. //"list_two": patients_two,
  8567. })
  8568. }
  8569. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  8570. newArr = make([]*service.Patients, 0)
  8571. for i := 0; i < len(patient); i++ {
  8572. repeat := false
  8573. for j := i + 1; j < len(patient); j++ {
  8574. if patient[i].ID == patient[j].ID {
  8575. repeat = true
  8576. break
  8577. }
  8578. }
  8579. if !repeat {
  8580. newArr = append(newArr, patient[i])
  8581. }
  8582. }
  8583. return
  8584. }
  8585. func (c *HisApiController) GetHisChargePatientInfo() {
  8586. patient_id, _ := c.GetInt64("patient_id")
  8587. his_patient_id, _ := c.GetInt64("his_patient_id")
  8588. record_date := c.GetString("record_date")
  8589. //start_time := c.GetString("start_time")
  8590. //end_time := c.GetString("end_time")
  8591. order_status, _ := c.GetInt64("type", 0)
  8592. p_type, _ := c.GetInt64("p_type", 0)
  8593. order_id, _ := c.GetInt64("order_id", 0)
  8594. timeLayout := "2006-01-02"
  8595. loc, _ := time.LoadLocation("Local")
  8596. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8597. if err != nil {
  8598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8599. return
  8600. }
  8601. recordDateTime := theTime.Unix()
  8602. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8603. //if err != nil {
  8604. //
  8605. //}
  8606. //startRecordDateTime := startTime.Unix()
  8607. //
  8608. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8609. //if err != nil {
  8610. //
  8611. //}
  8612. //endRecordDateTime := endTime.Unix()
  8613. admin := c.GetAdminUserInfo()
  8614. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8615. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8616. var prescriptions []*models.HisPrescription
  8617. //var unChargeMonthPrescriptions []*models.HisPrescription
  8618. order, _ := service.GetHisOrderByID(order_id)
  8619. if order_status == 1 || order_status == 0 {
  8620. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8621. } else if order_status == 2 {
  8622. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8623. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8624. }
  8625. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8626. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8627. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8628. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8629. //获取所有科室信息
  8630. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8631. c.ServeSuccessJSON(map[string]interface{}{
  8632. "his_info": his_patient_info,
  8633. "xt_info": xt_patient_info,
  8634. "prescription": prescriptions,
  8635. "case_history": case_history,
  8636. "info": patientPrescriptionInfo,
  8637. "last_info": lastPatientPrescriptionInfo,
  8638. "order": order,
  8639. "doctors": doctors,
  8640. "department": department,
  8641. })
  8642. return
  8643. }
  8644. func (c *HisApiController) GetAllOrderDetail() {
  8645. order_id, _ := c.GetInt64("id", 0)
  8646. order, _ := service.GetHisOrderByID(order_id)
  8647. if order.ID == 0 {
  8648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8649. return
  8650. }
  8651. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8652. org_id := c.GetAdminUserInfo().CurrentOrgId
  8653. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8654. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8655. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8656. c.ServeSuccessJSON(map[string]interface{}{
  8657. "order": order,
  8658. "order_info": order_info,
  8659. "patient": patient,
  8660. "admin_info": adminInfo,
  8661. "hospital_record": record,
  8662. })
  8663. return
  8664. }
  8665. func (c *HisApiController) GetAllOrderDetailCollect() {
  8666. order_id, _ := c.GetInt64("id", 0)
  8667. order, _ := service.GetHisOrderByID(order_id)
  8668. if order.ID == 0 {
  8669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8670. return
  8671. }
  8672. org_id := c.GetAdminUserInfo().CurrentOrgId
  8673. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8674. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8675. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8676. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8677. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8678. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8679. var bedCostTotal float64 = 0 //床位总费
  8680. //var bedCostSelfTotal float64 = 0 //床位自费
  8681. var operationCostTotal float64 = 0 //手术费
  8682. //var operationCostSelfTotal float64 = 0 //手术费
  8683. var otherCostTotal float64 = 0 //其他费用
  8684. //var otherCostSelfTotal float64 = 0 //其他费用
  8685. var materialCostTotal float64 = 0 //材料费
  8686. //var materialCostSelfTotal float64 = 0 //材料费
  8687. var westernMedicineCostTotal float64 = 0 //西药费
  8688. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8689. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8690. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8691. var checkCostTotal float64 = 0 //检查费
  8692. //var checkCostSelfTotal float64 = 0 //检查费
  8693. var laboratoryCostTotal float64 = 0 //化验费
  8694. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8695. var treatCostTotal float64 = 0 //治疗费用
  8696. //var treatCostSelfTotal float64 = 0 //治疗费用
  8697. var zhenChaCostTotal float64 = 0 //其他费用
  8698. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8699. decimal.DivisionPrecision = 2
  8700. var BalanceAccountsType int64
  8701. if his.ID > 0 {
  8702. BalanceAccountsType = his.BalanceAccountsType
  8703. } else {
  8704. BalanceAccountsType = record.BalanceAccountsType
  8705. }
  8706. if BalanceAccountsType != 2 {
  8707. for _, item := range order_info {
  8708. if org_id == 10215 {
  8709. if item.MedChrgitmType == "01" { //床位费
  8710. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8711. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8712. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8713. }
  8714. if item.MedChrgitmType == "02" { //诊察费
  8715. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8716. //zhenChaCostSelfTotal = zhenChaCostTotal
  8717. }
  8718. if item.MedChrgitmType == "03" { //检查费
  8719. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8720. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8721. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8722. }
  8723. //if item.MedChrgitmType == "02" { //检查费
  8724. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8725. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8726. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8727. //}
  8728. if item.MedChrgitmType == "04" { //化验费
  8729. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8730. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8731. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8732. }
  8733. if item.MedChrgitmType == "05" { //治疗费
  8734. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8735. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8736. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8737. }
  8738. if item.MedChrgitmType == "06" { //手术费
  8739. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8740. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8741. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8742. }
  8743. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8744. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8745. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8746. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8747. }
  8748. if item.MedChrgitmType == "09" { //西药费
  8749. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8750. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8751. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8752. }
  8753. if item.MedChrgitmType == "11" { //中成费
  8754. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8755. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8756. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8757. }
  8758. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8759. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8760. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8761. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8762. }
  8763. } else if org_id == 10188 || org_id == 10217 {
  8764. if item.MedChrgitmType == "01" { //床位费
  8765. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8766. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8767. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8768. }
  8769. if item.MedChrgitmType == "02" { //诊察费
  8770. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8771. //zhenChaCostSelfTotal = zhenChaCostTotal
  8772. }
  8773. if item.MedChrgitmType == "03" { //检查费
  8774. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8775. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8776. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8777. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8778. }
  8779. //if item.MedChrgitmType == "02" { //检查费
  8780. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8781. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8782. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8783. //}
  8784. if item.MedChrgitmType == "04" { //化验费
  8785. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8786. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8787. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8788. }
  8789. if item.MedChrgitmType == "05" { //治疗费
  8790. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8791. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8792. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8793. }
  8794. if item.MedChrgitmType == "06" { //手术费
  8795. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8796. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8797. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8798. }
  8799. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8800. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8801. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8802. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8803. }
  8804. if item.MedChrgitmType == "09" { //西药费
  8805. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8806. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8807. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8808. }
  8809. if item.MedChrgitmType == "11" { //中成费
  8810. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8811. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8812. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8813. }
  8814. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8815. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8816. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8817. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8818. }
  8819. } else {
  8820. if item.MedChrgitmType == "01" { //床位费
  8821. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8822. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8823. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8824. }
  8825. //if item.MedChrgitmType == "02" { //诊察费
  8826. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8827. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8828. //}
  8829. if item.MedChrgitmType == "03" { //检查费
  8830. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8831. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8832. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8833. }
  8834. //if item.MedChrgitmType == "02" { //检查费
  8835. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8836. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8837. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8838. //}
  8839. if item.MedChrgitmType == "04" { //化验费
  8840. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8841. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8842. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8843. }
  8844. if item.MedChrgitmType == "05" { //治疗费
  8845. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8846. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8847. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8848. }
  8849. if item.MedChrgitmType == "06" { //手术费
  8850. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8851. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8852. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8853. }
  8854. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8855. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8856. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8857. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8858. }
  8859. if item.MedChrgitmType == "09" { //西药费
  8860. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8861. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8862. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8863. }
  8864. if item.MedChrgitmType == "11" { //中成费
  8865. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8866. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8867. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8868. }
  8869. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8870. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8871. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8872. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8873. }
  8874. }
  8875. }
  8876. c.ServeSuccessJSON(map[string]interface{}{
  8877. "order": order,
  8878. "order_info": order_info,
  8879. "patient": patient,
  8880. "admin_info": adminInfo,
  8881. "his_hospital": record,
  8882. "bedCostTotal": bedCostTotal,
  8883. "operationCostTotal": operationCostTotal,
  8884. "otherCostTotal": otherCostTotal,
  8885. "materialCostTotal": materialCostTotal,
  8886. "westernMedicineCostTotal": westernMedicineCostTotal,
  8887. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8888. "checkCostTotal": checkCostTotal,
  8889. "zhenChaCostTotal": zhenChaCostTotal,
  8890. "laboratoryCostTotal": laboratoryCostTotal,
  8891. "treatCostTotal": treatCostTotal,
  8892. })
  8893. } else {
  8894. for _, item := range order_info {
  8895. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8896. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8897. item.MedChrgitmType = "09"
  8898. }
  8899. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8900. if item.HisPrescriptionProject.Type == 2 {
  8901. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8902. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8903. case 0:
  8904. item.MedChrgitmType = "0"
  8905. break
  8906. case 1:
  8907. item.MedChrgitmType = "14"
  8908. break
  8909. case 2:
  8910. item.MedChrgitmType = "05"
  8911. break
  8912. case 3:
  8913. item.MedChrgitmType = "03"
  8914. break
  8915. case 4:
  8916. item.MedChrgitmType = "03"
  8917. break
  8918. case 5:
  8919. item.MedChrgitmType = "08"
  8920. break
  8921. case 6:
  8922. item.MedChrgitmType = "14"
  8923. break
  8924. case 7:
  8925. item.MedChrgitmType = "14"
  8926. break
  8927. case 8:
  8928. item.MedChrgitmType = "03"
  8929. break
  8930. case 9:
  8931. item.MedChrgitmType = "14"
  8932. break
  8933. case 10:
  8934. item.MedChrgitmType = "14"
  8935. break
  8936. case 11:
  8937. item.MedChrgitmType = "06"
  8938. break
  8939. case 12:
  8940. item.MedChrgitmType = "12"
  8941. break
  8942. case 13:
  8943. item.MedChrgitmType = "01"
  8944. break
  8945. case 14:
  8946. item.MedChrgitmType = "04"
  8947. break
  8948. case 15:
  8949. item.MedChrgitmType = "14"
  8950. break
  8951. }
  8952. } else {
  8953. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8954. case 1:
  8955. item.MedChrgitmType = "14"
  8956. break
  8957. case 2:
  8958. item.MedChrgitmType = "05"
  8959. break
  8960. case 3:
  8961. item.MedChrgitmType = "04"
  8962. break
  8963. case 4:
  8964. item.MedChrgitmType = "14"
  8965. break
  8966. case 5:
  8967. item.MedChrgitmType = "08"
  8968. break
  8969. case 6:
  8970. item.MedChrgitmType = "14"
  8971. break
  8972. case 7:
  8973. item.MedChrgitmType = "14"
  8974. break
  8975. case 8:
  8976. item.MedChrgitmType = "03"
  8977. break
  8978. case 9:
  8979. item.MedChrgitmType = "14"
  8980. break
  8981. }
  8982. }
  8983. } else if item.HisPrescriptionProject.Type == 3 {
  8984. item.MedChrgitmType = "08"
  8985. }
  8986. }
  8987. }
  8988. for _, item := range order_info {
  8989. if org_id == 10215 {
  8990. if item.MedChrgitmType == "01" { //床位费
  8991. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8992. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8993. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8994. }
  8995. if item.MedChrgitmType == "02" { //诊察费
  8996. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8997. //zhenChaCostSelfTotal = zhenChaCostTotal
  8998. }
  8999. if item.MedChrgitmType == "03" { //检查费
  9000. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9001. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9002. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9003. }
  9004. //if item.MedChrgitmType == "02" { //检查费
  9005. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9006. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9007. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9008. //}
  9009. if item.MedChrgitmType == "04" { //化验费
  9010. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9011. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9012. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9013. }
  9014. if item.MedChrgitmType == "05" { //治疗费
  9015. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9016. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9017. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9018. }
  9019. if item.MedChrgitmType == "06" { //手术费
  9020. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9021. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9022. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9023. }
  9024. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9025. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9026. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9027. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9028. }
  9029. if item.MedChrgitmType == "09" { //西药费
  9030. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9031. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9032. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9033. }
  9034. if item.MedChrgitmType == "11" { //中成费
  9035. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9036. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9037. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9038. }
  9039. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9040. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9041. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9042. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9043. }
  9044. } else {
  9045. if item.MedChrgitmType == "01" { //床位费
  9046. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9047. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9048. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9049. }
  9050. //if item.MedChrgitmType == "02" { //诊察费
  9051. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9052. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9053. //}
  9054. if item.MedChrgitmType == "03" { //检查费
  9055. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9056. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9057. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9058. }
  9059. //if item.MedChrgitmType == "02" { //检查费
  9060. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9061. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9062. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9063. //}
  9064. if item.MedChrgitmType == "04" { //化验费
  9065. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9066. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9067. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9068. }
  9069. if item.MedChrgitmType == "05" { //治疗费
  9070. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9071. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9072. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9073. }
  9074. if item.MedChrgitmType == "06" { //手术费
  9075. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9076. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9077. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9078. }
  9079. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9080. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9081. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9082. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9083. }
  9084. if item.MedChrgitmType == "09" { //西药费
  9085. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9086. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9087. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9088. }
  9089. if item.MedChrgitmType == "11" { //中成费
  9090. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9091. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9092. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9093. }
  9094. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9095. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9096. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9097. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9098. }
  9099. }
  9100. }
  9101. c.ServeSuccessJSON(map[string]interface{}{
  9102. "order": order,
  9103. "order_info": order_info,
  9104. "patient": patient,
  9105. "admin_info": adminInfo,
  9106. "his_hospital": record,
  9107. "bedCostTotal": bedCostTotal,
  9108. "operationCostTotal": operationCostTotal,
  9109. "otherCostTotal": otherCostTotal,
  9110. "materialCostTotal": materialCostTotal,
  9111. "westernMedicineCostTotal": westernMedicineCostTotal,
  9112. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9113. "checkCostTotal": checkCostTotal,
  9114. "zhenChaCostTotal": zhenChaCostTotal,
  9115. "laboratoryCostTotal": laboratoryCostTotal,
  9116. "treatCostTotal": treatCostTotal,
  9117. })
  9118. }
  9119. }
  9120. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9121. page, _ := c.GetInt64("page")
  9122. limit, _ := c.GetInt64("limit")
  9123. keywords := c.GetString("keywords")
  9124. start_time := c.GetString("start_time")
  9125. end_time := c.GetString("end_time")
  9126. //clr_type := c.GetString("clr_type")
  9127. insutype := c.GetString("insutype")
  9128. timeLayout := "2006-01-02"
  9129. loc, _ := time.LoadLocation("Local")
  9130. var theStartTIme int64
  9131. if len(start_time) > 0 {
  9132. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9133. theStartTIme = theTime.Unix()
  9134. }
  9135. var theEndtTIme int64
  9136. if len(end_time) > 0 {
  9137. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9138. theEndtTIme = theTime.Unix()
  9139. }
  9140. if page <= 0 {
  9141. page = 1
  9142. }
  9143. if limit <= 0 {
  9144. limit = 10
  9145. }
  9146. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9147. c.ServeSuccessJSON(map[string]interface{}{
  9148. "total": total,
  9149. "list": list,
  9150. })
  9151. return
  9152. }
  9153. func (c *HisApiController) GetPutOnRecordList() {
  9154. page, _ := c.GetInt64("page")
  9155. limit, _ := c.GetInt64("limit")
  9156. keywords := c.GetString("keywords")
  9157. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9158. if page <= 0 {
  9159. page = 1
  9160. }
  9161. if limit <= 0 {
  9162. limit = 10
  9163. }
  9164. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9165. c.ServeSuccessJSON(map[string]interface{}{
  9166. "total": total,
  9167. "list": list,
  9168. })
  9169. return
  9170. }
  9171. func (c *HisApiController) GetCompareData() {
  9172. start_time := c.GetString("start_time")
  9173. end_time := c.GetString("end_time")
  9174. insutype := c.GetString("insutype")
  9175. clr_type := c.GetString("clr_type")
  9176. timeLayout := "2006-01-02"
  9177. loc, _ := time.LoadLocation("Local")
  9178. var theStartTIme int64
  9179. if len(start_time) > 0 {
  9180. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9181. if err != nil {
  9182. theStartTIme = 0
  9183. }
  9184. theStartTIme = theTime.Unix()
  9185. }
  9186. var theEndtTIme int64
  9187. if len(end_time) > 0 {
  9188. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9189. if err != nil {
  9190. theEndtTIme = 0
  9191. }
  9192. theEndtTIme = theTime.Unix()
  9193. }
  9194. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9195. fmt.Println(err)
  9196. if err == nil {
  9197. c.ServeSuccessJSON(map[string]interface{}{
  9198. "list": formData,
  9199. })
  9200. } else {
  9201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9202. return
  9203. }
  9204. }
  9205. func (c *HisApiController) GetFaPiaoData() {
  9206. order_id, _ := c.GetInt64("order_id")
  9207. patient_id, _ := c.GetInt64("patient_id")
  9208. //number := c.GetString("number")
  9209. adminUser := c.GetAdminUserInfo()
  9210. order, _ := service.GetHisOrderByID(order_id)
  9211. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9212. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9213. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9214. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9215. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9216. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9217. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9218. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9219. var bedCostTotal float64 = 0 //床位总费
  9220. var bedCostSelfTotal float64 = 0 //床位自费
  9221. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9222. var operationCostTotal float64 = 0 //手术费
  9223. var operationCostSelfTotal float64 = 0 //手术费
  9224. var operationCostPartSelfTotal float64 = 0 //手术费
  9225. var otherCostTotal float64 = 0 //其他费用
  9226. var otherCostSelfTotal float64 = 0 //其他费用
  9227. var otherCostPartSelfTotal float64 = 0 //其他费用
  9228. var materialCostTotal float64 = 0 //材料费
  9229. var materialCostSelfTotal float64 = 0 //材料费
  9230. var materialCostPartSelfTotal float64 = 0 //材料费
  9231. var westernMedicineCostTotal float64 = 0 //西药费
  9232. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9233. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9234. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9235. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9236. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9237. var checkCostTotal float64 = 0 //检查费
  9238. var checkCostSelfTotal float64 = 0 //检查费
  9239. var checkCostPartSelfTotal float64 = 0 //检查费
  9240. var hiliCostTotal float64 = 0 //护理费
  9241. var hiliCostSelfTotal float64 = 0 //护理费
  9242. var hiliCostPartSelfTotal float64 = 0 //护理费
  9243. var laboratoryCostTotal float64 = 0 //化验费
  9244. var laboratoryCostSelfTotal float64 = 0 //化验费
  9245. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9246. var treatCostTotal float64 = 0 //治疗费用
  9247. var treatCostSelfTotal float64 = 0 //治疗费用
  9248. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9249. var zhenChaCostTotal float64 = 0 //其他费用
  9250. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9251. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9252. decimal.DivisionPrecision = 2
  9253. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9254. var balanceAccountsType int64
  9255. if his.ID > 0 {
  9256. balanceAccountsType = his.BalanceAccountsType
  9257. } else {
  9258. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9259. }
  9260. if balanceAccountsType == 2 {
  9261. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9262. for _, item := range orderInfos_two {
  9263. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9264. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9265. item.MedChrgitmType = "09"
  9266. }
  9267. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9268. if item.HisPrescriptionProject.Type == 2 {
  9269. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9270. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9271. case 0:
  9272. item.MedChrgitmType = "0"
  9273. break
  9274. case 1:
  9275. item.MedChrgitmType = "14"
  9276. break
  9277. case 2:
  9278. item.MedChrgitmType = "05"
  9279. break
  9280. case 3:
  9281. item.MedChrgitmType = "03"
  9282. break
  9283. case 4:
  9284. item.MedChrgitmType = "03"
  9285. break
  9286. case 5:
  9287. item.MedChrgitmType = "08"
  9288. break
  9289. case 6:
  9290. item.MedChrgitmType = "14"
  9291. break
  9292. case 7:
  9293. item.MedChrgitmType = "14"
  9294. break
  9295. case 8:
  9296. item.MedChrgitmType = "03"
  9297. break
  9298. case 9:
  9299. item.MedChrgitmType = "14"
  9300. break
  9301. case 10:
  9302. item.MedChrgitmType = "14"
  9303. break
  9304. case 11:
  9305. item.MedChrgitmType = "06"
  9306. break
  9307. case 12:
  9308. item.MedChrgitmType = "12"
  9309. break
  9310. case 13:
  9311. item.MedChrgitmType = "01"
  9312. break
  9313. case 14:
  9314. item.MedChrgitmType = "04"
  9315. break
  9316. case 15:
  9317. item.MedChrgitmType = "02"
  9318. break
  9319. }
  9320. } else {
  9321. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9322. case 1:
  9323. item.MedChrgitmType = "14"
  9324. break
  9325. case 2:
  9326. item.MedChrgitmType = "05"
  9327. break
  9328. case 3:
  9329. item.MedChrgitmType = "03"
  9330. break
  9331. case 4:
  9332. item.MedChrgitmType = "03"
  9333. break
  9334. case 5:
  9335. item.MedChrgitmType = "08"
  9336. break
  9337. case 6:
  9338. item.MedChrgitmType = "14"
  9339. break
  9340. case 7:
  9341. item.MedChrgitmType = "14"
  9342. break
  9343. case 8:
  9344. item.MedChrgitmType = "03"
  9345. break
  9346. case 9:
  9347. item.MedChrgitmType = "14"
  9348. break
  9349. }
  9350. }
  9351. } else if item.HisPrescriptionProject.Type == 3 {
  9352. item.MedChrgitmType = "08"
  9353. }
  9354. }
  9355. }
  9356. for _, item := range orderInfos_two {
  9357. fmt.Println(item.MedChrgitmType)
  9358. if item.MedChrgitmType == "07" { //床位费
  9359. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9360. hiliCostSelfTotal = hiliCostTotal
  9361. }
  9362. if item.MedChrgitmType == "01" { //床位费
  9363. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9364. bedCostSelfTotal = bedCostTotal
  9365. }
  9366. if item.MedChrgitmType == "02" { //诊察费
  9367. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9368. zhenChaCostSelfTotal = zhenChaCostTotal
  9369. }
  9370. if item.MedChrgitmType == "03" { //检查费
  9371. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9372. checkCostSelfTotal = checkCostTotal
  9373. }
  9374. if item.MedChrgitmType == "04" { //化验费
  9375. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9376. laboratoryCostSelfTotal = laboratoryCostTotal
  9377. }
  9378. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9379. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9380. treatCostSelfTotal = treatCostTotal
  9381. }
  9382. if item.MedChrgitmType == "06" { //手术费
  9383. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9384. operationCostSelfTotal = treatCostTotal
  9385. }
  9386. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  9387. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9388. materialCostSelfTotal = materialCostTotal
  9389. }
  9390. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9391. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9392. westernMedicineCostSelfTotal = westernMedicineCostTotal
  9393. }
  9394. if item.MedChrgitmType == "11" { //中成费
  9395. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9396. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9397. }
  9398. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9399. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9400. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9401. otherCostSelfTotal = otherCostTotal
  9402. }
  9403. } else {
  9404. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9405. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9406. otherCostSelfTotal = otherCostTotal
  9407. }
  9408. }
  9409. }
  9410. } else {
  9411. for _, item := range orderInfos {
  9412. if item.MedChrgitmType == "01" { //床位费
  9413. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9414. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9415. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9416. }
  9417. if item.MedChrgitmType == "02" { //诊察费
  9418. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9419. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9420. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9421. }
  9422. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9423. if item.MedChrgitmType == "03" { //检查费
  9424. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9425. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9426. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9427. }
  9428. } else {
  9429. if item.MedChrgitmType == "03" { //检查费
  9430. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9431. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9432. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9433. }
  9434. }
  9435. if item.MedChrgitmType == "04" { //化验费
  9436. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9437. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9438. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9439. }
  9440. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9441. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9442. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9443. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9444. }
  9445. if item.MedChrgitmType == "06" { //手术费
  9446. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9447. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9448. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9449. }
  9450. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  9451. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9452. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9453. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9454. }
  9455. if item.MedChrgitmType == "07" { //护理
  9456. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9457. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9458. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9459. }
  9460. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9461. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9462. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9463. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9464. }
  9465. if item.MedChrgitmType == "11" { //中成费
  9466. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9467. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9468. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9469. }
  9470. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9471. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9472. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9473. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9474. }
  9475. }
  9476. }
  9477. timeLayout := "2006-01-02"
  9478. loc, _ := time.LoadLocation("Local")
  9479. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9480. if err != nil {
  9481. }
  9482. startRecordDateTime := startTime.Unix()
  9483. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9484. if err != nil {
  9485. }
  9486. endRecordDateTime := endTime.Unix()
  9487. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9488. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9489. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9490. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  9491. c.ServeSuccessJSON(map[string]interface{}{
  9492. "charge_admin_name": charge_admin.UserName,
  9493. "order_number": order.Number, //业务流水号
  9494. "id_card_no": his.IdCardNo, //社会保障号
  9495. "patient": patient,
  9496. "department_name": department.Name, //科室
  9497. "number": his.Number, //门诊号
  9498. "date": order.SettleAccountsDate, //结算日期
  9499. "name": order.PsnName, //姓名
  9500. "gender": patient.Gender, //性别
  9501. "psn_cash_money": order.PsnCashPay, //个人支付
  9502. "pay_way": "门诊", //结算方式
  9503. "medfee_sumamt": order.MedfeeSumamt, //总费用
  9504. "admin_user_name": admin.UserName, //收款员
  9505. "order": order,
  9506. "order_info": orderInfos_two,
  9507. "his": his,
  9508. "bedCostTotal": bedCostTotal,
  9509. "bedCostSelfTotal": bedCostSelfTotal,
  9510. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9511. "operationCostTotal": operationCostTotal,
  9512. "operationCostSelfTotal": operationCostSelfTotal,
  9513. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9514. "otherCostTotal": otherCostTotal,
  9515. "otherCostSelfTotal": otherCostSelfTotal,
  9516. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9517. "materialCostTotal": materialCostTotal,
  9518. "materialCostSelfTotal": materialCostSelfTotal,
  9519. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9520. "westernMedicineCostTotal": westernMedicineCostTotal,
  9521. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9522. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9523. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9524. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9525. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9526. "checkCostTotal": checkCostTotal,
  9527. "checkCostSelfTotal": checkCostSelfTotal,
  9528. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9529. "laboratoryCostTotal": laboratoryCostTotal,
  9530. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9531. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9532. "treatCostTotal": treatCostTotal,
  9533. "treatCostSelfTotal": treatCostSelfTotal,
  9534. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9535. "zhenChaCostTotal": zhenChaCostTotal,
  9536. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9537. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9538. "his_hospital_record": his_hospital_record,
  9539. "pre_pay_money": pre_pay_money,
  9540. "refund_sum": sum,
  9541. "doctor_info": doctor_info,
  9542. "hiliCostTotal": hiliCostTotal,
  9543. "hiliCostSelfTotal": hiliCostSelfTotal,
  9544. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  9545. })
  9546. }
  9547. //func (c *HisApiController) GetFaPiaoDatas() {
  9548. // order_ids := c.GetString("order_ids")
  9549. // patient_id, _ := c.GetInt64("patient_id")
  9550. // adminUser := c.GetAdminUserInfo()
  9551. //
  9552. // orders := strings.Split(order_ids, ",")
  9553. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9554. //
  9555. // for _, item := range orders {
  9556. // order_id, _ := strconv.ParseInt(item, 10, 64)
  9557. // order, _ := service.GetHisOrderByID(order_id)
  9558. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9559. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9560. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9561. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9562. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9563. //
  9564. // }
  9565. //
  9566. // var bedCostTotal float64 = 0 //床位总费
  9567. // var bedCostSelfTotal float64 = 0 //床位自费
  9568. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9569. //
  9570. // var operationCostTotal float64 = 0 //手术费
  9571. // var operationCostSelfTotal float64 = 0 //手术费
  9572. // var operationCostPartSelfTotal float64 = 0 //手术费
  9573. //
  9574. // var otherCostTotal float64 = 0 //其他费用
  9575. // var otherCostSelfTotal float64 = 0 //其他费用
  9576. // var otherCostPartSelfTotal float64 = 0 //其他费用
  9577. //
  9578. // var materialCostTotal float64 = 0 //材料费
  9579. // var materialCostSelfTotal float64 = 0 //材料费
  9580. // var materialCostPartSelfTotal float64 = 0 //材料费
  9581. //
  9582. // var westernMedicineCostTotal float64 = 0 //西药费
  9583. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  9584. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9585. //
  9586. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9587. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9588. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9589. //
  9590. // var checkCostTotal float64 = 0 //检查费
  9591. // var checkCostSelfTotal float64 = 0 //检查费
  9592. // var checkCostPartSelfTotal float64 = 0 //检查费
  9593. //
  9594. // var laboratoryCostTotal float64 = 0 //化验费
  9595. // var laboratoryCostSelfTotal float64 = 0 //化验费
  9596. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9597. //
  9598. // var treatCostTotal float64 = 0 //治疗费用
  9599. // var treatCostSelfTotal float64 = 0 //治疗费用
  9600. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  9601. //
  9602. // var zhenChaCostTotal float64 = 0 //其他费用
  9603. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  9604. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9605. //
  9606. // decimal.DivisionPrecision = 2
  9607. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9608. //
  9609. // var balanceAccountsType int64
  9610. // if his.ID > 0 {
  9611. // balanceAccountsType = his.BalanceAccountsType
  9612. // } else {
  9613. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9614. // }
  9615. // if balanceAccountsType == 2 {
  9616. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9617. // for _, item := range orderInfos_two {
  9618. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9619. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9620. // item.MedChrgitmType = "09"
  9621. // }
  9622. //
  9623. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9624. // if item.HisPrescriptionProject.Type == 2 {
  9625. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9626. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9627. // case 0:
  9628. // item.MedChrgitmType = "0"
  9629. // break
  9630. // case 1:
  9631. // item.MedChrgitmType = "14"
  9632. // break
  9633. // case 2:
  9634. // item.MedChrgitmType = "05"
  9635. //
  9636. // break
  9637. // case 3:
  9638. // item.MedChrgitmType = "03"
  9639. //
  9640. // break
  9641. // case 4:
  9642. // item.MedChrgitmType = "03"
  9643. //
  9644. // break
  9645. // case 5:
  9646. // item.MedChrgitmType = "08"
  9647. //
  9648. // break
  9649. // case 6:
  9650. // item.MedChrgitmType = "14"
  9651. //
  9652. // break
  9653. // case 7:
  9654. // item.MedChrgitmType = "14"
  9655. //
  9656. // break
  9657. // case 8:
  9658. // item.MedChrgitmType = "03"
  9659. // break
  9660. // case 9:
  9661. // item.MedChrgitmType = "14"
  9662. // break
  9663. // case 10:
  9664. // item.MedChrgitmType = "14"
  9665. // break
  9666. // case 11:
  9667. // item.MedChrgitmType = "06"
  9668. // break
  9669. // case 12:
  9670. // item.MedChrgitmType = "12"
  9671. // break
  9672. // case 13:
  9673. // item.MedChrgitmType = "01"
  9674. // break
  9675. // case 14:
  9676. // item.MedChrgitmType = "04"
  9677. // break
  9678. // case 15:
  9679. // item.MedChrgitmType = "02"
  9680. // break
  9681. //
  9682. // }
  9683. //
  9684. // } else {
  9685. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9686. //
  9687. // case 1:
  9688. // item.MedChrgitmType = "14"
  9689. // break
  9690. // case 2:
  9691. // item.MedChrgitmType = "05"
  9692. //
  9693. // break
  9694. // case 3:
  9695. // item.MedChrgitmType = "03"
  9696. //
  9697. // break
  9698. // case 4:
  9699. // item.MedChrgitmType = "03"
  9700. //
  9701. // break
  9702. // case 5:
  9703. // item.MedChrgitmType = "08"
  9704. //
  9705. // break
  9706. // case 6:
  9707. // item.MedChrgitmType = "14"
  9708. //
  9709. // break
  9710. // case 7:
  9711. // item.MedChrgitmType = "14"
  9712. //
  9713. // break
  9714. // case 8:
  9715. // item.MedChrgitmType = "03"
  9716. // break
  9717. // case 9:
  9718. // item.MedChrgitmType = "14"
  9719. // break
  9720. //
  9721. // }
  9722. //
  9723. // }
  9724. //
  9725. // } else if item.HisPrescriptionProject.Type == 3 {
  9726. // item.MedChrgitmType = "08"
  9727. // }
  9728. // }
  9729. // }
  9730. //
  9731. // for _, item := range orderInfos_two {
  9732. // fmt.Println(item.MedChrgitmType)
  9733. // if item.MedChrgitmType == "01" { //床位费
  9734. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9735. // bedCostSelfTotal = bedCostTotal
  9736. // }
  9737. //
  9738. // if item.MedChrgitmType == "02" { //诊察费
  9739. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9740. // zhenChaCostSelfTotal = zhenChaCostTotal
  9741. // }
  9742. //
  9743. // if item.MedChrgitmType == "03" { //检查费
  9744. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9745. // checkCostSelfTotal = checkCostTotal
  9746. // }
  9747. //
  9748. // if item.MedChrgitmType == "04" { //化验费
  9749. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9750. // laboratoryCostSelfTotal = laboratoryCostTotal
  9751. // }
  9752. //
  9753. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9754. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9755. // treatCostSelfTotal = treatCostTotal
  9756. // }
  9757. //
  9758. // if item.MedChrgitmType == "06" { //手术费
  9759. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9760. // operationCostSelfTotal = treatCostTotal
  9761. // }
  9762. //
  9763. // if item.MedChrgitmType == "08" { //材料费
  9764. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9765. // materialCostSelfTotal = materialCostTotal
  9766. // }
  9767. //
  9768. // if item.MedChrgitmType == "09" { //西药费
  9769. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9770. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9771. // }
  9772. //
  9773. // if item.MedChrgitmType == "11" { //中成费
  9774. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9775. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9776. // }
  9777. //
  9778. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9779. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9780. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9781. // otherCostSelfTotal = otherCostTotal
  9782. // }
  9783. // } else {
  9784. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9785. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9786. // otherCostSelfTotal = otherCostTotal
  9787. // }
  9788. //
  9789. // }
  9790. //
  9791. // }
  9792. //
  9793. // } else {
  9794. // for _, item := range orderInfos {
  9795. // if item.MedChrgitmType == "01" { //床位费
  9796. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9797. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9798. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9799. // }
  9800. //
  9801. // if item.MedChrgitmType == "02" { //诊察费
  9802. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9803. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9804. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9805. // }
  9806. //
  9807. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9808. // if item.MedChrgitmType == "03" { //检查费
  9809. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9810. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9811. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9812. //
  9813. // }
  9814. // } else {
  9815. // if item.MedChrgitmType == "03" { //检查费
  9816. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9817. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9818. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9819. // }
  9820. //
  9821. // }
  9822. //
  9823. // if item.MedChrgitmType == "04" { //化验费
  9824. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9825. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9826. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9827. //
  9828. // }
  9829. //
  9830. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  9831. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9832. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9833. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9834. //
  9835. // }
  9836. //
  9837. // if item.MedChrgitmType == "06" { //手术费
  9838. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9839. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9840. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9841. // }
  9842. //
  9843. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9844. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9845. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9846. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9847. // }
  9848. //
  9849. // if item.MedChrgitmType == "09" { //西药费
  9850. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9851. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9852. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9853. // }
  9854. //
  9855. // if item.MedChrgitmType == "11" { //中成费
  9856. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9857. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9858. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9859. // }
  9860. //
  9861. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9862. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9863. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9864. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9865. // }
  9866. //
  9867. // }
  9868. // }
  9869. // timeLayout := "2006-01-02"
  9870. // loc, _ := time.LoadLocation("Local")
  9871. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9872. // if err != nil {
  9873. // }
  9874. // startRecordDateTime := startTime.Unix()
  9875. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9876. // if err != nil {
  9877. // }
  9878. // endRecordDateTime := endTime.Unix()
  9879. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9880. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9881. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9882. //
  9883. // c.ServeSuccessJSON(map[string]interface{}{
  9884. // "order_number": order.Number, //业务流水号
  9885. // "id_card_no": his.IdCardNo, //社会保障号
  9886. // "department_name": department.Name, //科室
  9887. // "number": his.Number, //门诊号
  9888. // "date": order.SettleAccountsDate, //结算日期
  9889. // "name": order.PsnName, //姓名
  9890. // "gender": patient.Gender, //性别
  9891. // "psn_cash_money": order.PsnCashPay, //个人支付
  9892. // "pay_way": "门诊", //结算方式
  9893. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  9894. // "admin_user_name": admin.UserName, //收款员
  9895. // "order": order,
  9896. // "order_info": orderInfos_two,
  9897. // "his": his,
  9898. // "bedCostTotal": bedCostTotal,
  9899. // "bedCostSelfTotal": bedCostSelfTotal,
  9900. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9901. // "operationCostTotal": operationCostTotal,
  9902. // "operationCostSelfTotal": operationCostSelfTotal,
  9903. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9904. // "otherCostTotal": otherCostTotal,
  9905. // "otherCostSelfTotal": otherCostSelfTotal,
  9906. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9907. // "materialCostTotal": materialCostTotal,
  9908. // "materialCostSelfTotal": materialCostSelfTotal,
  9909. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9910. // "westernMedicineCostTotal": westernMedicineCostTotal,
  9911. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9912. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9913. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9914. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9915. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9916. // "checkCostTotal": checkCostTotal,
  9917. // "checkCostSelfTotal": checkCostSelfTotal,
  9918. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9919. // "laboratoryCostTotal": laboratoryCostTotal,
  9920. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9921. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9922. // "treatCostTotal": treatCostTotal,
  9923. // "treatCostSelfTotal": treatCostSelfTotal,
  9924. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9925. // "zhenChaCostTotal": zhenChaCostTotal,
  9926. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9927. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9928. // "his_hospital_record": his_hospital_record,
  9929. // "pre_pay_money": pre_pay_money,
  9930. // "refund_sum": sum,
  9931. // })
  9932. //
  9933. //}
  9934. func (this *HisApiController) GetIncomeStatisticsData() {
  9935. start_time := this.GetString("start_time")
  9936. end_time := this.GetString("end_time")
  9937. key_words := this.GetString("key_words")
  9938. limit, _ := this.GetInt64("limit")
  9939. page, _ := this.GetInt64("page")
  9940. if page <= 0 {
  9941. page = 1
  9942. }
  9943. if limit <= 0 {
  9944. limit = 10
  9945. }
  9946. statistics_type, _ := this.GetInt64("statistics_type")
  9947. admin := this.GetAdminUserInfo()
  9948. timeLayout := "2006-01-02"
  9949. loc, _ := time.LoadLocation("Local")
  9950. var theStartTIme int64
  9951. if len(start_time) > 0 {
  9952. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9953. if err != nil {
  9954. theStartTIme = 0
  9955. }
  9956. theStartTIme = theTime.Unix()
  9957. }
  9958. var theEndtTIme int64
  9959. if len(end_time) > 0 {
  9960. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9961. if err != nil {
  9962. theEndtTIme = 0
  9963. }
  9964. theEndtTIme = theTime.Unix()
  9965. }
  9966. if statistics_type == 1 {
  9967. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9968. this.ServeSuccessJSON(map[string]interface{}{
  9969. "list": list,
  9970. "total": total,
  9971. })
  9972. } else {
  9973. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9974. this.ServeSuccessJSON(map[string]interface{}{
  9975. "list": list,
  9976. "total": total,
  9977. })
  9978. }
  9979. }
  9980. func (c *HisApiController) PostProjectInformation() {
  9981. adminUser := c.GetAdminUserInfo()
  9982. orgId := adminUser.CurrentOrgId
  9983. dataBody := make(map[string]interface{}, 0)
  9984. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9985. if err != nil {
  9986. utils.ErrorLog(err.Error())
  9987. return
  9988. }
  9989. utils.ErrorLog("%v", dataBody)
  9990. var projectList []*models.HisProject
  9991. var total_goods []interface{}
  9992. tempProjects := dataBody["projects"].([]interface{})
  9993. total_goods = tempProjects
  9994. for index, projectMap := range tempProjects {
  9995. projectM := projectMap.(map[string]interface{})
  9996. var project models.HisProject
  9997. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  9998. utils.ErrorLog("project_name")
  9999. return
  10000. }
  10001. project_name, _ := projectM["project_name"].(string)
  10002. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  10003. err_log := models.ExportErrLog{
  10004. LogType: 6,
  10005. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10006. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  10007. Status: 1,
  10008. CreateTime: time.Now().Unix(),
  10009. UpdateTime: time.Now().Unix(),
  10010. ExportTime: time.Now().Unix(),
  10011. }
  10012. service.CreateExportErrLog(&err_log)
  10013. continue
  10014. }
  10015. project.ProjectName = project_name
  10016. prices := projectM["price"].(string)
  10017. price, _ := strconv.ParseFloat(prices, 64)
  10018. if price <= 0 { //名字为空则生成一条导入错误日志
  10019. err_log := models.ExportErrLog{
  10020. LogType: 6,
  10021. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10022. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10023. Status: 1,
  10024. CreateTime: time.Now().Unix(),
  10025. UpdateTime: time.Now().Unix(),
  10026. ExportTime: time.Now().Unix(),
  10027. }
  10028. service.CreateExportErrLog(&err_log)
  10029. continue
  10030. }
  10031. project.Price = price
  10032. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10033. utils.ErrorLog("unit_id")
  10034. return
  10035. }
  10036. unit := projectM["unit"].(string)
  10037. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10038. err_log := models.ExportErrLog{
  10039. LogType: 6,
  10040. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10041. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10042. Status: 1,
  10043. CreateTime: time.Now().Unix(),
  10044. UpdateTime: time.Now().Unix(),
  10045. ExportTime: time.Now().Unix(),
  10046. }
  10047. service.CreateExportErrLog(&err_log)
  10048. continue
  10049. }
  10050. project.Unit = unit
  10051. cost_classify := projectM["cost_classify"].(string)
  10052. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10053. err_log := models.ExportErrLog{
  10054. LogType: 6,
  10055. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10056. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10057. Status: 1,
  10058. CreateTime: time.Now().Unix(),
  10059. UpdateTime: time.Now().Unix(),
  10060. ExportTime: time.Now().Unix(),
  10061. }
  10062. service.CreateExportErrLog(&err_log)
  10063. continue
  10064. }
  10065. var costClassify = "费用类别"
  10066. var cost_classify_id int64
  10067. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10068. if len(cost_classify) != 0 {
  10069. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10070. if errcode == gorm.ErrRecordNotFound {
  10071. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10072. dataconfig := models.DictDataconfig{
  10073. ParentId: costClassifyConfig.ID,
  10074. Module: "system",
  10075. OrgId: orgId,
  10076. Name: cost_classify,
  10077. FieldName: "",
  10078. Value: costConfig.Value + 1,
  10079. CreatedTime: "",
  10080. UpdatedTime: "",
  10081. CreateUserId: adminUser.AdminUser.Id,
  10082. Status: 1,
  10083. Remark: "",
  10084. DeleteIdSystem: 0,
  10085. Title: "",
  10086. Content: "",
  10087. Order: 0,
  10088. Code: "",
  10089. }
  10090. service.CreatedDicConfig(&dataconfig)
  10091. }
  10092. }
  10093. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10094. for _, it := range costClassList {
  10095. if cost_classify == it.Name {
  10096. cost_classify_id = int64(it.Value)
  10097. }
  10098. }
  10099. project.CostClassify = cost_classify_id
  10100. executive_section := projectM["executive_section"].(string)
  10101. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10102. err_log := models.ExportErrLog{
  10103. LogType: 6,
  10104. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10105. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10106. Status: 1,
  10107. CreateTime: time.Now().Unix(),
  10108. UpdateTime: time.Now().Unix(),
  10109. ExportTime: time.Now().Unix(),
  10110. }
  10111. service.CreateExportErrLog(&err_log)
  10112. continue
  10113. }
  10114. if len(executive_section) != 0 {
  10115. //查找科室是否有内容
  10116. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10117. if errcodedepart == gorm.ErrRecordNotFound {
  10118. department := models.XtHisDepartment{
  10119. Name: executive_section,
  10120. Status: 1,
  10121. UserOrgId: adminUser.CurrentOrgId,
  10122. CreatedTime: time.Now().Unix(),
  10123. }
  10124. service.CreateDePartment(&department)
  10125. }
  10126. }
  10127. var executive_section_id int64
  10128. departMentList, _ := service.GetAllDepartMent(orgId)
  10129. for _, it := range departMentList {
  10130. if executive_section == it.Name {
  10131. executive_section_id = it.ID
  10132. }
  10133. }
  10134. project.ExecutiveSection = executive_section_id
  10135. medical_coverage := projectM["medical_coverage"].(string)
  10136. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10137. err_log := models.ExportErrLog{
  10138. LogType: 6,
  10139. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10140. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10141. Status: 1,
  10142. CreateTime: time.Now().Unix(),
  10143. UpdateTime: time.Now().Unix(),
  10144. ExportTime: time.Now().Unix(),
  10145. }
  10146. service.CreateExportErrLog(&err_log)
  10147. continue
  10148. }
  10149. var medicalCoverage = "医保等级"
  10150. var medical_coverage_id int64
  10151. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10152. if len(medical_coverage) != 0 {
  10153. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10154. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10155. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10156. dataconfig := models.DictDataconfig{
  10157. ParentId: medicalCoverageConfig.ID,
  10158. Module: "system",
  10159. OrgId: orgId,
  10160. Name: medical_coverage,
  10161. FieldName: "",
  10162. Value: medicalCoverageConfig.Value + 1,
  10163. CreatedTime: "",
  10164. UpdatedTime: "",
  10165. CreateUserId: adminUser.AdminUser.Id,
  10166. Status: 1,
  10167. Remark: "",
  10168. DeleteIdSystem: 0,
  10169. Title: "",
  10170. Content: "",
  10171. Order: 0,
  10172. Code: "",
  10173. }
  10174. service.CreatedDicConfig(&dataconfig)
  10175. }
  10176. }
  10177. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10178. for _, it := range medicalCoverageList {
  10179. if medical_coverage == it.Name {
  10180. medical_coverage_id = int64(it.Value)
  10181. }
  10182. }
  10183. project.MedicalCoverage = medical_coverage_id
  10184. pinyin := projectM["pinyin"].(string)
  10185. project.Pinyin = pinyin
  10186. wubi := projectM["wubi"].(string)
  10187. project.Wubi = wubi
  10188. statistical_classification := projectM["statistical_classification"].(string)
  10189. var statisticalClassification = "统计分类"
  10190. var statistical_classification_id int64
  10191. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10192. if len(statistical_classification) != 0 {
  10193. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10194. if classificationerrcodes == gorm.ErrRecordNotFound {
  10195. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10196. dataconfig := models.DictDataconfig{
  10197. ParentId: classiFication.ID,
  10198. Module: "system",
  10199. OrgId: orgId,
  10200. Name: statistical_classification,
  10201. FieldName: "",
  10202. Value: classiFicationConfig.Value + 1,
  10203. CreatedTime: "",
  10204. UpdatedTime: "",
  10205. CreateUserId: adminUser.AdminUser.Id,
  10206. Status: 1,
  10207. Remark: "",
  10208. DeleteIdSystem: 0,
  10209. Title: "",
  10210. Content: "",
  10211. Order: 0,
  10212. Code: "",
  10213. }
  10214. service.CreatedDicConfig(&dataconfig)
  10215. }
  10216. }
  10217. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10218. for _, it := range classiFicationList {
  10219. if statistical_classification == it.Name {
  10220. statistical_classification_id = int64(it.Value)
  10221. }
  10222. }
  10223. project.StatisticalClassification = statistical_classification_id
  10224. disease_directory := int64(projectM["disease_directory"].(float64))
  10225. project.DiseaseDirectory = disease_directory
  10226. is_record := int64(projectM["is_record"].(float64))
  10227. project.IsRecord = is_record
  10228. medical_code := projectM["medical_code"].(string)
  10229. project.MedicalCode = medical_code
  10230. tube_color := projectM["tube_color"].(string)
  10231. var tubeColor = "试管颜色"
  10232. var tube_color_id int64
  10233. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10234. if len(tube_color) != 0 {
  10235. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10236. if errcodetube == gorm.ErrRecordNotFound {
  10237. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10238. dataconfig := models.DictDataconfig{
  10239. ParentId: tubeColorConfig.ID,
  10240. Module: "system",
  10241. OrgId: orgId,
  10242. Name: tube_color,
  10243. FieldName: "",
  10244. Value: tubeConfig.Value + 1,
  10245. CreatedTime: "",
  10246. UpdatedTime: "",
  10247. CreateUserId: adminUser.AdminUser.Id,
  10248. Status: 1,
  10249. Remark: "",
  10250. DeleteIdSystem: 0,
  10251. Title: "",
  10252. Content: "",
  10253. Order: 0,
  10254. Code: "",
  10255. }
  10256. service.CreatedDicConfig(&dataconfig)
  10257. }
  10258. }
  10259. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10260. for _, it := range tubeColorList {
  10261. if tube_color == it.Name {
  10262. tube_color_id = int64(it.Value)
  10263. }
  10264. }
  10265. project.TubeColor = tube_color_id
  10266. single_dose := projectM["single_dose"].(string)
  10267. project.SingleDose = single_dose
  10268. execution_frequency := projectM["execution_frequency"].(string)
  10269. project.ExecutionFrequency = execution_frequency
  10270. delivery_way := projectM["delivery_way"].(string)
  10271. project.DeliveryWay = delivery_way
  10272. number_days := projectM["number_days"].(string)
  10273. project.NumberDays = number_days
  10274. total := projectM["total"].(string)
  10275. project.Total = total
  10276. medical_status := int64(projectM["medical_status"].(float64))
  10277. project.MedicalStatus = medical_status
  10278. category := int64(projectM["category"].(float64))
  10279. project.Category = category
  10280. specail_project := int64(projectM["specail_project"].(float64))
  10281. project.SpecailProject = specail_project
  10282. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10283. project.SocialSecurityDirectoryCode = social_security_directory_code
  10284. remark := projectM["remark"].(string)
  10285. project.Remark = remark
  10286. record_date := projectM["record_date"].(string)
  10287. timeLayout := "2006-01-02"
  10288. loc, _ := time.LoadLocation("Local")
  10289. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10290. project.RecordDate = theTime.Unix()
  10291. projectList = append(projectList, &project)
  10292. }
  10293. export_time := time.Now().Unix()
  10294. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  10295. if len(projectList) > 0 {
  10296. for _, item := range projectList {
  10297. hans := item.ProjectName // 要转换的汉字字符串
  10298. // 创建一个拼音转换器
  10299. p := pinyin.NewArgs()
  10300. // 将汉字转为拼音
  10301. pinyinSlice := pinyin.Pinyin(hans, p)
  10302. // 输出拼音
  10303. fmt.Println("Pinyin:", pinyinSlice)
  10304. // 获取首字母
  10305. firstLetter := ""
  10306. for _, py := range pinyinSlice {
  10307. if len(py) > 0 {
  10308. firstLetter += string(py[0][0])
  10309. }
  10310. }
  10311. item.FirstLetter = firstLetter
  10312. project := models.HisProject{
  10313. ProjectName: item.ProjectName,
  10314. Price: item.Price,
  10315. Unit: item.Unit,
  10316. CostClassify: item.CostClassify,
  10317. ExecutiveSection: item.ExecutiveSection,
  10318. MedicalCoverage: item.MedicalCoverage,
  10319. UserOrgId: orgId,
  10320. Status: 1,
  10321. CreatedTime: time.Now().Unix(),
  10322. Pinyin: item.Pinyin,
  10323. Wubi: item.Wubi,
  10324. StatisticalClassification: item.StatisticalClassification,
  10325. DiseaseDirectory: item.DiseaseDirectory,
  10326. IsRecord: item.IsRecord,
  10327. MedicalCode: item.MedicalCode,
  10328. TubeColor: item.TubeColor,
  10329. SingleDose: item.SingleDose,
  10330. DeliveryWay: item.DeliveryWay,
  10331. NumberDays: item.NumberDays,
  10332. Total: item.Total,
  10333. Category: item.Category,
  10334. MedicalStatus: item.MedicalStatus,
  10335. SpecailProject: item.SpecailProject,
  10336. RecordDate: item.RecordDate,
  10337. Remark: item.Remark,
  10338. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10339. ExecutionFrequency: item.ExecutionFrequency,
  10340. FirstLetter: item.FirstLetter,
  10341. }
  10342. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10343. if errcodeproject == gorm.ErrRecordNotFound {
  10344. service.CreateProjectInfomation(&project)
  10345. } else if errcodeproject == nil {
  10346. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10347. }
  10348. log := models.ExportLog{
  10349. LogType: 6,
  10350. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10351. TotalNum: int64(len(total_goods)),
  10352. FailNum: int64(len(errLogs)),
  10353. SuccessNum: int64(len(projectList)),
  10354. CreateTime: time.Now().Unix(),
  10355. UpdateTime: time.Now().Unix(),
  10356. ExportTime: export_time,
  10357. Status: 1,
  10358. }
  10359. service.CreateExportLog(&log)
  10360. c.ServeSuccessJSON(map[string]interface{}{
  10361. "msg": "导入成功",
  10362. "total_num": len(total_goods),
  10363. "success_num": len(projectList),
  10364. "fail_num": int64(len(errLogs)),
  10365. })
  10366. }
  10367. } else {
  10368. log := models.ExportLog{
  10369. LogType: 6,
  10370. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10371. TotalNum: int64(len(total_goods)),
  10372. FailNum: int64(len(errLogs)),
  10373. SuccessNum: int64(len(projectList)),
  10374. CreateTime: time.Now().Unix(),
  10375. UpdateTime: time.Now().Unix(),
  10376. ExportTime: export_time,
  10377. Status: 1,
  10378. }
  10379. service.CreateExportLog(&log)
  10380. c.ServeSuccessJSON(map[string]interface{}{
  10381. "msg": "导入成功",
  10382. "total_num": len(total_goods),
  10383. "success_num": len(projectList),
  10384. "fail_num": int64(len(errLogs)),
  10385. })
  10386. }
  10387. }
  10388. //func (this *HisApiController) EditProjectInformation(){
  10389. //
  10390. // id, _ := this.GetInt64("id")
  10391. // project_team := this.GetString("project_team")
  10392. // price := this.GetString("price")
  10393. // price_float, _ := strconv.ParseFloat(price, 64)
  10394. // pinyin := this.GetString("pinyin")
  10395. // wubi := this.GetString("wubi")
  10396. // tube_color, _ := this.GetInt64("tube_color")
  10397. // team_type, _ := this.GetInt64("team_type")
  10398. // remark := this.GetString("remark")
  10399. // ids := this.GetString("ids")
  10400. // item_id := this.GetString("item_id")
  10401. // projectTeam := models.XtHisProjectTeam{
  10402. // ProjectTeam: project_team,
  10403. // Price: price_float,
  10404. // Pinyin: pinyin,
  10405. // Wubi: wubi,
  10406. // TubeColor: tube_color,
  10407. // TeamType: team_type,
  10408. // Remark: remark,
  10409. // ProjectId: ids,
  10410. // ItemId: item_id,
  10411. // }
  10412. //
  10413. //
  10414. // dataBody := make(map[string]interface{}, 0)
  10415. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10416. // if err != nil {
  10417. // utils.ErrorLog(err.Error())
  10418. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10419. // return
  10420. // }
  10421. //
  10422. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10423. //
  10424. //
  10425. // if err != nil {
  10426. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10427. // return
  10428. // }
  10429. //
  10430. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10431. // infos, _ := dataBody["info"].([]interface{})
  10432. // if len(infos) > 0 {
  10433. // var ids []string
  10434. //
  10435. // for _, item := range infos {
  10436. // items := item.(map[string]interface{})
  10437. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10438. // utils.ErrorLog("id")
  10439. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10440. // return
  10441. // }
  10442. // id := int64(items["id"].(float64))
  10443. //
  10444. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10445. // utils.ErrorLog("type")
  10446. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10447. // return
  10448. // }
  10449. // types := int64(items["type"].(float64))
  10450. //
  10451. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10452. // utils.ErrorLog("number")
  10453. // }
  10454. //
  10455. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10456. //
  10457. // projectList := models.XtHisProjectList{
  10458. // Number: number,
  10459. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10460. // ProjectId: id,
  10461. // Status: 1,
  10462. // CreatedTime: time.Now().Unix(),
  10463. // UpdatedTime: time.Now().Unix(),
  10464. // TeamId: projectTeam.ID,
  10465. // Type: types,
  10466. // }
  10467. // list := projectList
  10468. //
  10469. // service.CreateProjectList(&list)
  10470. //
  10471. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10472. //
  10473. // }
  10474. // ids_str := strings.Join(ids, ",")
  10475. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10476. // service.SaveProjectTeam(&projectTeam)
  10477. // this.ServeSuccessJSON(map[string]interface{}{
  10478. // "projectTeam": projectTeam,
  10479. // })
  10480. // }
  10481. // }
  10482. //}
  10483. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10484. name := c.GetString("name")
  10485. mode_id, _ := c.GetInt64("mode", 0)
  10486. types, _ := c.GetInt64("type", 0)
  10487. patient_id, _ := c.GetInt64("patient_id", 0)
  10488. types = 1
  10489. adminInfo := c.GetAdminUserInfo()
  10490. template := &models.HisPrescriptionTemplate{
  10491. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10492. PatientId: patient_id,
  10493. Type: types,
  10494. Status: 1,
  10495. Ctime: time.Now().Unix(),
  10496. Mtime: time.Now().Unix(),
  10497. Name: name,
  10498. Mode: mode_id,
  10499. }
  10500. dataBody := make(map[string]interface{}, 0)
  10501. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10502. if err != nil {
  10503. utils.ErrorLog(err.Error())
  10504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10505. return
  10506. }
  10507. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10508. //如果已经存在记录则删除处方
  10509. if template_one.ID > 0 {
  10510. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10511. var ids []int64
  10512. var org_id int64
  10513. for _, item := range ps {
  10514. org_id = c.GetAdminUserInfo().CurrentOrgId
  10515. ids = append(ids, item.ID)
  10516. }
  10517. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10518. if err2 == nil {
  10519. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10520. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10521. if len(prescriptions) > 0 {
  10522. for _, item := range prescriptions {
  10523. items := item.(map[string]interface{})
  10524. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10525. utils.ErrorLog("type")
  10526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10527. return
  10528. }
  10529. types := int64(items["type"].(float64))
  10530. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10531. utils.ErrorLog("med_type")
  10532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10533. return
  10534. }
  10535. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10536. ctime := time.Now().Unix()
  10537. prescription := &models.HisPrescriptionInfoTemplate{
  10538. PatientId: patient_id,
  10539. UserOrgId: adminInfo.CurrentOrgId,
  10540. Ctime: ctime,
  10541. Mtime: ctime,
  10542. Type: types,
  10543. Modifier: adminInfo.AdminUser.Id,
  10544. Creator: adminInfo.AdminUser.Id,
  10545. Status: 1,
  10546. PTemplateId: template_one.ID,
  10547. MedType: med_type,
  10548. }
  10549. service.CreateHisPrescriptionInfoTemplate(prescription)
  10550. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10551. advices := items["advices"].([]interface{})
  10552. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10553. ctime := time.Now().Unix()
  10554. mtime := ctime
  10555. if len(advices) > 0 {
  10556. for _, advice := range advices {
  10557. var s models.HisPrescriptionAdviceTemplate
  10558. s.PrescriptionId = prescription.ID
  10559. s.AdviceType = 2
  10560. s.StopState = 2
  10561. s.ExecutionState = 2
  10562. s.Status = 1
  10563. s.UserOrgId = adminInfo.CurrentOrgId
  10564. s.CreatedTime = ctime
  10565. s.UpdatedTime = mtime
  10566. s.PatientId = patient_id
  10567. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10568. if errcode > 0 {
  10569. c.ServeFailJSONWithSGJErrorCode(errcode)
  10570. return
  10571. }
  10572. service.CreateHisPrescriptionAdviceTemplate(&s)
  10573. }
  10574. }
  10575. }
  10576. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10577. projects := items["project"].([]interface{})
  10578. if len(projects) > 0 {
  10579. for _, project := range projects {
  10580. var p models.HisPrescriptionProjectTemplate
  10581. p.PrescriptionId = prescription.ID
  10582. p.Ctime = time.Now().Unix()
  10583. p.Mtime = time.Now().Unix()
  10584. p.PatientId = patient_id
  10585. p.UserOrgId = adminInfo.CurrentOrgId
  10586. p.Status = 1
  10587. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10588. if errcode > 0 {
  10589. c.ServeFailJSONWithSGJErrorCode(errcode)
  10590. return
  10591. }
  10592. service.CreateHisPrescriptionProjectTemplate(&p)
  10593. }
  10594. }
  10595. }
  10596. }
  10597. c.ServeSuccessJSON(map[string]interface{}{
  10598. "msg": "创建成功",
  10599. })
  10600. }
  10601. }
  10602. } else {
  10603. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10604. return
  10605. }
  10606. } else {
  10607. err3 := service.CreateHisPrescriptionTemplate(template)
  10608. if err3 == nil {
  10609. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10610. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10611. if len(prescriptions) > 0 {
  10612. for _, item := range prescriptions {
  10613. items := item.(map[string]interface{})
  10614. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10615. utils.ErrorLog("type")
  10616. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10617. return
  10618. }
  10619. types := int64(items["type"].(float64))
  10620. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10621. utils.ErrorLog("med_type")
  10622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10623. return
  10624. }
  10625. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10626. ctime := time.Now().Unix()
  10627. prescription := &models.HisPrescriptionInfoTemplate{
  10628. PatientId: patient_id,
  10629. UserOrgId: adminInfo.CurrentOrgId,
  10630. Ctime: ctime,
  10631. Mtime: ctime,
  10632. Type: types,
  10633. Modifier: adminInfo.AdminUser.Id,
  10634. Creator: adminInfo.AdminUser.Id,
  10635. Status: 1,
  10636. PTemplateId: template.ID,
  10637. MedType: med_type,
  10638. }
  10639. service.CreateHisPrescriptionInfoTemplate(prescription)
  10640. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10641. advices := items["advices"].([]interface{})
  10642. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10643. ctime := time.Now().Unix()
  10644. mtime := ctime
  10645. if len(advices) > 0 {
  10646. for _, advice := range advices {
  10647. var s models.HisPrescriptionAdviceTemplate
  10648. s.PrescriptionId = prescription.ID
  10649. s.AdviceType = 2
  10650. s.StopState = 2
  10651. s.ExecutionState = 2
  10652. s.Status = 1
  10653. s.UserOrgId = adminInfo.CurrentOrgId
  10654. s.CreatedTime = ctime
  10655. s.UpdatedTime = mtime
  10656. s.PatientId = patient_id
  10657. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10658. if errcode > 0 {
  10659. c.ServeFailJSONWithSGJErrorCode(errcode)
  10660. return
  10661. }
  10662. service.CreateHisPrescriptionAdviceTemplate(&s)
  10663. }
  10664. }
  10665. }
  10666. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10667. projects := items["project"].([]interface{})
  10668. if len(projects) > 0 {
  10669. for _, project := range projects {
  10670. var p models.HisPrescriptionProjectTemplate
  10671. p.PrescriptionId = prescription.ID
  10672. p.Ctime = time.Now().Unix()
  10673. p.Mtime = time.Now().Unix()
  10674. p.PatientId = patient_id
  10675. p.UserOrgId = adminInfo.CurrentOrgId
  10676. p.Status = 1
  10677. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10678. if errcode > 0 {
  10679. c.ServeFailJSONWithSGJErrorCode(errcode)
  10680. return
  10681. }
  10682. service.CreateHisPrescriptionProjectTemplate(&p)
  10683. }
  10684. }
  10685. }
  10686. }
  10687. c.ServeSuccessJSON(map[string]interface{}{
  10688. "msg": "创建成功",
  10689. })
  10690. }
  10691. }
  10692. } else {
  10693. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10694. return
  10695. }
  10696. }
  10697. }
  10698. func (c *HisApiController) PreSettle() {
  10699. id, _ := c.GetInt64("id")
  10700. record_time := c.GetString("record_time")
  10701. his_patient_id, _ := c.GetInt64("his_patient_id")
  10702. timeLayout := "2006-01-02"
  10703. loc, _ := time.LoadLocation("Local")
  10704. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10705. diagnosis_id := c.GetString("diagnosis")
  10706. sick_type, _ := c.GetInt64("sick_type")
  10707. reg_type, _ := c.GetInt64("p_type")
  10708. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10709. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10710. if err != nil {
  10711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10712. return
  10713. }
  10714. recordDateTime := theTime.Unix()
  10715. adminUser := c.GetAdminUserInfo()
  10716. var prescriptions []*models.HisPrescription
  10717. var start_time int64
  10718. var end_time int64
  10719. ids_str := c.GetString("ids")
  10720. ids_arr := strings.Split(ids_str, ",")
  10721. fmt.Println(reg_type)
  10722. if settle_accounts_type == 1 { //日结
  10723. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10724. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10725. } else {
  10726. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10727. }
  10728. fmt.Println(prescriptions)
  10729. } else { //月结
  10730. start_time_str := c.GetString("start_time")
  10731. end_time_str := c.GetString("end_time")
  10732. timeLayout := "2006-01-02"
  10733. loc, _ := time.LoadLocation("Local")
  10734. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10735. if err != nil {
  10736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10737. return
  10738. }
  10739. recordStartTime := theStartTime.Unix()
  10740. start_time = recordStartTime
  10741. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10742. if err != nil {
  10743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10744. return
  10745. }
  10746. recordEndTime := theEndTime.Unix()
  10747. end_time = recordEndTime
  10748. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10749. }
  10750. if reg_type == 1111 || reg_type == 1112 {
  10751. reg_type = 11
  10752. }
  10753. timestamp := time.Now().Unix()
  10754. tempTime := time.Unix(timestamp, 0)
  10755. timeFormat := tempTime.Format("20060102150405")
  10756. chrgBchno := rand.Intn(100000) + 10000
  10757. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10758. strconv.FormatInt(his.PatientId, 10)
  10759. var ids []int64
  10760. for _, item := range prescriptions {
  10761. ids = append(ids, item.ID)
  10762. }
  10763. fmt.Println(ids)
  10764. var total float64
  10765. for _, item := range prescriptions {
  10766. fmt.Println(item)
  10767. if item.Type == 1 { //药品
  10768. for _, subItem := range item.HisDoctorAdviceInfo {
  10769. total = total + (subItem.Price * subItem.PrescribingNumber)
  10770. }
  10771. }
  10772. if item.Type == 2 { //项目
  10773. for _, subItem := range item.HisPrescriptionProject {
  10774. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10775. total = total + (subItem.Price * cnt)
  10776. }
  10777. }
  10778. for _, subItem := range item.HisAdditionalCharge {
  10779. total = total + (subItem.Price * float64(subItem.Count))
  10780. }
  10781. }
  10782. allTotal := fmt.Sprintf("%.2f", total)
  10783. totals, _ := strconv.ParseFloat(allTotal, 64)
  10784. order := &models.HisOrder{
  10785. UserOrgId: adminUser.CurrentOrgId,
  10786. HisPatientId: his.ID,
  10787. PatientId: id,
  10788. SettleAccountsDate: recordDateTime,
  10789. Ctime: time.Now().Unix(),
  10790. Mtime: time.Now().Unix(),
  10791. Status: 1,
  10792. OrderStatus: 1,
  10793. MdtrtId: his.Number,
  10794. Number: chrg_bchno,
  10795. MedfeeSumamt: totals,
  10796. SettleEndTime: end_time,
  10797. SettleStartTime: start_time,
  10798. SettleType: settle_accounts_type,
  10799. PsnPartAmt: totals,
  10800. PsnCashPay: totals,
  10801. PType: 2,
  10802. IsPre: 1,
  10803. MedType: strconv.Itoa(int(reg_type)),
  10804. Diagnosis: diagnosis_id,
  10805. }
  10806. err = service.CreateOrder(order)
  10807. if err != nil {
  10808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10809. return
  10810. }
  10811. var customs []*Custom
  10812. for _, item := range prescriptions {
  10813. fmt.Println(item.Type)
  10814. if item.Type == 1 { //药品
  10815. for _, subItem := range item.HisDoctorAdviceInfo {
  10816. cus := &Custom{
  10817. AdviceId: subItem.ID,
  10818. ProjectId: 0,
  10819. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10820. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10821. FeedetlSn: subItem.FeedetlSn,
  10822. Price: fmt.Sprintf("%.2f", subItem.Price),
  10823. MedListCodg: subItem.MedListCodg,
  10824. Type: 1,
  10825. }
  10826. customs = append(customs, cus)
  10827. }
  10828. }
  10829. if item.Type == 2 { //项目
  10830. for _, subItem := range item.HisPrescriptionProject {
  10831. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10832. cus := &Custom{
  10833. AdviceId: 0,
  10834. ProjectId: subItem.ID,
  10835. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10836. Cut: fmt.Sprintf("%.2f", cnt),
  10837. FeedetlSn: subItem.FeedetlSn,
  10838. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10839. MedListCodg: subItem.MedListCodg,
  10840. Type: 2,
  10841. }
  10842. customs = append(customs, cus)
  10843. }
  10844. }
  10845. for _, item := range item.HisAdditionalCharge {
  10846. cus := &Custom{
  10847. ItemId: item.ID,
  10848. AdviceId: 0,
  10849. ProjectId: 0,
  10850. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10851. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10852. FeedetlSn: item.FeedetlSn,
  10853. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10854. MedListCodg: item.XtHisAddtionConfig.Code,
  10855. Type: 3,
  10856. }
  10857. customs = append(customs, cus)
  10858. }
  10859. }
  10860. fmt.Println(customs)
  10861. for _, item := range customs {
  10862. var advice_id int64 = 0
  10863. var project_id int64 = 0
  10864. var item_id int64 = 0
  10865. var types int64 = 0
  10866. if item.Type == 1 {
  10867. advice_id = item.AdviceId
  10868. project_id = 0
  10869. item_id = 0
  10870. } else if item.Type == 2 {
  10871. advice_id = 0
  10872. item_id = 0
  10873. project_id = item.ProjectId
  10874. } else if item.Type == 3 {
  10875. advice_id = 0
  10876. item_id = item.ItemId
  10877. project_id = 0
  10878. }
  10879. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10880. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10881. pric, _ := strconv.ParseFloat(item.Price, 32)
  10882. info := &models.HisOrderInfo{
  10883. OrderNumber: order.Number,
  10884. UploadDate: time.Now().Unix(),
  10885. AdviceId: advice_id,
  10886. DetItemFeeSumamt: detItemFeeSumamt,
  10887. Cnt: cut,
  10888. Pric: pric,
  10889. PatientId: id,
  10890. Status: 1,
  10891. Mtime: time.Now().Unix(),
  10892. Ctime: time.Now().Unix(),
  10893. UserOrgId: adminUser.CurrentOrgId,
  10894. HisPatientId: his.ID,
  10895. OrderId: order.ID,
  10896. ProjectId: project_id,
  10897. Type: types,
  10898. ItemId: item_id,
  10899. }
  10900. service.CreateOrderInfo(info)
  10901. }
  10902. his.SickType = sick_type
  10903. service.UpdataHisPateint(&his)
  10904. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  10905. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  10906. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  10907. if err == nil {
  10908. c.ServeSuccessJSON(map[string]interface{}{
  10909. "msg": "结算成功",
  10910. })
  10911. }
  10912. }
  10913. type CustomOrderInfo struct {
  10914. Name string
  10915. Spec string
  10916. Unit string
  10917. Count float64
  10918. Price float64
  10919. Total float64
  10920. }
  10921. func (c *HisApiController) GetPrivateExpensesInfo() {
  10922. order_id, _ := c.GetInt64("id", 0)
  10923. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  10924. order, _ := service.GetHisOrderByID(order_id)
  10925. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  10926. if order.ID == 0 {
  10927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10928. return
  10929. }
  10930. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  10931. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10932. org_id := c.GetAdminUserInfo().CurrentOrgId
  10933. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10934. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10935. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  10936. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  10937. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  10938. //var orderInfos_four []*models.HisOrderInfoTwo
  10939. //for _, item := range orderInfos_three {
  10940. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  10941. // item.HisPrescriptionProject.IsCheckTeam = 1
  10942. // orderInfos_four = append(orderInfos_four, item)
  10943. //
  10944. // }
  10945. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  10946. // item.HisPrescriptionProject.IsCheckTeam = 2
  10947. // orderInfos_two = append(orderInfos_two, item)
  10948. // }
  10949. //}
  10950. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  10951. //var cus_slice []CustomOrderInfo
  10952. //for _, item := range new_order_info {
  10953. // var cus CustomOrderInfo
  10954. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  10955. // cus.Unit = ""
  10956. // cus.Spec = ""
  10957. // var total float64
  10958. // for _, subItem := range orderInfos_four {
  10959. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  10960. // total = total + subItem.DetItemFeeSumamt
  10961. // fmt.Println(subItem.DetItemFeeSumamt)
  10962. // }
  10963. // }
  10964. // cus.Count = 1
  10965. // cus.Total = total
  10966. // cus_slice = append(cus_slice, cus)
  10967. //}
  10968. orderInfos = append(orderInfos, orderInfos_two...)
  10969. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  10970. //orderInfos = append(orderInfos, orderInfos_three...)
  10971. //}/**/
  10972. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10973. c.ServeSuccessJSON(map[string]interface{}{
  10974. "order": order,
  10975. "order_info": orderInfos,
  10976. "patient": patient,
  10977. "admin_info": adminInfo,
  10978. "his": his,
  10979. "current_admin": role,
  10980. "org_config": miConfig,
  10981. //"new_order_info": cus_slice,
  10982. })
  10983. }
  10984. func (this *HisApiController) ChangeMedType() {
  10985. med_type := this.GetString("med_type")
  10986. old_med_type := this.GetString("old_med_type")
  10987. ids := this.GetString("ids")
  10988. settle_type, _ := this.GetInt64("settle_type")
  10989. start_time := this.GetString("start_time")
  10990. end_time := this.GetString("end_time")
  10991. ids_arr := strings.Split(ids, ",")
  10992. if settle_type == 1 { //日结
  10993. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  10994. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  10995. prescription.MedType = med_type
  10996. err := service.SaveHisPrescriptionTwo(&prescription)
  10997. if err == nil {
  10998. this.ServeSuccessJSON(map[string]interface{}{
  10999. "msg": "修改成功",
  11000. })
  11001. } else {
  11002. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11003. return
  11004. }
  11005. } else if settle_type == 2 {
  11006. timeLayout := "2006-01-02"
  11007. loc, _ := time.LoadLocation("Local")
  11008. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11009. if err != nil {
  11010. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11011. return
  11012. }
  11013. recordStartTime := theStartTime.Unix()
  11014. start_time_timestamp := recordStartTime
  11015. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  11016. if err != nil {
  11017. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11018. return
  11019. }
  11020. recordEndTime := theEndTime.Unix()
  11021. end_time_timestamp := recordEndTime
  11022. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11023. if updateErr == nil {
  11024. this.ServeSuccessJSON(map[string]interface{}{
  11025. "msg": "修改成功",
  11026. })
  11027. } else {
  11028. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11029. return
  11030. }
  11031. }
  11032. }
  11033. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11034. patient_id, _ := c.GetInt64("patient_id")
  11035. his_patient_id, _ := c.GetInt64("his_patient_id")
  11036. record_date := c.GetString("record_date")
  11037. start_time := c.GetString("start_time")
  11038. end_time := c.GetString("end_time")
  11039. order_status, _ := c.GetInt64("type", 0)
  11040. p_type, _ := c.GetInt64("p_type", 0)
  11041. order_id, _ := c.GetInt64("order_id", 0)
  11042. timeLayout := "2006-01-02"
  11043. loc, _ := time.LoadLocation("Local")
  11044. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11045. if err != nil {
  11046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11047. return
  11048. }
  11049. recordDateTime := theTime.Unix()
  11050. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11051. if err != nil {
  11052. }
  11053. startRecordDateTime := startTime.Unix()
  11054. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11055. if err != nil {
  11056. }
  11057. endRecordDateTime := endTime.Unix()
  11058. admin := c.GetAdminUserInfo()
  11059. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11060. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11061. order, _ := service.GetHisOrderByID(order_id)
  11062. var monthPrescriptions []*models.HisPrescription
  11063. if order_status == 1 || order_status == 0 {
  11064. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11065. } else if order_status == 2 {
  11066. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11067. }
  11068. var settle_total float64
  11069. for _, item := range monthPrescriptions {
  11070. if len(item.HisPrescriptionProject) > 0 {
  11071. for _, subItem := range item.HisPrescriptionProject {
  11072. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11073. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11074. settle_total = settle_total + total
  11075. }
  11076. }
  11077. if len(item.HisDoctorAdviceInfo) > 0 {
  11078. for _, subItem := range item.HisDoctorAdviceInfo {
  11079. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11080. settle_total = settle_total + total
  11081. }
  11082. }
  11083. }
  11084. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11085. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11086. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11087. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11088. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11089. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11090. //获取所有科室信息
  11091. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11092. var dia string
  11093. for _, item := range month_p_info {
  11094. if len(dia) == 0 {
  11095. dia = item.Diagnosis
  11096. } else {
  11097. dia = dia + "," + item.Diagnosis
  11098. }
  11099. }
  11100. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11101. dia_arr = removeEmptyStrings(dia_arr)
  11102. c.ServeSuccessJSON(map[string]interface{}{
  11103. "his_info": his_patient_info,
  11104. "xt_info": xt_patient_info,
  11105. "case_history": case_history,
  11106. "info": patientPrescriptionInfo,
  11107. "last_info": lastPatientPrescriptionInfo,
  11108. "month_prescriptions": monthPrescriptions,
  11109. "order": order,
  11110. "doctors": doctors,
  11111. "department": department,
  11112. "settle_total": settle_total,
  11113. "dia_arr": dia_arr,
  11114. })
  11115. return
  11116. }
  11117. func removeEmptyStrings(input []string) []string {
  11118. var output []string
  11119. for _, s := range input {
  11120. if s != "" {
  11121. output = append(output, s)
  11122. }
  11123. }
  11124. return output
  11125. }
  11126. func removeDuplicates(input []string) []string {
  11127. seen := make(map[string]bool)
  11128. output := []string{}
  11129. for _, s := range input {
  11130. if _, exists := seen[s]; !exists {
  11131. seen[s] = true
  11132. output = append(output, s)
  11133. }
  11134. }
  11135. return output
  11136. }
  11137. func (c *HisApiController) GetHisMonthPatientInfo() {
  11138. patient_id, _ := c.GetInt64("patient_id")
  11139. his_patient_id, _ := c.GetInt64("his_patient_id")
  11140. record_date := c.GetString("record_date")
  11141. number := c.GetString("number")
  11142. start_time := c.GetString("start_time")
  11143. end_time := c.GetString("end_time")
  11144. p_type, _ := c.GetInt64("p_type")
  11145. timeLayout := "2006-01-02"
  11146. loc, _ := time.LoadLocation("Local")
  11147. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11148. if err != nil {
  11149. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11150. return
  11151. }
  11152. recordDateTime := theTime.Unix()
  11153. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11154. if err != nil {
  11155. }
  11156. startRecordDateTime := startTime.Unix()
  11157. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11158. if err != nil {
  11159. }
  11160. endRecordDateTime := endTime.Unix()
  11161. admin := c.GetAdminUserInfo()
  11162. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11163. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11164. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11165. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11166. var settle_total float64
  11167. for _, item := range monthPrescriptions {
  11168. if len(item.HisPrescriptionProject) > 0 {
  11169. for _, subItem := range item.HisPrescriptionProject {
  11170. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11171. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11172. settle_total = settle_total + total
  11173. }
  11174. }
  11175. if len(item.HisDoctorAdviceInfo) > 0 {
  11176. for _, subItem := range item.HisDoctorAdviceInfo {
  11177. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11178. settle_total = settle_total + total
  11179. }
  11180. }
  11181. }
  11182. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11183. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11184. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11185. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11186. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11187. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11188. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11189. //获取所有科室信息
  11190. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11191. c.ServeSuccessJSON(map[string]interface{}{
  11192. "his_info": his_patient_info,
  11193. "xt_info": xt_patient_info,
  11194. "case_history": case_history,
  11195. "info": patientPrescriptionInfo,
  11196. "month_prescriptions": monthPrescriptions,
  11197. "order": order,
  11198. "doctors": doctors,
  11199. "department": department,
  11200. "count": count,
  11201. "drugStockConfig": drugStockConfig,
  11202. "last_info": lastPatientPrescriptionInfo,
  11203. "settle_total": settle_total,
  11204. })
  11205. return
  11206. }
  11207. func (c *HisApiController) GetAllOrder() {
  11208. org_id := c.GetAdminUserInfo().CurrentOrgId
  11209. orders, _ := service.GetNewHisOrderList(org_id)
  11210. c.ServeSuccessJSON(map[string]interface{}{
  11211. "order": orders,
  11212. })
  11213. return
  11214. }
  11215. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11216. newArr = make([]*models.HisOrderInfoTwo, 0)
  11217. for i := 0; i < len(arr); i++ {
  11218. repeat := false
  11219. for j := i + 1; j < len(arr); j++ {
  11220. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11221. repeat = true
  11222. break
  11223. }
  11224. }
  11225. if !repeat {
  11226. newArr = append(newArr, arr[i])
  11227. }
  11228. }
  11229. return
  11230. }
  11231. // 修改处方退库操作 参数传修改之前的处方数据
  11232. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11233. if advice.ExecutionState == 1 {
  11234. //查询该病人该药品是否有库存记录
  11235. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11236. if errcode == gorm.ErrRecordNotFound {
  11237. } else {
  11238. //退库
  11239. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11240. if advice.PrescribingNumberUnit == drug.MinUnit {
  11241. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11242. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11243. //退库
  11244. warehouseInfo := models.DrugWarehouseInfo{
  11245. StockMinNumber: prescribingNumber,
  11246. }
  11247. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11248. operation_time := time.Now().Unix()
  11249. creater := advice.AdviceDoctor
  11250. ctime := time.Now().Unix()
  11251. timeStr := time.Now().Format("2006-01-02")
  11252. timeArr := strings.Split(timeStr, "-")
  11253. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11254. total = total + 1
  11255. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11256. cancelStock := models.DrugCancelStock{
  11257. OrderNumber: orderNumber,
  11258. OperaTime: operation_time,
  11259. OrgId: advice.UserOrgId,
  11260. Creater: creater,
  11261. Ctime: ctime,
  11262. Status: 1,
  11263. ReturnTime: advice.AdviceDate,
  11264. Dealer: info.Dealer,
  11265. Manufacturer: info.Manufacturer,
  11266. Type: 1,
  11267. }
  11268. service.AddSigleDrugCancelStock(&cancelStock)
  11269. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11270. dealer, _ := service.GetDealerById(info.Dealer)
  11271. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11272. cancelStockInfo := models.DrugCancelStockInfo{
  11273. OrderNumber: cancelInfo.OrderNumber,
  11274. CancelStockId: cancelInfo.ID,
  11275. DrugId: info.DrugId,
  11276. Count: info.Count,
  11277. Status: 1,
  11278. Ctime: ctime,
  11279. OrgId: advice.UserOrgId,
  11280. Type: 1,
  11281. Manufacturer: manufactureName.ManufacturerName,
  11282. Dealer: dealer.DealerName,
  11283. Total: 0,
  11284. RetailPrice: info.RetailPrice,
  11285. RetailTotalPrice: info.RetailTotalPrice,
  11286. Price: info.Price,
  11287. RegisterAccount: "",
  11288. Remark: info.Remark,
  11289. BatchNumber: info.BatchNumber,
  11290. MaxUnit: info.CountUnit,
  11291. ProductDate: info.ProductDate,
  11292. ExpiryDate: info.ExpiryDate,
  11293. BatchNumberId: info.WarehouseInfoId,
  11294. }
  11295. flow := models.DrugFlow{
  11296. WarehousingId: 0,
  11297. DrugId: info.DrugId,
  11298. Number: "",
  11299. BatchNumber: info.BatchNumber,
  11300. Count: info.Count,
  11301. UserOrgId: advice.UserOrgId,
  11302. PatientId: 0,
  11303. SystemTime: ctime,
  11304. ConsumableType: 4,
  11305. IsSys: 0,
  11306. WarehousingOrder: "",
  11307. WarehouseOutId: 0,
  11308. WarehouseOutOrderNumber: "",
  11309. IsEdit: 0,
  11310. CancelStockId: cancelStock.ID,
  11311. CancelOrderNumber: cancelStock.OrderNumber,
  11312. Manufacturer: info.Manufacturer,
  11313. Dealer: info.Dealer,
  11314. Creator: advice.UserOrgId,
  11315. UpdateCreator: 0,
  11316. Status: 1,
  11317. Ctime: time.Now().Unix(),
  11318. Mtime: 0,
  11319. Price: info.Price,
  11320. WarehousingDetailId: 0,
  11321. WarehouseOutDetailId: 0,
  11322. CancelOutDetailId: 0,
  11323. ExpireDate: info.ExpiryDate,
  11324. ProductDate: info.ProductDate,
  11325. MaxUnit: info.CountUnit,
  11326. MinUnit: "",
  11327. }
  11328. service.CreatedCancelStock(cancelStockInfo)
  11329. service.CreateDrugFlowOne(flow)
  11330. } else {
  11331. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11332. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11333. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11334. warehouseInfo := models.DrugWarehouseInfo{
  11335. StockMinNumber: prescribingNumber,
  11336. }
  11337. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11338. }
  11339. operation_time := time.Now().Unix()
  11340. creater := advice.AdviceDoctor
  11341. ctime := time.Now().Unix()
  11342. timeStr := time.Now().Format("2006-01-02")
  11343. timeArr := strings.Split(timeStr, "-")
  11344. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11345. total = total + 1
  11346. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11347. cancelStock := models.DrugCancelStock{
  11348. OrderNumber: orderNumber,
  11349. OperaTime: operation_time,
  11350. OrgId: advice.UserOrgId,
  11351. Creater: creater,
  11352. Ctime: ctime,
  11353. Status: 1,
  11354. ReturnTime: advice.AdviceDate,
  11355. Dealer: info.Dealer,
  11356. Manufacturer: info.Manufacturer,
  11357. Type: 1,
  11358. }
  11359. service.AddSigleDrugCancelStock(&cancelStock)
  11360. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11361. dealer, _ := service.GetDealerById(info.Dealer)
  11362. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11363. cancelStockInfo := models.DrugCancelStockInfo{
  11364. OrderNumber: cancelInfo.OrderNumber,
  11365. CancelStockId: cancelInfo.ID,
  11366. DrugId: info.DrugId,
  11367. Count: info.Count,
  11368. Status: 1,
  11369. Ctime: ctime,
  11370. OrgId: advice.UserOrgId,
  11371. Type: 1,
  11372. Manufacturer: manufactureName.ManufacturerName,
  11373. Dealer: dealer.DealerName,
  11374. Total: 0,
  11375. RetailPrice: info.RetailPrice,
  11376. RetailTotalPrice: info.RetailTotalPrice,
  11377. Price: info.Price,
  11378. RegisterAccount: "",
  11379. Remark: info.Remark,
  11380. BatchNumber: info.BatchNumber,
  11381. MaxUnit: info.CountUnit,
  11382. ProductDate: info.ProductDate,
  11383. ExpiryDate: info.ExpiryDate,
  11384. BatchNumberId: info.WarehouseInfoId,
  11385. }
  11386. flow := models.DrugFlow{
  11387. WarehousingId: 0,
  11388. DrugId: info.DrugId,
  11389. Number: "",
  11390. BatchNumber: info.BatchNumber,
  11391. Count: info.Count,
  11392. UserOrgId: advice.UserOrgId,
  11393. PatientId: 0,
  11394. SystemTime: ctime,
  11395. ConsumableType: 4,
  11396. IsSys: 0,
  11397. WarehousingOrder: "",
  11398. WarehouseOutId: 0,
  11399. WarehouseOutOrderNumber: "",
  11400. IsEdit: 0,
  11401. CancelStockId: cancelStock.ID,
  11402. CancelOrderNumber: cancelStock.OrderNumber,
  11403. Manufacturer: info.Manufacturer,
  11404. Dealer: info.Dealer,
  11405. Creator: advice.AdviceDoctor,
  11406. UpdateCreator: 0,
  11407. Status: 1,
  11408. Ctime: time.Now().Unix(),
  11409. Mtime: 0,
  11410. Price: info.Price,
  11411. WarehousingDetailId: 0,
  11412. WarehouseOutDetailId: 0,
  11413. CancelOutDetailId: 0,
  11414. ExpireDate: info.ExpiryDate,
  11415. ProductDate: info.ProductDate,
  11416. MaxUnit: info.CountUnit,
  11417. MinUnit: "",
  11418. }
  11419. service.CreatedCancelStock(cancelStockInfo)
  11420. service.CreateDrugFlowOne(flow)
  11421. }
  11422. }
  11423. }
  11424. return err
  11425. }
  11426. func (this *HisApiController) DeleteNCDS() {
  11427. id, _ := this.GetInt64("id", 0)
  11428. if id > 0 {
  11429. service.DeletePsnNCDSRecordById(id)
  11430. this.ServeSuccessJSON(map[string]interface{}{
  11431. "msg": "删除成功",
  11432. })
  11433. } else {
  11434. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11435. return
  11436. }
  11437. }
  11438. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11439. id, _ := c.GetInt64("id")
  11440. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11441. c.ServeSuccessJSON(map[string]interface{}{
  11442. "advice": advice,
  11443. })
  11444. return
  11445. }
  11446. func (c *HisApiController) GetHisMonthChargePatientList() {
  11447. record_date := c.GetString("record_date")
  11448. start_time := c.GetString("start_time")
  11449. end_time := c.GetString("end_time")
  11450. timeLayout := "2006-01-02"
  11451. loc, _ := time.LoadLocation("Local")
  11452. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11453. if err != nil {
  11454. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11455. return
  11456. }
  11457. if err != nil {
  11458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11459. return
  11460. }
  11461. recordDateTime := theTime.Unix()
  11462. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11463. if err != nil {
  11464. }
  11465. startRecordDateTime := startTime.Unix()
  11466. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11467. if err != nil {
  11468. }
  11469. endRecordDateTime := endTime.Unix()
  11470. adminInfo := c.GetAdminUserInfo()
  11471. var tempMonthChargePatients []*service.MonthChargePatients
  11472. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11473. for _, item := range tempPatients {
  11474. //过滤没有处方的
  11475. if len(item.HisPrescription) == 0 {
  11476. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11477. }
  11478. }
  11479. c.ServeSuccessJSON(map[string]interface{}{
  11480. "list": tempMonthChargePatients,
  11481. })
  11482. }
  11483. // PrescriptionDifference 医嘱数量差值结构体
  11484. type PrescriptionDrugDifference struct {
  11485. DrugID int64 //基础库药品id
  11486. ID int64 //医嘱id
  11487. Difference float64 //差值
  11488. Unit string //单位
  11489. }
  11490. type PrescriptionGoodDifference struct {
  11491. GoodID int64 //基础库项目耗材id
  11492. ID int64 //医嘱id
  11493. Difference int64 //差值
  11494. Unit string //单位
  11495. Type int64 //类型
  11496. }
  11497. type EditCustomData struct {
  11498. adviceList []*models.HisDoctorAdviceInfo
  11499. projectList []*models.HisPrescriptionProject
  11500. }
  11501. type SrcCustomData struct {
  11502. adviceList []*models.HisDoctorAdviceInfo
  11503. projectList []*models.HisPrescriptionProject
  11504. }
  11505. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11506. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11507. differences := make([]*PrescriptionDrugDifference, 0)
  11508. // 创建一个 map 来存储第一个切片中的药品信息
  11509. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11510. for _, advice := range firstPrescription {
  11511. firstMap[advice.DrugId] = advice
  11512. }
  11513. // 遍历第二个切片中的药品信息,并比较数量差值
  11514. for _, advice := range secondPrescription {
  11515. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11516. diff := &PrescriptionDrugDifference{
  11517. DrugID: advice.DrugId,
  11518. ID: firstAdvice.ID,
  11519. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11520. Unit: firstAdvice.PrescribingNumberUnit,
  11521. }
  11522. differences = append(differences, diff)
  11523. }
  11524. }
  11525. return differences
  11526. }
  11527. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11528. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11529. differences := make([]*PrescriptionGoodDifference, 0)
  11530. // 创建一个 map 来存储第一个切片中的耗材信息
  11531. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11532. for _, good := range firstPrescription {
  11533. firstMap[good.ProjectId] = good
  11534. }
  11535. // 遍历第二个切片中的耗材信息,并比较数量差值
  11536. for _, good := range secondPrescription {
  11537. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11538. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11539. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11540. diff := &PrescriptionGoodDifference{
  11541. GoodID: good.ProjectId,
  11542. ID: firstGood.ID,
  11543. Difference: count - firstCount,
  11544. Unit: firstGood.Unit,
  11545. Type: firstGood.Type,
  11546. }
  11547. differences = append(differences, diff)
  11548. }
  11549. }
  11550. return differences
  11551. }
  11552. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11553. var adviceList []*models.HisDoctorAdviceInfo
  11554. var projectList []*models.HisPrescriptionProject
  11555. var advice_ids []int64
  11556. var project_ids []int64
  11557. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11558. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11559. //var tempPrescription *models.HisPrescriptionProjectscription
  11560. if len(prescriptions) > 0 {
  11561. for _, item := range prescriptions {
  11562. items := item.(map[string]interface{})
  11563. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11564. advices := items["advices"].([]interface{})
  11565. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11566. groupNo := int64(0)
  11567. ctime := time.Now().Unix()
  11568. mtime := ctime
  11569. if len(advices) > 0 {
  11570. for _, advice := range advices {
  11571. var s models.HisDoctorAdviceInfo
  11572. s.AdviceType = 2
  11573. s.StopState = 2
  11574. s.ExecutionState = 2
  11575. s.Status = 1
  11576. s.Groupno = groupNo
  11577. s.CreatedTime = ctime
  11578. s.UpdatedTime = mtime
  11579. s.IsSettle = 2
  11580. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11581. //存储切片中
  11582. if s.ID > 0 {
  11583. advice_ids = append(advice_ids, s.ID)
  11584. adviceList = append(adviceList, &s)
  11585. }
  11586. }
  11587. }
  11588. }
  11589. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11590. projects := items["project"].([]interface{})
  11591. if len(projects) > 0 {
  11592. for _, project := range projects {
  11593. var p models.HisPrescriptionProject
  11594. p.Ctime = time.Now().Unix()
  11595. p.Mtime = time.Now().Unix()
  11596. p.Status = 1
  11597. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11598. if p.ID > 0 {
  11599. project_ids = append(project_ids, p.ID)
  11600. projectList = append(projectList, &p)
  11601. }
  11602. }
  11603. }
  11604. }
  11605. }
  11606. }
  11607. }
  11608. editCustomData.projectList = projectList
  11609. editCustomData.adviceList = adviceList
  11610. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11611. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11612. srcCustomData.adviceList = list
  11613. srcCustomData.projectList = list2
  11614. return
  11615. }