his_api_controller.go 506KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015
  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 = time.Now().Unix()
  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. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3620. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3621. var tempPrescription *models.HisPrescription
  3622. if len(prescriptions) > 0 {
  3623. for _, item := range prescriptions {
  3624. items := item.(map[string]interface{})
  3625. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3626. utils.ErrorLog("id")
  3627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3628. return
  3629. }
  3630. id := int64(items["id"].(float64))
  3631. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3632. tempPrescription = &new_prescription
  3633. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3634. utils.ErrorLog("type")
  3635. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3636. return
  3637. }
  3638. types := int64(items["type"].(float64))
  3639. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3640. utils.ErrorLog("med_type")
  3641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3642. return
  3643. }
  3644. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3645. if med_type == "0" {
  3646. med_type = "14"
  3647. }
  3648. //if order_status == 0 {
  3649. // order_status = 1
  3650. //}
  3651. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3652. utils.ErrorLog("pre_time")
  3653. }
  3654. preTime, _ := items["pre_time"].(string)
  3655. timeLayout := "2006-01-02"
  3656. loc, _ := time.LoadLocation("Local")
  3657. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3658. result := strings.Split(preTime, " ")
  3659. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3660. fmt.Println("theTime30000000000000000000000", theTime3.Unix())
  3661. if err != nil {
  3662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3663. return
  3664. }
  3665. pTime := theTime2.Unix()
  3666. ctime := time.Now().Unix()
  3667. if tempPrescription.ID == 0 {
  3668. prescription := &models.HisPrescription{
  3669. ID: 0,
  3670. PatientId: patient_id,
  3671. UserOrgId: adminInfo.CurrentOrgId,
  3672. RecordDate: recordDateTime,
  3673. Ctime: ctime,
  3674. Mtime: ctime,
  3675. Type: types,
  3676. Modifier: adminInfo.AdminUser.Id,
  3677. Creator: adminInfo.AdminUser.Id,
  3678. Status: 1,
  3679. Doctor: role.UserName,
  3680. HisPatientId: his_patient_id,
  3681. OrderStatus: 1,
  3682. BatchNumber: "",
  3683. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3684. PreTime: pTime,
  3685. PType: p_type,
  3686. MedType: med_type,
  3687. }
  3688. tempPrescription = prescription
  3689. service.SaveHisPrescription(tempPrescription)
  3690. redis := service.RedisClient()
  3691. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3692. redis.Set(key, "", time.Second)
  3693. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3694. redis.Set(keyOne, "", time.Second)
  3695. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3696. redis.Set(keySeven, "", time.Second)
  3697. defer redis.Close()
  3698. } else {
  3699. tempPrescription.ID = id
  3700. tempPrescription.Type = types
  3701. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3702. tempPrescription.Mtime = time.Now().Unix()
  3703. tempPrescription.Doctor = role.UserName
  3704. //tempPrescription.OrderStatus = order_status
  3705. tempPrescription.PreTime = pTime
  3706. tempPrescription.MedType = med_type
  3707. service.SaveHisPrescription(tempPrescription)
  3708. redis := service.RedisClient()
  3709. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3710. redis.Set(key, "", time.Second)
  3711. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3712. redis.Set(keyOne, "", time.Second)
  3713. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3714. redis.Set(keySeven, "", time.Second)
  3715. defer redis.Close()
  3716. }
  3717. //service.SaveHisPrescription(prescription)
  3718. //更改患者挂号状态
  3719. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3720. fmt.Println("更改失败", err2)
  3721. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3722. advices := items["advices"].([]interface{})
  3723. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3724. groupNo := int64(0)
  3725. ctime := time.Now().Unix()
  3726. mtime := ctime
  3727. if len(advices) > 0 {
  3728. for _, advice := range advices {
  3729. var s models.HisDoctorAdviceInfo
  3730. s.PrescriptionId = tempPrescription.ID
  3731. s.AdviceType = 2
  3732. s.AdviceDoctor = doctor_id
  3733. s.StopState = 2
  3734. s.ExecutionState = 2
  3735. s.AdviceDate = theTime3.Unix()
  3736. s.Status = 1
  3737. s.UserOrgId = adminInfo.CurrentOrgId
  3738. s.RecordDate = theTime3.Unix()
  3739. s.StartTime = tempPrescription.PreTime
  3740. s.Groupno = groupNo
  3741. s.CreatedTime = ctime
  3742. s.UpdatedTime = mtime
  3743. s.PatientId = patient_id
  3744. s.HisPatientId = his_patient_id
  3745. s.StartTime = pTime
  3746. s.IsSettle = 2
  3747. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3748. if errcode > 0 {
  3749. c.ServeFailJSONWithSGJErrorCode(errcode)
  3750. return
  3751. }
  3752. s.StartTime = pTime
  3753. var total_count int64 //处方总库存
  3754. //查询改药品信息
  3755. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3756. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3757. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3758. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3759. total_count += prescribingNumberSeven * medical.MinNumber
  3760. }
  3761. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3762. total_count += prescribingNumberSeven
  3763. }
  3764. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3765. total_count += prescribingNumberSeven
  3766. }
  3767. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3768. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3769. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3770. if s.Price != lastWarehouse.RetailPrice {
  3771. s.Price = lastWarehouse.RetailPrice
  3772. }
  3773. if s.Price == 0 {
  3774. s.Price = lastWarehouse.RetailPrice
  3775. }
  3776. }
  3777. service.CreateHisDoctorAdvice(&s)
  3778. //记录日志
  3779. byterequest, _ := json.Marshal(s)
  3780. adviceLog := models.XtDoctorAdviceLog{
  3781. UserOrgId: s.UserOrgId,
  3782. PatientId: s.PatientId,
  3783. AdminUserId: adminInfo.AdminUser.Id,
  3784. Module: 1,
  3785. ErrLog: string(byterequest),
  3786. Status: 1,
  3787. Ctime: time.Now().Unix(),
  3788. Mtime: 0,
  3789. Source: "电脑端新建his医嘱",
  3790. RecordDate: s.AdviceDate,
  3791. }
  3792. service.CreateDoctorAdviceLog(adviceLog)
  3793. //存储切片中
  3794. adviceList = append(adviceList, s)
  3795. redis := service.RedisClient()
  3796. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3797. redis.Set(key, "", time.Second)
  3798. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3799. redis.Set(keyOne, "", time.Second)
  3800. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3801. redis.Set(keySeven, "", time.Second)
  3802. var randNum int
  3803. randNum = rand.Intn(10000) + 1000
  3804. timestamp := time.Now().Unix()
  3805. tempTime := time.Unix(timestamp, 0)
  3806. timeFormat := tempTime.Format("20060102150405")
  3807. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3808. service.CreateHisDoctorAdvice(&s)
  3809. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3810. redis.Set(keySix, "", time.Second)
  3811. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3812. redis.Set(keyFive, "", time.Second)
  3813. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3814. redis.Set(keyEight, "", time.Second)
  3815. defer redis.Close()
  3816. }
  3817. }
  3818. }
  3819. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3820. projects := items["project"].([]interface{})
  3821. if len(projects) > 0 {
  3822. for _, project := range projects {
  3823. var p models.HisPrescriptionProject
  3824. p.PrescriptionId = tempPrescription.ID
  3825. p.Ctime = time.Now().Unix()
  3826. p.Mtime = time.Now().Unix()
  3827. p.PatientId = patient_id
  3828. p.RecordDate = theTime3.Unix()
  3829. p.Doctor = doctor_id
  3830. p.UserOrgId = adminInfo.CurrentOrgId
  3831. p.HisPatientId = his_patient_id
  3832. p.Status = 1
  3833. p.StartTime = pTime
  3834. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3835. if errcode > 0 {
  3836. c.ServeFailJSONWithSGJErrorCode(errcode)
  3837. return
  3838. }
  3839. if p.ID == 0 {
  3840. p.IsOut = 2
  3841. }
  3842. if p.ID > 0 {
  3843. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3844. p.IsOut = projectDetail.IsOut
  3845. }
  3846. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3847. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3848. if p.Type == 3 {
  3849. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3850. if p.Price != lastWarehouse.PackingPrice {
  3851. p.Price = lastWarehouse.PackingPrice
  3852. }
  3853. if p.Unit == "" {
  3854. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3855. p.Unit = goodInfoOne.PackingUnit
  3856. }
  3857. }
  3858. }
  3859. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3860. //
  3861. // if p.Type == 3 {
  3862. // //查询该耗材是否停用
  3863. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3864. // //表示该耗材已经停用,不能保存
  3865. // if goodInfoSeven.ID == 0 {
  3866. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3867. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3868. // return
  3869. // }
  3870. // }
  3871. //
  3872. //}
  3873. service.CreateHisProjectTwo(&p)
  3874. //记录日志
  3875. byterequest, _ := json.Marshal(p)
  3876. adviceLog := models.XtDoctorAdviceLog{
  3877. UserOrgId: p.UserOrgId,
  3878. PatientId: p.PatientId,
  3879. AdminUserId: adminInfo.AdminUser.Id,
  3880. Module: 1,
  3881. ErrLog: string(byterequest),
  3882. Status: 1,
  3883. Ctime: time.Now().Unix(),
  3884. Mtime: 0,
  3885. Source: "电脑端新建his项目",
  3886. RecordDate: p.RecordDate,
  3887. }
  3888. service.CreateDoctorAdviceLog(adviceLog)
  3889. projectList = append(projectList, p)
  3890. var randNum int
  3891. randNum = rand.Intn(10000) + 1000
  3892. timestamp := time.Now().Unix()
  3893. tempTime := time.Unix(timestamp, 0)
  3894. timeFormat := tempTime.Format("20060102150405")
  3895. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3896. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3897. //新增或者编辑项目,修改对应的标签数据
  3898. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3899. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3900. var label models.HisLabelPrintInfo
  3901. project, _ := service.GetProjectDetail(p.ProjectId)
  3902. if project.CostClassify == 3 { //类别为检验检查
  3903. if p.TeamId > 0 { //检验检查组套
  3904. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3905. if tempLabel.ID == 0 {
  3906. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3907. label.Number = tempPrescription.PrescriptionNumber
  3908. label.ProjectId = project.ID
  3909. label.Status = 1
  3910. label.IsPrint = 2
  3911. label.DoctorId = info.DoctorId
  3912. label.UserOrgId = p.UserOrgId
  3913. label.PatientId = patient_id
  3914. label.RecordDate = recordDateTime
  3915. label.Ctime = time.Now().Unix()
  3916. label.Mtime = time.Now().Unix()
  3917. label.ItemId = p.TeamId
  3918. label.FeedetlSn = p.FeedetlSn
  3919. label.PProjectId = p.ID
  3920. label.ProjectName = team.ProjectTeam
  3921. label.PatientName = patient.Name
  3922. service.CreateHisLabelRecord(&label)
  3923. }
  3924. } else { //单条检验检查项目
  3925. label.Number = tempPrescription.PrescriptionNumber
  3926. label.ProjectId = project.ID
  3927. label.Status = 1
  3928. label.DoctorId = info.DoctorId
  3929. label.UserOrgId = p.UserOrgId
  3930. label.PatientId = patient_id
  3931. label.RecordDate = recordDateTime
  3932. label.IsPrint = 2
  3933. label.Ctime = time.Now().Unix()
  3934. label.Mtime = time.Now().Unix()
  3935. label.FeedetlSn = p.FeedetlSn
  3936. label.PProjectId = p.ID
  3937. label.ItemId = p.TeamId
  3938. label.ProjectName = project.ProjectName
  3939. label.PatientName = patient.Name
  3940. service.CreateHisLabelRecord(&label)
  3941. }
  3942. }
  3943. }
  3944. }
  3945. service.SaveHisProjectTwo(&p)
  3946. }
  3947. }
  3948. }
  3949. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3950. // addition := items["addition"].([]interface{})
  3951. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3952. // ctime := time.Now().Unix()
  3953. // mtime := ctime
  3954. // if len(addition) > 0 {
  3955. // for _, item := range addition {
  3956. // var s models.HisAdditionalCharge
  3957. // s.PrescriptionId = tempPrescription.ID
  3958. // s.Status = 1
  3959. // s.UserOrgId = adminInfo.CurrentOrgId
  3960. // s.RecordDate = recordDateTime
  3961. // s.CreatedTime = ctime
  3962. // s.UpdatedTime = mtime
  3963. // s.PatientId = patient_id
  3964. // s.HisPatientId = his_patient_id
  3965. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3966. // if errcode > 0 {
  3967. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3968. // return
  3969. // }
  3970. // service.CreateAdditionalCharge(&s)
  3971. // var randNum int
  3972. // randNum = rand.Intn(10000) + 1000
  3973. // timestamp := time.Now().Unix()
  3974. // tempTime := time.Unix(timestamp, 0)
  3975. // timeFormat := tempTime.Format("20060102150405")
  3976. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3977. // service.CreateAdditionalCharge(&s)
  3978. //
  3979. // }
  3980. // }
  3981. //}
  3982. }
  3983. }
  3984. //查询今日该患者开的药品处方
  3985. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3986. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3987. //药品出库
  3988. if drugOutConfig.IsOpen == 1 {
  3989. for _, item := range hisdoctorlist {
  3990. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3991. // 查询该药品最后一次出库记录
  3992. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3993. if len(druginfo) > 0 {
  3994. //回退库存
  3995. for _, it := range druginfo {
  3996. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3997. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3998. }
  3999. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  4000. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4001. }
  4002. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  4003. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  4004. }
  4005. }
  4006. }
  4007. //删除记录
  4008. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  4009. //查询最后一次数据
  4010. if drugOutConfig.IsOpen == 1 {
  4011. //出库
  4012. if drug.IsUse == 2 {
  4013. creater := adminInfo.AdminUser.Id
  4014. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  4015. }
  4016. //更新字典里面的库存
  4017. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  4018. var sum_count int64
  4019. for _, its := range stockInfo {
  4020. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  4021. if its.MaxUnit == baseDrug.MaxUnit {
  4022. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  4023. }
  4024. sum_count += its.StockMaxNumber + its.StockMinNumber
  4025. }
  4026. //更新基础库存
  4027. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  4028. //剩余库存
  4029. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  4030. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  4031. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  4032. }
  4033. }
  4034. }
  4035. //耗材保存处方出库
  4036. if goodOutConfig.IsOpen == 1 {
  4037. //查询今日耗材出库数量
  4038. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  4039. for _, item := range hisgoodlist {
  4040. //查询历史出库数据
  4041. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4042. var out_count_five int64
  4043. for _, item := range flowGood {
  4044. out_count_five += item.Count
  4045. }
  4046. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  4047. if out_count_five != parseIntCount {
  4048. //查询耗材最后一次出库记录
  4049. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  4050. //查询默认出库仓库库存
  4051. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4052. if len(wareOut) > 0 {
  4053. for _, it := range wareOut {
  4054. //回退库存
  4055. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  4056. //删除出库记录
  4057. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  4058. }
  4059. }
  4060. timeStr := time.Now().Format("2006-01-02")
  4061. timeArr := strings.Split(timeStr, "-")
  4062. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  4063. total = total + 1
  4064. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  4065. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  4066. number = number + total
  4067. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  4068. operation_time := time.Now().Unix()
  4069. creater := c.GetAdminUserInfo().AdminUser.Id
  4070. recordDateStr := time.Now().Format("2006-01-02")
  4071. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  4072. nowtime := recordDate.Unix()
  4073. warehouseOut := models.WarehouseOut{
  4074. WarehouseOutOrderNumber: warehousing_out_order,
  4075. OperationTime: operation_time,
  4076. OrgId: adminInfo.CurrentOrgId,
  4077. Creater: creater,
  4078. Ctime: time.Now().Unix(),
  4079. Status: 1,
  4080. WarehouseOutTime: nowtime,
  4081. Type: 1,
  4082. StorehouseId: storeConfig.StorehouseOutInfo,
  4083. IsCheck: 1,
  4084. IsSys: 1,
  4085. }
  4086. //查询是否生成出库单
  4087. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4088. if out.ID == 0 {
  4089. service.AddSigleWarehouseOut(&warehouseOut)
  4090. }
  4091. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  4092. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4093. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  4094. dialyPrepareOne := models.DialysisBeforePrepare{
  4095. GoodTypeId: goodObj.GoodTypeId,
  4096. GoodId: item.ProjectId,
  4097. PatientId: item.PatientId,
  4098. RecordDate: item.RecordDate,
  4099. UserOrgId: adminInfo.CurrentOrgId,
  4100. Count: parseIntCount,
  4101. Ctime: time.Now().Unix(),
  4102. Creater: creater,
  4103. Status: 1,
  4104. StorehouseId: houseConfig.StorehouseOutInfo,
  4105. ProjectId: item.ID,
  4106. }
  4107. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  4108. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  4109. //查询历史出库数据
  4110. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4111. var out_count int64
  4112. for _, item := range flowGood {
  4113. out_count += item.Count
  4114. }
  4115. //如果历史数和当前数据不想等才进行退库出库
  4116. if out_count != parseIntCount {
  4117. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4118. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4119. detail := models.AutomaticReduceDetail{
  4120. WarehouseOutId: 0,
  4121. WarehouseOutOrderNumber: "",
  4122. PatientId: item.PatientId,
  4123. Ctime: time.Now().Unix(),
  4124. Mtime: 0,
  4125. Status: 1,
  4126. RecordTime: item.RecordDate,
  4127. OrgId: item.UserOrgId,
  4128. GoodId: item.ProjectId,
  4129. GoodTypeId: 0,
  4130. Count: parseIntCount,
  4131. Type: 0,
  4132. ProjectId: item.ID,
  4133. StorehouseId: 0,
  4134. }
  4135. service.CreateAutoDetail(detail)
  4136. //查询剩余库存
  4137. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4138. var sum_count int64
  4139. for _, item := range goodList {
  4140. sum_count += item.StockCount
  4141. }
  4142. //更新剩余库存
  4143. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4144. //耗材
  4145. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4146. }
  4147. }
  4148. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4149. //查询历史出库数据
  4150. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4151. var out_count int64
  4152. for _, item := range flowGood {
  4153. out_count += item.Count
  4154. }
  4155. //如果历史数和当前数据不想等才进行退库出库
  4156. if out_count != parseIntCount {
  4157. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4158. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4159. detail := models.AutomaticReduceDetail{
  4160. WarehouseOutId: 0,
  4161. WarehouseOutOrderNumber: "",
  4162. PatientId: item.PatientId,
  4163. Ctime: time.Now().Unix(),
  4164. Mtime: 0,
  4165. Status: 1,
  4166. RecordTime: item.RecordDate,
  4167. OrgId: item.UserOrgId,
  4168. GoodId: item.ProjectId,
  4169. GoodTypeId: 0,
  4170. Count: parseIntCount,
  4171. Type: 0,
  4172. ProjectId: item.ID,
  4173. StorehouseId: 0,
  4174. }
  4175. service.CreateAutoDetail(detail)
  4176. //查询剩余库存
  4177. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4178. var sum_count int64
  4179. for _, item := range goodList {
  4180. sum_count += item.StockCount
  4181. }
  4182. //更新剩余库存
  4183. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4184. //耗材
  4185. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4186. }
  4187. }
  4188. }
  4189. }
  4190. }
  4191. }
  4192. tx.Commit()
  4193. if err == nil {
  4194. c.ServeSuccessJSON(map[string]interface{}{
  4195. "msg": "保存成功",
  4196. })
  4197. return
  4198. } else {
  4199. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4200. return
  4201. }
  4202. }
  4203. }
  4204. //func (c *HisApiController) EditHisPrescription() {
  4205. // record_date := c.GetString("record_date")
  4206. // patient_id, _ := c.GetInt64("patient_id")
  4207. // reg_type, _ := c.GetInt64("reg_type")
  4208. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4209. // diagnose := c.GetString("diagnose")
  4210. // sick_type, _ := c.GetInt64("sick_type")
  4211. // sick_history := c.GetString("sick_history")
  4212. // doctor_id, _ := c.GetInt64("doctor", 0)
  4213. // department, _ := c.GetInt64("department", 0)
  4214. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4215. // p_type, _ := c.GetInt64("p_type")
  4216. //
  4217. // dataBody := make(map[string]interface{}, 0)
  4218. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4219. // if err != nil {
  4220. // utils.ErrorLog(err.Error())
  4221. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4222. // return
  4223. // }
  4224. //
  4225. // timeLayout := "2006-01-02"
  4226. // loc, _ := time.LoadLocation("Local")
  4227. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4228. // if err != nil {
  4229. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4230. // return
  4231. // }
  4232. // adminInfo := c.GetAdminUserInfo()
  4233. // recordDateTime := theTime.Unix()
  4234. //
  4235. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4236. //
  4237. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4238. // var hpInfo models.HisPrescriptionInfo
  4239. // if info.ID == 0 {
  4240. // var randNum int
  4241. // randNum = rand.Intn(10000) + 1000
  4242. // timestamp := time.Now().Unix()
  4243. // tempTime := time.Unix(timestamp, 0)
  4244. // timeFormat := tempTime.Format("20060102150405")
  4245. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4246. //
  4247. // hpInfo = models.HisPrescriptionInfo{
  4248. // UserOrgId: adminInfo.CurrentOrgId,
  4249. // RecordDate: theTime.Unix(),
  4250. // PatientId: patient_id,
  4251. // Status: 1,
  4252. // Ctime: time.Now().Unix(),
  4253. // Mtime: time.Now().Unix(),
  4254. // Creator: adminInfo.AdminUser.Id,
  4255. // Modifier: adminInfo.AdminUser.Id,
  4256. // Diagnosis: diagnose,
  4257. // SickHistory: sick_history,
  4258. // Departments: department,
  4259. // RegisterType: reg_type,
  4260. // PrescriptionNumber: p_number,
  4261. // PrescriptionStatus: 1,
  4262. // Doctor: role.UserName,
  4263. // DoctorId: doctor_id,
  4264. // SickType: sick_type,
  4265. // PType: p_type,
  4266. // }
  4267. // service.SavePatientPrescriptionInfo(hpInfo)
  4268. //
  4269. // } else {
  4270. // hpInfo = models.HisPrescriptionInfo{
  4271. // ID: info.ID,
  4272. // UserOrgId: adminInfo.CurrentOrgId,
  4273. // RecordDate: info.RecordDate,
  4274. // PatientId: info.PatientId,
  4275. // Status: 1,
  4276. // Ctime: info.Ctime,
  4277. // Mtime: time.Now().Unix(),
  4278. // Creator: info.Creator,
  4279. // Modifier: adminInfo.AdminUser.Id,
  4280. // Diagnosis: diagnose,
  4281. // SickHistory: sick_history,
  4282. // Departments: department,
  4283. // RegisterType: reg_type,
  4284. // PrescriptionNumber: info.PrescriptionNumber,
  4285. // Doctor: role.UserName,
  4286. // PrescriptionStatus: info.PrescriptionStatus,
  4287. // DoctorId: doctor_id,
  4288. // SickType: sick_type,
  4289. // PType: info.PType,
  4290. // }
  4291. // service.SavePatientPrescriptionInfo(hpInfo)
  4292. // }
  4293. //
  4294. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4295. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4296. //
  4297. // if len(prescriptions) > 0 {
  4298. // for _, item := range prescriptions {
  4299. // items := item.(map[string]interface{})
  4300. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4301. // utils.ErrorLog("id")
  4302. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4303. // return
  4304. // }
  4305. // id := int64(items["id"].(float64))
  4306. //
  4307. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4308. // utils.ErrorLog("type")
  4309. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4310. // return
  4311. // }
  4312. // types := int64(items["type"].(float64))
  4313. //
  4314. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4315. // utils.ErrorLog("med_type")
  4316. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4317. // return
  4318. // }
  4319. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4320. //
  4321. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4322. //
  4323. // ctime := time.Now().Unix()
  4324. //
  4325. // prescription := &models.HisPrescription{
  4326. // ID: id,
  4327. // PatientId: patient_id,
  4328. // UserOrgId: adminInfo.CurrentOrgId,
  4329. // RecordDate: recordDateTime,
  4330. // Ctime: ctime,
  4331. // Mtime: ctime,
  4332. // Type: types,
  4333. // Modifier: adminInfo.AdminUser.Id,
  4334. // Creator: adminInfo.AdminUser.Id,
  4335. // Status: 1,
  4336. // Doctor: role.UserName,
  4337. // HisPatientId: his_patient_id,
  4338. // OrderStatus: 1,
  4339. // BatchNumber: "",
  4340. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4341. // PType: hpInfo.PType,
  4342. // MedType: med_type,
  4343. // }
  4344. //
  4345. // if historyPrescription.ID > 0 {
  4346. // prescription.PreTime = historyPrescription.PreTime
  4347. //
  4348. // }
  4349. //
  4350. // service.SaveHisPrescription(prescription)
  4351. //
  4352. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4353. // advices := items["advices"].([]interface{})
  4354. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4355. // groupNo := int64(0)
  4356. // ctime := time.Now().Unix()
  4357. // mtime := ctime
  4358. // if len(advices) > 0 {
  4359. // for _, advice := range advices {
  4360. // var s models.HisDoctorAdviceInfo
  4361. // s.PrescriptionId = prescription.ID
  4362. // s.AdviceType = 2
  4363. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4364. // s.StopState = 2
  4365. // s.ExecutionState = 2
  4366. // s.AdviceDate = recordDateTime
  4367. // s.Status = 1
  4368. // s.UserOrgId = adminInfo.CurrentOrgId
  4369. // s.RecordDate = recordDateTime
  4370. // s.StartTime = prescription.PreTime
  4371. // s.Groupno = groupNo
  4372. // s.CreatedTime = ctime
  4373. // s.UpdatedTime = mtime
  4374. // s.PatientId = patient_id
  4375. // s.HisPatientId = his_patient_id
  4376. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4377. // if errcode > 0 {
  4378. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4379. // return
  4380. // }
  4381. //
  4382. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4383. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4384. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4385. // if s.Price == 0 {
  4386. // s.Price = lastWarehouse.RetailPrice
  4387. // }
  4388. // }
  4389. //
  4390. // service.CreateHisDoctorAdvice(&s)
  4391. // //记录日志
  4392. // byterequest, _ := json.Marshal(s)
  4393. // adviceLog := models.XtDoctorAdviceLog{
  4394. // UserOrgId: s.UserOrgId,
  4395. // PatientId: s.PatientId,
  4396. // AdminUserId: adminInfo.AdminUser.Id,
  4397. // Module: 1,
  4398. // ErrLog: string(byterequest),
  4399. // Status: 1,
  4400. // Ctime: time.Now().Unix(),
  4401. // Mtime: 0,
  4402. // Source: "电脑端his医嘱修改",
  4403. // RecordDate: s.AdviceDate,
  4404. // }
  4405. // service.CreateDoctorAdviceLog(adviceLog)
  4406. // redis := service.RedisClient()
  4407. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4408. // redis.Set(key, "", time.Second)
  4409. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4410. // fmt.Println("keyOne", keyOne)
  4411. // redis.Set(keyOne, "", time.Second)
  4412. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4413. // redis.Set(keySeven, "", time.Second)
  4414. // redis.Close()
  4415. //
  4416. // }
  4417. // }
  4418. // }
  4419. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4420. // projects := items["project"].([]interface{})
  4421. // if len(projects) > 0 {
  4422. // for _, project := range projects {
  4423. // var p models.HisPrescriptionProject
  4424. // p.PrescriptionId = prescription.ID
  4425. // p.Ctime = time.Now().Unix()
  4426. // p.Mtime = time.Now().Unix()
  4427. // p.PatientId = patient_id
  4428. // p.RecordDate = recordDateTime
  4429. // p.UserOrgId = adminInfo.CurrentOrgId
  4430. // p.HisPatientId = his_patient_id
  4431. // p.Status = 1
  4432. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4433. // if errcode > 0 {
  4434. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4435. // return
  4436. // }
  4437. // service.CreateHisProjectTwo(&p)
  4438. //
  4439. // //记录日志
  4440. // byterequest, _ := json.Marshal(p)
  4441. // adviceLog := models.XtDoctorAdviceLog{
  4442. // UserOrgId: p.UserOrgId,
  4443. // PatientId: p.PatientId,
  4444. // AdminUserId: adminInfo.AdminUser.Id,
  4445. // Module: 1,
  4446. // ErrLog: string(byterequest),
  4447. // Status: 1,
  4448. // Ctime: time.Now().Unix(),
  4449. // Mtime: 0,
  4450. // Source: "电脑端his项目修改",
  4451. // RecordDate: p.RecordDate,
  4452. // }
  4453. // service.CreateDoctorAdviceLog(adviceLog)
  4454. // }
  4455. // }
  4456. // }
  4457. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4458. // addition := items["addition"].([]interface{})
  4459. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4460. // ctime := time.Now().Unix()
  4461. // mtime := ctime
  4462. // if len(addition) > 0 {
  4463. // for _, item := range addition {
  4464. // var s models.HisAdditionalCharge
  4465. // s.PrescriptionId = prescription.ID
  4466. // s.Status = 1
  4467. // s.UserOrgId = adminInfo.CurrentOrgId
  4468. // s.RecordDate = recordDateTime
  4469. // s.CreatedTime = ctime
  4470. // s.UpdatedTime = mtime
  4471. // s.PatientId = patient_id
  4472. // s.HisPatientId = his_patient_id
  4473. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4474. // if errcode > 0 {
  4475. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4476. // return
  4477. // }
  4478. // service.CreateAdditionalCharge(&s)
  4479. // }
  4480. // }
  4481. // }
  4482. //
  4483. // }
  4484. // }
  4485. // }
  4486. // if err == nil {
  4487. // c.ServeSuccessJSON(map[string]interface{}{
  4488. // "msg": "保存成功",
  4489. // })
  4490. // return
  4491. //
  4492. // } else {
  4493. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4494. // return
  4495. // }
  4496. //}
  4497. func (c *HisApiController) DeletePrescription() {
  4498. prescription_id, _ := c.GetInt64("id")
  4499. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4500. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4501. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4502. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4503. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4504. //耗材保存处方出库
  4505. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4506. //已收费和已发药限制逻辑
  4507. isCharge := false
  4508. isMedicine := false
  4509. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4510. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4511. for _, item := range new_prescriptions {
  4512. if item.IsMedicine == 1 {
  4513. isMedicine = true
  4514. }
  4515. }
  4516. for _, item := range new_prescriptions {
  4517. if item.OrderStatus == 4 {
  4518. isCharge = true
  4519. }
  4520. }
  4521. if p_err != nil {
  4522. if new_prescription.ID > 0 {
  4523. if new_prescription.OrderStatus == 2 {
  4524. isCharge = true
  4525. }
  4526. }
  4527. }
  4528. for _, item := range advices {
  4529. if item.IsMedicine == 1 {
  4530. isMedicine = true
  4531. }
  4532. }
  4533. if isCharge {
  4534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4535. return
  4536. }
  4537. if isMedicine {
  4538. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4539. return
  4540. }
  4541. //已收费和已发药限制逻辑
  4542. if len(projects) > 0 {
  4543. for _, item := range projects {
  4544. service.DeletePrintInfo(item.ID) //删除打印信息
  4545. if goodOutConfig.IsOpen != 1 {
  4546. if stockConfig.IsOpen == 1 {
  4547. if item.Type == 3 && item.IsOut == 1 {
  4548. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4549. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4550. good.Total = good.Total + f_count
  4551. service.UpdateGoodInfo(&good)
  4552. operation_time := time.Now().Unix()
  4553. creater := c.GetAdminUserInfo().AdminUser.Id
  4554. //创建退库单
  4555. timeStr := time.Now().Format("2006-01-02")
  4556. timeArr := strings.Split(timeStr, "-")
  4557. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4558. total = total + 1
  4559. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4560. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4561. cancelStock := models.CancelStock{
  4562. OrderNumber: orderNumber,
  4563. OperaTime: operation_time,
  4564. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4565. Creater: creater,
  4566. Ctime: time.Now().Unix(),
  4567. Status: 1,
  4568. ReturnTime: item.RecordDate,
  4569. Type: 1,
  4570. StorehouseId: houseConfig.StorehouseOutInfo,
  4571. IsCheck: 1,
  4572. }
  4573. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4574. if msgerrkonde == gorm.ErrRecordNotFound {
  4575. service.AddSigleCancelStock(&cancelStock)
  4576. }
  4577. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4578. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4579. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4580. //查询该耗材是否出库
  4581. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4582. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4583. deaerler, _ := service.GetDealerById(info.Dealer)
  4584. var total_count int64
  4585. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4586. total_count += count
  4587. if info.ID > 0 {
  4588. if info.Count >= total_count {
  4589. //回退库存
  4590. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4591. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4592. var flush_count int64
  4593. for _, it := range goodList {
  4594. flush_count += it.StockCount
  4595. }
  4596. cancelStockInfo := models.CancelStockInfo{
  4597. GoodId: item.ProjectId,
  4598. CancelStockId: cancel.ID,
  4599. GoodTypeId: good.GoodTypeId,
  4600. Count: prescribingNumber,
  4601. Price: info.Price,
  4602. Total: 0,
  4603. ProductDate: info.ProductDate,
  4604. ExpiryDate: info.ExpiryDate,
  4605. Ctime: time.Now().Unix(),
  4606. Status: 1,
  4607. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4608. OrderNumber: cancel.OrderNumber,
  4609. Type: 0,
  4610. Dealer: deaerler.DealerName,
  4611. Manufacturer: manufacturer.ManufacturerName,
  4612. Number: info.Number,
  4613. RegisterAccount: "",
  4614. Remark: "",
  4615. WarehouseInfoId: info.WarehouseInfotId,
  4616. PatientId: info.PatientId,
  4617. RecordDate: info.SysRecordTime,
  4618. StorehouseId: houseConfig.StorehouseOutInfo,
  4619. IsCheck: 1,
  4620. }
  4621. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4622. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4623. flow := models.VmStockFlow{
  4624. WarehousingId: info.WarehouseInfotId,
  4625. GoodId: item.ProjectId,
  4626. Number: info.Number,
  4627. LicenseNumber: info.LicenseNumber,
  4628. Count: prescribingNumber,
  4629. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4630. PatientId: item.PatientId,
  4631. SystemTime: info.SysRecordTime,
  4632. ConsumableType: 7,
  4633. IsSys: 0,
  4634. WarehousingOrder: "",
  4635. WarehouseOutId: info.WarehouseOutId,
  4636. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4637. IsEdit: 0,
  4638. CancelStockId: cancel.ID,
  4639. CancelOrderNumber: cancel.OrderNumber,
  4640. Manufacturer: manufacturer.ID,
  4641. Dealer: 0,
  4642. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4643. UpdateCreator: 0,
  4644. Status: 1,
  4645. Ctime: time.Now().Unix(),
  4646. Mtime: 0,
  4647. Price: info.Price,
  4648. WarehousingDetailId: info.WarehouseInfotId,
  4649. WarehouseOutDetailId: info.ID,
  4650. CancelOutDetailId: cancelInfo.ID,
  4651. ProductDate: info.ProductDate,
  4652. ExpireDate: info.ExpiryDate,
  4653. StorehouseId: houseConfig.StorehouseOutInfo,
  4654. OverCount: flush_count,
  4655. }
  4656. service.CreateStockFlowOne(flow)
  4657. //退库数量增加
  4658. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4659. //出库数量减少
  4660. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4661. }
  4662. if info.Count < total_count {
  4663. //回退库存
  4664. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4665. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4666. var flush_count int64
  4667. for _, it := range goodList {
  4668. flush_count += it.StockCount
  4669. }
  4670. cancelStockInfo := models.CancelStockInfo{
  4671. GoodId: item.ProjectId,
  4672. CancelStockId: cancel.ID,
  4673. GoodTypeId: good.GoodTypeId,
  4674. Count: info.Count,
  4675. Price: info.Price,
  4676. Total: 0,
  4677. ProductDate: info.ProductDate,
  4678. ExpiryDate: info.ExpiryDate,
  4679. Ctime: time.Now().Unix(),
  4680. Status: 1,
  4681. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4682. OrderNumber: cancel.OrderNumber,
  4683. Type: 0,
  4684. Dealer: deaerler.DealerName,
  4685. Manufacturer: manufacturer.ManufacturerName,
  4686. Number: info.Number,
  4687. RegisterAccount: "",
  4688. Remark: "",
  4689. WarehouseInfoId: info.WarehouseInfotId,
  4690. PatientId: info.PatientId,
  4691. RecordDate: info.SysRecordTime,
  4692. StorehouseId: houseConfig.StorehouseOutInfo,
  4693. IsCheck: 1,
  4694. }
  4695. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4696. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4697. flow := models.VmStockFlow{
  4698. WarehousingId: info.WarehouseInfotId,
  4699. GoodId: item.ProjectId,
  4700. Number: info.Number,
  4701. LicenseNumber: info.LicenseNumber,
  4702. Count: info.Count,
  4703. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4704. PatientId: item.PatientId,
  4705. SystemTime: info.SysRecordTime,
  4706. ConsumableType: 7,
  4707. IsSys: 0,
  4708. WarehousingOrder: "",
  4709. WarehouseOutId: info.WarehouseOutId,
  4710. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4711. IsEdit: 0,
  4712. CancelStockId: cancel.ID,
  4713. CancelOrderNumber: cancel.OrderNumber,
  4714. Manufacturer: manufacturer.ID,
  4715. Dealer: 0,
  4716. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4717. UpdateCreator: 0,
  4718. Status: 1,
  4719. Ctime: time.Now().Unix(),
  4720. Mtime: 0,
  4721. Price: info.Price,
  4722. WarehousingDetailId: info.WarehouseInfotId,
  4723. WarehouseOutDetailId: info.ID,
  4724. CancelOutDetailId: cancelInfo.ID,
  4725. ProductDate: info.ProductDate,
  4726. ExpireDate: info.ExpiryDate,
  4727. StorehouseId: houseConfig.StorehouseOutInfo,
  4728. OverCount: flush_count,
  4729. }
  4730. service.CreateStockFlowOne(flow)
  4731. //退库数量增加
  4732. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4733. //出库数量减少
  4734. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4735. }
  4736. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4737. var flush_count int64
  4738. for _, it := range goodList {
  4739. flush_count += it.StockCount
  4740. }
  4741. //查询已出库数量
  4742. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4743. if prescribingNumber < dialysisInfo.Count {
  4744. //改变数量
  4745. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4746. }
  4747. if prescribingNumber >= dialysisInfo.Count {
  4748. //删除出库表
  4749. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4750. }
  4751. //更新库存
  4752. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4753. //更新基础库库存
  4754. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4755. }
  4756. }
  4757. }
  4758. }
  4759. //保存耗材出库
  4760. if goodOutConfig.IsOpen == 1 {
  4761. if item.Type == 3 {
  4762. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4763. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4764. good.Total = good.Total + f_count
  4765. service.UpdateGoodInfo(&good)
  4766. operation_time := time.Now().Unix()
  4767. creater := c.GetAdminUserInfo().AdminUser.Id
  4768. //创建退库单
  4769. timeStr := time.Now().Format("2006-01-02")
  4770. timeArr := strings.Split(timeStr, "-")
  4771. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4772. total = total + 1
  4773. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4774. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4775. cancelStock := models.CancelStock{
  4776. OrderNumber: orderNumber,
  4777. OperaTime: operation_time,
  4778. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4779. Creater: creater,
  4780. Ctime: time.Now().Unix(),
  4781. Status: 1,
  4782. ReturnTime: item.RecordDate,
  4783. Type: 1,
  4784. StorehouseId: houseConfig.StorehouseOutInfo,
  4785. IsCheck: 1,
  4786. }
  4787. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4788. if msgerrkonde == gorm.ErrRecordNotFound {
  4789. service.AddSigleCancelStock(&cancelStock)
  4790. }
  4791. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4792. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4793. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4794. //查询该耗材是否出库
  4795. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4796. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4797. deaerler, _ := service.GetDealerById(info.Dealer)
  4798. var total_count int64
  4799. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4800. total_count += count
  4801. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4802. var flush_count int64
  4803. for _, it := range goodList {
  4804. flush_count += it.StockCount
  4805. }
  4806. fmt.Println("历史出库数据", info.Count)
  4807. fmt.Println("出库数量", total_count)
  4808. if info.ID > 0 {
  4809. cancelStockInfo := models.CancelStockInfo{
  4810. GoodId: item.ProjectId,
  4811. CancelStockId: cancel.ID,
  4812. GoodTypeId: good.GoodTypeId,
  4813. Count: prescribingNumber,
  4814. Price: info.Price,
  4815. Total: 0,
  4816. ProductDate: info.ProductDate,
  4817. ExpiryDate: info.ExpiryDate,
  4818. Ctime: time.Now().Unix(),
  4819. Status: 1,
  4820. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4821. OrderNumber: cancel.OrderNumber,
  4822. Type: 0,
  4823. Dealer: deaerler.DealerName,
  4824. Manufacturer: manufacturer.ManufacturerName,
  4825. Number: info.Number,
  4826. RegisterAccount: "",
  4827. Remark: "",
  4828. WarehouseInfoId: info.WarehouseInfotId,
  4829. PatientId: info.PatientId,
  4830. RecordDate: info.SysRecordTime,
  4831. StorehouseId: houseConfig.StorehouseOutInfo,
  4832. IsCheck: 1,
  4833. }
  4834. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4835. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4836. //查询出库数量
  4837. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4838. //出库数据 大于 退库数量
  4839. if len(list) > 0 {
  4840. for _, it := range list {
  4841. //回退库存
  4842. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4843. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4844. var flush_count_one int64
  4845. for _, it := range goodList {
  4846. flush_count_one += it.StockCount
  4847. }
  4848. //查询该批次是否有退库数据
  4849. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4850. creater := c.GetAdminUserInfo().AdminUser.Id
  4851. flow := models.VmStockFlow{
  4852. WarehousingId: it.WarehouseInfotId,
  4853. GoodId: it.GoodId,
  4854. Number: it.Number,
  4855. LicenseNumber: it.LicenseNumber,
  4856. Count: it.Count,
  4857. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4858. PatientId: it.PatientId,
  4859. SystemTime: it.SysRecordTime,
  4860. ConsumableType: 7,
  4861. IsSys: 0,
  4862. WarehousingOrder: "",
  4863. WarehouseOutId: it.WarehouseOutId,
  4864. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4865. IsEdit: 0,
  4866. CancelStockId: cancel.ID,
  4867. CancelOrderNumber: cancel.OrderNumber,
  4868. Manufacturer: manufacturer.ID,
  4869. Dealer: 0,
  4870. Creator: creater,
  4871. UpdateCreator: 0,
  4872. Status: 1,
  4873. Ctime: time.Now().Unix(),
  4874. Mtime: 0,
  4875. Price: it.Price,
  4876. WarehousingDetailId: it.WarehouseInfotId,
  4877. WarehouseOutDetailId: it.ID,
  4878. CancelOutDetailId: cancelInfo.ID,
  4879. ProductDate: it.ProductDate,
  4880. ExpireDate: it.ExpiryDate,
  4881. StorehouseId: houseConfig.StorehouseOutInfo,
  4882. OverCount: flush_count_one,
  4883. }
  4884. service.CreateStockFlowOne(flow)
  4885. //if flow.ID > 0 {
  4886. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  4887. //}
  4888. }
  4889. }
  4890. //flow := models.VmStockFlow{
  4891. // WarehousingId: info.WarehouseInfotId,
  4892. // GoodId: item.ProjectId,
  4893. // Number: info.Number,
  4894. // LicenseNumber: info.LicenseNumber,
  4895. // Count: prescribingNumber,
  4896. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4897. // PatientId: item.PatientId,
  4898. // SystemTime: info.SysRecordTime,
  4899. // ConsumableType: 7,
  4900. // IsSys: 0,
  4901. // WarehousingOrder: "",
  4902. // WarehouseOutId: info.WarehouseOutId,
  4903. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4904. // IsEdit: 0,
  4905. // CancelStockId: cancel.ID,
  4906. // CancelOrderNumber: cancel.OrderNumber,
  4907. // Manufacturer: manufacturer.ID,
  4908. // Dealer: 0,
  4909. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  4910. // UpdateCreator: 0,
  4911. // Status: 1,
  4912. // Ctime: time.Now().Unix(),
  4913. // Mtime: 0,
  4914. // Price: info.Price,
  4915. // WarehousingDetailId: info.WarehouseInfotId,
  4916. // WarehouseOutDetailId: info.ID,
  4917. // CancelOutDetailId: cancelInfo.ID,
  4918. // ProductDate: info.ProductDate,
  4919. // ExpireDate: info.ExpiryDate,
  4920. // StorehouseId: houseConfig.StorehouseOutInfo,
  4921. // OverCount: flush_count,
  4922. //}
  4923. //service.CreateStockFlowOne(flow)
  4924. //退库数量增加
  4925. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4926. //出库数量减少
  4927. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4928. //查询已出库数量
  4929. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4930. if prescribingNumber < dialysisInfo.Count {
  4931. //改变数量
  4932. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4933. }
  4934. if prescribingNumber >= dialysisInfo.Count {
  4935. //删除出库表
  4936. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4937. }
  4938. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4939. var flush_count_one int64
  4940. for _, it := range goodList {
  4941. flush_count_one += it.StockCount
  4942. }
  4943. //更新库存
  4944. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4945. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4946. //更新基础库库存
  4947. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4948. }
  4949. }
  4950. }
  4951. }
  4952. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4953. fmt.Println(err)
  4954. }
  4955. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4956. fmt.Println(err)
  4957. if len(advices) > 0 {
  4958. for _, item := range advices {
  4959. redis := service.RedisClient()
  4960. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4961. redis.Set(keyFive, "", time.Second)
  4962. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4963. redis.Set(keyOne, "", time.Second)
  4964. redis.Close()
  4965. }
  4966. }
  4967. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4968. if len(advices) > 0 {
  4969. for _, item := range advices {
  4970. creater := c.GetAdminUserInfo().AdminUser.Id
  4971. service.DrugAutoAddCancelInfo(item, creater)
  4972. }
  4973. }
  4974. } else {
  4975. if drugOutConfig.IsOpen == 1 {
  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 len(advices) > 0 {
  4984. for _, item := range advices {
  4985. creater := c.GetAdminUserInfo().AdminUser.Id
  4986. service.DrugAutoAddCancelInfo(item, creater)
  4987. }
  4988. }
  4989. }
  4990. }
  4991. c.ServeSuccessJSON(map[string]interface{}{
  4992. "msg": "删除成功",
  4993. })
  4994. return
  4995. }
  4996. func (c *HisApiController) DeleteDoctorAdvice() {
  4997. id, _ := c.GetInt64("id")
  4998. advice, _ := service.GetHisDoctorAdvicesById(id)
  4999. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5000. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5001. //已收费和已发药的限制逻辑
  5002. isCharge := false
  5003. isMedicine := false
  5004. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5005. //获取今天该患者所有处方,判断是否发药或者收费
  5006. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5007. for _, item := range new_prescriptions {
  5008. if item.IsMedicine == 1 {
  5009. isMedicine = true
  5010. }
  5011. }
  5012. for _, item := range new_prescriptions {
  5013. if item.OrderStatus == 4 {
  5014. isCharge = true
  5015. }
  5016. }
  5017. if isMedicine {
  5018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5019. return
  5020. }
  5021. if isCharge {
  5022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5023. return
  5024. }
  5025. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  5026. for _, item := range advices {
  5027. if item.IsMedicine == 1 {
  5028. isMedicine = true
  5029. }
  5030. }
  5031. if isMedicine {
  5032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  5033. return
  5034. }
  5035. if new_prescription.ID > 0 {
  5036. if new_prescription.OrderStatus == 2 {
  5037. isCharge = true
  5038. }
  5039. }
  5040. if isCharge {
  5041. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5042. return
  5043. }
  5044. //已收费和已发药的限制逻辑
  5045. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  5046. redis := service.RedisClient()
  5047. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  5048. redis.Set(keyFive, "", time.Second)
  5049. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  5050. redis.Set(keyOne, "", time.Second)
  5051. defer redis.Close()
  5052. if err == nil {
  5053. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  5054. //查询是否在处方中出库
  5055. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5056. if openConfig.IsOpen != 1 {
  5057. //判断该医嘱是否执行了
  5058. if advice.ExecutionState == 1 {
  5059. creater := c.GetAdminUserInfo().AdminUser.Id
  5060. service.DrugAutoAddCancelInfo(&advice, creater)
  5061. }
  5062. }
  5063. //开启保存处方扣减功能
  5064. if openConfig.IsOpen == 1 {
  5065. creater := c.GetAdminUserInfo().AdminUser.Id
  5066. service.DrugAutoAddCancelInfo(&advice, creater)
  5067. }
  5068. } else {
  5069. if drugOutConfig.IsOpen == 1 {
  5070. //查询是否在处方中出库
  5071. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  5072. if openConfig.IsOpen != 1 {
  5073. //判断该医嘱是否执行了
  5074. if advice.ExecutionState == 1 {
  5075. creater := c.GetAdminUserInfo().AdminUser.Id
  5076. service.DrugAutoAddCancelInfo(&advice, creater)
  5077. }
  5078. }
  5079. //开启保存处方扣减功能
  5080. if openConfig.IsOpen == 1 {
  5081. creater := c.GetAdminUserInfo().AdminUser.Id
  5082. service.DrugAutoAddCancelInfo(&advice, creater)
  5083. }
  5084. } else {
  5085. //判断该医嘱是否执行了
  5086. if advice.ExecutionState == 1 {
  5087. creater := c.GetAdminUserInfo().AdminUser.Id
  5088. service.DrugAutoAddCancelInfo(&advice, creater)
  5089. }
  5090. }
  5091. }
  5092. c.ServeSuccessJSON(map[string]interface{}{
  5093. "msg": "删除成功",
  5094. })
  5095. return
  5096. } else {
  5097. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5098. return
  5099. }
  5100. }
  5101. func (c *HisApiController) DeleteProject() {
  5102. id, _ := c.GetInt64("id")
  5103. adminInfo := c.GetAdminUserInfo()
  5104. project, _ := service.GetHisProjectByID(id)
  5105. // var consumable models.DialysisBeforePrepare
  5106. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  5107. //耗材保存处方出库
  5108. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  5109. isCharge := false
  5110. isMedicine := false
  5111. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  5112. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  5113. for _, item := range new_prescriptions {
  5114. if item.IsMedicine == 1 {
  5115. isMedicine = true
  5116. }
  5117. }
  5118. for _, item := range new_prescriptions {
  5119. if item.OrderStatus == 4 {
  5120. isCharge = true
  5121. }
  5122. }
  5123. if isMedicine {
  5124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  5125. return
  5126. }
  5127. if isCharge {
  5128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  5129. return
  5130. }
  5131. if new_prescription.ID > 0 {
  5132. if new_prescription.OrderStatus == 2 {
  5133. isCharge = true
  5134. }
  5135. }
  5136. if isCharge {
  5137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  5138. return
  5139. }
  5140. service.DeletePrintInfo(id)
  5141. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  5142. label.Status = 0
  5143. service.CreateHisLabelRecordTwo(&label)
  5144. fmt.Println(goodOutConfig.IsOpen)
  5145. if goodOutConfig.IsOpen != 1 {
  5146. if stockConfig.IsOpen == 1 {
  5147. if project.Type == 2 {
  5148. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5149. fmt.Println(err)
  5150. }
  5151. if project.Type == 3 && project.IsOut == 1 {
  5152. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5153. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5154. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5155. operation_time := time.Now().Unix()
  5156. creater := adminInfo.AdminUser.Id
  5157. //创建退库单
  5158. timeStr := time.Now().Format("2006-01-02")
  5159. timeArr := strings.Split(timeStr, "-")
  5160. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5161. total = total + 1
  5162. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5163. cancelStock := models.CancelStock{
  5164. OrderNumber: orderNumber,
  5165. OperaTime: operation_time,
  5166. OrgId: adminInfo.CurrentOrgId,
  5167. Creater: creater,
  5168. Ctime: time.Now().Unix(),
  5169. Status: 1,
  5170. ReturnTime: project.RecordDate,
  5171. Type: 1,
  5172. StorehouseId: houseConfig.StorehouseOutInfo,
  5173. IsCheck: 1,
  5174. }
  5175. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5176. if msgerrkonde == gorm.ErrRecordNotFound {
  5177. service.AddSigleCancelStock(&cancelStock)
  5178. }
  5179. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5180. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5181. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5182. //查询是否有出库
  5183. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5184. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5185. deaerler, _ := service.GetDealerById(info.Dealer)
  5186. if info.ID > 0 {
  5187. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5188. if info.Count >= prescribingNumber {
  5189. cancelStockInfo := models.CancelStockInfo{
  5190. GoodId: project.ProjectId,
  5191. CancelStockId: cancel.ID,
  5192. GoodTypeId: good.GoodTypeId,
  5193. Count: prescribingNumber,
  5194. Price: info.Price,
  5195. Total: 0,
  5196. ProductDate: info.ProductDate,
  5197. ExpiryDate: info.ExpiryDate,
  5198. Ctime: time.Now().Unix(),
  5199. Status: 1,
  5200. OrgId: adminInfo.CurrentOrgId,
  5201. OrderNumber: cancel.OrderNumber,
  5202. Type: 0,
  5203. Dealer: deaerler.DealerName,
  5204. Manufacturer: manufacturer.ManufacturerName,
  5205. Number: info.Number,
  5206. RegisterAccount: "",
  5207. Remark: "",
  5208. WarehouseInfoId: info.WarehouseInfotId,
  5209. PatientId: info.PatientId,
  5210. RecordDate: info.SysRecordTime,
  5211. StorehouseId: houseConfig.StorehouseOutInfo,
  5212. IsCheck: 1,
  5213. }
  5214. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5215. //回退库存
  5216. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5217. //退库数量增加
  5218. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5219. //出库数量减少
  5220. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5221. }
  5222. if info.Count < prescribingNumber {
  5223. cancelStockInfo := models.CancelStockInfo{
  5224. GoodId: project.ProjectId,
  5225. CancelStockId: cancel.ID,
  5226. GoodTypeId: good.GoodTypeId,
  5227. Count: info.Count,
  5228. Price: info.Price,
  5229. Total: 0,
  5230. ProductDate: info.ProductDate,
  5231. ExpiryDate: info.ExpiryDate,
  5232. Ctime: time.Now().Unix(),
  5233. Status: 1,
  5234. OrgId: adminInfo.CurrentOrgId,
  5235. OrderNumber: cancel.OrderNumber,
  5236. Type: 0,
  5237. Dealer: deaerler.DealerName,
  5238. Manufacturer: manufacturer.ManufacturerName,
  5239. Number: info.Number,
  5240. RegisterAccount: "",
  5241. Remark: "",
  5242. WarehouseInfoId: info.WarehouseInfotId,
  5243. PatientId: info.PatientId,
  5244. RecordDate: info.SysRecordTime,
  5245. StorehouseId: houseConfig.StorehouseOutInfo,
  5246. IsCheck: 1,
  5247. }
  5248. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5249. //回退库存
  5250. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5251. //退库数量增加
  5252. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5253. //出库数量减少
  5254. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5255. }
  5256. //查询剩余库存
  5257. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5258. var over_count int64
  5259. for _, it := range goodList {
  5260. over_count += it.StockCount
  5261. }
  5262. //出库数据 大于 退库数量
  5263. if info.Count >= prescribingNumber {
  5264. flow := models.VmStockFlow{
  5265. WarehousingId: info.WarehouseInfotId,
  5266. GoodId: project.ProjectId,
  5267. Number: info.Number,
  5268. LicenseNumber: info.LicenseNumber,
  5269. Count: prescribingNumber,
  5270. UserOrgId: adminInfo.CurrentOrgId,
  5271. PatientId: project.PatientId,
  5272. SystemTime: info.SysRecordTime,
  5273. ConsumableType: 7,
  5274. IsSys: 0,
  5275. WarehousingOrder: "",
  5276. WarehouseOutId: info.WarehouseOutId,
  5277. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5278. IsEdit: 0,
  5279. CancelStockId: cancel.ID,
  5280. CancelOrderNumber: cancel.OrderNumber,
  5281. Manufacturer: manufacturer.ID,
  5282. Dealer: 0,
  5283. Creator: adminInfo.AdminUser.Id,
  5284. UpdateCreator: 0,
  5285. Status: 1,
  5286. Ctime: time.Now().Unix(),
  5287. Mtime: 0,
  5288. Price: info.Price,
  5289. WarehousingDetailId: info.WarehouseInfotId,
  5290. WarehouseOutDetailId: info.ID,
  5291. CancelOutDetailId: cancelInfo.ID,
  5292. ProductDate: info.ProductDate,
  5293. ExpireDate: info.ExpiryDate,
  5294. StorehouseId: houseConfig.StorehouseOutInfo,
  5295. OverCount: over_count,
  5296. }
  5297. service.CreateStockFlowOne(flow)
  5298. }
  5299. //出库数据小于退库数据
  5300. if info.Count < prescribingNumber {
  5301. flow := models.VmStockFlow{
  5302. WarehousingId: info.WarehouseInfotId,
  5303. GoodId: project.ProjectId,
  5304. Number: info.Number,
  5305. LicenseNumber: info.LicenseNumber,
  5306. Count: info.Count,
  5307. UserOrgId: adminInfo.CurrentOrgId,
  5308. PatientId: project.PatientId,
  5309. SystemTime: info.SysRecordTime,
  5310. ConsumableType: 7,
  5311. IsSys: 0,
  5312. WarehousingOrder: "",
  5313. WarehouseOutId: info.WarehouseOutId,
  5314. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5315. IsEdit: 0,
  5316. CancelStockId: cancel.ID,
  5317. CancelOrderNumber: cancel.OrderNumber,
  5318. Manufacturer: manufacturer.ID,
  5319. Dealer: 0,
  5320. Creator: adminInfo.AdminUser.Id,
  5321. UpdateCreator: 0,
  5322. Status: 1,
  5323. Ctime: time.Now().Unix(),
  5324. Mtime: 0,
  5325. Price: info.Price,
  5326. WarehousingDetailId: info.WarehouseInfotId,
  5327. WarehouseOutDetailId: info.ID,
  5328. CancelOutDetailId: cancelInfo.ID,
  5329. ProductDate: info.ProductDate,
  5330. ExpireDate: info.ExpiryDate,
  5331. StorehouseId: houseConfig.StorehouseOutInfo,
  5332. OverCount: over_count,
  5333. }
  5334. service.CreateStockFlowOne(flow)
  5335. }
  5336. //查询已出库数量
  5337. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5338. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  5339. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  5340. if prescribingNumber < dialysisInfo.Count {
  5341. //改变数量
  5342. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5343. }
  5344. if prescribingNumber >= dialysisInfo.Count {
  5345. //删除出库表
  5346. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5347. }
  5348. //更新剩余库存
  5349. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5350. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5351. var total_count_one int64
  5352. for _, it := range stockList {
  5353. total_count_one += it.StockCount
  5354. }
  5355. //基础库插入数据
  5356. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5357. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5358. var flush_count int64
  5359. for _, it := range goodListOne {
  5360. flush_count += it.StockCount
  5361. }
  5362. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5363. if errs != nil {
  5364. goodErrcode := models.XtGoodErrcode{
  5365. UserOrgId: project.UserOrgId,
  5366. Errcode: "手动出库更新剩余出库失败",
  5367. GoodId: project.ProjectId,
  5368. Status: 1,
  5369. Ctime: time.Now().Unix(),
  5370. Mtime: 0,
  5371. Count: 0,
  5372. StockCount: 0,
  5373. Creater: creater,
  5374. BatchNumberId: 0,
  5375. WarehouseOutId: 0,
  5376. }
  5377. service.CreateGoodErrcode(goodErrcode)
  5378. }
  5379. }
  5380. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5381. fmt.Println(err)
  5382. } else {
  5383. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5384. fmt.Println(err)
  5385. }
  5386. } else {
  5387. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5388. fmt.Println(err)
  5389. }
  5390. }
  5391. //保存处方出库
  5392. if goodOutConfig.IsOpen == 1 {
  5393. if project.Type == 3 {
  5394. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5395. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5396. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5397. operation_time := time.Now().Unix()
  5398. creater := adminInfo.AdminUser.Id
  5399. //创建退库单
  5400. timeStr := time.Now().Format("2006-01-02")
  5401. timeArr := strings.Split(timeStr, "-")
  5402. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5403. total = total + 1
  5404. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5405. cancelStock := models.CancelStock{
  5406. OrderNumber: orderNumber,
  5407. OperaTime: operation_time,
  5408. OrgId: adminInfo.CurrentOrgId,
  5409. Creater: creater,
  5410. Ctime: time.Now().Unix(),
  5411. Status: 1,
  5412. ReturnTime: project.RecordDate,
  5413. Type: 1,
  5414. StorehouseId: houseConfig.StorehouseOutInfo,
  5415. IsCheck: 1,
  5416. }
  5417. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5418. if msgerrkonde == gorm.ErrRecordNotFound {
  5419. service.AddSigleCancelStock(&cancelStock)
  5420. }
  5421. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5422. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5423. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5424. //获取出库数据
  5425. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5426. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5427. deaerler, _ := service.GetDealerById(info.Dealer)
  5428. if info.ID > 0 {
  5429. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5430. if info.Count >= prescribingNumber {
  5431. cancelStockInfo := models.CancelStockInfo{
  5432. GoodId: project.ProjectId,
  5433. CancelStockId: cancel.ID,
  5434. GoodTypeId: good.GoodTypeId,
  5435. Count: prescribingNumber,
  5436. Price: info.Price,
  5437. Total: 0,
  5438. ProductDate: info.ProductDate,
  5439. ExpiryDate: info.ExpiryDate,
  5440. Ctime: time.Now().Unix(),
  5441. Status: 1,
  5442. OrgId: adminInfo.CurrentOrgId,
  5443. OrderNumber: cancel.OrderNumber,
  5444. Type: 0,
  5445. Dealer: deaerler.DealerName,
  5446. Manufacturer: manufacturer.ManufacturerName,
  5447. Number: info.Number,
  5448. RegisterAccount: "",
  5449. Remark: "",
  5450. WarehouseInfoId: info.WarehouseInfotId,
  5451. PatientId: info.PatientId,
  5452. RecordDate: info.SysRecordTime,
  5453. StorehouseId: houseConfig.StorehouseOutInfo,
  5454. IsCheck: 1,
  5455. }
  5456. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5457. //退库数量增加
  5458. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5459. //出库数量减少
  5460. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5461. }
  5462. if info.Count < prescribingNumber {
  5463. cancelStockInfo := models.CancelStockInfo{
  5464. GoodId: project.ProjectId,
  5465. CancelStockId: cancel.ID,
  5466. GoodTypeId: good.GoodTypeId,
  5467. Count: prescribingNumber,
  5468. Price: info.Price,
  5469. Total: 0,
  5470. ProductDate: info.ProductDate,
  5471. ExpiryDate: info.ExpiryDate,
  5472. Ctime: time.Now().Unix(),
  5473. Status: 1,
  5474. OrgId: adminInfo.CurrentOrgId,
  5475. OrderNumber: cancel.OrderNumber,
  5476. Type: 0,
  5477. Dealer: deaerler.DealerName,
  5478. Manufacturer: manufacturer.ManufacturerName,
  5479. Number: info.Number,
  5480. RegisterAccount: "",
  5481. Remark: "",
  5482. WarehouseInfoId: info.WarehouseInfotId,
  5483. PatientId: info.PatientId,
  5484. RecordDate: info.SysRecordTime,
  5485. StorehouseId: houseConfig.StorehouseOutInfo,
  5486. IsCheck: 1,
  5487. }
  5488. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5489. //回退库存
  5490. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5491. }
  5492. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5493. var over_count int64
  5494. for _, it := range goodList {
  5495. over_count += it.StockCount
  5496. }
  5497. //查询出库数量
  5498. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  5499. //出库数据 大于 退库数量
  5500. if len(list) > 0 {
  5501. for _, it := range list {
  5502. //回退库存
  5503. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5504. //退库数量增加
  5505. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  5506. //出库数量减少
  5507. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  5508. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5509. var over_count_one int64
  5510. for _, it := range goodList {
  5511. over_count_one += it.StockCount
  5512. }
  5513. //查询该批次是否有退库数据
  5514. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  5515. flow := models.VmStockFlow{
  5516. WarehousingId: it.WarehouseInfotId,
  5517. GoodId: it.GoodId,
  5518. Number: it.Number,
  5519. LicenseNumber: it.LicenseNumber,
  5520. Count: it.Count,
  5521. UserOrgId: adminInfo.CurrentOrgId,
  5522. PatientId: it.PatientId,
  5523. SystemTime: it.SysRecordTime,
  5524. ConsumableType: 7,
  5525. IsSys: 0,
  5526. WarehousingOrder: "",
  5527. WarehouseOutId: it.WarehouseOutId,
  5528. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5529. IsEdit: 0,
  5530. CancelStockId: cancel.ID,
  5531. CancelOrderNumber: cancel.OrderNumber,
  5532. Manufacturer: manufacturer.ID,
  5533. Dealer: 0,
  5534. Creator: adminInfo.AdminUser.Id,
  5535. UpdateCreator: 0,
  5536. Status: 1,
  5537. Ctime: time.Now().Unix(),
  5538. Mtime: 0,
  5539. Price: it.Price,
  5540. WarehousingDetailId: it.WarehouseInfotId,
  5541. WarehouseOutDetailId: it.ID,
  5542. CancelOutDetailId: cancelInfo.ID,
  5543. ProductDate: it.ProductDate,
  5544. ExpireDate: it.ExpiryDate,
  5545. StorehouseId: houseConfig.StorehouseOutInfo,
  5546. OverCount: over_count_one,
  5547. }
  5548. service.CreateStockFlowOne(flow)
  5549. }
  5550. }
  5551. //查询已出库数量
  5552. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5553. if prescribingNumber < dialysisInfo.Count {
  5554. //改变数量
  5555. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5556. }
  5557. if prescribingNumber >= dialysisInfo.Count {
  5558. //删除出库表
  5559. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5560. }
  5561. //更新剩余库存
  5562. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5563. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5564. var total_count_one int64
  5565. for _, it := range stockList {
  5566. total_count_one += it.StockCount
  5567. }
  5568. //基础库插入数据
  5569. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5570. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5571. var flush_count int64
  5572. for _, it := range goodListOne {
  5573. flush_count += it.StockCount
  5574. }
  5575. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5576. if errs != nil {
  5577. goodErrcode := models.XtGoodErrcode{
  5578. UserOrgId: project.UserOrgId,
  5579. Errcode: "手动出库更新剩余出库失败",
  5580. GoodId: project.ProjectId,
  5581. Status: 1,
  5582. Ctime: time.Now().Unix(),
  5583. Mtime: 0,
  5584. Count: 0,
  5585. StockCount: 0,
  5586. Creater: creater,
  5587. BatchNumberId: 0,
  5588. WarehouseOutId: 0,
  5589. }
  5590. service.CreateGoodErrcode(goodErrcode)
  5591. }
  5592. }
  5593. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5594. fmt.Println(err)
  5595. } else {
  5596. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5597. fmt.Println(err)
  5598. }
  5599. }
  5600. c.ServeSuccessJSON(map[string]interface{}{
  5601. "msg": "删除成功",
  5602. })
  5603. return
  5604. }
  5605. func (c *HisApiController) CreateHisAdditionalCharge() {
  5606. his_patient_id, _ := c.GetInt64("his_patient_id")
  5607. patient_id, _ := c.GetInt64("patient_id")
  5608. record_date := c.GetString("record_date")
  5609. timeLayout := "2006-01-02"
  5610. loc, _ := time.LoadLocation("Local")
  5611. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5612. if err != nil {
  5613. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5614. return
  5615. }
  5616. adminInfo := c.GetAdminUserInfo()
  5617. recordDateTime := theTime.Unix()
  5618. dataBody := make(map[string]interface{}, 0)
  5619. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5620. if err != nil {
  5621. utils.ErrorLog(err.Error())
  5622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5623. return
  5624. }
  5625. var additions []*models.HisAdditionalCharge
  5626. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5627. additions, _ := dataBody["addition"].([]interface{})
  5628. if len(additions) > 0 {
  5629. for _, item := range additions {
  5630. items := item.(map[string]interface{})
  5631. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5632. utils.ErrorLog("item_id")
  5633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5634. return
  5635. }
  5636. item_id := int64(items["item_id"].(float64))
  5637. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5638. utils.ErrorLog("item_name")
  5639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5640. return
  5641. }
  5642. item_name := items["item_name"].(string)
  5643. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5644. utils.ErrorLog("price")
  5645. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5646. return
  5647. }
  5648. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5649. ctime := time.Now().Unix()
  5650. additional := &models.HisAdditionalCharge{
  5651. PatientId: patient_id,
  5652. HisPatientId: his_patient_id,
  5653. UserOrgId: adminInfo.CurrentOrgId,
  5654. RecordDate: recordDateTime,
  5655. CreatedTime: ctime,
  5656. UpdatedTime: ctime,
  5657. Modifier: adminInfo.AdminUser.Id,
  5658. Creator: adminInfo.AdminUser.Id,
  5659. Price: price,
  5660. ItemName: item_name,
  5661. ItemId: item_id,
  5662. Status: 1,
  5663. }
  5664. additions = append(additions, additional)
  5665. }
  5666. }
  5667. }
  5668. for _, item := range additions {
  5669. service.CreateAddtionalCharge(item)
  5670. }
  5671. c.ServeSuccessJSON(map[string]interface{}{
  5672. "msg": "创建成功",
  5673. })
  5674. }
  5675. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5676. blood_fat := c.GetString("blood_fat")
  5677. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5678. blood_sugar := c.GetString("blood_sugar")
  5679. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5680. chief_conplaint := c.GetString("chief_conplaint")
  5681. dbp := c.GetString("dbp")
  5682. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5683. delivery_way, _ := c.GetInt64("delivery_way")
  5684. diagnostic := c.GetString("diagnostic")
  5685. family_history := c.GetString("family_history")
  5686. height := c.GetString("height")
  5687. history_of_present_illness := c.GetString("history_of_present_illness")
  5688. is_infect, _ := c.GetInt64("is_infect")
  5689. past_history := c.GetString("past_history")
  5690. patient_id, _ := c.GetInt64("patient_id")
  5691. his_patient_id, _ := c.GetInt64("his_patient_id")
  5692. personal_history := c.GetString("personal_history")
  5693. pulse := c.GetString("pulse")
  5694. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5695. sbp := c.GetString("sbp")
  5696. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5697. heightfloat, _ := strconv.ParseFloat(height, 64)
  5698. sicktype := c.GetString("sick_type")
  5699. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5700. symptom := c.GetString("symptom")
  5701. sick_date := c.GetString("sick_date")
  5702. temperatures := c.GetString("temperature")
  5703. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5704. record_date := c.GetString("record_date")
  5705. breathing := c.GetString("breathing")
  5706. doctor_advice := c.GetString("doctor_advice")
  5707. remark := c.GetString("remark")
  5708. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5709. sick, _ := c.GetInt64("sick")
  5710. diagnose, _ := c.GetInt64("diagnose")
  5711. //id, _ := c.GetInt64("id")
  5712. timeLayout := "2006-01-02"
  5713. loc, _ := time.LoadLocation("Local")
  5714. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5715. allergic_history := c.GetString("allergic_history")
  5716. if err != nil {
  5717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5718. return
  5719. }
  5720. recordDateTime := theTime.Unix()
  5721. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5722. if err != nil {
  5723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5724. return
  5725. }
  5726. sickTimes := sickTime.Unix()
  5727. ctime := time.Now().Unix()
  5728. primary_disease := c.GetString("primary_disease")
  5729. confirm_failure_date := c.GetString("confirm_failure_date")
  5730. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5731. drug_allergy_history := c.GetString("drug_allergy_history")
  5732. physical_examination := c.GetString("physical_examination")
  5733. special_inspection := c.GetString("special_inspection")
  5734. lab_apparatus := c.GetString("lab_apparatus")
  5735. caseHistory := models.HisPatientCaseHistory{
  5736. HisPatientId: his_patient_id,
  5737. PatientId: patient_id,
  5738. Temperature: temperature,
  5739. BloodSugar: bloodsugarfloat,
  5740. Pulse: pulsefloat,
  5741. Sbp: sbpfloat,
  5742. Dbp: dbpfloat,
  5743. Height: heightfloat,
  5744. BloodFat: bloodfatfloat,
  5745. SickType: sick_type,
  5746. Symptom: symptom,
  5747. SickDate: sickTimes,
  5748. IsInfect: is_infect,
  5749. HistoryOfPresentIllness: history_of_present_illness,
  5750. PastHistory: past_history,
  5751. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5752. ChiefConplaint: chief_conplaint,
  5753. PersonalHistory: personal_history,
  5754. FamilyHistory: family_history,
  5755. Diagnostic: diagnostic,
  5756. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5757. Status: 1,
  5758. Ctime: ctime,
  5759. Mtime: ctime,
  5760. RecordDate: recordDateTime,
  5761. DeliveryWay: delivery_way,
  5762. Breathing: breathingfloat,
  5763. DoctorAdvice: doctor_advice,
  5764. Remark: remark,
  5765. Sick: sick,
  5766. Diagnose: diagnose,
  5767. AllergicHistory: allergic_history,
  5768. PrimaryDisease: primary_disease,
  5769. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5770. DrugAllergyHistory: drug_allergy_history,
  5771. PhysicalExamination: physical_examination,
  5772. SpecialInspection: special_inspection,
  5773. LabApparatus: lab_apparatus,
  5774. }
  5775. //查询该患者是否有病历
  5776. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5777. if errcodes == gorm.ErrRecordNotFound {
  5778. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5779. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5780. if err != nil {
  5781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5782. return
  5783. }
  5784. c.ServeSuccessJSON(map[string]interface{}{
  5785. "caseHistory": caseHistory,
  5786. "historyInfo": historyInfo,
  5787. })
  5788. return
  5789. } else if errcodes == nil {
  5790. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5791. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5792. if err != nil {
  5793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5794. return
  5795. }
  5796. c.ServeSuccessJSON(map[string]interface{}{
  5797. "caseHistory": caseHistory,
  5798. "historyInfo": historyInfo,
  5799. })
  5800. }
  5801. //查询该患者是否有病历
  5802. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5803. //if errcode == gorm.ErrRecordNotFound {
  5804. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5805. // if err != nil {
  5806. // c.ServeSuccessJSON(map[string]interface{}{
  5807. // "msg": "保存成功",
  5808. // })
  5809. // }
  5810. //} else if errcode == nil {
  5811. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5812. // return
  5813. //}
  5814. }
  5815. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5816. patient_id, _ := c.GetInt64("patient_id", 0)
  5817. adminUser := c.GetAdminUserInfo()
  5818. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5819. c.ServeSuccessJSON(map[string]interface{}{
  5820. "list": caseHistorys,
  5821. })
  5822. }
  5823. func (c *HisApiController) GetHisPatientCaseHistory() {
  5824. record_date, _ := c.GetInt64("record_date", 0)
  5825. patient_id, _ := c.GetInt64("patient_id", 0)
  5826. admin := c.GetAdminUserInfo()
  5827. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5828. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5829. c.ServeSuccessJSON(map[string]interface{}{
  5830. "info": info,
  5831. "case_history": case_history,
  5832. })
  5833. }
  5834. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5835. template_name := c.GetString("template_name")
  5836. template_remark := c.GetString("template_remark")
  5837. doctor := c.GetAdminUserInfo().AdminUser.Id
  5838. diagnostic := c.GetString("diagnostic")
  5839. chief_conplaint := c.GetString("chief_conplain")
  5840. history_of_present_illness := c.GetString("history_of_present_illness")
  5841. past_history := c.GetString("past_history")
  5842. personal_history := c.GetString("personal_history")
  5843. family_history := c.GetString("family_history")
  5844. user_name := c.GetString("user_name")
  5845. doctor_advice := c.GetString("doctor_advice")
  5846. remark := c.GetString("remark")
  5847. //record_date := c.GetString("record_date")
  5848. //fmt.Println("record_date--------",record_date)
  5849. //timeLayout := "2006-01-02"
  5850. //loc, _ := time.LoadLocation("Local")
  5851. //
  5852. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5853. //if err != nil {
  5854. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5855. // return
  5856. //}
  5857. //recordDateTime := theTime.Unix()
  5858. ctime := time.Now().Unix()
  5859. template := models.HisCaseHistoryTemplate{
  5860. HistoryOfPresentIllness: history_of_present_illness,
  5861. PastHistory: past_history,
  5862. ChiefConplaint: chief_conplaint,
  5863. PersonalHistory: personal_history,
  5864. FamilyHistory: family_history,
  5865. Diagnostic: diagnostic,
  5866. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5867. Status: 1,
  5868. Ctime: ctime,
  5869. Mtime: ctime,
  5870. RecordDate: time.Now().Unix(),
  5871. TemplateName: template_name,
  5872. TemplateRemark: template_remark,
  5873. Creator: doctor,
  5874. Modifier: doctor,
  5875. UserName: user_name,
  5876. DoctorAdvice: doctor_advice,
  5877. Remark: remark,
  5878. }
  5879. err := service.SaveHisPatientCaseHistoryTemplate(template)
  5880. if err == nil {
  5881. c.ServeSuccessJSON(map[string]interface{}{
  5882. "msg": "保存成功",
  5883. })
  5884. } else {
  5885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5886. return
  5887. }
  5888. }
  5889. func (c *HisApiController) GetCaseHistoryTemplate() {
  5890. timeLayout := "2006-01-02"
  5891. loc, _ := time.LoadLocation("Local")
  5892. keyword := c.GetString("keyword")
  5893. start_time := c.GetString("start_time")
  5894. end_time := c.GetString("end_time")
  5895. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5896. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5897. admin := c.GetAdminUserInfo()
  5898. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  5899. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  5900. c.ServeSuccessJSON(map[string]interface{}{
  5901. "template": template,
  5902. //"history": history,
  5903. })
  5904. }
  5905. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5906. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5907. utils.ErrorLog("drug_name")
  5908. return enums.ErrorCodeParamWrong
  5909. }
  5910. adviceName, _ := json["drug_name"].(string)
  5911. if len(adviceName) == 0 {
  5912. utils.ErrorLog("len(advice_name) == 0")
  5913. return enums.ErrorCodeParamWrong
  5914. }
  5915. advice.AdviceName = adviceName
  5916. adviceDesc, _ := json["advice_desc"].(string)
  5917. advice.AdviceDesc = adviceDesc
  5918. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5919. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5920. advice.DrugSpec = drugSpec
  5921. }
  5922. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5923. remark, _ := json["remark"].(string)
  5924. advice.Remark = remark
  5925. }
  5926. if json["id"] == nil {
  5927. advice.DrugId = 0
  5928. } else {
  5929. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5930. drug_id := int64(json["id"].(float64))
  5931. advice.DrugId = drug_id
  5932. }
  5933. }
  5934. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5935. advice_id := int64(json["advice_id"].(float64))
  5936. advice.ID = advice_id
  5937. if advice.ID > 0 {
  5938. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5939. if err == nil {
  5940. if hisAdvice.ID > 0 {
  5941. advice.ExecutionTime = hisAdvice.ExecutionTime
  5942. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5943. advice.ExecutionState = hisAdvice.ExecutionState
  5944. advice.CheckTime = hisAdvice.CheckTime
  5945. advice.Checker = hisAdvice.Checker
  5946. advice.CheckState = hisAdvice.CheckState
  5947. advice.StartTime = hisAdvice.StartTime
  5948. advice.FeedetlSn = hisAdvice.FeedetlSn
  5949. }
  5950. }
  5951. }
  5952. }
  5953. //
  5954. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5955. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5956. // advice.ExecutionTime = execution_time
  5957. //}
  5958. //
  5959. //
  5960. //
  5961. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5962. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5963. // advice.ExecutionStaff = execution_staff
  5964. //}
  5965. //
  5966. //
  5967. //
  5968. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5969. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5970. // advice.ExecutionState = execution_state
  5971. //}
  5972. //
  5973. //
  5974. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5975. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5976. // advice.CheckTime = check_time
  5977. //}
  5978. //
  5979. //
  5980. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5981. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5982. // advice.CheckState = check_state
  5983. //}
  5984. //
  5985. //
  5986. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5987. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5988. // advice.Checker = checker
  5989. //}
  5990. //
  5991. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5992. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5993. // advice.StartTime = start_time
  5994. //}
  5995. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5996. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5997. advice.IsSelfDrug = is_self_drug
  5998. }
  5999. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6000. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6001. drug_way_count, _ := json["drug_way_count"].(string)
  6002. advice.DrugWayCount = drug_way_count
  6003. }
  6004. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6005. drugSpecUnit, _ := json["min_unit"].(string)
  6006. advice.DrugSpecUnit = drugSpecUnit
  6007. }
  6008. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6009. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6010. advice.SingleDose = singleDose
  6011. }
  6012. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6013. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6014. advice.SingleDoseUnit = singleDoseUnit
  6015. }
  6016. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6017. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6018. advice.PrescribingNumber = prescribingNumber
  6019. }
  6020. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6021. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6022. advice.PrescribingNumberUnit = prescribingNumberUnit
  6023. }
  6024. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6025. deliveryWay, _ := json["delivery_way"].(string)
  6026. advice.DeliveryWay = deliveryWay
  6027. }
  6028. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6029. executionFrequency, _ := json["execution_frequency"].(string)
  6030. advice.ExecutionFrequency = executionFrequency
  6031. }
  6032. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6033. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6034. advice.Price = price
  6035. }
  6036. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6037. med_list_codg, _ := json["medical_insurance_number"].(string)
  6038. advice.MedListCodg = med_list_codg
  6039. }
  6040. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6041. day := int64(json["day"].(float64))
  6042. advice.Day = day
  6043. }
  6044. return 0
  6045. }
  6046. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6047. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6048. id := int64(json["id"].(float64))
  6049. project.ID = id
  6050. historyProject, _ := service.GetHisProjectByID(id)
  6051. project.FeedetlSn = historyProject.FeedetlSn
  6052. }
  6053. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6054. project_id := int64(json["project_id"].(float64))
  6055. project.ProjectId = project_id
  6056. }
  6057. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6058. // price := int64(json["price"].(float64))
  6059. // formatInt_price := strconv.FormatInt(price, 10)
  6060. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6061. // project.Price = float_price
  6062. // }
  6063. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6064. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6065. project.Price = price
  6066. }
  6067. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6068. total, _ := json["total"].(string)
  6069. project.Count = total
  6070. }
  6071. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6072. medical_code, _ := json["medical_code"].(string)
  6073. project.MedListCodg = medical_code
  6074. }
  6075. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6076. single_dose, _ := json["single_dose"].(string)
  6077. project.SingleDose = single_dose
  6078. }
  6079. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6080. delivery_way, _ := json["delivery_way"].(string)
  6081. project.DeliveryWay = delivery_way
  6082. }
  6083. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6084. execution_frequency, _ := json["execution_frequency"].(string)
  6085. project.ExecutionFrequency = execution_frequency
  6086. }
  6087. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6088. remark, _ := json["remark"].(string)
  6089. project.Remark = remark
  6090. }
  6091. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6092. day, _ := json["number_days"].(string)
  6093. project.Day = day
  6094. }
  6095. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6096. unit, _ := json["unit"].(string)
  6097. project.Unit = unit
  6098. }
  6099. return 0
  6100. }
  6101. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6102. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6103. id := int64(json["id"].(float64))
  6104. historyAddtions, _ := service.GetHisAdditionByID(id)
  6105. additionalCharge.ID = id
  6106. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  6107. }
  6108. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6109. item_id := int64(json["item_id"].(float64))
  6110. additionalCharge.ItemId = item_id
  6111. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6112. if config.ID > 0 {
  6113. if len(config.Code) > 0 {
  6114. additionalCharge.MedListCodg = config.Code
  6115. }
  6116. }
  6117. }
  6118. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6119. // price := int64(json["price"].(float64))
  6120. // formatInt_price := strconv.FormatInt(price, 10)
  6121. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6122. // additionalCharge.Price = float_price
  6123. // }
  6124. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6125. // price := int64(json["price"].(float64))
  6126. // formatInt_price := strconv.FormatInt(price, 10)
  6127. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6128. // additionalCharge.Price = float_price
  6129. //}
  6130. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6131. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6132. additionalCharge.Price = price
  6133. }
  6134. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6135. count, _ := json["count"].(string)
  6136. counts, _ := strconv.ParseInt(count, 10, 64)
  6137. additionalCharge.Count = counts
  6138. }
  6139. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6140. item_name, _ := json["item_name"].(string)
  6141. additionalCharge.ItemName = item_name
  6142. }
  6143. return 0
  6144. }
  6145. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6146. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6147. utils.ErrorLog("drug_name")
  6148. return enums.ErrorCodeParamWrong
  6149. }
  6150. adviceName, _ := json["drug_name"].(string)
  6151. if len(adviceName) == 0 {
  6152. utils.ErrorLog("len(advice_name) == 0")
  6153. return enums.ErrorCodeParamWrong
  6154. }
  6155. advice.AdviceName = adviceName
  6156. adviceDesc, _ := json["advice_desc"].(string)
  6157. advice.AdviceDesc = adviceDesc
  6158. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6159. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6160. advice.DrugSpec = drugSpec
  6161. }
  6162. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6163. remark, _ := json["remark"].(string)
  6164. advice.Remark = remark
  6165. }
  6166. if json["id"] == nil {
  6167. advice.DrugId = 0
  6168. } else {
  6169. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6170. drug_id := int64(json["id"].(float64))
  6171. advice.DrugId = drug_id
  6172. }
  6173. }
  6174. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6175. groupno := int64(json["groupno"].(float64))
  6176. advice.Groupno = groupno
  6177. }
  6178. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6179. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6180. advice.IsSelfDrug = is_self_drug
  6181. }
  6182. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6183. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6184. drug_way_count, _ := json["drug_way_count"].(string)
  6185. advice.DrugWayCount = drug_way_count
  6186. }
  6187. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6188. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6189. advice.HospApprFlag = hosp_appr_flag
  6190. }
  6191. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6192. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6193. advice.PrescribingNumber = prescribingNumber
  6194. }
  6195. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6196. // frequency_type := int64(json["frequency_type"].(float64))
  6197. // advice.FrequencyType = frequency_type
  6198. //}
  6199. //
  6200. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6201. // day_count := int64(json["day_count"].(float64))
  6202. // advice.DayCount = day_count
  6203. //}
  6204. //
  6205. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6206. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6207. // week_day, _ := json["week_day"].(string)
  6208. // advice.WeekDay = week_day
  6209. //}
  6210. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6211. drugSpecUnit, _ := json["min_unit"].(string)
  6212. advice.DrugSpecUnit = drugSpecUnit
  6213. }
  6214. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6215. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6216. advice.SingleDose = singleDose
  6217. }
  6218. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6219. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6220. advice.SingleDoseUnit = singleDoseUnit
  6221. }
  6222. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6223. deliveryWay, _ := json["delivery_way"].(string)
  6224. advice.DeliveryWay = deliveryWay
  6225. }
  6226. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6227. executionFrequency, _ := json["execution_frequency"].(string)
  6228. advice.ExecutionFrequency = executionFrequency
  6229. }
  6230. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6231. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6232. advice.Price = price
  6233. }
  6234. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6235. med_list_codg, _ := json["medical_insurance_number"].(string)
  6236. advice.MedListCodg = med_list_codg
  6237. }
  6238. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6239. day := int64(json["day"].(float64))
  6240. advice.Day = day
  6241. }
  6242. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6243. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6244. advice.PrescribingNumberUnit = prescribingNumberUnit
  6245. }
  6246. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6247. advice_id := int64(json["advice_id"].(float64))
  6248. advice.ID = advice_id
  6249. if advice.ID > 0 {
  6250. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6251. if err == nil {
  6252. if hisAdvice.ID > 0 {
  6253. advice.ExecutionTime = hisAdvice.ExecutionTime
  6254. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6255. advice.ExecutionState = hisAdvice.ExecutionState
  6256. advice.CheckTime = hisAdvice.CheckTime
  6257. advice.Checker = hisAdvice.Checker
  6258. advice.CheckState = hisAdvice.CheckState
  6259. advice.StartTime = hisAdvice.StartTime
  6260. advice.HospApprFlag = hisAdvice.HospApprFlag
  6261. advice.IsMedicine = hisAdvice.IsMedicine
  6262. if hisAdvice.UserOrgId == 10028 {
  6263. 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 {
  6264. advice.ExecutionTime = 0
  6265. advice.ExecutionStaff = 0
  6266. advice.ExecutionState = 2
  6267. advice.CheckTime = 0
  6268. advice.Checker = 0
  6269. advice.CheckState = 2
  6270. }
  6271. } else {
  6272. 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 {
  6273. advice.ExecutionTime = 0
  6274. advice.ExecutionStaff = 0
  6275. advice.ExecutionState = 2
  6276. advice.CheckTime = 0
  6277. advice.Checker = 0
  6278. advice.CheckState = 2
  6279. }
  6280. }
  6281. //advice.Groupno = hisAdvice.Groupno
  6282. }
  6283. }
  6284. }
  6285. }
  6286. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6287. //
  6288. //if drugStockConfig.IsOpen == 1 {
  6289. //
  6290. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6291. // if advice.ID == 0 { //医嘱不存在
  6292. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6293. // drug.Total = drug.Total - advice.PrescribingNumber
  6294. // service.UpdateBaseDrugLib(&drug)
  6295. //
  6296. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6297. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6298. // drug.Total = drug.Total - num
  6299. // service.UpdateBaseDrugLib(&drug)
  6300. // }
  6301. //
  6302. // } else if advice.ID > 0 { //医嘱存在
  6303. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6304. // var num float64
  6305. //
  6306. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6307. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6308. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6309. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6310. // drug.Total = drug.Total + num
  6311. // service.UpdateBaseDrugLib(&drug)
  6312. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6313. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6314. // drug.Total = drug.Total - num
  6315. // service.UpdateBaseDrugLib(&drug)
  6316. // }
  6317. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6318. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6319. // if num2 > advice.PrescribingNumber {
  6320. // num = num2 - advice.PrescribingNumber
  6321. // drug.Total = drug.Total + num
  6322. // service.UpdateBaseDrugLib(&drug)
  6323. // } else if num2 < advice.PrescribingNumber {
  6324. // num = advice.PrescribingNumber - num2
  6325. // drug.Total = drug.Total - num
  6326. // service.UpdateBaseDrugLib(&drug)
  6327. // }
  6328. //
  6329. // }
  6330. //
  6331. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6332. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6333. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6334. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6335. // if num1 > num2 {
  6336. // num = num1 - num2
  6337. // drug.Total = drug.Total + num
  6338. // service.UpdateBaseDrugLib(&drug)
  6339. // } else if num1 < num2 {
  6340. // num = num2 - num1
  6341. // drug.Total = drug.Total - num
  6342. // service.UpdateBaseDrugLib(&drug)
  6343. // }
  6344. //
  6345. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6346. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6347. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6348. // if hisAdvice.PrescribingNumber > num2 {
  6349. // num = hisAdvice.PrescribingNumber - num2
  6350. // drug.Total = drug.Total + num
  6351. // service.UpdateBaseDrugLib(&drug)
  6352. // } else if num2 < advice.PrescribingNumber {
  6353. // num = num2 - hisAdvice.PrescribingNumber
  6354. // drug.Total = drug.Total - num
  6355. // service.UpdateBaseDrugLib(&drug)
  6356. // }
  6357. //
  6358. // }
  6359. // }
  6360. // }
  6361. //}
  6362. //
  6363. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6364. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6365. // advice.ExecutionTime = execution_time
  6366. //}
  6367. //
  6368. //
  6369. //
  6370. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6371. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6372. // advice.ExecutionStaff = execution_staff
  6373. //}
  6374. //
  6375. //
  6376. //
  6377. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6378. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6379. // advice.ExecutionState = execution_state
  6380. //}
  6381. //
  6382. //
  6383. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6384. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6385. // advice.CheckTime = check_time
  6386. //}
  6387. //
  6388. //
  6389. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6390. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6391. // advice.CheckState = check_state
  6392. //}
  6393. //
  6394. //
  6395. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6396. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6397. // advice.Checker = checker
  6398. //}
  6399. //
  6400. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6401. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6402. // advice.StartTime = start_time
  6403. //}
  6404. return 0
  6405. }
  6406. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6407. project.ExecutionStaff = 0
  6408. project.ExecutionState = 2
  6409. project.ExecutionTime = 0
  6410. project.Checker = 0
  6411. project.CheckState = 2
  6412. project.CheckTime = 0
  6413. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6414. id := int64(json["id"].(float64))
  6415. project.ID = id
  6416. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6417. project.ExecutionStaff = temp_project.ExecutionStaff
  6418. project.ExecutionState = temp_project.ExecutionState
  6419. project.ExecutionTime = temp_project.ExecutionTime
  6420. project.Checker = temp_project.Checker
  6421. project.CheckState = temp_project.CheckState
  6422. project.CheckTime = temp_project.CheckTime
  6423. project.TeamId = temp_project.TeamId
  6424. }
  6425. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6426. types := int64(json["type"].(float64))
  6427. project.Type = types
  6428. }
  6429. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6430. project_id := int64(json["project_id"].(float64))
  6431. project.ProjectId = project_id
  6432. }
  6433. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6434. team_id := int64(json["team_id"].(float64))
  6435. project.TeamId = team_id
  6436. }
  6437. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6438. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6439. project.Price = price
  6440. }
  6441. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6442. total, _ := json["total"].(string)
  6443. //totals, _ := strconv.ParseInt(total, 10, 64)
  6444. project.Count = total
  6445. }
  6446. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6447. medical_code, _ := json["medical_code"].(string)
  6448. project.MedListCodg = medical_code
  6449. }
  6450. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6451. single_dose, _ := json["single_dose"].(string)
  6452. project.SingleDose = single_dose
  6453. }
  6454. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6455. delivery_way, _ := json["delivery_way"].(string)
  6456. project.DeliveryWay = delivery_way
  6457. }
  6458. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6459. execution_frequency, _ := json["execution_frequency"].(string)
  6460. project.ExecutionFrequency = execution_frequency
  6461. }
  6462. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6463. remark, _ := json["remark"].(string)
  6464. project.Remark = remark
  6465. }
  6466. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6467. day, _ := json["number_days"].(string)
  6468. project.Day = day
  6469. }
  6470. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6471. unit, _ := json["unit"].(string)
  6472. project.Unit = unit
  6473. }
  6474. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6475. // frequency_type := int64(json["frequency_type"].(float64))
  6476. // project.FrequencyType = frequency_type
  6477. //}
  6478. //
  6479. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6480. // day_count := int64(json["day_count"].(float64))
  6481. // project.DayCount = day_count
  6482. //}
  6483. //
  6484. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6485. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6486. // week_day, _ := json["week_day"].(string)
  6487. // project.WeekDay = week_day
  6488. //}
  6489. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6490. //
  6491. //if project.ID == 0 {
  6492. // if stockConfig.IsOpen == 1 {
  6493. // if project.Type == 3 {
  6494. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6495. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6496. // good.Total = good.Total - f_count
  6497. // service.UpdateGoodInfo(&good)
  6498. // }
  6499. // }
  6500. //
  6501. //} else {
  6502. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6503. //
  6504. // if stockConfig.IsOpen == 1 {
  6505. // if project.Type == 3 {
  6506. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6507. // if project.Count < temp_project.Count {
  6508. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6509. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6510. //
  6511. // other_count := f_count_two - f_count_one
  6512. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6513. // good.Total = good.Total + other_count_two
  6514. // service.UpdateGoodInfo(&good)
  6515. // } else 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_one - f_count_two
  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. // }
  6524. //
  6525. // }
  6526. // }
  6527. //
  6528. //}
  6529. return 0
  6530. }
  6531. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6532. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6533. utils.ErrorLog("drug_name")
  6534. return enums.ErrorCodeParamWrong
  6535. }
  6536. adviceName, _ := json["drug_name"].(string)
  6537. if len(adviceName) == 0 {
  6538. utils.ErrorLog("len(advice_name) == 0")
  6539. return enums.ErrorCodeParamWrong
  6540. }
  6541. advice.AdviceName = adviceName
  6542. adviceDesc, _ := json["advice_desc"].(string)
  6543. advice.AdviceDesc = adviceDesc
  6544. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6545. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6546. advice.DrugSpec = drugSpec
  6547. }
  6548. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6549. remark, _ := json["remark"].(string)
  6550. advice.Remark = remark
  6551. }
  6552. if json["id"] == nil {
  6553. advice.DrugId = 0
  6554. } else {
  6555. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6556. drug_id := int64(json["id"].(float64))
  6557. advice.DrugId = drug_id
  6558. }
  6559. }
  6560. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6561. groupno := int64(json["groupno"].(float64))
  6562. advice.Groupno = groupno
  6563. }
  6564. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6565. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6566. advice.IsSelfDrug = is_self_drug
  6567. }
  6568. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6569. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6570. drug_way_count, _ := json["drug_way_count"].(string)
  6571. advice.DrugWayCount = drug_way_count
  6572. }
  6573. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6574. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6575. advice.HospApprFlag = hosp_appr_flag
  6576. }
  6577. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6578. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6579. advice.PrescribingNumber = prescribingNumber
  6580. }
  6581. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6582. // frequency_type := int64(json["frequency_type"].(float64))
  6583. // advice.FrequencyType = frequency_type
  6584. //}
  6585. //
  6586. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6587. // day_count := int64(json["day_count"].(float64))
  6588. // advice.DayCount = day_count
  6589. //}
  6590. //
  6591. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6592. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6593. // week_day, _ := json["week_day"].(string)
  6594. // advice.WeekDay = week_day
  6595. //}
  6596. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6597. drugSpecUnit, _ := json["min_unit"].(string)
  6598. advice.DrugSpecUnit = drugSpecUnit
  6599. }
  6600. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6601. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6602. advice.SingleDose = singleDose
  6603. }
  6604. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6605. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6606. advice.SingleDoseUnit = singleDoseUnit
  6607. }
  6608. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6609. deliveryWay, _ := json["delivery_way"].(string)
  6610. advice.DeliveryWay = deliveryWay
  6611. }
  6612. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6613. executionFrequency, _ := json["execution_frequency"].(string)
  6614. advice.ExecutionFrequency = executionFrequency
  6615. }
  6616. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6617. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6618. advice.Price = price
  6619. }
  6620. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6621. med_list_codg, _ := json["medical_insurance_number"].(string)
  6622. advice.MedListCodg = med_list_codg
  6623. }
  6624. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6625. day := int64(json["day"].(float64))
  6626. advice.Day = day
  6627. }
  6628. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6629. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6630. advice.PrescribingNumberUnit = prescribingNumberUnit
  6631. }
  6632. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6633. advice_id := int64(json["advice_id"].(float64))
  6634. advice.ID = advice_id
  6635. if advice.ID > 0 {
  6636. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6637. if err == nil {
  6638. if hisAdvice.ID > 0 {
  6639. advice.ExecutionTime = hisAdvice.ExecutionTime
  6640. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6641. advice.ExecutionState = hisAdvice.ExecutionState
  6642. advice.CheckTime = hisAdvice.CheckTime
  6643. advice.Checker = hisAdvice.Checker
  6644. advice.CheckState = hisAdvice.CheckState
  6645. advice.StartTime = hisAdvice.StartTime
  6646. advice.HospApprFlag = hisAdvice.HospApprFlag
  6647. advice.IsMedicine = hisAdvice.IsMedicine
  6648. if hisAdvice.UserOrgId == 10028 {
  6649. 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 {
  6650. advice.ExecutionTime = 0
  6651. advice.ExecutionStaff = 0
  6652. advice.ExecutionState = 2
  6653. advice.CheckTime = 0
  6654. advice.Checker = 0
  6655. advice.CheckState = 2
  6656. }
  6657. } else {
  6658. 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 {
  6659. advice.ExecutionTime = 0
  6660. advice.ExecutionStaff = 0
  6661. advice.ExecutionState = 2
  6662. advice.CheckTime = 0
  6663. advice.Checker = 0
  6664. advice.CheckState = 2
  6665. }
  6666. }
  6667. //advice.Groupno = hisAdvice.Groupno
  6668. }
  6669. }
  6670. }
  6671. }
  6672. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6673. //
  6674. //if drugStockConfig.IsOpen == 1 {
  6675. //
  6676. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6677. // if advice.ID == 0 { //医嘱不存在
  6678. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6679. // drug.Total = drug.Total - advice.PrescribingNumber
  6680. // service.UpdateBaseDrugLib(&drug)
  6681. //
  6682. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6683. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6684. // drug.Total = drug.Total - num
  6685. // service.UpdateBaseDrugLib(&drug)
  6686. // }
  6687. //
  6688. // } else if advice.ID > 0 { //医嘱存在
  6689. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6690. // var num float64
  6691. //
  6692. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6693. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6694. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6695. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6696. // drug.Total = drug.Total + num
  6697. // service.UpdateBaseDrugLib(&drug)
  6698. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6699. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6700. // drug.Total = drug.Total - num
  6701. // service.UpdateBaseDrugLib(&drug)
  6702. // }
  6703. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6704. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6705. // if num2 > advice.PrescribingNumber {
  6706. // num = num2 - advice.PrescribingNumber
  6707. // drug.Total = drug.Total + num
  6708. // service.UpdateBaseDrugLib(&drug)
  6709. // } else if num2 < advice.PrescribingNumber {
  6710. // num = advice.PrescribingNumber - num2
  6711. // drug.Total = drug.Total - num
  6712. // service.UpdateBaseDrugLib(&drug)
  6713. // }
  6714. //
  6715. // }
  6716. //
  6717. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6718. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6719. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6720. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6721. // if num1 > num2 {
  6722. // num = num1 - num2
  6723. // drug.Total = drug.Total + num
  6724. // service.UpdateBaseDrugLib(&drug)
  6725. // } else if num1 < num2 {
  6726. // num = num2 - num1
  6727. // drug.Total = drug.Total - num
  6728. // service.UpdateBaseDrugLib(&drug)
  6729. // }
  6730. //
  6731. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6732. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6733. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6734. // if hisAdvice.PrescribingNumber > num2 {
  6735. // num = hisAdvice.PrescribingNumber - num2
  6736. // drug.Total = drug.Total + num
  6737. // service.UpdateBaseDrugLib(&drug)
  6738. // } else if num2 < advice.PrescribingNumber {
  6739. // num = num2 - hisAdvice.PrescribingNumber
  6740. // drug.Total = drug.Total - num
  6741. // service.UpdateBaseDrugLib(&drug)
  6742. // }
  6743. //
  6744. // }
  6745. // }
  6746. // }
  6747. //}
  6748. //
  6749. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6750. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6751. // advice.ExecutionTime = execution_time
  6752. //}
  6753. //
  6754. //
  6755. //
  6756. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6757. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6758. // advice.ExecutionStaff = execution_staff
  6759. //}
  6760. //
  6761. //
  6762. //
  6763. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6764. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6765. // advice.ExecutionState = execution_state
  6766. //}
  6767. //
  6768. //
  6769. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6770. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6771. // advice.CheckTime = check_time
  6772. //}
  6773. //
  6774. //
  6775. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6776. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6777. // advice.CheckState = check_state
  6778. //}
  6779. //
  6780. //
  6781. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6782. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6783. // advice.Checker = checker
  6784. //}
  6785. //
  6786. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6787. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6788. // advice.StartTime = start_time
  6789. //}
  6790. return 0
  6791. }
  6792. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6793. project.ExecutionStaff = 0
  6794. project.ExecutionState = 2
  6795. project.ExecutionTime = 0
  6796. project.Checker = 0
  6797. project.CheckState = 2
  6798. project.CheckTime = 0
  6799. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6800. id := int64(json["id"].(float64))
  6801. project.ID = id
  6802. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6803. project.ExecutionStaff = temp_project.ExecutionStaff
  6804. project.ExecutionState = temp_project.ExecutionState
  6805. project.ExecutionTime = temp_project.ExecutionTime
  6806. project.Checker = temp_project.Checker
  6807. project.CheckState = temp_project.CheckState
  6808. project.CheckTime = temp_project.CheckTime
  6809. project.TeamId = temp_project.TeamId
  6810. }
  6811. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6812. types := int64(json["type"].(float64))
  6813. project.Type = types
  6814. }
  6815. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6816. project_id := int64(json["project_id"].(float64))
  6817. project.ProjectId = project_id
  6818. }
  6819. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6820. team_id := int64(json["team_id"].(float64))
  6821. project.TeamId = team_id
  6822. }
  6823. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6824. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6825. project.Price = price
  6826. }
  6827. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6828. total, _ := json["total"].(string)
  6829. //totals, _ := strconv.ParseInt(total, 10, 64)
  6830. project.Count = total
  6831. }
  6832. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6833. medical_code, _ := json["medical_code"].(string)
  6834. project.MedListCodg = medical_code
  6835. }
  6836. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6837. single_dose, _ := json["single_dose"].(string)
  6838. project.SingleDose = single_dose
  6839. }
  6840. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6841. delivery_way, _ := json["delivery_way"].(string)
  6842. project.DeliveryWay = delivery_way
  6843. }
  6844. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6845. execution_frequency, _ := json["execution_frequency"].(string)
  6846. project.ExecutionFrequency = execution_frequency
  6847. }
  6848. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6849. remark, _ := json["remark"].(string)
  6850. project.Remark = remark
  6851. }
  6852. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6853. day, _ := json["number_days"].(string)
  6854. project.Day = day
  6855. }
  6856. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6857. unit, _ := json["unit"].(string)
  6858. project.Unit = unit
  6859. }
  6860. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6861. // frequency_type := int64(json["frequency_type"].(float64))
  6862. // project.FrequencyType = frequency_type
  6863. //}
  6864. //
  6865. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6866. // day_count := int64(json["day_count"].(float64))
  6867. // project.DayCount = day_count
  6868. //}
  6869. //
  6870. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6871. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6872. // week_day, _ := json["week_day"].(string)
  6873. // project.WeekDay = week_day
  6874. //}
  6875. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6876. //
  6877. //if project.ID == 0 {
  6878. // if stockConfig.IsOpen == 1 {
  6879. // if project.Type == 3 {
  6880. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6881. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6882. // good.Total = good.Total - f_count
  6883. // service.UpdateGoodInfo(&good)
  6884. // }
  6885. // }
  6886. //
  6887. //} else {
  6888. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6889. //
  6890. // if stockConfig.IsOpen == 1 {
  6891. // if project.Type == 3 {
  6892. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6893. // if project.Count < temp_project.Count {
  6894. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6895. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6896. //
  6897. // other_count := f_count_two - f_count_one
  6898. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6899. // good.Total = good.Total + other_count_two
  6900. // service.UpdateGoodInfo(&good)
  6901. // } else if project.Count > temp_project.Count {
  6902. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6903. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6904. //
  6905. // other_count := f_count_one - f_count_two
  6906. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6907. // good.Total = good.Total - other_count_two
  6908. // service.UpdateGoodInfo(&good)
  6909. // }
  6910. //
  6911. // }
  6912. // }
  6913. //
  6914. //}
  6915. return 0
  6916. }
  6917. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6918. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6919. id := int64(json["id"].(float64))
  6920. additionalCharge.ID = id
  6921. }
  6922. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6923. item_id := int64(json["item_id"].(float64))
  6924. additionalCharge.ItemId = item_id
  6925. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6926. if config.ID > 0 {
  6927. if len(config.Code) > 0 {
  6928. additionalCharge.MedListCodg = config.Code
  6929. }
  6930. }
  6931. }
  6932. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6933. // price := int64(json["price"].(float64))
  6934. // formatInt_price := strconv.FormatInt(price, 10)
  6935. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6936. // additionalCharge.Price = float_price
  6937. // }
  6938. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6939. // price := int64(json["price"].(float64))
  6940. // formatInt_price := strconv.FormatInt(price, 10)
  6941. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6942. // additionalCharge.Price = float_price
  6943. //}
  6944. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6945. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6946. additionalCharge.Price = price
  6947. }
  6948. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6949. count, _ := json["count"].(string)
  6950. counts, _ := strconv.ParseInt(count, 10, 64)
  6951. additionalCharge.Count = counts
  6952. }
  6953. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6954. item_name, _ := json["item_name"].(string)
  6955. additionalCharge.ItemName = item_name
  6956. }
  6957. return 0
  6958. }
  6959. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  6960. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6961. utils.ErrorLog("drug_name")
  6962. return enums.ErrorCodeParamWrong
  6963. }
  6964. adviceName, _ := json["drug_name"].(string)
  6965. if len(adviceName) == 0 {
  6966. utils.ErrorLog("len(advice_name) == 0")
  6967. return enums.ErrorCodeParamWrong
  6968. }
  6969. advice.AdviceName = adviceName
  6970. adviceDesc, _ := json["advice_desc"].(string)
  6971. advice.AdviceDesc = adviceDesc
  6972. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6973. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6974. advice.DrugSpec = drugSpec
  6975. }
  6976. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6977. remark, _ := json["remark"].(string)
  6978. advice.Remark = remark
  6979. }
  6980. if json["id"] == nil {
  6981. advice.DrugId = 0
  6982. } else {
  6983. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6984. drug_id := int64(json["id"].(float64))
  6985. advice.DrugId = drug_id
  6986. }
  6987. }
  6988. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6989. groupno := int64(json["groupno"].(float64))
  6990. advice.Groupno = groupno
  6991. }
  6992. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6993. drugSpecUnit, _ := json["min_unit"].(string)
  6994. advice.DrugSpecUnit = drugSpecUnit
  6995. }
  6996. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6997. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6998. advice.SingleDose = singleDose
  6999. }
  7000. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  7001. singleDoseUnit, _ := json["single_dose_unit"].(string)
  7002. advice.SingleDoseUnit = singleDoseUnit
  7003. }
  7004. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  7005. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  7006. advice.PrescribingNumber = prescribingNumber
  7007. }
  7008. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  7009. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  7010. advice.PrescribingNumberUnit = prescribingNumberUnit
  7011. }
  7012. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7013. deliveryWay, _ := json["delivery_way"].(string)
  7014. advice.DeliveryWay = deliveryWay
  7015. }
  7016. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7017. executionFrequency, _ := json["execution_frequency"].(string)
  7018. advice.ExecutionFrequency = executionFrequency
  7019. }
  7020. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  7021. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  7022. advice.Price = price
  7023. }
  7024. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  7025. med_list_codg, _ := json["medical_insurance_number"].(string)
  7026. advice.MedListCodg = med_list_codg
  7027. }
  7028. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  7029. day := int64(json["day"].(float64))
  7030. advice.Day = day
  7031. }
  7032. advice.FrequencyType = 1
  7033. return 0
  7034. }
  7035. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  7036. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  7037. types := int64(json["type"].(float64))
  7038. project.Type = types
  7039. }
  7040. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  7041. project_id := int64(json["project_id"].(float64))
  7042. project.ProjectId = project_id
  7043. }
  7044. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  7045. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  7046. project.Price = price
  7047. }
  7048. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  7049. total, _ := json["total"].(string)
  7050. //totals, _ := strconv.ParseInt(total, 10, 64)
  7051. project.Count = total
  7052. }
  7053. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  7054. medical_code, _ := json["medical_code"].(string)
  7055. project.MedListCodg = medical_code
  7056. }
  7057. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  7058. single_dose, _ := json["single_dose"].(string)
  7059. project.SingleDose = single_dose
  7060. }
  7061. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  7062. delivery_way, _ := json["delivery_way"].(string)
  7063. project.DeliveryWay = delivery_way
  7064. }
  7065. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  7066. execution_frequency, _ := json["execution_frequency"].(string)
  7067. project.ExecutionFrequency = execution_frequency
  7068. }
  7069. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  7070. remark, _ := json["remark"].(string)
  7071. project.Remark = remark
  7072. }
  7073. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  7074. day, _ := json["number_days"].(string)
  7075. project.Day = day
  7076. }
  7077. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  7078. unit, _ := json["unit"].(string)
  7079. project.Unit = unit
  7080. }
  7081. project.FrequencyType = 1
  7082. return 0
  7083. }
  7084. func (c *HisApiController) GetHisOrderListTwo() {
  7085. start_time := c.GetString("start_time")
  7086. end_time := c.GetString("end_time")
  7087. timeLayout := "2006-01-02"
  7088. loc, _ := time.LoadLocation("Local")
  7089. var startTime int64
  7090. if len(start_time) > 0 {
  7091. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7092. if err != nil {
  7093. //fmt.Println(err)
  7094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7095. return
  7096. }
  7097. startTime = theTime.Unix()
  7098. }
  7099. var endTime int64
  7100. if len(end_time) > 0 {
  7101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7102. if err != nil {
  7103. utils.ErrorLog(err.Error())
  7104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7105. return
  7106. }
  7107. endTime = theTime.Unix()
  7108. }
  7109. adminUser := c.GetAdminUserInfo()
  7110. org_id := adminUser.CurrentOrgId
  7111. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  7112. if err == nil {
  7113. c.ServeSuccessJSON(map[string]interface{}{
  7114. "order2": order,
  7115. })
  7116. } else {
  7117. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7118. return
  7119. }
  7120. }
  7121. func (c *HisApiController) GetHisOrderList() {
  7122. page, _ := c.GetInt64("page", -1)
  7123. limit, _ := c.GetInt64("limit", -1)
  7124. start_time := c.GetString("start_time")
  7125. end_time := c.GetString("end_time")
  7126. types, _ := c.GetInt64("type", 0)
  7127. keywords := c.GetString("keywords")
  7128. p_type, _ := c.GetInt64("p_type", 0)
  7129. sort_type, _ := c.GetInt64("sort_type", 0)
  7130. charge_type, _ := c.GetInt64("charge_type", 0)
  7131. sch_type, _ := c.GetInt64("sch_type", 0)
  7132. zone_type, _ := c.GetInt64("zone_type", 0)
  7133. med_type, _ := c.GetInt64("med_type", 0)
  7134. timeLayout := "2006-01-02"
  7135. loc, _ := time.LoadLocation("Local")
  7136. var startTime int64
  7137. if len(start_time) > 0 {
  7138. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7139. if err != nil {
  7140. //fmt.Println(err)
  7141. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7142. return
  7143. }
  7144. startTime = theTime.Unix()
  7145. }
  7146. var endTime int64
  7147. if len(end_time) > 0 {
  7148. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7149. if err != nil {
  7150. utils.ErrorLog(err.Error())
  7151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7152. return
  7153. }
  7154. endTime = theTime.Unix()
  7155. }
  7156. adminUser := c.GetAdminUserInfo()
  7157. org_id := adminUser.CurrentOrgId
  7158. 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)
  7159. for _, item := range order {
  7160. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7161. item.DoctorName = info.Doctor
  7162. item.DepartmentName = info.XtHisDepartment.Name
  7163. }
  7164. if err == nil {
  7165. c.ServeSuccessJSON(map[string]interface{}{
  7166. "order": order,
  7167. "total": total,
  7168. })
  7169. } else {
  7170. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7171. return
  7172. }
  7173. }
  7174. func (c *HisApiController) GetHisOrder() {
  7175. patient_id, _ := c.GetInt64("patient_id", 0)
  7176. number := c.GetString("number")
  7177. adminInfo := c.GetAdminUserInfo()
  7178. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7179. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7180. if err == nil {
  7181. c.ServeSuccessJSON(map[string]interface{}{
  7182. "order": order,
  7183. "prescription": prescriptions,
  7184. })
  7185. } else {
  7186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7187. return
  7188. }
  7189. }
  7190. func (c *HisApiController) GetHisPrescriptionList() {
  7191. record_date := c.GetString("record_date")
  7192. keywords := c.GetString("keywords")
  7193. page, _ := c.GetInt64("page")
  7194. limit, _ := c.GetInt64("limit")
  7195. sch_type, _ := c.GetInt64("sch_type")
  7196. timeLayout := "2006-01-02"
  7197. loc, _ := time.LoadLocation("Local")
  7198. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7199. if err != nil {
  7200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7201. return
  7202. }
  7203. recordDateTime := theTime.Unix()
  7204. adminInfo := c.GetAdminUserInfo()
  7205. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7206. //adminInfo := c.GetAdminUserInfo()
  7207. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7208. //fmt.Println(prescriptionOrder)
  7209. if err == nil {
  7210. c.ServeSuccessJSON(map[string]interface{}{
  7211. "order": prescriptionOrder,
  7212. "total": total,
  7213. })
  7214. } else {
  7215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7216. return
  7217. }
  7218. }
  7219. func (c *HisApiController) GetHisPrescriptionInfo() {
  7220. id, _ := c.GetInt64("id")
  7221. adminInfo := c.GetAdminUserInfo()
  7222. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7223. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7224. if err == nil {
  7225. c.ServeSuccessJSON(map[string]interface{}{
  7226. "order": prescriptionOrder,
  7227. "prescription": prescription,
  7228. })
  7229. } else {
  7230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7231. return
  7232. }
  7233. }
  7234. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7235. adminUser := c.GetAdminUserInfo()
  7236. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7237. c.ServeSuccessJSON(map[string]interface{}{
  7238. "config": config,
  7239. })
  7240. }
  7241. type ResultTwo struct {
  7242. ErrMsg interface{} `json:"err_msg"`
  7243. InfRefmsgid string `json:"inf_refmsgid"`
  7244. Infcode int64 `json:"infcode"`
  7245. Output struct {
  7246. Baseinfo struct {
  7247. Age float64 `json:"age"`
  7248. Brdy string `json:"brdy"`
  7249. Certno string `json:"certno"`
  7250. Gend string `json:"gend"`
  7251. Naty string `json:"naty"`
  7252. PsnCertType string `json:"psn_cert_type"`
  7253. PsnName string `json:"psn_name"`
  7254. PsnNo string `json:"psn_no"`
  7255. } `json:"baseinfo"`
  7256. Idetinfo []interface{} `json:"idetinfo"`
  7257. Iinfo []struct {
  7258. Balc float64 `json:"balc"`
  7259. CvlservFlag string `json:"cvlserv_flag"`
  7260. EmpName string `json:"emp_name"`
  7261. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7262. Insutype string `json:"insutype"`
  7263. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7264. PausInsuDate interface{} `json:"paus_insu_date"`
  7265. PsnInsuDate string `json:"psn_insu_date"`
  7266. PsnInsuStas string `json:"psn_insu_stas"`
  7267. PsnType string `json:"psn_type"`
  7268. } `json:"insuinfo"`
  7269. } `json:"output"`
  7270. RefmsgTime string `json:"refmsg_time"`
  7271. RespondTime string `json:"respond_time"`
  7272. Signtype interface{} `json:"signtype"`
  7273. WarnInfo interface{} `json:"warn_info"`
  7274. }
  7275. type ResultThree struct {
  7276. Cainfo interface{} `json:"cainfo"`
  7277. ErrMsg interface{} `json:"err_msg"`
  7278. InfRefmsgid string `json:"inf_refmsgid"`
  7279. Infcode int64 `json:"infcode"`
  7280. Output struct {
  7281. Data struct {
  7282. IptOtpNo string `json:"ipt_otp_no"`
  7283. MdtrtID string `json:"mdtrt_id"`
  7284. PsnNo string `json:"psn_no"`
  7285. } `json:"data"`
  7286. } `json:"output"`
  7287. RefmsgTime string `json:"refmsg_time"`
  7288. RespondTime string `json:"respond_time"`
  7289. Signtype interface{} `json:"signtype"`
  7290. WarnMsg interface{} `json:"warn_msg"`
  7291. }
  7292. type ResultFour struct {
  7293. Cainfo string `json:"cainfo"`
  7294. ErrMsg string `json:"err_msg"`
  7295. InfRefmsgid string `json:"inf_refmsgid"`
  7296. Infcode int64 `json:"infcode"`
  7297. Output struct {
  7298. Result []struct {
  7299. BasMednFlag string `json:"bas_medn_flag"`
  7300. ChldMedcFlag string `json:"chld_medc_flag"`
  7301. ChrgitmLv string `json:"chrgitm_lv"`
  7302. Cnt float64 `json:"cnt"`
  7303. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  7304. DrtReimFlag string `json:"drt_reim_flag"`
  7305. FeedetlSn string `json:"feedetl_sn"`
  7306. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7307. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  7308. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7309. ListSpItemFlag string `json:"list_sp_item_flag"`
  7310. LmtUsedFlag string `json:"lmt_used_flag"`
  7311. MedChrgitmType string `json:"med_chrgitm_type"`
  7312. Memo string `json:"memo"`
  7313. OverlmtAmt float64 `json:"overlmt_amt"`
  7314. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7315. Pric float64 `json:"pric"`
  7316. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  7317. SelfpayProp float64 `json:"selfpay_prop"`
  7318. } `json:"result"`
  7319. } `json:"output"`
  7320. RefmsgTime string `json:"refmsg_time"`
  7321. RespondTime string `json:"respond_time"`
  7322. Signtype string `json:"signtype"`
  7323. WarnMsg string `json:"warn_msg"`
  7324. }
  7325. type ResultFive struct {
  7326. Insutype string `json:"insutype"`
  7327. }
  7328. type ResultSix struct {
  7329. Cainfo interface{} `json:"cainfo"`
  7330. ErrMsg interface{} `json:"err_msg"`
  7331. InfRefmsgid string `json:"inf_refmsgid"`
  7332. Infcode int64 `json:"infcode"`
  7333. Output struct {
  7334. } `json:"output"`
  7335. RefmsgTime string `json:"refmsg_time"`
  7336. RespondTime string `json:"respond_time"`
  7337. Signtype interface{} `json:"signtype"`
  7338. WarnMsg interface{} `json:"warn_msg"`
  7339. }
  7340. type ResultSeven struct {
  7341. Cainfo string `json:"cainfo"`
  7342. ErrMsg string `json:"err_msg"`
  7343. InfRefmsgid string `json:"inf_refmsgid"`
  7344. Infcode int64 `json:"infcode"`
  7345. Output struct {
  7346. Setldetail []interface{} `json:"setldetail"`
  7347. Setlinfo struct {
  7348. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7349. AcctPay float64 `json:"acct_pay"`
  7350. ActPayDedc float64 `json:"act_pay_dedc"`
  7351. Age float64 `json:"age"`
  7352. Balc float64 `json:"balc"`
  7353. Brdy string `json:"brdy"`
  7354. Certno string `json:"certno"`
  7355. ClrOptins string `json:"clr_optins"`
  7356. ClrType string `json:"clr_type"`
  7357. ClrWay string `json:"clr_way"`
  7358. CvlservFlag string `json:"cvlserv_flag"`
  7359. CvlservPay float64 `json:"cvlserv_pay"`
  7360. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7361. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7362. Gend string `json:"gend"`
  7363. HifesPay float64 `json:"hifes_pay"`
  7364. HifmiPay float64 `json:"hifmi_pay"`
  7365. HifobPay float64 `json:"hifob_pay"`
  7366. HifpPay float64 `json:"hifp_pay"`
  7367. HospPartAmt float64 `json:"hosp_part_amt"`
  7368. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7369. Insutype string `json:"insutype"`
  7370. MafPay float64 `json:"maf_pay"`
  7371. MdtrtCertType string `json:"mdtrt_cert_type"`
  7372. MdtrtID string `json:"mdtrt_id"`
  7373. MedType string `json:"med_type"`
  7374. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7375. MedinsSetlID string `json:"medins_setl_id"`
  7376. Naty string `json:"naty"`
  7377. OthPay float64 `json:"oth_pay"`
  7378. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7379. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7380. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7381. PsnCashPay float64 `json:"psn_cash_pay"`
  7382. PsnCertType string `json:"psn_cert_type"`
  7383. PsnName string `json:"psn_name"`
  7384. PsnNo string `json:"psn_no"`
  7385. PsnPartAmt float64 `json:"psn_part_amt"`
  7386. PsnType string `json:"psn_type"`
  7387. SetlID string `json:"setl_id"`
  7388. SetlTime string `json:"setl_time"`
  7389. } `json:"setlinfo"`
  7390. } `json:"output"`
  7391. RefmsgTime string `json:"refmsg_time"`
  7392. RespondTime string `json:"respond_time"`
  7393. Signtype interface{} `json:"signtype"`
  7394. WarnMsg interface{} `json:"warn_msg"`
  7395. }
  7396. type ResultEight struct {
  7397. Cainfo string `json:"cainfo"`
  7398. ErrMsg string `json:"err_msg"`
  7399. InfRefmsgid string `json:"inf_refmsgid"`
  7400. Infcode int64 `json:"infcode"`
  7401. Output struct {
  7402. Stmtinfo struct {
  7403. SetlOptins string `json:"setl_optins"`
  7404. StmtRslt string `json:"stmt_rslt"`
  7405. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  7406. } `json:"stmtinfo"`
  7407. } `json:"output"`
  7408. RefmsgTime string `json:"refmsg_time"`
  7409. RespondTime string `json:"respond_time"`
  7410. Signtype interface{} `json:"signtype"`
  7411. WarnMsg interface{} `json:"warn_msg"`
  7412. }
  7413. type ResultNine struct {
  7414. Cainfo string `json:"cainfo"`
  7415. ErrMsg string `json:"err_msg"`
  7416. InfRefmsgid string `json:"inf_refmsgid"`
  7417. Infcode int64 `json:"infcode"`
  7418. Output struct {
  7419. FileQuryNo string `json:"file_qury_no"`
  7420. } `json:"output"`
  7421. RefmsgTime string `json:"refmsg_time"`
  7422. RespondTime string `json:"respond_time"`
  7423. Signtype interface{} `json:"signtype"`
  7424. WarnMsg interface{} `json:"warn_msg"`
  7425. }
  7426. type ResultTen struct {
  7427. Cainfo string `json:"cainfo"`
  7428. ErrMsg string `json:"err_msg"`
  7429. InfRefmsgid string `json:"inf_refmsgid"`
  7430. Infcode int64 `json:"infcode"`
  7431. Output struct {
  7432. DldEndtime string `json:"dld_endtime"`
  7433. FileQuryNo string `json:"file_qury_no"`
  7434. Filename string `json:"filename"`
  7435. } `json:"output"`
  7436. RefmsgTime string `json:"refmsg_time"`
  7437. RespondTime string `json:"respond_time"`
  7438. Signtype interface{} `json:"signtype"`
  7439. WarnMsg interface{} `json:"warn_msg"`
  7440. }
  7441. type ResultEleven struct {
  7442. Cainfo string `json:"cainfo"`
  7443. ErrMsg string `json:"err_msg"`
  7444. InfRefmsgid string `json:"inf_refmsgid"`
  7445. Infcode int64 `json:"infcode"`
  7446. Output struct {
  7447. Setlinfo struct {
  7448. FixmedinsName string `json:"fixmedins_name"`
  7449. FixmedinsCode string `json:"fixmedins_code"`
  7450. PsnNo string `json:"psn_no"`
  7451. PsnName string `json:"psn_name"`
  7452. HifobPay float64 `json:"hifob_pay"`
  7453. Gend string `json:"gend"`
  7454. Brdy string `json:"brdy"`
  7455. PsnCertType string `json:"psn_cert_type"`
  7456. PsnType string `json:"psn_type"`
  7457. EmpName string `json:"emp_name"`
  7458. Certno string `json:"certno"`
  7459. Insutype string `json:"insutype"`
  7460. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7461. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7462. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7463. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7464. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7465. ActPayDedc float64 `json:"act_pay_dedc"`
  7466. HifpPay float64 `json:"hifp_pay"`
  7467. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7468. CvlservPay float64 `json:"cvlserv_pay"`
  7469. HifesPay float64 `json:"hifes_pay"`
  7470. HifmiPay float64 `json:"hifmi_pay"`
  7471. MafPay float64 `json:"maf_pay"`
  7472. OthPay float64 `json:"oth_pay"`
  7473. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7474. PsnPay float64 `json:"psn_pay"`
  7475. AcctPay float64 `json:"acct_pay"`
  7476. CashPayamt float64 `json:"cash_payamt"`
  7477. Balc float64 `json:"balc"`
  7478. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7479. MedinsSetlId string `json:"medins_setl_id"`
  7480. RefdSetlFlag string `json:"refd_setl_flag"`
  7481. SetlTime string `json:"setl_time"`
  7482. MedType string `json:"med_type"`
  7483. } `json:"setlinfo"`
  7484. } `json:"output"`
  7485. RefmsgTime string `json:"refmsg_time"`
  7486. RespondTime string `json:"respond_time"`
  7487. Signtype interface{} `json:"signtype"`
  7488. WarnMsg interface{} `json:"warn_msg"`
  7489. }
  7490. type Custom struct {
  7491. DetItemFeeSumamt string
  7492. Cut string
  7493. FeedetlSn string
  7494. Price string
  7495. MedListCodg string
  7496. Type int64
  7497. AdviceId int64
  7498. ProjectId int64
  7499. ItemId int64
  7500. }
  7501. // 获取个人信息----挂号-----上传就诊信息
  7502. func (c *HisApiController) GetRegisterInfo() {
  7503. id, _ := c.GetInt64("id")
  7504. record_time := c.GetString("record_time")
  7505. settlementValue, _ := c.GetInt64("settlement_value")
  7506. medical_insurance_card := c.GetString("medical_insurance_card")
  7507. name := c.GetString("name")
  7508. id_card_type, _ := c.GetInt64("id_card_type")
  7509. certificates, _ := c.GetInt64("certificates")
  7510. medical_care, _ := c.GetInt64("medical_care")
  7511. birthday := c.GetString("birthday")
  7512. age, _ := c.GetInt64("age")
  7513. id_card := c.GetString("id_card")
  7514. register_type, _ := c.GetInt64("register")
  7515. doctor, _ := c.GetInt64("doctor")
  7516. department, _ := c.GetInt64("department")
  7517. gender, _ := c.GetInt64("sex")
  7518. phone := c.GetString("phone")
  7519. registration_fee, _ := c.GetFloat("registration_fee")
  7520. medical_expenses, _ := c.GetFloat("medical_expenses")
  7521. social_type, _ := c.GetInt64("social_type")
  7522. //diagnosis_id, _ := c.GetInt64("diagnosis")
  7523. diagnosis_ids := c.GetString("diagnosis")
  7524. sick_type, _ := c.GetInt64("sick_type")
  7525. reg_type := c.GetString("p_type")
  7526. timeLayout := "2006-01-02"
  7527. loc, _ := time.LoadLocation("Local")
  7528. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  7529. birthUnix := birthdays.Unix()
  7530. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7531. if err != nil {
  7532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7533. return
  7534. }
  7535. recordDateTime := theTime.Unix()
  7536. adminInfo := c.GetAdminUserInfo()
  7537. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  7538. if tempPatient.ID == 0 {
  7539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  7540. return
  7541. }
  7542. var patient service.Patients
  7543. if id == 0 {
  7544. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  7545. } else {
  7546. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  7547. }
  7548. if patient.ID == 0 {
  7549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7550. return
  7551. }
  7552. if len(patient.IdCardNo) == 0 {
  7553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  7554. return
  7555. }
  7556. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7557. if len(his) >= 1 {
  7558. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  7559. if len(his) >= 1 && order.ID == 0 {
  7560. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  7561. return
  7562. }
  7563. }
  7564. timeStr := time.Now().Format("2006-01-02 15:04:05")
  7565. fmt.Println(timeStr)
  7566. timeArr := strings.Split(timeStr, " ")
  7567. fmt.Println(timeArr)
  7568. timeArrTwo := strings.Split(timeArr[0], "-")
  7569. timeArrThree := strings.Split(timeArr[1], ":")
  7570. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  7571. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7572. if len(lists) == 0 {
  7573. var hisPatient models.XtHisPatient
  7574. hisPatient = models.XtHisPatient{
  7575. Name: name,
  7576. Age: age,
  7577. Gender: gender,
  7578. Birthday: birthUnix,
  7579. Phone: phone,
  7580. MedicalTreatmentType: medical_care,
  7581. IdType: certificates,
  7582. IdCardNo: id_card,
  7583. BalanceAccountsType: settlementValue,
  7584. SocialType: social_type,
  7585. MedicalInsuranceNumber: medical_insurance_card,
  7586. RegisterType: register_type,
  7587. RegisterCost: registration_fee,
  7588. TreatmentCost: medical_expenses,
  7589. AdminUserId: adminInfo.AdminUser.Id,
  7590. UserOrgId: adminInfo.CurrentOrgId,
  7591. Status: 1,
  7592. RecordDate: recordDateTime,
  7593. IsReturn: 1,
  7594. PatientId: patient.ID,
  7595. Ctime: time.Now().Unix(),
  7596. Mtime: time.Now().Unix(),
  7597. Number: str,
  7598. IdCardType: id_card_type,
  7599. Departments: department,
  7600. Doctor: doctor,
  7601. PType: reg_type,
  7602. Diagnosis: diagnosis_ids,
  7603. SickType: sick_type,
  7604. }
  7605. service.CreateHisPatient(&hisPatient)
  7606. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7607. c.ServeSuccessJSON(map[string]interface{}{
  7608. "his_info": hisPatient,
  7609. })
  7610. } else {
  7611. //chrgBchno := rand.Intn(1000000) + 10000
  7612. var hisPatient models.XtHisPatient
  7613. hisPatient = models.XtHisPatient{
  7614. Name: name,
  7615. Age: age,
  7616. Gender: gender,
  7617. Birthday: birthUnix,
  7618. Phone: phone,
  7619. MedicalTreatmentType: medical_care,
  7620. IdType: certificates,
  7621. IdCardNo: id_card,
  7622. BalanceAccountsType: settlementValue,
  7623. SocialType: social_type,
  7624. MedicalInsuranceNumber: medical_insurance_card,
  7625. RegisterType: register_type,
  7626. RegisterCost: registration_fee,
  7627. TreatmentCost: medical_expenses,
  7628. AdminUserId: adminInfo.AdminUser.Id,
  7629. UserOrgId: adminInfo.CurrentOrgId,
  7630. Status: 1,
  7631. RecordDate: recordDateTime,
  7632. IsReturn: 1,
  7633. PatientId: patient.ID,
  7634. Ctime: time.Now().Unix(),
  7635. Mtime: time.Now().Unix(),
  7636. Number: str,
  7637. IdCardType: id_card_type,
  7638. Departments: department,
  7639. Doctor: doctor,
  7640. PType: reg_type,
  7641. Diagnosis: diagnosis_ids,
  7642. SickType: sick_type,
  7643. }
  7644. service.CreateHisPatient(&hisPatient)
  7645. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7646. c.ServeSuccessJSON(map[string]interface{}{
  7647. "his_info": hisPatient,
  7648. })
  7649. }
  7650. }
  7651. // 上传明细----结算
  7652. func (c *HisApiController) GetUploadInfo() {
  7653. id, _ := c.GetInt64("id")
  7654. record_time := c.GetString("record_time")
  7655. his_patient_id, _ := c.GetInt64("his_patient_id")
  7656. oth_desc := c.GetString("oth_desc")
  7657. pay_way, _ := c.GetInt64("pay_way")
  7658. pay_ways := c.GetString("pay_ways")
  7659. pay_price, _ := c.GetFloat("pay_price")
  7660. pay_card_no := c.GetString("pay_card_no")
  7661. discount_price, _ := c.GetFloat("discount_price")
  7662. preferential_price, _ := c.GetFloat("preferential_price")
  7663. reality_price, _ := c.GetFloat("reality_price")
  7664. found_price, _ := c.GetFloat("found_price")
  7665. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7666. private_price, _ := c.GetFloat("private_price")
  7667. timeLayout := "2006-01-02"
  7668. loc, _ := time.LoadLocation("Local")
  7669. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7670. fapiao_code := c.GetString("fapiao_code")
  7671. fapiao_number := c.GetString("fapiao_number")
  7672. diagnosis_id := c.GetString("diagnosis")
  7673. sick_type, _ := c.GetInt64("sick_type")
  7674. reg_type, _ := c.GetInt64("p_type")
  7675. order_id, _ := c.GetInt64("order_id")
  7676. cash_pay := c.GetString("cash_pay")
  7677. wechat_pay := c.GetString("wechat_pay")
  7678. ali_pay := c.GetString("ali_pay")
  7679. jifen_pay := c.GetString("jifen_pay")
  7680. band_card_pay := c.GetString("band_card_pay")
  7681. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7682. tmp_decimal := c.GetString("tmp_decimal")
  7683. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7684. var decimal float64 //本次使用的押金
  7685. var errmsg error
  7686. tx := service.XTWriteDB().Begin() //开了事务
  7687. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7688. defer func() {
  7689. if errmsg != nil {
  7690. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7691. tx.Rollback()
  7692. } else {
  7693. tx.Commit()
  7694. }
  7695. }()
  7696. fmt.Println("dec_way", dec_way)
  7697. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7698. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7699. return
  7700. }
  7701. if len(tmp_decimal) > 0 {
  7702. if tmp_decimal[0] == 45 {
  7703. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7704. return
  7705. }
  7706. }
  7707. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7708. fmt.Println(errs)
  7709. decimal = tt
  7710. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7711. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7712. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7713. if err != nil {
  7714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7715. return
  7716. }
  7717. recordDateTime := theTime.Unix()
  7718. adminUser := c.GetAdminUserInfo()
  7719. var prescriptions []*models.HisPrescription
  7720. var prescriptionsOne []*models.HisPrescription
  7721. var start_time int64
  7722. var end_time int64
  7723. ids_str := c.GetString("ids")
  7724. ids_arr := strings.Split(ids_str, ",")
  7725. if tempOrder.ID == 0 {
  7726. if settle_accounts_type == 1 { //日结
  7727. fmt.Println(reg_type)
  7728. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7729. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7730. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7731. } else {
  7732. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7733. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7734. }
  7735. } else { //月结
  7736. start_time_str := c.GetString("start_time")
  7737. end_time_str := c.GetString("end_time")
  7738. timeLayout := "2006-01-02"
  7739. loc, _ := time.LoadLocation("Local")
  7740. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7741. if err != nil {
  7742. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7743. return
  7744. }
  7745. recordStartTime := theStartTime.Unix()
  7746. start_time = recordStartTime
  7747. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7748. if err != nil {
  7749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7750. return
  7751. }
  7752. recordEndTime := theEndTime.Unix()
  7753. end_time = recordEndTime
  7754. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7755. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7756. }
  7757. var goods []*models.DialysisBeforePrepareGoods
  7758. var newGoods []*models.NewDialysisBeforePrepareGoods
  7759. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7760. var infos []*models.HisDoctorAdviceInfo
  7761. var infoList []*models.HisDoctorAdviceInfo
  7762. var hisAdvice []*models.HisDoctorAdviceInfo
  7763. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7764. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7765. //判断库存不足
  7766. //结算出库开关
  7767. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7768. if settConfig.IsOpen == 1 {
  7769. //判断库存的地方
  7770. for _, info := range prescriptions {
  7771. if info.Type == 1 {
  7772. infos = append(infos, info.HisDoctorAdviceInfo...)
  7773. }
  7774. if info.Type == 2 {
  7775. for _, sumItem := range info.HisPrescriptionProject {
  7776. if sumItem.Type == 3 {
  7777. var good models.DialysisBeforePrepareGoods
  7778. var newGood models.NewDialysisBeforePrepareGoods
  7779. good.GoodId = sumItem.GoodInfo.ID
  7780. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7781. count, _ := strconv.Atoi(sumItem.Count)
  7782. good.Count = int64(count)
  7783. good.StorehouseId = houseConfig.StorehouseOutInfo
  7784. good.ProjectId = sumItem.ID
  7785. goods = append(goods, &good)
  7786. newGood.GoodId = sumItem.GoodInfo.ID
  7787. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7788. count2, _ := strconv.Atoi(sumItem.Count)
  7789. newGood.Count = int64(count2)
  7790. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7791. newGood.ProjectId = sumItem.ID
  7792. newGoods = append(newGoods, &newGood)
  7793. }
  7794. }
  7795. }
  7796. }
  7797. for _, info := range prescriptionsOne {
  7798. if info.Type == 1 {
  7799. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7800. }
  7801. if info.Type == 2 {
  7802. for _, sumItem := range info.HisPrescriptionProject {
  7803. if sumItem.Type == 3 {
  7804. var newGood models.NewDialysisBeforePrepareGoods
  7805. newGood.GoodId = sumItem.GoodInfo.ID
  7806. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7807. count2, _ := strconv.Atoi(sumItem.Count)
  7808. newGood.Count = int64(count2)
  7809. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7810. newGood.ProjectId = sumItem.ID
  7811. newGoodOne = append(newGoodOne, &newGood)
  7812. }
  7813. }
  7814. }
  7815. }
  7816. //判断
  7817. for _, itemOne := range infos {
  7818. for _, itemTwo := range hisAdvice {
  7819. if itemOne.DrugId == itemTwo.DrugId {
  7820. itemTwo.Child = append(itemTwo.Child, itemOne)
  7821. }
  7822. }
  7823. }
  7824. for _, itemTwo := range hisAdvice {
  7825. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7826. var sum_out_count int64
  7827. for _, itemThree := range itemTwo.Child {
  7828. var prescribing_number int64
  7829. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7830. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7831. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7832. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7833. }
  7834. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7835. prescribing_number = parseIntPrescribingNumber
  7836. }
  7837. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7838. prescribing_number = parseIntPrescribingNumber
  7839. }
  7840. sum_out_count += prescribing_number
  7841. }
  7842. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  7843. if sum_out_count > drugStockOut.FlushCount {
  7844. c.ServeSuccessJSON(map[string]interface{}{
  7845. "msg": "2",
  7846. "drug": medical,
  7847. })
  7848. return
  7849. }
  7850. }
  7851. for _, itemOne := range newGoods {
  7852. for _, item := range newGoodOne {
  7853. if itemOne.GoodId == item.GoodId {
  7854. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  7855. }
  7856. }
  7857. }
  7858. for _, item := range newGoodOne {
  7859. var sum_out_count_one int64
  7860. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  7861. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  7862. sum_out_count_one += itemOne.Count
  7863. }
  7864. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7865. fmt.Println("sum_out_count_one", sum_out_count_one)
  7866. fmt.Println("list.FlushCount", list.FlushCount)
  7867. if sum_out_count_one > list.FlushCount {
  7868. c.ServeSuccessJSON(map[string]interface{}{
  7869. "msg": "3",
  7870. "good": good,
  7871. })
  7872. return
  7873. }
  7874. }
  7875. }
  7876. timestamp := time.Now().Unix()
  7877. tempTime := time.Unix(timestamp, 0)
  7878. timeFormat := tempTime.Format("20060102150405")
  7879. chrgBchno := rand.Intn(100000) + 10000
  7880. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7881. strconv.FormatInt(his.PatientId, 10)
  7882. var ids []int64
  7883. for _, item := range prescriptions {
  7884. ids = append(ids, item.ID)
  7885. }
  7886. var total float64
  7887. for _, item := range prescriptions {
  7888. fmt.Println(item)
  7889. if item.Type == 1 { //药品
  7890. for _, subItem := range item.HisDoctorAdviceInfo {
  7891. total = total + (subItem.Price * subItem.PrescribingNumber)
  7892. }
  7893. }
  7894. if item.Type == 2 { //项目
  7895. for _, subItem := range item.HisPrescriptionProject {
  7896. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7897. total = total + (subItem.Price * cnt)
  7898. }
  7899. }
  7900. for _, subItem := range item.HisAdditionalCharge {
  7901. total = total + (subItem.Price * float64(subItem.Count))
  7902. }
  7903. }
  7904. if reg_type == 1111 || reg_type == 1112 {
  7905. reg_type = 11
  7906. }
  7907. tm := time.Unix(time.Now().Unix(), 0)
  7908. allTotal := fmt.Sprintf("%.4f", total)
  7909. totals, _ := strconv.ParseFloat(allTotal, 64)
  7910. order := &models.HisOrder{
  7911. UserOrgId: adminUser.CurrentOrgId,
  7912. HisPatientId: his.ID,
  7913. PatientId: id,
  7914. SettleAccountsDate: recordDateTime,
  7915. Ctime: time.Now().Unix(),
  7916. Mtime: time.Now().Unix(),
  7917. Status: 1,
  7918. OrderStatus: 2,
  7919. MdtrtId: his.Number,
  7920. Number: chrg_bchno,
  7921. MedfeeSumamt: totals,
  7922. PayWay: pay_way,
  7923. PayWays: pay_ways,
  7924. PayPrice: pay_price,
  7925. MedType: strconv.Itoa(int(reg_type)),
  7926. PayCardNo: pay_card_no,
  7927. DiscountPrice: discount_price,
  7928. PreferentialPrice: preferential_price,
  7929. RealityPrice: reality_price,
  7930. FoundPrice: found_price,
  7931. MedicalInsurancePrice: medical_insurance_price,
  7932. PrivatePrice: private_price,
  7933. SettleEndTime: end_time,
  7934. SettleStartTime: start_time,
  7935. PsnPartAmt: totals,
  7936. PsnCashPay: totals,
  7937. SettleType: settle_accounts_type,
  7938. FaPiaoCode: fapiao_code,
  7939. FaPiaoNumber: fapiao_number,
  7940. Diagnosis: diagnosis_id,
  7941. PType: 2,
  7942. SetlTime: tm.Format("2006-01-02 15:04:05"),
  7943. Decimal: decimal,
  7944. OthDesc: oth_desc,
  7945. CashPay: cash_pay,
  7946. WechatPay: wechat_pay,
  7947. AliPay: ali_pay,
  7948. JifenPay: jifen_pay,
  7949. BandCardPay: band_card_pay,
  7950. Creator: adminUser.AdminUser.Id,
  7951. }
  7952. err = service.CreateOrderTX(order, tx)
  7953. if err != nil {
  7954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7955. return
  7956. }
  7957. var customs []*Custom
  7958. for _, item := range prescriptions {
  7959. if item.Type == 1 { //药品a
  7960. for _, subItem := range item.HisDoctorAdviceInfo {
  7961. cus := &Custom{
  7962. AdviceId: subItem.ID,
  7963. ProjectId: 0,
  7964. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  7965. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  7966. FeedetlSn: subItem.FeedetlSn,
  7967. Price: fmt.Sprintf("%.4f", subItem.Price),
  7968. MedListCodg: subItem.MedListCodg,
  7969. Type: 1,
  7970. }
  7971. customs = append(customs, cus)
  7972. }
  7973. }
  7974. if item.Type == 2 { //项目
  7975. for _, subItem := range item.HisPrescriptionProject {
  7976. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7977. cus := &Custom{
  7978. AdviceId: 0,
  7979. ProjectId: subItem.ID,
  7980. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  7981. Cut: fmt.Sprintf("%.4f", cnt),
  7982. FeedetlSn: subItem.FeedetlSn,
  7983. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  7984. MedListCodg: subItem.MedListCodg,
  7985. Type: 2,
  7986. }
  7987. customs = append(customs, cus)
  7988. }
  7989. }
  7990. for _, item := range item.HisAdditionalCharge {
  7991. cus := &Custom{
  7992. ItemId: item.ID,
  7993. AdviceId: 0,
  7994. ProjectId: 0,
  7995. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  7996. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  7997. FeedetlSn: item.FeedetlSn,
  7998. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  7999. MedListCodg: item.XtHisAddtionConfig.Code,
  8000. Type: 3,
  8001. }
  8002. customs = append(customs, cus)
  8003. }
  8004. }
  8005. for _, item := range customs {
  8006. var advice_id int64 = 0
  8007. var project_id int64 = 0
  8008. var item_id int64 = 0
  8009. var types int64 = 0
  8010. if item.Type == 1 {
  8011. advice_id = item.AdviceId
  8012. project_id = 0
  8013. item_id = 0
  8014. } else if item.Type == 2 {
  8015. advice_id = 0
  8016. item_id = 0
  8017. project_id = item.ProjectId
  8018. } else if item.Type == 3 {
  8019. advice_id = 0
  8020. item_id = item.ItemId
  8021. project_id = 0
  8022. }
  8023. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8024. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8025. pric, _ := strconv.ParseFloat(item.Price, 32)
  8026. info := &models.HisOrderInfo{
  8027. OrderNumber: order.Number,
  8028. UploadDate: time.Now().Unix(),
  8029. AdviceId: advice_id,
  8030. DetItemFeeSumamt: detItemFeeSumamt,
  8031. Cnt: cut,
  8032. Pric: pric,
  8033. PatientId: id,
  8034. Status: 1,
  8035. Mtime: time.Now().Unix(),
  8036. Ctime: time.Now().Unix(),
  8037. UserOrgId: adminUser.CurrentOrgId,
  8038. HisPatientId: his.ID,
  8039. OrderId: order.ID,
  8040. ProjectId: project_id,
  8041. Type: types,
  8042. ItemId: item_id,
  8043. }
  8044. service.CreateOrderInfoTX(info, tx)
  8045. }
  8046. his.Diagnosis = diagnosis_id
  8047. his.SickType = sick_type
  8048. his.RegisterType = reg_type
  8049. his.MedicalTreatmentType = reg_type
  8050. service.UpdataHisPateintTX(&his, tx)
  8051. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  8052. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  8053. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  8054. //判断是否使用了押金
  8055. if dec_way == "true" {
  8056. tmpstring := strconv.FormatInt(order.ID, 10)
  8057. //扣押金
  8058. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  8059. order.Decimal = decimal
  8060. service.UpDateOrderTwo(order, tx)
  8061. if errmsg != nil {
  8062. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  8063. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8064. return
  8065. }
  8066. }
  8067. if err == nil {
  8068. for _, info := range prescriptions {
  8069. if info.Type == 1 {
  8070. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  8071. }
  8072. if info.Type == 2 {
  8073. for _, sumItem := range info.HisPrescriptionProject {
  8074. if sumItem.Type == 3 {
  8075. var good models.DialysisBeforePrepareGoods
  8076. var newGood models.NewDialysisBeforePrepareGoods
  8077. var oldGood models.OldDialysisBeforePrepareGoods
  8078. good.GoodId = sumItem.GoodInfo.ID
  8079. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8080. count, _ := strconv.Atoi(sumItem.Count)
  8081. good.Count = int64(count)
  8082. good.StorehouseId = houseConfig.StorehouseOutInfo
  8083. good.ProjectId = sumItem.ID
  8084. good.PatientId = sumItem.PatientId
  8085. goods = append(goods, &good)
  8086. newGood.GoodId = sumItem.GoodInfo.ID
  8087. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8088. count2, _ := strconv.Atoi(sumItem.Count)
  8089. newGood.Count = int64(count2)
  8090. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8091. newGood.ProjectId = sumItem.ID
  8092. newGood.PatientId = sumItem.HisPatientId
  8093. newGoods = append(newGoods, &newGood)
  8094. oldGood.GoodId = sumItem.GoodInfo.ID
  8095. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  8096. count3, _ := strconv.Atoi(sumItem.Count)
  8097. oldGood.Count = int64(count3)
  8098. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  8099. oldGood.ProjectId = sumItem.ID
  8100. oldGood.RecordDate = sumItem.RecordDate
  8101. oldGood.PatientId = sumItem.HisPatientId
  8102. oldGoods = append(oldGoods, &oldGood)
  8103. }
  8104. }
  8105. }
  8106. }
  8107. if settConfig.IsOpen == 1 {
  8108. for _, item := range infoList {
  8109. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  8110. if medical.IsUse == 2 {
  8111. //药品出库
  8112. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  8113. //查询默认仓库
  8114. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  8115. //查询默认仓库剩余多少库存
  8116. var sum_count int64
  8117. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  8118. for _, its := range stockInfo {
  8119. if its.MaxUnit == medical.MaxUnit {
  8120. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  8121. }
  8122. sum_count += its.StockMaxNumber + its.StockMinNumber
  8123. }
  8124. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  8125. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  8126. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  8127. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  8128. }
  8129. }
  8130. orgId := c.GetAdminUserInfo().CurrentOrgId
  8131. if len(oldGoods) > 0 {
  8132. timeStr := time.Now().Format("2006-01-02")
  8133. timeArr := strings.Split(timeStr, "-")
  8134. total, _ := service.FindAllWarehouseOut(orgId)
  8135. total = total + 1
  8136. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  8137. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  8138. number = number + total
  8139. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  8140. operation_time := time.Now().Unix()
  8141. creater := c.GetAdminUserInfo().AdminUser.Id
  8142. //查询默认出库仓库库存
  8143. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8144. recordDateStr := time.Now().Format("2006-01-02")
  8145. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8146. nowtime := recordDate.Unix()
  8147. warehouseOut := models.WarehouseOut{
  8148. WarehouseOutOrderNumber: warehousing_out_order,
  8149. OperationTime: operation_time,
  8150. OrgId: orgId,
  8151. Creater: creater,
  8152. Ctime: time.Now().Unix(),
  8153. Status: 1,
  8154. WarehouseOutTime: nowtime,
  8155. Type: 1,
  8156. StorehouseId: storeConfig.StorehouseOutInfo,
  8157. IsCheck: 1,
  8158. OrderId: order.ID,
  8159. IsSys: 5,
  8160. }
  8161. //查询是否生成出库单
  8162. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8163. if out.ID == 0 {
  8164. service.AddSigleWarehouseOut(&warehouseOut)
  8165. }
  8166. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8167. for _, item := range oldGoods {
  8168. dialyPrepareOne := models.DialysisBeforePrepare{
  8169. GoodTypeId: item.GoodTypeId,
  8170. GoodId: item.GoodId,
  8171. PatientId: his.PatientId,
  8172. RecordDate: item.RecordDate,
  8173. UserOrgId: adminUser.CurrentOrgId,
  8174. Count: item.Count,
  8175. Ctime: time.Now().Unix(),
  8176. Creater: adminUser.AdminUser.Id,
  8177. CommdityCode: item.CommdityCode,
  8178. Status: 1,
  8179. StorehouseId: houseConfig.StorehouseOutInfo,
  8180. }
  8181. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8182. //非零用
  8183. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8184. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8185. //查询剩余库存
  8186. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8187. var sum_count int64
  8188. for _, item := range goodList {
  8189. sum_count += item.StockCount
  8190. }
  8191. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8192. //耗材
  8193. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8194. }
  8195. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8196. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8197. //查询剩余库存
  8198. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8199. var sum_count int64
  8200. for _, item := range goodList {
  8201. sum_count += item.StockCount
  8202. }
  8203. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8204. //耗材
  8205. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8206. }
  8207. }
  8208. }
  8209. }
  8210. c.ServeSuccessJSON(map[string]interface{}{
  8211. "msg": "结算成功",
  8212. })
  8213. }
  8214. }
  8215. }
  8216. // 退款
  8217. func (c *HisApiController) Refund() {
  8218. order_id, _ := c.GetInt64("order_id")
  8219. order, _ := service.GetHisOrderByID(order_id)
  8220. adminUser := c.GetAdminUserInfo()
  8221. orgid := c.GetAdminUserInfo().CurrentOrgId
  8222. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8223. if err != nil {
  8224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8225. return
  8226. }
  8227. tmp := strconv.FormatInt(order.ID, 10)
  8228. //当押金不为零时产生退费记录
  8229. if order.Decimal != 0 {
  8230. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8231. if err != nil {
  8232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8233. return
  8234. }
  8235. }
  8236. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8237. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8238. var goods []*models.DialysisBeforePrepareGoods
  8239. var newGoods []*models.NewDialysisBeforePrepareGoods
  8240. var infos []*models.HisDoctorAdviceInfo
  8241. for _, info := range orders {
  8242. if info.AdviceId > 0 && info.ProjectId == 0 {
  8243. infos = append(infos, &info.HisDoctorAdviceInfo)
  8244. }
  8245. if info.ProjectId > 0 && info.AdviceId == 0 {
  8246. if info.HisPrescriptionProject.Type == 3 {
  8247. var good models.DialysisBeforePrepareGoods
  8248. var newGood models.NewDialysisBeforePrepareGoods
  8249. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8250. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8251. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8252. good.Count = int64(count)
  8253. good.StorehouseId = houseConfig.StorehouseOutInfo
  8254. good.ProjectId = info.HisPrescriptionProject.ID
  8255. good.PatientId = info.PatientId
  8256. good.OrderId = order_id
  8257. goods = append(goods, &good)
  8258. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8259. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8260. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8261. newGood.Count = int64(count2)
  8262. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8263. newGood.ProjectId = info.HisPrescriptionProject.ID
  8264. newGood.RecordDate = order.SettleAccountsDate
  8265. newGood.UserOrgId = order.UserOrgId
  8266. newGood.PatientId = info.PatientId
  8267. newGood.OrderId = order_id
  8268. newGoods = append(newGoods, &newGood)
  8269. }
  8270. }
  8271. }
  8272. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8273. if settConfig.IsOpen == 1 {
  8274. for _, item := range infos {
  8275. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8276. }
  8277. for _, item := range newGoods {
  8278. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8279. }
  8280. }
  8281. c.ServeSuccessJSON(map[string]interface{}{
  8282. "msg": "退费成功",
  8283. })
  8284. }
  8285. func (c *HisApiController) RefundNumber() {
  8286. his_patient_id, _ := c.GetInt64("id")
  8287. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8288. info.Status = 0
  8289. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  8290. if count > 0 {
  8291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  8292. return
  8293. }
  8294. err := service.SaveHisPatient(info)
  8295. if err == nil {
  8296. c.ServeSuccessJSON(map[string]interface{}{
  8297. "msg": "退号成功",
  8298. })
  8299. } else {
  8300. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8301. return
  8302. }
  8303. }
  8304. func (this *HisApiController) AdditionalCharge() {
  8305. dataBody := make(map[string]interface{}, 0)
  8306. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8307. fmt.Println(err)
  8308. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  8309. patient_id := int64(dataBody["patient_id"].(float64))
  8310. medicineData, _ := dataBody["medicineData"].([]interface{})
  8311. adminUserInfo := this.GetAdminUserInfo()
  8312. orgId := adminUserInfo.CurrentOrgId
  8313. admin_user_id := adminUserInfo.AdminUser.Id
  8314. timeStr := time.Now().Format("2006-01-02")
  8315. timeLayout := "2006-01-02 15:04:05"
  8316. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8317. timenow := timeStringToTime.Unix()
  8318. var additionalCharges []*models.HisAdditionalCharge
  8319. for _, item := range medicineData {
  8320. var randNum int
  8321. randNum = rand.Intn(10000) + 1000
  8322. timestamp := time.Now().Unix()
  8323. tempTime := time.Unix(timestamp, 0)
  8324. timeFormat := tempTime.Format("20060102150405")
  8325. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  8326. items := item.(map[string]interface{})
  8327. money := items["price"].(string)
  8328. item_id_str := items["item_id"].(string)
  8329. name := items["name"].(string)
  8330. id_str := items["id"].(string)
  8331. moneys, _ := strconv.ParseInt(money, 10, 64)
  8332. monStr := strconv.FormatInt(moneys, 10)
  8333. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  8334. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  8335. id, _ := strconv.ParseInt(id_str, 10, 64)
  8336. additionalCharge := &models.HisAdditionalCharge{
  8337. ID: id,
  8338. HisPatientId: his_patient_id,
  8339. UserOrgId: orgId,
  8340. PatientId: patient_id,
  8341. RecordDate: timenow,
  8342. Price: monneyStr,
  8343. Status: 1,
  8344. ItemName: name,
  8345. ItemId: item_id,
  8346. AdminUserId: admin_user_id,
  8347. CreatedTime: time.Now().Unix(),
  8348. OrderStatus: 0,
  8349. PrescriptionNumber: "",
  8350. BatchNumber: "",
  8351. FeedetlSn: p_number,
  8352. }
  8353. service.CreateAdditionalCharge(additionalCharge)
  8354. additionalCharges = append(additionalCharges, additionalCharge)
  8355. }
  8356. this.ServeSuccessJSON(map[string]interface{}{
  8357. "msg": "添加成功",
  8358. "additional_charges": additionalCharges,
  8359. })
  8360. }
  8361. func (this *HisApiController) DeleteAddition() {
  8362. id, _ := this.GetInt64("id")
  8363. //TODO 需要判断是否已经结算
  8364. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  8365. if err == nil {
  8366. this.ServeSuccessJSON(map[string]interface{}{
  8367. "msg": "删除成功",
  8368. })
  8369. return
  8370. } else {
  8371. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8372. return
  8373. }
  8374. }
  8375. func (this *HisApiController) GetAdminUsers() {
  8376. adminUser := this.GetAdminUserInfo()
  8377. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  8378. this.ServeSuccessJSON(map[string]interface{}{
  8379. "doctors": doctors,
  8380. })
  8381. }
  8382. func (this *HisApiController) GetLastOrNextHisPrescription() {
  8383. change_type, _ := this.GetInt64("type", 0)
  8384. record_date := this.GetString("record_time")
  8385. patient_id, _ := this.GetInt64("patient_id", 0)
  8386. p_type, _ := this.GetInt64("p_type", 0)
  8387. timeLayout := "2006-01-02"
  8388. loc, _ := time.LoadLocation("Local")
  8389. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8390. record_time := theAdviceRecordTime.Unix()
  8391. adminUserInfo := this.GetAdminUserInfo()
  8392. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  8393. if err == nil {
  8394. if len(prescriptions) == 0 {
  8395. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  8396. return
  8397. } else {
  8398. this.ServeSuccessJSON(map[string]interface{}{
  8399. "prescriptions": prescriptions,
  8400. })
  8401. return
  8402. }
  8403. } else {
  8404. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8405. return
  8406. }
  8407. }
  8408. func (this *HisApiController) GetCallHisPrescription() {
  8409. patient_id, _ := this.GetInt64("patient_id", 0)
  8410. timeLayout := "2006-01-02"
  8411. loc, _ := time.LoadLocation("Local")
  8412. start_time := this.GetString("start_time")
  8413. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8414. end_time := this.GetString("end_time")
  8415. p_type, _ := this.GetInt64("p_type")
  8416. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8417. adminUserInfo := this.GetAdminUserInfo()
  8418. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  8419. if err == nil {
  8420. this.ServeSuccessJSON(map[string]interface{}{
  8421. "prescriptions": prescriptions,
  8422. })
  8423. return
  8424. } else {
  8425. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8426. return
  8427. }
  8428. }
  8429. func (this *HisApiController) GetHisDayPrescription() {
  8430. timeLayout := "2006-01-02"
  8431. loc, _ := time.LoadLocation("Local")
  8432. start_time := this.GetString("start_time")
  8433. patient_id, _ := this.GetInt64("patient_id", 0)
  8434. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8435. end_time := this.GetString("end_time")
  8436. p_type, _ := this.GetInt64("p_type")
  8437. order_status, _ := this.GetInt64("type")
  8438. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8439. adminUserInfo := this.GetAdminUserInfo()
  8440. var dayHisPrescription []*models.HisPrescription
  8441. var err error
  8442. if order_status == 1 || order_status == 0 {
  8443. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8444. } else if order_status == 2 {
  8445. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8446. }
  8447. var settle_total float64
  8448. for _, item := range dayHisPrescription {
  8449. if len(item.HisPrescriptionProject) > 0 {
  8450. for _, subItem := range item.HisPrescriptionProject {
  8451. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8452. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8453. settle_total = settle_total + total
  8454. }
  8455. }
  8456. if len(item.HisDoctorAdviceInfo) > 0 {
  8457. for _, subItem := range item.HisDoctorAdviceInfo {
  8458. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8459. settle_total = settle_total + total
  8460. }
  8461. }
  8462. }
  8463. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8464. if err == nil {
  8465. this.ServeSuccessJSON(map[string]interface{}{
  8466. "day_prescription": dayHisPrescription,
  8467. "settle_total": settle_total,
  8468. })
  8469. return
  8470. } else {
  8471. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8472. return
  8473. }
  8474. }
  8475. func (c *HisApiController) GetHisChargePatientList() {
  8476. record_date := c.GetString("record_date")
  8477. order_status, _ := c.GetInt64("type")
  8478. sch_type, _ := c.GetInt64("sch_type")
  8479. timeLayout := "2006-01-02"
  8480. loc, _ := time.LoadLocation("Local")
  8481. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8482. if err != nil {
  8483. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8484. return
  8485. }
  8486. recordDateTime := theTime.Unix()
  8487. adminInfo := c.GetAdminUserInfo()
  8488. var tempPatients []*service.NewTempPatients
  8489. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  8490. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  8491. if order_status != 2 {
  8492. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8493. } else {
  8494. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8495. }
  8496. } else {
  8497. if order_status != 2 {
  8498. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8499. } else {
  8500. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8501. }
  8502. }
  8503. var patients []*service.NewTempPatients
  8504. var patients_two []*service.NewTempPatients
  8505. for _, item := range tempPatients {
  8506. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  8507. //过滤掉没挂号的和没开处方的
  8508. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  8509. patients = append(patients, item)
  8510. }
  8511. //过滤掉没挂号的
  8512. if len(item.HisPatient) > 0 {
  8513. patients_two = append(patients_two, item)
  8514. }
  8515. } else {
  8516. if len(item.HisPrescription) > 0 {
  8517. patients = append(patients, item)
  8518. }
  8519. }
  8520. }
  8521. c.ServeSuccessJSON(map[string]interface{}{
  8522. "list": patients,
  8523. "list_two": patients_two,
  8524. })
  8525. }
  8526. func (c *HisApiController) GetHisUnRegisterPatientList() {
  8527. record_date := c.GetString("record_date")
  8528. timeLayout := "2006-01-02"
  8529. loc, _ := time.LoadLocation("Local")
  8530. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8531. if err != nil {
  8532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8533. return
  8534. }
  8535. recordDateTime := theTime.Unix()
  8536. adminUser := c.GetAdminUserInfo()
  8537. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  8538. var patients []*service.Patients
  8539. for _, item := range tempPatients {
  8540. if item.HisPatient.ID == 0 {
  8541. patients = append(patients, item)
  8542. }
  8543. }
  8544. c.ServeSuccessJSON(map[string]interface{}{
  8545. "list": patients,
  8546. //"list_two": patients_two,
  8547. })
  8548. }
  8549. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  8550. newArr = make([]*service.Patients, 0)
  8551. for i := 0; i < len(patient); i++ {
  8552. repeat := false
  8553. for j := i + 1; j < len(patient); j++ {
  8554. if patient[i].ID == patient[j].ID {
  8555. repeat = true
  8556. break
  8557. }
  8558. }
  8559. if !repeat {
  8560. newArr = append(newArr, patient[i])
  8561. }
  8562. }
  8563. return
  8564. }
  8565. func (c *HisApiController) GetHisChargePatientInfo() {
  8566. patient_id, _ := c.GetInt64("patient_id")
  8567. his_patient_id, _ := c.GetInt64("his_patient_id")
  8568. record_date := c.GetString("record_date")
  8569. //start_time := c.GetString("start_time")
  8570. //end_time := c.GetString("end_time")
  8571. order_status, _ := c.GetInt64("type", 0)
  8572. p_type, _ := c.GetInt64("p_type", 0)
  8573. order_id, _ := c.GetInt64("order_id", 0)
  8574. timeLayout := "2006-01-02"
  8575. loc, _ := time.LoadLocation("Local")
  8576. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8577. if err != nil {
  8578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8579. return
  8580. }
  8581. recordDateTime := theTime.Unix()
  8582. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8583. //if err != nil {
  8584. //
  8585. //}
  8586. //startRecordDateTime := startTime.Unix()
  8587. //
  8588. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8589. //if err != nil {
  8590. //
  8591. //}
  8592. //endRecordDateTime := endTime.Unix()
  8593. admin := c.GetAdminUserInfo()
  8594. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8595. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8596. var prescriptions []*models.HisPrescription
  8597. //var unChargeMonthPrescriptions []*models.HisPrescription
  8598. order, _ := service.GetHisOrderByID(order_id)
  8599. if order_status == 1 || order_status == 0 {
  8600. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8601. } else if order_status == 2 {
  8602. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8603. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8604. }
  8605. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8606. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8607. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8608. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8609. //获取所有科室信息
  8610. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8611. c.ServeSuccessJSON(map[string]interface{}{
  8612. "his_info": his_patient_info,
  8613. "xt_info": xt_patient_info,
  8614. "prescription": prescriptions,
  8615. "case_history": case_history,
  8616. "info": patientPrescriptionInfo,
  8617. "last_info": lastPatientPrescriptionInfo,
  8618. "order": order,
  8619. "doctors": doctors,
  8620. "department": department,
  8621. })
  8622. return
  8623. }
  8624. func (c *HisApiController) GetAllOrderDetail() {
  8625. order_id, _ := c.GetInt64("id", 0)
  8626. order, _ := service.GetHisOrderByID(order_id)
  8627. if order.ID == 0 {
  8628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8629. return
  8630. }
  8631. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8632. org_id := c.GetAdminUserInfo().CurrentOrgId
  8633. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8634. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8635. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8636. c.ServeSuccessJSON(map[string]interface{}{
  8637. "order": order,
  8638. "order_info": order_info,
  8639. "patient": patient,
  8640. "admin_info": adminInfo,
  8641. "hospital_record": record,
  8642. })
  8643. return
  8644. }
  8645. func (c *HisApiController) GetAllOrderDetailCollect() {
  8646. order_id, _ := c.GetInt64("id", 0)
  8647. order, _ := service.GetHisOrderByID(order_id)
  8648. if order.ID == 0 {
  8649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8650. return
  8651. }
  8652. org_id := c.GetAdminUserInfo().CurrentOrgId
  8653. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8654. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8655. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8656. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8657. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8658. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8659. var bedCostTotal float64 = 0 //床位总费
  8660. //var bedCostSelfTotal float64 = 0 //床位自费
  8661. var operationCostTotal float64 = 0 //手术费
  8662. //var operationCostSelfTotal float64 = 0 //手术费
  8663. var otherCostTotal float64 = 0 //其他费用
  8664. //var otherCostSelfTotal float64 = 0 //其他费用
  8665. var materialCostTotal float64 = 0 //材料费
  8666. //var materialCostSelfTotal float64 = 0 //材料费
  8667. var westernMedicineCostTotal float64 = 0 //西药费
  8668. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8669. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8670. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8671. var checkCostTotal float64 = 0 //检查费
  8672. //var checkCostSelfTotal float64 = 0 //检查费
  8673. var laboratoryCostTotal float64 = 0 //化验费
  8674. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8675. var treatCostTotal float64 = 0 //治疗费用
  8676. //var treatCostSelfTotal float64 = 0 //治疗费用
  8677. var zhenChaCostTotal float64 = 0 //其他费用
  8678. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8679. decimal.DivisionPrecision = 2
  8680. var BalanceAccountsType int64
  8681. if his.ID > 0 {
  8682. BalanceAccountsType = his.BalanceAccountsType
  8683. } else {
  8684. BalanceAccountsType = record.BalanceAccountsType
  8685. }
  8686. if BalanceAccountsType != 2 {
  8687. for _, item := range order_info {
  8688. if org_id == 10215 {
  8689. if item.MedChrgitmType == "01" { //床位费
  8690. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8691. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8692. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8693. }
  8694. if item.MedChrgitmType == "02" { //诊察费
  8695. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8696. //zhenChaCostSelfTotal = zhenChaCostTotal
  8697. }
  8698. if item.MedChrgitmType == "03" { //检查费
  8699. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8700. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8701. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8702. }
  8703. //if item.MedChrgitmType == "02" { //检查费
  8704. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8705. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8706. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8707. //}
  8708. if item.MedChrgitmType == "04" { //化验费
  8709. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8710. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8711. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8712. }
  8713. if item.MedChrgitmType == "05" { //治疗费
  8714. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8715. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8716. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8717. }
  8718. if item.MedChrgitmType == "06" { //手术费
  8719. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8720. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8721. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8722. }
  8723. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8724. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8725. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8726. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8727. }
  8728. if item.MedChrgitmType == "09" { //西药费
  8729. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8730. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8731. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8732. }
  8733. if item.MedChrgitmType == "11" { //中成费
  8734. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8735. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8736. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8737. }
  8738. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8739. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8740. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8741. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8742. }
  8743. } else if org_id == 10188 || org_id == 10217 {
  8744. if item.MedChrgitmType == "01" { //床位费
  8745. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8746. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8747. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8748. }
  8749. if item.MedChrgitmType == "02" { //诊察费
  8750. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8751. //zhenChaCostSelfTotal = zhenChaCostTotal
  8752. }
  8753. if item.MedChrgitmType == "03" { //检查费
  8754. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8755. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8756. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8757. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8758. }
  8759. //if item.MedChrgitmType == "02" { //检查费
  8760. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8761. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8762. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8763. //}
  8764. if item.MedChrgitmType == "04" { //化验费
  8765. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8766. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8767. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8768. }
  8769. if item.MedChrgitmType == "05" { //治疗费
  8770. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8771. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8772. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8773. }
  8774. if item.MedChrgitmType == "06" { //手术费
  8775. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8776. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8777. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8778. }
  8779. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8780. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8781. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8782. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8783. }
  8784. if item.MedChrgitmType == "09" { //西药费
  8785. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8786. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8787. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8788. }
  8789. if item.MedChrgitmType == "11" { //中成费
  8790. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8791. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8792. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8793. }
  8794. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8795. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8796. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8797. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8798. }
  8799. } else {
  8800. if item.MedChrgitmType == "01" { //床位费
  8801. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8802. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8803. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8804. }
  8805. //if item.MedChrgitmType == "02" { //诊察费
  8806. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8807. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8808. //}
  8809. if item.MedChrgitmType == "03" { //检查费
  8810. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8811. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8812. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8813. }
  8814. //if item.MedChrgitmType == "02" { //检查费
  8815. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8816. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8817. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8818. //}
  8819. if item.MedChrgitmType == "04" { //化验费
  8820. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8821. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8822. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8823. }
  8824. if item.MedChrgitmType == "05" { //治疗费
  8825. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8826. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8827. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8828. }
  8829. if item.MedChrgitmType == "06" { //手术费
  8830. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8831. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8832. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8833. }
  8834. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8835. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8836. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8837. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8838. }
  8839. if item.MedChrgitmType == "09" { //西药费
  8840. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8841. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8842. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8843. }
  8844. if item.MedChrgitmType == "11" { //中成费
  8845. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8846. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8847. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8848. }
  8849. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8850. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8851. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8852. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8853. }
  8854. }
  8855. }
  8856. c.ServeSuccessJSON(map[string]interface{}{
  8857. "order": order,
  8858. "order_info": order_info,
  8859. "patient": patient,
  8860. "admin_info": adminInfo,
  8861. "his_hospital": record,
  8862. "bedCostTotal": bedCostTotal,
  8863. "operationCostTotal": operationCostTotal,
  8864. "otherCostTotal": otherCostTotal,
  8865. "materialCostTotal": materialCostTotal,
  8866. "westernMedicineCostTotal": westernMedicineCostTotal,
  8867. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8868. "checkCostTotal": checkCostTotal,
  8869. "zhenChaCostTotal": zhenChaCostTotal,
  8870. "laboratoryCostTotal": laboratoryCostTotal,
  8871. "treatCostTotal": treatCostTotal,
  8872. })
  8873. } else {
  8874. for _, item := range order_info {
  8875. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8876. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8877. item.MedChrgitmType = "09"
  8878. }
  8879. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8880. if item.HisPrescriptionProject.Type == 2 {
  8881. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8882. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8883. case 0:
  8884. item.MedChrgitmType = "0"
  8885. break
  8886. case 1:
  8887. item.MedChrgitmType = "14"
  8888. break
  8889. case 2:
  8890. item.MedChrgitmType = "05"
  8891. break
  8892. case 3:
  8893. item.MedChrgitmType = "03"
  8894. break
  8895. case 4:
  8896. item.MedChrgitmType = "03"
  8897. break
  8898. case 5:
  8899. item.MedChrgitmType = "08"
  8900. break
  8901. case 6:
  8902. item.MedChrgitmType = "14"
  8903. break
  8904. case 7:
  8905. item.MedChrgitmType = "14"
  8906. break
  8907. case 8:
  8908. item.MedChrgitmType = "03"
  8909. break
  8910. case 9:
  8911. item.MedChrgitmType = "14"
  8912. break
  8913. case 10:
  8914. item.MedChrgitmType = "14"
  8915. break
  8916. case 11:
  8917. item.MedChrgitmType = "06"
  8918. break
  8919. case 12:
  8920. item.MedChrgitmType = "12"
  8921. break
  8922. case 13:
  8923. item.MedChrgitmType = "01"
  8924. break
  8925. case 14:
  8926. item.MedChrgitmType = "04"
  8927. break
  8928. case 15:
  8929. item.MedChrgitmType = "14"
  8930. break
  8931. }
  8932. } else {
  8933. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8934. case 1:
  8935. item.MedChrgitmType = "14"
  8936. break
  8937. case 2:
  8938. item.MedChrgitmType = "05"
  8939. break
  8940. case 3:
  8941. item.MedChrgitmType = "04"
  8942. break
  8943. case 4:
  8944. item.MedChrgitmType = "14"
  8945. break
  8946. case 5:
  8947. item.MedChrgitmType = "08"
  8948. break
  8949. case 6:
  8950. item.MedChrgitmType = "14"
  8951. break
  8952. case 7:
  8953. item.MedChrgitmType = "14"
  8954. break
  8955. case 8:
  8956. item.MedChrgitmType = "03"
  8957. break
  8958. case 9:
  8959. item.MedChrgitmType = "14"
  8960. break
  8961. }
  8962. }
  8963. } else if item.HisPrescriptionProject.Type == 3 {
  8964. item.MedChrgitmType = "08"
  8965. }
  8966. }
  8967. }
  8968. for _, item := range order_info {
  8969. if org_id == 10215 {
  8970. if item.MedChrgitmType == "01" { //床位费
  8971. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8972. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8973. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8974. }
  8975. if item.MedChrgitmType == "02" { //诊察费
  8976. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8977. //zhenChaCostSelfTotal = zhenChaCostTotal
  8978. }
  8979. if item.MedChrgitmType == "03" { //检查费
  8980. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8981. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8982. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8983. }
  8984. //if item.MedChrgitmType == "02" { //检查费
  8985. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8986. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8987. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8988. //}
  8989. if item.MedChrgitmType == "04" { //化验费
  8990. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8991. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8992. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8993. }
  8994. if item.MedChrgitmType == "05" { //治疗费
  8995. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8996. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8997. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8998. }
  8999. if item.MedChrgitmType == "06" { //手术费
  9000. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9001. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9002. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9003. }
  9004. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9005. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9006. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9007. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9008. }
  9009. if item.MedChrgitmType == "09" { //西药费
  9010. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9011. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9012. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9013. }
  9014. if item.MedChrgitmType == "11" { //中成费
  9015. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9016. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9017. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9018. }
  9019. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9020. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9021. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9022. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9023. }
  9024. } else {
  9025. if item.MedChrgitmType == "01" { //床位费
  9026. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9027. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9028. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9029. }
  9030. //if item.MedChrgitmType == "02" { //诊察费
  9031. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9032. // //zhenChaCostSelfTotal = zhenChaCostTotal
  9033. //}
  9034. if item.MedChrgitmType == "03" { //检查费
  9035. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9036. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9037. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9038. }
  9039. //if item.MedChrgitmType == "02" { //检查费
  9040. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9041. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9042. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9043. //}
  9044. if item.MedChrgitmType == "04" { //化验费
  9045. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9046. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9047. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9048. }
  9049. if item.MedChrgitmType == "05" { //治疗费
  9050. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9051. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9052. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9053. }
  9054. if item.MedChrgitmType == "06" { //手术费
  9055. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9056. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9057. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9058. }
  9059. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  9060. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9061. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9062. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9063. }
  9064. if item.MedChrgitmType == "09" { //西药费
  9065. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9066. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9067. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9068. }
  9069. if item.MedChrgitmType == "11" { //中成费
  9070. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9071. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9072. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9073. }
  9074. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9075. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9076. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9077. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9078. }
  9079. }
  9080. }
  9081. c.ServeSuccessJSON(map[string]interface{}{
  9082. "order": order,
  9083. "order_info": order_info,
  9084. "patient": patient,
  9085. "admin_info": adminInfo,
  9086. "his_hospital": record,
  9087. "bedCostTotal": bedCostTotal,
  9088. "operationCostTotal": operationCostTotal,
  9089. "otherCostTotal": otherCostTotal,
  9090. "materialCostTotal": materialCostTotal,
  9091. "westernMedicineCostTotal": westernMedicineCostTotal,
  9092. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9093. "checkCostTotal": checkCostTotal,
  9094. "zhenChaCostTotal": zhenChaCostTotal,
  9095. "laboratoryCostTotal": laboratoryCostTotal,
  9096. "treatCostTotal": treatCostTotal,
  9097. })
  9098. }
  9099. }
  9100. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  9101. page, _ := c.GetInt64("page")
  9102. limit, _ := c.GetInt64("limit")
  9103. keywords := c.GetString("keywords")
  9104. start_time := c.GetString("start_time")
  9105. end_time := c.GetString("end_time")
  9106. //clr_type := c.GetString("clr_type")
  9107. insutype := c.GetString("insutype")
  9108. timeLayout := "2006-01-02"
  9109. loc, _ := time.LoadLocation("Local")
  9110. var theStartTIme int64
  9111. if len(start_time) > 0 {
  9112. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9113. theStartTIme = theTime.Unix()
  9114. }
  9115. var theEndtTIme int64
  9116. if len(end_time) > 0 {
  9117. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9118. theEndtTIme = theTime.Unix()
  9119. }
  9120. if page <= 0 {
  9121. page = 1
  9122. }
  9123. if limit <= 0 {
  9124. limit = 10
  9125. }
  9126. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  9127. c.ServeSuccessJSON(map[string]interface{}{
  9128. "total": total,
  9129. "list": list,
  9130. })
  9131. return
  9132. }
  9133. func (c *HisApiController) GetPutOnRecordList() {
  9134. page, _ := c.GetInt64("page")
  9135. limit, _ := c.GetInt64("limit")
  9136. keywords := c.GetString("keywords")
  9137. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  9138. if page <= 0 {
  9139. page = 1
  9140. }
  9141. if limit <= 0 {
  9142. limit = 10
  9143. }
  9144. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9145. c.ServeSuccessJSON(map[string]interface{}{
  9146. "total": total,
  9147. "list": list,
  9148. })
  9149. return
  9150. }
  9151. func (c *HisApiController) GetCompareData() {
  9152. start_time := c.GetString("start_time")
  9153. end_time := c.GetString("end_time")
  9154. insutype := c.GetString("insutype")
  9155. clr_type := c.GetString("clr_type")
  9156. timeLayout := "2006-01-02"
  9157. loc, _ := time.LoadLocation("Local")
  9158. var theStartTIme int64
  9159. if len(start_time) > 0 {
  9160. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9161. if err != nil {
  9162. theStartTIme = 0
  9163. }
  9164. theStartTIme = theTime.Unix()
  9165. }
  9166. var theEndtTIme int64
  9167. if len(end_time) > 0 {
  9168. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9169. if err != nil {
  9170. theEndtTIme = 0
  9171. }
  9172. theEndtTIme = theTime.Unix()
  9173. }
  9174. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9175. fmt.Println(err)
  9176. if err == nil {
  9177. c.ServeSuccessJSON(map[string]interface{}{
  9178. "list": formData,
  9179. })
  9180. } else {
  9181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9182. return
  9183. }
  9184. }
  9185. func (c *HisApiController) GetFaPiaoData() {
  9186. order_id, _ := c.GetInt64("order_id")
  9187. patient_id, _ := c.GetInt64("patient_id")
  9188. //number := c.GetString("number")
  9189. adminUser := c.GetAdminUserInfo()
  9190. order, _ := service.GetHisOrderByID(order_id)
  9191. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9192. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9193. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9194. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9195. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9196. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9197. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9198. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9199. var bedCostTotal float64 = 0 //床位总费
  9200. var bedCostSelfTotal float64 = 0 //床位自费
  9201. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9202. var operationCostTotal float64 = 0 //手术费
  9203. var operationCostSelfTotal float64 = 0 //手术费
  9204. var operationCostPartSelfTotal float64 = 0 //手术费
  9205. var otherCostTotal float64 = 0 //其他费用
  9206. var otherCostSelfTotal float64 = 0 //其他费用
  9207. var otherCostPartSelfTotal float64 = 0 //其他费用
  9208. var materialCostTotal float64 = 0 //材料费
  9209. var materialCostSelfTotal float64 = 0 //材料费
  9210. var materialCostPartSelfTotal float64 = 0 //材料费
  9211. var westernMedicineCostTotal float64 = 0 //西药费
  9212. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9213. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9214. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9215. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9216. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9217. var checkCostTotal float64 = 0 //检查费
  9218. var checkCostSelfTotal float64 = 0 //检查费
  9219. var checkCostPartSelfTotal float64 = 0 //检查费
  9220. var hiliCostTotal float64 = 0 //护理费
  9221. var hiliCostSelfTotal float64 = 0 //护理费
  9222. var hiliCostPartSelfTotal float64 = 0 //护理费
  9223. var laboratoryCostTotal float64 = 0 //化验费
  9224. var laboratoryCostSelfTotal float64 = 0 //化验费
  9225. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9226. var treatCostTotal float64 = 0 //治疗费用
  9227. var treatCostSelfTotal float64 = 0 //治疗费用
  9228. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9229. var zhenChaCostTotal float64 = 0 //其他费用
  9230. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9231. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9232. decimal.DivisionPrecision = 2
  9233. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9234. var balanceAccountsType int64
  9235. if his.ID > 0 {
  9236. balanceAccountsType = his.BalanceAccountsType
  9237. } else {
  9238. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9239. }
  9240. if balanceAccountsType == 2 {
  9241. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9242. for _, item := range orderInfos_two {
  9243. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9244. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9245. item.MedChrgitmType = "09"
  9246. }
  9247. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9248. if item.HisPrescriptionProject.Type == 2 {
  9249. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9250. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9251. case 0:
  9252. item.MedChrgitmType = "0"
  9253. break
  9254. case 1:
  9255. item.MedChrgitmType = "14"
  9256. break
  9257. case 2:
  9258. item.MedChrgitmType = "05"
  9259. break
  9260. case 3:
  9261. item.MedChrgitmType = "03"
  9262. break
  9263. case 4:
  9264. item.MedChrgitmType = "03"
  9265. break
  9266. case 5:
  9267. item.MedChrgitmType = "08"
  9268. break
  9269. case 6:
  9270. item.MedChrgitmType = "14"
  9271. break
  9272. case 7:
  9273. item.MedChrgitmType = "14"
  9274. break
  9275. case 8:
  9276. item.MedChrgitmType = "03"
  9277. break
  9278. case 9:
  9279. item.MedChrgitmType = "14"
  9280. break
  9281. case 10:
  9282. item.MedChrgitmType = "14"
  9283. break
  9284. case 11:
  9285. item.MedChrgitmType = "06"
  9286. break
  9287. case 12:
  9288. item.MedChrgitmType = "12"
  9289. break
  9290. case 13:
  9291. item.MedChrgitmType = "01"
  9292. break
  9293. case 14:
  9294. item.MedChrgitmType = "04"
  9295. break
  9296. case 15:
  9297. item.MedChrgitmType = "02"
  9298. break
  9299. }
  9300. } else {
  9301. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9302. case 1:
  9303. item.MedChrgitmType = "14"
  9304. break
  9305. case 2:
  9306. item.MedChrgitmType = "05"
  9307. break
  9308. case 3:
  9309. item.MedChrgitmType = "03"
  9310. break
  9311. case 4:
  9312. item.MedChrgitmType = "03"
  9313. break
  9314. case 5:
  9315. item.MedChrgitmType = "08"
  9316. break
  9317. case 6:
  9318. item.MedChrgitmType = "14"
  9319. break
  9320. case 7:
  9321. item.MedChrgitmType = "14"
  9322. break
  9323. case 8:
  9324. item.MedChrgitmType = "03"
  9325. break
  9326. case 9:
  9327. item.MedChrgitmType = "14"
  9328. break
  9329. }
  9330. }
  9331. } else if item.HisPrescriptionProject.Type == 3 {
  9332. item.MedChrgitmType = "08"
  9333. }
  9334. }
  9335. }
  9336. for _, item := range orderInfos_two {
  9337. fmt.Println(item.MedChrgitmType)
  9338. if item.MedChrgitmType == "07" { //床位费
  9339. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9340. hiliCostSelfTotal = hiliCostTotal
  9341. }
  9342. if item.MedChrgitmType == "01" { //床位费
  9343. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9344. bedCostSelfTotal = bedCostTotal
  9345. }
  9346. if item.MedChrgitmType == "02" { //诊察费
  9347. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9348. zhenChaCostSelfTotal = zhenChaCostTotal
  9349. }
  9350. if item.MedChrgitmType == "03" { //检查费
  9351. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9352. checkCostSelfTotal = checkCostTotal
  9353. }
  9354. if item.MedChrgitmType == "04" { //化验费
  9355. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9356. laboratoryCostSelfTotal = laboratoryCostTotal
  9357. }
  9358. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9359. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9360. treatCostSelfTotal = treatCostTotal
  9361. }
  9362. if item.MedChrgitmType == "06" { //手术费
  9363. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9364. operationCostSelfTotal = treatCostTotal
  9365. }
  9366. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  9367. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9368. materialCostSelfTotal = materialCostTotal
  9369. }
  9370. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9371. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9372. westernMedicineCostSelfTotal = westernMedicineCostTotal
  9373. }
  9374. if item.MedChrgitmType == "11" { //中成费
  9375. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9376. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9377. }
  9378. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9379. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9380. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9381. otherCostSelfTotal = otherCostTotal
  9382. }
  9383. } else {
  9384. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9385. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9386. otherCostSelfTotal = otherCostTotal
  9387. }
  9388. }
  9389. }
  9390. } else {
  9391. for _, item := range orderInfos {
  9392. if item.MedChrgitmType == "01" { //床位费
  9393. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9394. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9395. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9396. }
  9397. if item.MedChrgitmType == "02" { //诊察费
  9398. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9399. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9400. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9401. }
  9402. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9403. if item.MedChrgitmType == "03" { //检查费
  9404. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9405. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9406. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9407. }
  9408. } else {
  9409. if item.MedChrgitmType == "03" { //检查费
  9410. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9411. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9412. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9413. }
  9414. }
  9415. if item.MedChrgitmType == "04" { //化验费
  9416. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9417. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9418. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9419. }
  9420. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9421. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9422. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9423. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9424. }
  9425. if item.MedChrgitmType == "06" { //手术费
  9426. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9427. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9428. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9429. }
  9430. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  9431. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9432. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9433. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9434. }
  9435. if item.MedChrgitmType == "07" { //护理
  9436. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9437. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9438. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9439. }
  9440. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9441. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9442. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9443. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9444. }
  9445. if item.MedChrgitmType == "11" { //中成费
  9446. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9447. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9448. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9449. }
  9450. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9454. }
  9455. }
  9456. }
  9457. timeLayout := "2006-01-02"
  9458. loc, _ := time.LoadLocation("Local")
  9459. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9460. if err != nil {
  9461. }
  9462. startRecordDateTime := startTime.Unix()
  9463. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9464. if err != nil {
  9465. }
  9466. endRecordDateTime := endTime.Unix()
  9467. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9468. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9469. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9470. c.ServeSuccessJSON(map[string]interface{}{
  9471. "order_number": order.Number, //业务流水号
  9472. "id_card_no": his.IdCardNo, //社会保障号
  9473. "patient": patient,
  9474. "department_name": department.Name, //科室
  9475. "number": his.Number, //门诊号
  9476. "date": order.SettleAccountsDate, //结算日期
  9477. "name": order.PsnName, //姓名
  9478. "gender": patient.Gender, //性别
  9479. "psn_cash_money": order.PsnCashPay, //个人支付
  9480. "pay_way": "门诊", //结算方式
  9481. "medfee_sumamt": order.MedfeeSumamt, //总费用
  9482. "admin_user_name": admin.UserName, //收款员
  9483. "order": order,
  9484. "order_info": orderInfos_two,
  9485. "his": his,
  9486. "bedCostTotal": bedCostTotal,
  9487. "bedCostSelfTotal": bedCostSelfTotal,
  9488. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9489. "operationCostTotal": operationCostTotal,
  9490. "operationCostSelfTotal": operationCostSelfTotal,
  9491. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9492. "otherCostTotal": otherCostTotal,
  9493. "otherCostSelfTotal": otherCostSelfTotal,
  9494. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9495. "materialCostTotal": materialCostTotal,
  9496. "materialCostSelfTotal": materialCostSelfTotal,
  9497. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9498. "westernMedicineCostTotal": westernMedicineCostTotal,
  9499. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9500. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9501. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9502. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9503. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9504. "checkCostTotal": checkCostTotal,
  9505. "checkCostSelfTotal": checkCostSelfTotal,
  9506. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9507. "laboratoryCostTotal": laboratoryCostTotal,
  9508. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9509. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9510. "treatCostTotal": treatCostTotal,
  9511. "treatCostSelfTotal": treatCostSelfTotal,
  9512. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9513. "zhenChaCostTotal": zhenChaCostTotal,
  9514. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9515. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9516. "his_hospital_record": his_hospital_record,
  9517. "pre_pay_money": pre_pay_money,
  9518. "refund_sum": sum,
  9519. "doctor_info": doctor_info,
  9520. "hiliCostTotal": hiliCostTotal,
  9521. "hiliCostSelfTotal": hiliCostSelfTotal,
  9522. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  9523. })
  9524. }
  9525. //func (c *HisApiController) GetFaPiaoDatas() {
  9526. // order_ids := c.GetString("order_ids")
  9527. // patient_id, _ := c.GetInt64("patient_id")
  9528. // adminUser := c.GetAdminUserInfo()
  9529. //
  9530. // orders := strings.Split(order_ids, ",")
  9531. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9532. //
  9533. // for _, item := range orders {
  9534. // order_id, _ := strconv.ParseInt(item, 10, 64)
  9535. // order, _ := service.GetHisOrderByID(order_id)
  9536. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9537. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9538. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9539. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9540. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9541. //
  9542. // }
  9543. //
  9544. // var bedCostTotal float64 = 0 //床位总费
  9545. // var bedCostSelfTotal float64 = 0 //床位自费
  9546. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9547. //
  9548. // var operationCostTotal float64 = 0 //手术费
  9549. // var operationCostSelfTotal float64 = 0 //手术费
  9550. // var operationCostPartSelfTotal float64 = 0 //手术费
  9551. //
  9552. // var otherCostTotal float64 = 0 //其他费用
  9553. // var otherCostSelfTotal float64 = 0 //其他费用
  9554. // var otherCostPartSelfTotal float64 = 0 //其他费用
  9555. //
  9556. // var materialCostTotal float64 = 0 //材料费
  9557. // var materialCostSelfTotal float64 = 0 //材料费
  9558. // var materialCostPartSelfTotal float64 = 0 //材料费
  9559. //
  9560. // var westernMedicineCostTotal float64 = 0 //西药费
  9561. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  9562. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9563. //
  9564. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9565. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9566. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9567. //
  9568. // var checkCostTotal float64 = 0 //检查费
  9569. // var checkCostSelfTotal float64 = 0 //检查费
  9570. // var checkCostPartSelfTotal float64 = 0 //检查费
  9571. //
  9572. // var laboratoryCostTotal float64 = 0 //化验费
  9573. // var laboratoryCostSelfTotal float64 = 0 //化验费
  9574. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9575. //
  9576. // var treatCostTotal float64 = 0 //治疗费用
  9577. // var treatCostSelfTotal float64 = 0 //治疗费用
  9578. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  9579. //
  9580. // var zhenChaCostTotal float64 = 0 //其他费用
  9581. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  9582. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9583. //
  9584. // decimal.DivisionPrecision = 2
  9585. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9586. //
  9587. // var balanceAccountsType int64
  9588. // if his.ID > 0 {
  9589. // balanceAccountsType = his.BalanceAccountsType
  9590. // } else {
  9591. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9592. // }
  9593. // if balanceAccountsType == 2 {
  9594. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9595. // for _, item := range orderInfos_two {
  9596. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9597. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9598. // item.MedChrgitmType = "09"
  9599. // }
  9600. //
  9601. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9602. // if item.HisPrescriptionProject.Type == 2 {
  9603. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9604. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9605. // case 0:
  9606. // item.MedChrgitmType = "0"
  9607. // break
  9608. // case 1:
  9609. // item.MedChrgitmType = "14"
  9610. // break
  9611. // case 2:
  9612. // item.MedChrgitmType = "05"
  9613. //
  9614. // break
  9615. // case 3:
  9616. // item.MedChrgitmType = "03"
  9617. //
  9618. // break
  9619. // case 4:
  9620. // item.MedChrgitmType = "03"
  9621. //
  9622. // break
  9623. // case 5:
  9624. // item.MedChrgitmType = "08"
  9625. //
  9626. // break
  9627. // case 6:
  9628. // item.MedChrgitmType = "14"
  9629. //
  9630. // break
  9631. // case 7:
  9632. // item.MedChrgitmType = "14"
  9633. //
  9634. // break
  9635. // case 8:
  9636. // item.MedChrgitmType = "03"
  9637. // break
  9638. // case 9:
  9639. // item.MedChrgitmType = "14"
  9640. // break
  9641. // case 10:
  9642. // item.MedChrgitmType = "14"
  9643. // break
  9644. // case 11:
  9645. // item.MedChrgitmType = "06"
  9646. // break
  9647. // case 12:
  9648. // item.MedChrgitmType = "12"
  9649. // break
  9650. // case 13:
  9651. // item.MedChrgitmType = "01"
  9652. // break
  9653. // case 14:
  9654. // item.MedChrgitmType = "04"
  9655. // break
  9656. // case 15:
  9657. // item.MedChrgitmType = "02"
  9658. // break
  9659. //
  9660. // }
  9661. //
  9662. // } else {
  9663. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9664. //
  9665. // case 1:
  9666. // item.MedChrgitmType = "14"
  9667. // break
  9668. // case 2:
  9669. // item.MedChrgitmType = "05"
  9670. //
  9671. // break
  9672. // case 3:
  9673. // item.MedChrgitmType = "03"
  9674. //
  9675. // break
  9676. // case 4:
  9677. // item.MedChrgitmType = "03"
  9678. //
  9679. // break
  9680. // case 5:
  9681. // item.MedChrgitmType = "08"
  9682. //
  9683. // break
  9684. // case 6:
  9685. // item.MedChrgitmType = "14"
  9686. //
  9687. // break
  9688. // case 7:
  9689. // item.MedChrgitmType = "14"
  9690. //
  9691. // break
  9692. // case 8:
  9693. // item.MedChrgitmType = "03"
  9694. // break
  9695. // case 9:
  9696. // item.MedChrgitmType = "14"
  9697. // break
  9698. //
  9699. // }
  9700. //
  9701. // }
  9702. //
  9703. // } else if item.HisPrescriptionProject.Type == 3 {
  9704. // item.MedChrgitmType = "08"
  9705. // }
  9706. // }
  9707. // }
  9708. //
  9709. // for _, item := range orderInfos_two {
  9710. // fmt.Println(item.MedChrgitmType)
  9711. // if item.MedChrgitmType == "01" { //床位费
  9712. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9713. // bedCostSelfTotal = bedCostTotal
  9714. // }
  9715. //
  9716. // if item.MedChrgitmType == "02" { //诊察费
  9717. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9718. // zhenChaCostSelfTotal = zhenChaCostTotal
  9719. // }
  9720. //
  9721. // if item.MedChrgitmType == "03" { //检查费
  9722. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9723. // checkCostSelfTotal = checkCostTotal
  9724. // }
  9725. //
  9726. // if item.MedChrgitmType == "04" { //化验费
  9727. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9728. // laboratoryCostSelfTotal = laboratoryCostTotal
  9729. // }
  9730. //
  9731. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9732. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9733. // treatCostSelfTotal = treatCostTotal
  9734. // }
  9735. //
  9736. // if item.MedChrgitmType == "06" { //手术费
  9737. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9738. // operationCostSelfTotal = treatCostTotal
  9739. // }
  9740. //
  9741. // if item.MedChrgitmType == "08" { //材料费
  9742. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9743. // materialCostSelfTotal = materialCostTotal
  9744. // }
  9745. //
  9746. // if item.MedChrgitmType == "09" { //西药费
  9747. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9748. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9749. // }
  9750. //
  9751. // if item.MedChrgitmType == "11" { //中成费
  9752. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9753. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9754. // }
  9755. //
  9756. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9757. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9758. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9759. // otherCostSelfTotal = otherCostTotal
  9760. // }
  9761. // } else {
  9762. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9763. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9764. // otherCostSelfTotal = otherCostTotal
  9765. // }
  9766. //
  9767. // }
  9768. //
  9769. // }
  9770. //
  9771. // } else {
  9772. // for _, item := range orderInfos {
  9773. // if item.MedChrgitmType == "01" { //床位费
  9774. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9775. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9776. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9777. // }
  9778. //
  9779. // if item.MedChrgitmType == "02" { //诊察费
  9780. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9781. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9782. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9783. // }
  9784. //
  9785. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9786. // if item.MedChrgitmType == "03" { //检查费
  9787. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9788. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9789. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9790. //
  9791. // }
  9792. // } else {
  9793. // if item.MedChrgitmType == "03" { //检查费
  9794. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9795. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9796. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9797. // }
  9798. //
  9799. // }
  9800. //
  9801. // if item.MedChrgitmType == "04" { //化验费
  9802. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9803. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9804. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9805. //
  9806. // }
  9807. //
  9808. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  9809. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9810. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9811. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9812. //
  9813. // }
  9814. //
  9815. // if item.MedChrgitmType == "06" { //手术费
  9816. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9817. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9818. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9819. // }
  9820. //
  9821. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9822. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9823. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9824. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9825. // }
  9826. //
  9827. // if item.MedChrgitmType == "09" { //西药费
  9828. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9829. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9830. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9831. // }
  9832. //
  9833. // if item.MedChrgitmType == "11" { //中成费
  9834. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9835. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9836. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9837. // }
  9838. //
  9839. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9840. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9841. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9842. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9843. // }
  9844. //
  9845. // }
  9846. // }
  9847. // timeLayout := "2006-01-02"
  9848. // loc, _ := time.LoadLocation("Local")
  9849. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9850. // if err != nil {
  9851. // }
  9852. // startRecordDateTime := startTime.Unix()
  9853. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9854. // if err != nil {
  9855. // }
  9856. // endRecordDateTime := endTime.Unix()
  9857. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9858. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9859. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9860. //
  9861. // c.ServeSuccessJSON(map[string]interface{}{
  9862. // "order_number": order.Number, //业务流水号
  9863. // "id_card_no": his.IdCardNo, //社会保障号
  9864. // "department_name": department.Name, //科室
  9865. // "number": his.Number, //门诊号
  9866. // "date": order.SettleAccountsDate, //结算日期
  9867. // "name": order.PsnName, //姓名
  9868. // "gender": patient.Gender, //性别
  9869. // "psn_cash_money": order.PsnCashPay, //个人支付
  9870. // "pay_way": "门诊", //结算方式
  9871. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  9872. // "admin_user_name": admin.UserName, //收款员
  9873. // "order": order,
  9874. // "order_info": orderInfos_two,
  9875. // "his": his,
  9876. // "bedCostTotal": bedCostTotal,
  9877. // "bedCostSelfTotal": bedCostSelfTotal,
  9878. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9879. // "operationCostTotal": operationCostTotal,
  9880. // "operationCostSelfTotal": operationCostSelfTotal,
  9881. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9882. // "otherCostTotal": otherCostTotal,
  9883. // "otherCostSelfTotal": otherCostSelfTotal,
  9884. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9885. // "materialCostTotal": materialCostTotal,
  9886. // "materialCostSelfTotal": materialCostSelfTotal,
  9887. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9888. // "westernMedicineCostTotal": westernMedicineCostTotal,
  9889. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9890. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9891. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9892. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9893. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9894. // "checkCostTotal": checkCostTotal,
  9895. // "checkCostSelfTotal": checkCostSelfTotal,
  9896. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9897. // "laboratoryCostTotal": laboratoryCostTotal,
  9898. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9899. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9900. // "treatCostTotal": treatCostTotal,
  9901. // "treatCostSelfTotal": treatCostSelfTotal,
  9902. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9903. // "zhenChaCostTotal": zhenChaCostTotal,
  9904. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9905. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9906. // "his_hospital_record": his_hospital_record,
  9907. // "pre_pay_money": pre_pay_money,
  9908. // "refund_sum": sum,
  9909. // })
  9910. //
  9911. //}
  9912. func (this *HisApiController) GetIncomeStatisticsData() {
  9913. start_time := this.GetString("start_time")
  9914. end_time := this.GetString("end_time")
  9915. key_words := this.GetString("key_words")
  9916. limit, _ := this.GetInt64("limit")
  9917. page, _ := this.GetInt64("page")
  9918. if page <= 0 {
  9919. page = 1
  9920. }
  9921. if limit <= 0 {
  9922. limit = 10
  9923. }
  9924. statistics_type, _ := this.GetInt64("statistics_type")
  9925. admin := this.GetAdminUserInfo()
  9926. timeLayout := "2006-01-02"
  9927. loc, _ := time.LoadLocation("Local")
  9928. var theStartTIme int64
  9929. if len(start_time) > 0 {
  9930. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9931. if err != nil {
  9932. theStartTIme = 0
  9933. }
  9934. theStartTIme = theTime.Unix()
  9935. }
  9936. var theEndtTIme int64
  9937. if len(end_time) > 0 {
  9938. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9939. if err != nil {
  9940. theEndtTIme = 0
  9941. }
  9942. theEndtTIme = theTime.Unix()
  9943. }
  9944. if statistics_type == 1 {
  9945. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9946. this.ServeSuccessJSON(map[string]interface{}{
  9947. "list": list,
  9948. "total": total,
  9949. })
  9950. } else {
  9951. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9952. this.ServeSuccessJSON(map[string]interface{}{
  9953. "list": list,
  9954. "total": total,
  9955. })
  9956. }
  9957. }
  9958. func (c *HisApiController) PostProjectInformation() {
  9959. adminUser := c.GetAdminUserInfo()
  9960. orgId := adminUser.CurrentOrgId
  9961. dataBody := make(map[string]interface{}, 0)
  9962. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9963. if err != nil {
  9964. utils.ErrorLog(err.Error())
  9965. return
  9966. }
  9967. utils.ErrorLog("%v", dataBody)
  9968. var projectList []*models.HisProject
  9969. var total_goods []interface{}
  9970. tempProjects := dataBody["projects"].([]interface{})
  9971. total_goods = tempProjects
  9972. for index, projectMap := range tempProjects {
  9973. projectM := projectMap.(map[string]interface{})
  9974. var project models.HisProject
  9975. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  9976. utils.ErrorLog("project_name")
  9977. return
  9978. }
  9979. project_name, _ := projectM["project_name"].(string)
  9980. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  9981. err_log := models.ExportErrLog{
  9982. LogType: 6,
  9983. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9984. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  9985. Status: 1,
  9986. CreateTime: time.Now().Unix(),
  9987. UpdateTime: time.Now().Unix(),
  9988. ExportTime: time.Now().Unix(),
  9989. }
  9990. service.CreateExportErrLog(&err_log)
  9991. continue
  9992. }
  9993. project.ProjectName = project_name
  9994. prices := projectM["price"].(string)
  9995. price, _ := strconv.ParseFloat(prices, 64)
  9996. if price <= 0 { //名字为空则生成一条导入错误日志
  9997. err_log := models.ExportErrLog{
  9998. LogType: 6,
  9999. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10000. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  10001. Status: 1,
  10002. CreateTime: time.Now().Unix(),
  10003. UpdateTime: time.Now().Unix(),
  10004. ExportTime: time.Now().Unix(),
  10005. }
  10006. service.CreateExportErrLog(&err_log)
  10007. continue
  10008. }
  10009. project.Price = price
  10010. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  10011. utils.ErrorLog("unit_id")
  10012. return
  10013. }
  10014. unit := projectM["unit"].(string)
  10015. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  10016. err_log := models.ExportErrLog{
  10017. LogType: 6,
  10018. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10019. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  10020. Status: 1,
  10021. CreateTime: time.Now().Unix(),
  10022. UpdateTime: time.Now().Unix(),
  10023. ExportTime: time.Now().Unix(),
  10024. }
  10025. service.CreateExportErrLog(&err_log)
  10026. continue
  10027. }
  10028. project.Unit = unit
  10029. cost_classify := projectM["cost_classify"].(string)
  10030. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  10031. err_log := models.ExportErrLog{
  10032. LogType: 6,
  10033. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10034. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10035. Status: 1,
  10036. CreateTime: time.Now().Unix(),
  10037. UpdateTime: time.Now().Unix(),
  10038. ExportTime: time.Now().Unix(),
  10039. }
  10040. service.CreateExportErrLog(&err_log)
  10041. continue
  10042. }
  10043. var costClassify = "费用类别"
  10044. var cost_classify_id int64
  10045. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  10046. if len(cost_classify) != 0 {
  10047. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  10048. if errcode == gorm.ErrRecordNotFound {
  10049. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  10050. dataconfig := models.DictDataconfig{
  10051. ParentId: costClassifyConfig.ID,
  10052. Module: "system",
  10053. OrgId: orgId,
  10054. Name: cost_classify,
  10055. FieldName: "",
  10056. Value: costConfig.Value + 1,
  10057. CreatedTime: "",
  10058. UpdatedTime: "",
  10059. CreateUserId: adminUser.AdminUser.Id,
  10060. Status: 1,
  10061. Remark: "",
  10062. DeleteIdSystem: 0,
  10063. Title: "",
  10064. Content: "",
  10065. Order: 0,
  10066. Code: "",
  10067. }
  10068. service.CreatedDicConfig(&dataconfig)
  10069. }
  10070. }
  10071. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  10072. for _, it := range costClassList {
  10073. if cost_classify == it.Name {
  10074. cost_classify_id = int64(it.Value)
  10075. }
  10076. }
  10077. project.CostClassify = cost_classify_id
  10078. executive_section := projectM["executive_section"].(string)
  10079. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  10080. err_log := models.ExportErrLog{
  10081. LogType: 6,
  10082. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10083. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  10084. Status: 1,
  10085. CreateTime: time.Now().Unix(),
  10086. UpdateTime: time.Now().Unix(),
  10087. ExportTime: time.Now().Unix(),
  10088. }
  10089. service.CreateExportErrLog(&err_log)
  10090. continue
  10091. }
  10092. if len(executive_section) != 0 {
  10093. //查找科室是否有内容
  10094. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  10095. if errcodedepart == gorm.ErrRecordNotFound {
  10096. department := models.XtHisDepartment{
  10097. Name: executive_section,
  10098. Status: 1,
  10099. UserOrgId: adminUser.CurrentOrgId,
  10100. CreatedTime: time.Now().Unix(),
  10101. }
  10102. service.CreateDePartment(&department)
  10103. }
  10104. }
  10105. var executive_section_id int64
  10106. departMentList, _ := service.GetAllDepartMent(orgId)
  10107. for _, it := range departMentList {
  10108. if executive_section == it.Name {
  10109. executive_section_id = it.ID
  10110. }
  10111. }
  10112. project.ExecutiveSection = executive_section_id
  10113. medical_coverage := projectM["medical_coverage"].(string)
  10114. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  10115. err_log := models.ExportErrLog{
  10116. LogType: 6,
  10117. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10118. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  10119. Status: 1,
  10120. CreateTime: time.Now().Unix(),
  10121. UpdateTime: time.Now().Unix(),
  10122. ExportTime: time.Now().Unix(),
  10123. }
  10124. service.CreateExportErrLog(&err_log)
  10125. continue
  10126. }
  10127. var medicalCoverage = "医保等级"
  10128. var medical_coverage_id int64
  10129. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  10130. if len(medical_coverage) != 0 {
  10131. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  10132. if errormedicalcoverage == gorm.ErrRecordNotFound {
  10133. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  10134. dataconfig := models.DictDataconfig{
  10135. ParentId: medicalCoverageConfig.ID,
  10136. Module: "system",
  10137. OrgId: orgId,
  10138. Name: medical_coverage,
  10139. FieldName: "",
  10140. Value: medicalCoverageConfig.Value + 1,
  10141. CreatedTime: "",
  10142. UpdatedTime: "",
  10143. CreateUserId: adminUser.AdminUser.Id,
  10144. Status: 1,
  10145. Remark: "",
  10146. DeleteIdSystem: 0,
  10147. Title: "",
  10148. Content: "",
  10149. Order: 0,
  10150. Code: "",
  10151. }
  10152. service.CreatedDicConfig(&dataconfig)
  10153. }
  10154. }
  10155. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10156. for _, it := range medicalCoverageList {
  10157. if medical_coverage == it.Name {
  10158. medical_coverage_id = int64(it.Value)
  10159. }
  10160. }
  10161. project.MedicalCoverage = medical_coverage_id
  10162. pinyin := projectM["pinyin"].(string)
  10163. project.Pinyin = pinyin
  10164. wubi := projectM["wubi"].(string)
  10165. project.Wubi = wubi
  10166. statistical_classification := projectM["statistical_classification"].(string)
  10167. var statisticalClassification = "统计分类"
  10168. var statistical_classification_id int64
  10169. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10170. if len(statistical_classification) != 0 {
  10171. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10172. if classificationerrcodes == gorm.ErrRecordNotFound {
  10173. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10174. dataconfig := models.DictDataconfig{
  10175. ParentId: classiFication.ID,
  10176. Module: "system",
  10177. OrgId: orgId,
  10178. Name: statistical_classification,
  10179. FieldName: "",
  10180. Value: classiFicationConfig.Value + 1,
  10181. CreatedTime: "",
  10182. UpdatedTime: "",
  10183. CreateUserId: adminUser.AdminUser.Id,
  10184. Status: 1,
  10185. Remark: "",
  10186. DeleteIdSystem: 0,
  10187. Title: "",
  10188. Content: "",
  10189. Order: 0,
  10190. Code: "",
  10191. }
  10192. service.CreatedDicConfig(&dataconfig)
  10193. }
  10194. }
  10195. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10196. for _, it := range classiFicationList {
  10197. if statistical_classification == it.Name {
  10198. statistical_classification_id = int64(it.Value)
  10199. }
  10200. }
  10201. project.StatisticalClassification = statistical_classification_id
  10202. disease_directory := int64(projectM["disease_directory"].(float64))
  10203. project.DiseaseDirectory = disease_directory
  10204. is_record := int64(projectM["is_record"].(float64))
  10205. project.IsRecord = is_record
  10206. medical_code := projectM["medical_code"].(string)
  10207. project.MedicalCode = medical_code
  10208. tube_color := projectM["tube_color"].(string)
  10209. var tubeColor = "试管颜色"
  10210. var tube_color_id int64
  10211. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10212. if len(tube_color) != 0 {
  10213. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10214. if errcodetube == gorm.ErrRecordNotFound {
  10215. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10216. dataconfig := models.DictDataconfig{
  10217. ParentId: tubeColorConfig.ID,
  10218. Module: "system",
  10219. OrgId: orgId,
  10220. Name: tube_color,
  10221. FieldName: "",
  10222. Value: tubeConfig.Value + 1,
  10223. CreatedTime: "",
  10224. UpdatedTime: "",
  10225. CreateUserId: adminUser.AdminUser.Id,
  10226. Status: 1,
  10227. Remark: "",
  10228. DeleteIdSystem: 0,
  10229. Title: "",
  10230. Content: "",
  10231. Order: 0,
  10232. Code: "",
  10233. }
  10234. service.CreatedDicConfig(&dataconfig)
  10235. }
  10236. }
  10237. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10238. for _, it := range tubeColorList {
  10239. if tube_color == it.Name {
  10240. tube_color_id = int64(it.Value)
  10241. }
  10242. }
  10243. project.TubeColor = tube_color_id
  10244. single_dose := projectM["single_dose"].(string)
  10245. project.SingleDose = single_dose
  10246. execution_frequency := projectM["execution_frequency"].(string)
  10247. project.ExecutionFrequency = execution_frequency
  10248. delivery_way := projectM["delivery_way"].(string)
  10249. project.DeliveryWay = delivery_way
  10250. number_days := projectM["number_days"].(string)
  10251. project.NumberDays = number_days
  10252. total := projectM["total"].(string)
  10253. project.Total = total
  10254. medical_status := int64(projectM["medical_status"].(float64))
  10255. project.MedicalStatus = medical_status
  10256. category := int64(projectM["category"].(float64))
  10257. project.Category = category
  10258. specail_project := int64(projectM["specail_project"].(float64))
  10259. project.SpecailProject = specail_project
  10260. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10261. project.SocialSecurityDirectoryCode = social_security_directory_code
  10262. remark := projectM["remark"].(string)
  10263. project.Remark = remark
  10264. record_date := projectM["record_date"].(string)
  10265. timeLayout := "2006-01-02"
  10266. loc, _ := time.LoadLocation("Local")
  10267. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10268. project.RecordDate = theTime.Unix()
  10269. projectList = append(projectList, &project)
  10270. }
  10271. export_time := time.Now().Unix()
  10272. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  10273. if len(projectList) > 0 {
  10274. for _, item := range projectList {
  10275. hans := item.ProjectName // 要转换的汉字字符串
  10276. // 创建一个拼音转换器
  10277. p := pinyin.NewArgs()
  10278. // 将汉字转为拼音
  10279. pinyinSlice := pinyin.Pinyin(hans, p)
  10280. // 输出拼音
  10281. fmt.Println("Pinyin:", pinyinSlice)
  10282. // 获取首字母
  10283. firstLetter := ""
  10284. for _, py := range pinyinSlice {
  10285. if len(py) > 0 {
  10286. firstLetter += string(py[0][0])
  10287. }
  10288. }
  10289. item.FirstLetter = firstLetter
  10290. project := models.HisProject{
  10291. ProjectName: item.ProjectName,
  10292. Price: item.Price,
  10293. Unit: item.Unit,
  10294. CostClassify: item.CostClassify,
  10295. ExecutiveSection: item.ExecutiveSection,
  10296. MedicalCoverage: item.MedicalCoverage,
  10297. UserOrgId: orgId,
  10298. Status: 1,
  10299. CreatedTime: time.Now().Unix(),
  10300. Pinyin: item.Pinyin,
  10301. Wubi: item.Wubi,
  10302. StatisticalClassification: item.StatisticalClassification,
  10303. DiseaseDirectory: item.DiseaseDirectory,
  10304. IsRecord: item.IsRecord,
  10305. MedicalCode: item.MedicalCode,
  10306. TubeColor: item.TubeColor,
  10307. SingleDose: item.SingleDose,
  10308. DeliveryWay: item.DeliveryWay,
  10309. NumberDays: item.NumberDays,
  10310. Total: item.Total,
  10311. Category: item.Category,
  10312. MedicalStatus: item.MedicalStatus,
  10313. SpecailProject: item.SpecailProject,
  10314. RecordDate: item.RecordDate,
  10315. Remark: item.Remark,
  10316. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10317. ExecutionFrequency: item.ExecutionFrequency,
  10318. FirstLetter: item.FirstLetter,
  10319. }
  10320. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10321. if errcodeproject == gorm.ErrRecordNotFound {
  10322. service.CreateProjectInfomation(&project)
  10323. } else if errcodeproject == nil {
  10324. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10325. }
  10326. log := models.ExportLog{
  10327. LogType: 6,
  10328. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10329. TotalNum: int64(len(total_goods)),
  10330. FailNum: int64(len(errLogs)),
  10331. SuccessNum: int64(len(projectList)),
  10332. CreateTime: time.Now().Unix(),
  10333. UpdateTime: time.Now().Unix(),
  10334. ExportTime: export_time,
  10335. Status: 1,
  10336. }
  10337. service.CreateExportLog(&log)
  10338. c.ServeSuccessJSON(map[string]interface{}{
  10339. "msg": "导入成功",
  10340. "total_num": len(total_goods),
  10341. "success_num": len(projectList),
  10342. "fail_num": int64(len(errLogs)),
  10343. })
  10344. }
  10345. } else {
  10346. log := models.ExportLog{
  10347. LogType: 6,
  10348. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10349. TotalNum: int64(len(total_goods)),
  10350. FailNum: int64(len(errLogs)),
  10351. SuccessNum: int64(len(projectList)),
  10352. CreateTime: time.Now().Unix(),
  10353. UpdateTime: time.Now().Unix(),
  10354. ExportTime: export_time,
  10355. Status: 1,
  10356. }
  10357. service.CreateExportLog(&log)
  10358. c.ServeSuccessJSON(map[string]interface{}{
  10359. "msg": "导入成功",
  10360. "total_num": len(total_goods),
  10361. "success_num": len(projectList),
  10362. "fail_num": int64(len(errLogs)),
  10363. })
  10364. }
  10365. }
  10366. //func (this *HisApiController) EditProjectInformation(){
  10367. //
  10368. // id, _ := this.GetInt64("id")
  10369. // project_team := this.GetString("project_team")
  10370. // price := this.GetString("price")
  10371. // price_float, _ := strconv.ParseFloat(price, 64)
  10372. // pinyin := this.GetString("pinyin")
  10373. // wubi := this.GetString("wubi")
  10374. // tube_color, _ := this.GetInt64("tube_color")
  10375. // team_type, _ := this.GetInt64("team_type")
  10376. // remark := this.GetString("remark")
  10377. // ids := this.GetString("ids")
  10378. // item_id := this.GetString("item_id")
  10379. // projectTeam := models.XtHisProjectTeam{
  10380. // ProjectTeam: project_team,
  10381. // Price: price_float,
  10382. // Pinyin: pinyin,
  10383. // Wubi: wubi,
  10384. // TubeColor: tube_color,
  10385. // TeamType: team_type,
  10386. // Remark: remark,
  10387. // ProjectId: ids,
  10388. // ItemId: item_id,
  10389. // }
  10390. //
  10391. //
  10392. // dataBody := make(map[string]interface{}, 0)
  10393. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10394. // if err != nil {
  10395. // utils.ErrorLog(err.Error())
  10396. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10397. // return
  10398. // }
  10399. //
  10400. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10401. //
  10402. //
  10403. // if err != nil {
  10404. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10405. // return
  10406. // }
  10407. //
  10408. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10409. // infos, _ := dataBody["info"].([]interface{})
  10410. // if len(infos) > 0 {
  10411. // var ids []string
  10412. //
  10413. // for _, item := range infos {
  10414. // items := item.(map[string]interface{})
  10415. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10416. // utils.ErrorLog("id")
  10417. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10418. // return
  10419. // }
  10420. // id := int64(items["id"].(float64))
  10421. //
  10422. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10423. // utils.ErrorLog("type")
  10424. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10425. // return
  10426. // }
  10427. // types := int64(items["type"].(float64))
  10428. //
  10429. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10430. // utils.ErrorLog("number")
  10431. // }
  10432. //
  10433. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10434. //
  10435. // projectList := models.XtHisProjectList{
  10436. // Number: number,
  10437. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10438. // ProjectId: id,
  10439. // Status: 1,
  10440. // CreatedTime: time.Now().Unix(),
  10441. // UpdatedTime: time.Now().Unix(),
  10442. // TeamId: projectTeam.ID,
  10443. // Type: types,
  10444. // }
  10445. // list := projectList
  10446. //
  10447. // service.CreateProjectList(&list)
  10448. //
  10449. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10450. //
  10451. // }
  10452. // ids_str := strings.Join(ids, ",")
  10453. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10454. // service.SaveProjectTeam(&projectTeam)
  10455. // this.ServeSuccessJSON(map[string]interface{}{
  10456. // "projectTeam": projectTeam,
  10457. // })
  10458. // }
  10459. // }
  10460. //}
  10461. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10462. name := c.GetString("name")
  10463. mode_id, _ := c.GetInt64("mode", 0)
  10464. types, _ := c.GetInt64("type", 0)
  10465. patient_id, _ := c.GetInt64("patient_id", 0)
  10466. types = 1
  10467. adminInfo := c.GetAdminUserInfo()
  10468. template := &models.HisPrescriptionTemplate{
  10469. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10470. PatientId: patient_id,
  10471. Type: types,
  10472. Status: 1,
  10473. Ctime: time.Now().Unix(),
  10474. Mtime: time.Now().Unix(),
  10475. Name: name,
  10476. Mode: mode_id,
  10477. }
  10478. dataBody := make(map[string]interface{}, 0)
  10479. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10480. if err != nil {
  10481. utils.ErrorLog(err.Error())
  10482. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10483. return
  10484. }
  10485. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10486. //如果已经存在记录则删除处方
  10487. if template_one.ID > 0 {
  10488. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10489. var ids []int64
  10490. var org_id int64
  10491. for _, item := range ps {
  10492. org_id = c.GetAdminUserInfo().CurrentOrgId
  10493. ids = append(ids, item.ID)
  10494. }
  10495. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10496. if err2 == nil {
  10497. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10498. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10499. if len(prescriptions) > 0 {
  10500. for _, item := range prescriptions {
  10501. items := item.(map[string]interface{})
  10502. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10503. utils.ErrorLog("type")
  10504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10505. return
  10506. }
  10507. types := int64(items["type"].(float64))
  10508. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10509. utils.ErrorLog("med_type")
  10510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10511. return
  10512. }
  10513. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10514. ctime := time.Now().Unix()
  10515. prescription := &models.HisPrescriptionInfoTemplate{
  10516. PatientId: patient_id,
  10517. UserOrgId: adminInfo.CurrentOrgId,
  10518. Ctime: ctime,
  10519. Mtime: ctime,
  10520. Type: types,
  10521. Modifier: adminInfo.AdminUser.Id,
  10522. Creator: adminInfo.AdminUser.Id,
  10523. Status: 1,
  10524. PTemplateId: template_one.ID,
  10525. MedType: med_type,
  10526. }
  10527. service.CreateHisPrescriptionInfoTemplate(prescription)
  10528. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10529. advices := items["advices"].([]interface{})
  10530. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10531. ctime := time.Now().Unix()
  10532. mtime := ctime
  10533. if len(advices) > 0 {
  10534. for _, advice := range advices {
  10535. var s models.HisPrescriptionAdviceTemplate
  10536. s.PrescriptionId = prescription.ID
  10537. s.AdviceType = 2
  10538. s.StopState = 2
  10539. s.ExecutionState = 2
  10540. s.Status = 1
  10541. s.UserOrgId = adminInfo.CurrentOrgId
  10542. s.CreatedTime = ctime
  10543. s.UpdatedTime = mtime
  10544. s.PatientId = patient_id
  10545. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10546. if errcode > 0 {
  10547. c.ServeFailJSONWithSGJErrorCode(errcode)
  10548. return
  10549. }
  10550. service.CreateHisPrescriptionAdviceTemplate(&s)
  10551. }
  10552. }
  10553. }
  10554. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10555. projects := items["project"].([]interface{})
  10556. if len(projects) > 0 {
  10557. for _, project := range projects {
  10558. var p models.HisPrescriptionProjectTemplate
  10559. p.PrescriptionId = prescription.ID
  10560. p.Ctime = time.Now().Unix()
  10561. p.Mtime = time.Now().Unix()
  10562. p.PatientId = patient_id
  10563. p.UserOrgId = adminInfo.CurrentOrgId
  10564. p.Status = 1
  10565. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10566. if errcode > 0 {
  10567. c.ServeFailJSONWithSGJErrorCode(errcode)
  10568. return
  10569. }
  10570. service.CreateHisPrescriptionProjectTemplate(&p)
  10571. }
  10572. }
  10573. }
  10574. }
  10575. c.ServeSuccessJSON(map[string]interface{}{
  10576. "msg": "创建成功",
  10577. })
  10578. }
  10579. }
  10580. } else {
  10581. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10582. return
  10583. }
  10584. } else {
  10585. err3 := service.CreateHisPrescriptionTemplate(template)
  10586. if err3 == nil {
  10587. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10588. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10589. if len(prescriptions) > 0 {
  10590. for _, item := range prescriptions {
  10591. items := item.(map[string]interface{})
  10592. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10593. utils.ErrorLog("type")
  10594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10595. return
  10596. }
  10597. types := int64(items["type"].(float64))
  10598. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10599. utils.ErrorLog("med_type")
  10600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10601. return
  10602. }
  10603. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10604. ctime := time.Now().Unix()
  10605. prescription := &models.HisPrescriptionInfoTemplate{
  10606. PatientId: patient_id,
  10607. UserOrgId: adminInfo.CurrentOrgId,
  10608. Ctime: ctime,
  10609. Mtime: ctime,
  10610. Type: types,
  10611. Modifier: adminInfo.AdminUser.Id,
  10612. Creator: adminInfo.AdminUser.Id,
  10613. Status: 1,
  10614. PTemplateId: template.ID,
  10615. MedType: med_type,
  10616. }
  10617. service.CreateHisPrescriptionInfoTemplate(prescription)
  10618. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10619. advices := items["advices"].([]interface{})
  10620. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10621. ctime := time.Now().Unix()
  10622. mtime := ctime
  10623. if len(advices) > 0 {
  10624. for _, advice := range advices {
  10625. var s models.HisPrescriptionAdviceTemplate
  10626. s.PrescriptionId = prescription.ID
  10627. s.AdviceType = 2
  10628. s.StopState = 2
  10629. s.ExecutionState = 2
  10630. s.Status = 1
  10631. s.UserOrgId = adminInfo.CurrentOrgId
  10632. s.CreatedTime = ctime
  10633. s.UpdatedTime = mtime
  10634. s.PatientId = patient_id
  10635. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10636. if errcode > 0 {
  10637. c.ServeFailJSONWithSGJErrorCode(errcode)
  10638. return
  10639. }
  10640. service.CreateHisPrescriptionAdviceTemplate(&s)
  10641. }
  10642. }
  10643. }
  10644. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10645. projects := items["project"].([]interface{})
  10646. if len(projects) > 0 {
  10647. for _, project := range projects {
  10648. var p models.HisPrescriptionProjectTemplate
  10649. p.PrescriptionId = prescription.ID
  10650. p.Ctime = time.Now().Unix()
  10651. p.Mtime = time.Now().Unix()
  10652. p.PatientId = patient_id
  10653. p.UserOrgId = adminInfo.CurrentOrgId
  10654. p.Status = 1
  10655. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10656. if errcode > 0 {
  10657. c.ServeFailJSONWithSGJErrorCode(errcode)
  10658. return
  10659. }
  10660. service.CreateHisPrescriptionProjectTemplate(&p)
  10661. }
  10662. }
  10663. }
  10664. }
  10665. c.ServeSuccessJSON(map[string]interface{}{
  10666. "msg": "创建成功",
  10667. })
  10668. }
  10669. }
  10670. } else {
  10671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10672. return
  10673. }
  10674. }
  10675. }
  10676. func (c *HisApiController) PreSettle() {
  10677. id, _ := c.GetInt64("id")
  10678. record_time := c.GetString("record_time")
  10679. his_patient_id, _ := c.GetInt64("his_patient_id")
  10680. timeLayout := "2006-01-02"
  10681. loc, _ := time.LoadLocation("Local")
  10682. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10683. diagnosis_id := c.GetString("diagnosis")
  10684. sick_type, _ := c.GetInt64("sick_type")
  10685. reg_type, _ := c.GetInt64("p_type")
  10686. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10687. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10688. if err != nil {
  10689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10690. return
  10691. }
  10692. recordDateTime := theTime.Unix()
  10693. adminUser := c.GetAdminUserInfo()
  10694. var prescriptions []*models.HisPrescription
  10695. var start_time int64
  10696. var end_time int64
  10697. ids_str := c.GetString("ids")
  10698. ids_arr := strings.Split(ids_str, ",")
  10699. fmt.Println(reg_type)
  10700. if settle_accounts_type == 1 { //日结
  10701. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10702. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10703. } else {
  10704. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10705. }
  10706. fmt.Println(prescriptions)
  10707. } else { //月结
  10708. start_time_str := c.GetString("start_time")
  10709. end_time_str := c.GetString("end_time")
  10710. timeLayout := "2006-01-02"
  10711. loc, _ := time.LoadLocation("Local")
  10712. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10713. if err != nil {
  10714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10715. return
  10716. }
  10717. recordStartTime := theStartTime.Unix()
  10718. start_time = recordStartTime
  10719. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10720. if err != nil {
  10721. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10722. return
  10723. }
  10724. recordEndTime := theEndTime.Unix()
  10725. end_time = recordEndTime
  10726. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10727. }
  10728. if reg_type == 1111 || reg_type == 1112 {
  10729. reg_type = 11
  10730. }
  10731. timestamp := time.Now().Unix()
  10732. tempTime := time.Unix(timestamp, 0)
  10733. timeFormat := tempTime.Format("20060102150405")
  10734. chrgBchno := rand.Intn(100000) + 10000
  10735. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10736. strconv.FormatInt(his.PatientId, 10)
  10737. var ids []int64
  10738. for _, item := range prescriptions {
  10739. ids = append(ids, item.ID)
  10740. }
  10741. fmt.Println(ids)
  10742. var total float64
  10743. for _, item := range prescriptions {
  10744. fmt.Println(item)
  10745. if item.Type == 1 { //药品
  10746. for _, subItem := range item.HisDoctorAdviceInfo {
  10747. total = total + (subItem.Price * subItem.PrescribingNumber)
  10748. }
  10749. }
  10750. if item.Type == 2 { //项目
  10751. for _, subItem := range item.HisPrescriptionProject {
  10752. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10753. total = total + (subItem.Price * cnt)
  10754. }
  10755. }
  10756. for _, subItem := range item.HisAdditionalCharge {
  10757. total = total + (subItem.Price * float64(subItem.Count))
  10758. }
  10759. }
  10760. allTotal := fmt.Sprintf("%.2f", total)
  10761. totals, _ := strconv.ParseFloat(allTotal, 64)
  10762. order := &models.HisOrder{
  10763. UserOrgId: adminUser.CurrentOrgId,
  10764. HisPatientId: his.ID,
  10765. PatientId: id,
  10766. SettleAccountsDate: recordDateTime,
  10767. Ctime: time.Now().Unix(),
  10768. Mtime: time.Now().Unix(),
  10769. Status: 1,
  10770. OrderStatus: 1,
  10771. MdtrtId: his.Number,
  10772. Number: chrg_bchno,
  10773. MedfeeSumamt: totals,
  10774. SettleEndTime: end_time,
  10775. SettleStartTime: start_time,
  10776. SettleType: settle_accounts_type,
  10777. PsnPartAmt: totals,
  10778. PsnCashPay: totals,
  10779. PType: 2,
  10780. IsPre: 1,
  10781. MedType: strconv.Itoa(int(reg_type)),
  10782. Diagnosis: diagnosis_id,
  10783. }
  10784. err = service.CreateOrder(order)
  10785. if err != nil {
  10786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10787. return
  10788. }
  10789. var customs []*Custom
  10790. for _, item := range prescriptions {
  10791. fmt.Println(item.Type)
  10792. if item.Type == 1 { //药品
  10793. for _, subItem := range item.HisDoctorAdviceInfo {
  10794. cus := &Custom{
  10795. AdviceId: subItem.ID,
  10796. ProjectId: 0,
  10797. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10798. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10799. FeedetlSn: subItem.FeedetlSn,
  10800. Price: fmt.Sprintf("%.2f", subItem.Price),
  10801. MedListCodg: subItem.MedListCodg,
  10802. Type: 1,
  10803. }
  10804. customs = append(customs, cus)
  10805. }
  10806. }
  10807. if item.Type == 2 { //项目
  10808. for _, subItem := range item.HisPrescriptionProject {
  10809. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10810. cus := &Custom{
  10811. AdviceId: 0,
  10812. ProjectId: subItem.ID,
  10813. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10814. Cut: fmt.Sprintf("%.2f", cnt),
  10815. FeedetlSn: subItem.FeedetlSn,
  10816. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10817. MedListCodg: subItem.MedListCodg,
  10818. Type: 2,
  10819. }
  10820. customs = append(customs, cus)
  10821. }
  10822. }
  10823. for _, item := range item.HisAdditionalCharge {
  10824. cus := &Custom{
  10825. ItemId: item.ID,
  10826. AdviceId: 0,
  10827. ProjectId: 0,
  10828. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10829. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10830. FeedetlSn: item.FeedetlSn,
  10831. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10832. MedListCodg: item.XtHisAddtionConfig.Code,
  10833. Type: 3,
  10834. }
  10835. customs = append(customs, cus)
  10836. }
  10837. }
  10838. fmt.Println(customs)
  10839. for _, item := range customs {
  10840. var advice_id int64 = 0
  10841. var project_id int64 = 0
  10842. var item_id int64 = 0
  10843. var types int64 = 0
  10844. if item.Type == 1 {
  10845. advice_id = item.AdviceId
  10846. project_id = 0
  10847. item_id = 0
  10848. } else if item.Type == 2 {
  10849. advice_id = 0
  10850. item_id = 0
  10851. project_id = item.ProjectId
  10852. } else if item.Type == 3 {
  10853. advice_id = 0
  10854. item_id = item.ItemId
  10855. project_id = 0
  10856. }
  10857. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10858. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10859. pric, _ := strconv.ParseFloat(item.Price, 32)
  10860. info := &models.HisOrderInfo{
  10861. OrderNumber: order.Number,
  10862. UploadDate: time.Now().Unix(),
  10863. AdviceId: advice_id,
  10864. DetItemFeeSumamt: detItemFeeSumamt,
  10865. Cnt: cut,
  10866. Pric: pric,
  10867. PatientId: id,
  10868. Status: 1,
  10869. Mtime: time.Now().Unix(),
  10870. Ctime: time.Now().Unix(),
  10871. UserOrgId: adminUser.CurrentOrgId,
  10872. HisPatientId: his.ID,
  10873. OrderId: order.ID,
  10874. ProjectId: project_id,
  10875. Type: types,
  10876. ItemId: item_id,
  10877. }
  10878. service.CreateOrderInfo(info)
  10879. }
  10880. his.SickType = sick_type
  10881. service.UpdataHisPateint(&his)
  10882. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  10883. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  10884. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  10885. if err == nil {
  10886. c.ServeSuccessJSON(map[string]interface{}{
  10887. "msg": "结算成功",
  10888. })
  10889. }
  10890. }
  10891. type CustomOrderInfo struct {
  10892. Name string
  10893. Spec string
  10894. Unit string
  10895. Count float64
  10896. Price float64
  10897. Total float64
  10898. }
  10899. func (c *HisApiController) GetPrivateExpensesInfo() {
  10900. order_id, _ := c.GetInt64("id", 0)
  10901. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  10902. order, _ := service.GetHisOrderByID(order_id)
  10903. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  10904. if order.ID == 0 {
  10905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10906. return
  10907. }
  10908. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  10909. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10910. org_id := c.GetAdminUserInfo().CurrentOrgId
  10911. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10912. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10913. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  10914. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  10915. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  10916. //var orderInfos_four []*models.HisOrderInfoTwo
  10917. //for _, item := range orderInfos_three {
  10918. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  10919. // item.HisPrescriptionProject.IsCheckTeam = 1
  10920. // orderInfos_four = append(orderInfos_four, item)
  10921. //
  10922. // }
  10923. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  10924. // item.HisPrescriptionProject.IsCheckTeam = 2
  10925. // orderInfos_two = append(orderInfos_two, item)
  10926. // }
  10927. //}
  10928. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  10929. //var cus_slice []CustomOrderInfo
  10930. //for _, item := range new_order_info {
  10931. // var cus CustomOrderInfo
  10932. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  10933. // cus.Unit = ""
  10934. // cus.Spec = ""
  10935. // var total float64
  10936. // for _, subItem := range orderInfos_four {
  10937. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  10938. // total = total + subItem.DetItemFeeSumamt
  10939. // fmt.Println(subItem.DetItemFeeSumamt)
  10940. // }
  10941. // }
  10942. // cus.Count = 1
  10943. // cus.Total = total
  10944. // cus_slice = append(cus_slice, cus)
  10945. //}
  10946. orderInfos = append(orderInfos, orderInfos_two...)
  10947. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  10948. //orderInfos = append(orderInfos, orderInfos_three...)
  10949. //}/**/
  10950. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10951. c.ServeSuccessJSON(map[string]interface{}{
  10952. "order": order,
  10953. "order_info": orderInfos,
  10954. "patient": patient,
  10955. "admin_info": adminInfo,
  10956. "his": his,
  10957. "current_admin": role,
  10958. "org_config": miConfig,
  10959. //"new_order_info": cus_slice,
  10960. })
  10961. }
  10962. func (this *HisApiController) ChangeMedType() {
  10963. med_type := this.GetString("med_type")
  10964. old_med_type := this.GetString("old_med_type")
  10965. ids := this.GetString("ids")
  10966. settle_type, _ := this.GetInt64("settle_type")
  10967. start_time := this.GetString("start_time")
  10968. end_time := this.GetString("end_time")
  10969. ids_arr := strings.Split(ids, ",")
  10970. if settle_type == 1 { //日结
  10971. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  10972. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  10973. prescription.MedType = med_type
  10974. err := service.SaveHisPrescriptionTwo(&prescription)
  10975. if err == nil {
  10976. this.ServeSuccessJSON(map[string]interface{}{
  10977. "msg": "修改成功",
  10978. })
  10979. } else {
  10980. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10981. return
  10982. }
  10983. } else if settle_type == 2 {
  10984. timeLayout := "2006-01-02"
  10985. loc, _ := time.LoadLocation("Local")
  10986. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10987. if err != nil {
  10988. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10989. return
  10990. }
  10991. recordStartTime := theStartTime.Unix()
  10992. start_time_timestamp := recordStartTime
  10993. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  10994. if err != nil {
  10995. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10996. return
  10997. }
  10998. recordEndTime := theEndTime.Unix()
  10999. end_time_timestamp := recordEndTime
  11000. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  11001. if updateErr == nil {
  11002. this.ServeSuccessJSON(map[string]interface{}{
  11003. "msg": "修改成功",
  11004. })
  11005. } else {
  11006. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  11007. return
  11008. }
  11009. }
  11010. }
  11011. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  11012. patient_id, _ := c.GetInt64("patient_id")
  11013. his_patient_id, _ := c.GetInt64("his_patient_id")
  11014. record_date := c.GetString("record_date")
  11015. start_time := c.GetString("start_time")
  11016. end_time := c.GetString("end_time")
  11017. order_status, _ := c.GetInt64("type", 0)
  11018. p_type, _ := c.GetInt64("p_type", 0)
  11019. order_id, _ := c.GetInt64("order_id", 0)
  11020. timeLayout := "2006-01-02"
  11021. loc, _ := time.LoadLocation("Local")
  11022. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11023. if err != nil {
  11024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11025. return
  11026. }
  11027. recordDateTime := theTime.Unix()
  11028. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11029. if err != nil {
  11030. }
  11031. startRecordDateTime := startTime.Unix()
  11032. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11033. if err != nil {
  11034. }
  11035. endRecordDateTime := endTime.Unix()
  11036. admin := c.GetAdminUserInfo()
  11037. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  11038. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11039. order, _ := service.GetHisOrderByID(order_id)
  11040. var monthPrescriptions []*models.HisPrescription
  11041. if order_status == 1 || order_status == 0 {
  11042. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11043. } else if order_status == 2 {
  11044. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  11045. }
  11046. var settle_total float64
  11047. for _, item := range monthPrescriptions {
  11048. if len(item.HisPrescriptionProject) > 0 {
  11049. for _, subItem := range item.HisPrescriptionProject {
  11050. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11051. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11052. settle_total = settle_total + total
  11053. }
  11054. }
  11055. if len(item.HisDoctorAdviceInfo) > 0 {
  11056. for _, subItem := range item.HisDoctorAdviceInfo {
  11057. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11058. settle_total = settle_total + total
  11059. }
  11060. }
  11061. }
  11062. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11063. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11064. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11065. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11066. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11067. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11068. //获取所有科室信息
  11069. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11070. var dia string
  11071. for _, item := range month_p_info {
  11072. if len(dia) == 0 {
  11073. dia = item.Diagnosis
  11074. } else {
  11075. dia = dia + "," + item.Diagnosis
  11076. }
  11077. }
  11078. dia_arr := removeDuplicates(strings.Split(dia, ","))
  11079. dia_arr = removeEmptyStrings(dia_arr)
  11080. c.ServeSuccessJSON(map[string]interface{}{
  11081. "his_info": his_patient_info,
  11082. "xt_info": xt_patient_info,
  11083. "case_history": case_history,
  11084. "info": patientPrescriptionInfo,
  11085. "last_info": lastPatientPrescriptionInfo,
  11086. "month_prescriptions": monthPrescriptions,
  11087. "order": order,
  11088. "doctors": doctors,
  11089. "department": department,
  11090. "settle_total": settle_total,
  11091. "dia_arr": dia_arr,
  11092. })
  11093. return
  11094. }
  11095. func removeEmptyStrings(input []string) []string {
  11096. var output []string
  11097. for _, s := range input {
  11098. if s != "" {
  11099. output = append(output, s)
  11100. }
  11101. }
  11102. return output
  11103. }
  11104. func removeDuplicates(input []string) []string {
  11105. seen := make(map[string]bool)
  11106. output := []string{}
  11107. for _, s := range input {
  11108. if _, exists := seen[s]; !exists {
  11109. seen[s] = true
  11110. output = append(output, s)
  11111. }
  11112. }
  11113. return output
  11114. }
  11115. func (c *HisApiController) GetHisMonthPatientInfo() {
  11116. patient_id, _ := c.GetInt64("patient_id")
  11117. his_patient_id, _ := c.GetInt64("his_patient_id")
  11118. record_date := c.GetString("record_date")
  11119. number := c.GetString("number")
  11120. start_time := c.GetString("start_time")
  11121. end_time := c.GetString("end_time")
  11122. p_type, _ := c.GetInt64("p_type")
  11123. timeLayout := "2006-01-02"
  11124. loc, _ := time.LoadLocation("Local")
  11125. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11126. if err != nil {
  11127. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11128. return
  11129. }
  11130. recordDateTime := theTime.Unix()
  11131. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11132. if err != nil {
  11133. }
  11134. startRecordDateTime := startTime.Unix()
  11135. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11136. if err != nil {
  11137. }
  11138. endRecordDateTime := endTime.Unix()
  11139. admin := c.GetAdminUserInfo()
  11140. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  11141. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11142. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11143. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11144. var settle_total float64
  11145. for _, item := range monthPrescriptions {
  11146. if len(item.HisPrescriptionProject) > 0 {
  11147. for _, subItem := range item.HisPrescriptionProject {
  11148. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11149. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11150. settle_total = settle_total + total
  11151. }
  11152. }
  11153. if len(item.HisDoctorAdviceInfo) > 0 {
  11154. for _, subItem := range item.HisDoctorAdviceInfo {
  11155. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11156. settle_total = settle_total + total
  11157. }
  11158. }
  11159. }
  11160. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11161. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11162. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11163. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11164. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11165. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11166. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11167. //获取所有科室信息
  11168. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11169. c.ServeSuccessJSON(map[string]interface{}{
  11170. "his_info": his_patient_info,
  11171. "xt_info": xt_patient_info,
  11172. "case_history": case_history,
  11173. "info": patientPrescriptionInfo,
  11174. "month_prescriptions": monthPrescriptions,
  11175. "order": order,
  11176. "doctors": doctors,
  11177. "department": department,
  11178. "count": count,
  11179. "drugStockConfig": drugStockConfig,
  11180. "last_info": lastPatientPrescriptionInfo,
  11181. "settle_total": settle_total,
  11182. })
  11183. return
  11184. }
  11185. func (c *HisApiController) GetAllOrder() {
  11186. org_id := c.GetAdminUserInfo().CurrentOrgId
  11187. orders, _ := service.GetNewHisOrderList(org_id)
  11188. c.ServeSuccessJSON(map[string]interface{}{
  11189. "order": orders,
  11190. })
  11191. return
  11192. }
  11193. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11194. newArr = make([]*models.HisOrderInfoTwo, 0)
  11195. for i := 0; i < len(arr); i++ {
  11196. repeat := false
  11197. for j := i + 1; j < len(arr); j++ {
  11198. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11199. repeat = true
  11200. break
  11201. }
  11202. }
  11203. if !repeat {
  11204. newArr = append(newArr, arr[i])
  11205. }
  11206. }
  11207. return
  11208. }
  11209. // 修改处方退库操作 参数传修改之前的处方数据
  11210. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11211. if advice.ExecutionState == 1 {
  11212. //查询该病人该药品是否有库存记录
  11213. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11214. if errcode == gorm.ErrRecordNotFound {
  11215. } else {
  11216. //退库
  11217. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11218. if advice.PrescribingNumberUnit == drug.MinUnit {
  11219. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11220. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11221. //退库
  11222. warehouseInfo := models.DrugWarehouseInfo{
  11223. StockMinNumber: prescribingNumber,
  11224. }
  11225. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11226. operation_time := time.Now().Unix()
  11227. creater := advice.AdviceDoctor
  11228. ctime := time.Now().Unix()
  11229. timeStr := time.Now().Format("2006-01-02")
  11230. timeArr := strings.Split(timeStr, "-")
  11231. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11232. total = total + 1
  11233. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11234. cancelStock := models.DrugCancelStock{
  11235. OrderNumber: orderNumber,
  11236. OperaTime: operation_time,
  11237. OrgId: advice.UserOrgId,
  11238. Creater: creater,
  11239. Ctime: ctime,
  11240. Status: 1,
  11241. ReturnTime: advice.AdviceDate,
  11242. Dealer: info.Dealer,
  11243. Manufacturer: info.Manufacturer,
  11244. Type: 1,
  11245. }
  11246. service.AddSigleDrugCancelStock(&cancelStock)
  11247. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11248. dealer, _ := service.GetDealerById(info.Dealer)
  11249. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11250. cancelStockInfo := models.DrugCancelStockInfo{
  11251. OrderNumber: cancelInfo.OrderNumber,
  11252. CancelStockId: cancelInfo.ID,
  11253. DrugId: info.DrugId,
  11254. Count: info.Count,
  11255. Status: 1,
  11256. Ctime: ctime,
  11257. OrgId: advice.UserOrgId,
  11258. Type: 1,
  11259. Manufacturer: manufactureName.ManufacturerName,
  11260. Dealer: dealer.DealerName,
  11261. Total: 0,
  11262. RetailPrice: info.RetailPrice,
  11263. RetailTotalPrice: info.RetailTotalPrice,
  11264. Price: info.Price,
  11265. RegisterAccount: "",
  11266. Remark: info.Remark,
  11267. BatchNumber: info.BatchNumber,
  11268. MaxUnit: info.CountUnit,
  11269. ProductDate: info.ProductDate,
  11270. ExpiryDate: info.ExpiryDate,
  11271. BatchNumberId: info.WarehouseInfoId,
  11272. }
  11273. flow := models.DrugFlow{
  11274. WarehousingId: 0,
  11275. DrugId: info.DrugId,
  11276. Number: "",
  11277. BatchNumber: info.BatchNumber,
  11278. Count: info.Count,
  11279. UserOrgId: advice.UserOrgId,
  11280. PatientId: 0,
  11281. SystemTime: ctime,
  11282. ConsumableType: 4,
  11283. IsSys: 0,
  11284. WarehousingOrder: "",
  11285. WarehouseOutId: 0,
  11286. WarehouseOutOrderNumber: "",
  11287. IsEdit: 0,
  11288. CancelStockId: cancelStock.ID,
  11289. CancelOrderNumber: cancelStock.OrderNumber,
  11290. Manufacturer: info.Manufacturer,
  11291. Dealer: info.Dealer,
  11292. Creator: advice.UserOrgId,
  11293. UpdateCreator: 0,
  11294. Status: 1,
  11295. Ctime: time.Now().Unix(),
  11296. Mtime: 0,
  11297. Price: info.Price,
  11298. WarehousingDetailId: 0,
  11299. WarehouseOutDetailId: 0,
  11300. CancelOutDetailId: 0,
  11301. ExpireDate: info.ExpiryDate,
  11302. ProductDate: info.ProductDate,
  11303. MaxUnit: info.CountUnit,
  11304. MinUnit: "",
  11305. }
  11306. service.CreatedCancelStock(cancelStockInfo)
  11307. service.CreateDrugFlowOne(flow)
  11308. } else {
  11309. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11310. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11311. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11312. warehouseInfo := models.DrugWarehouseInfo{
  11313. StockMinNumber: prescribingNumber,
  11314. }
  11315. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11316. }
  11317. operation_time := time.Now().Unix()
  11318. creater := advice.AdviceDoctor
  11319. ctime := time.Now().Unix()
  11320. timeStr := time.Now().Format("2006-01-02")
  11321. timeArr := strings.Split(timeStr, "-")
  11322. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11323. total = total + 1
  11324. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11325. cancelStock := models.DrugCancelStock{
  11326. OrderNumber: orderNumber,
  11327. OperaTime: operation_time,
  11328. OrgId: advice.UserOrgId,
  11329. Creater: creater,
  11330. Ctime: ctime,
  11331. Status: 1,
  11332. ReturnTime: advice.AdviceDate,
  11333. Dealer: info.Dealer,
  11334. Manufacturer: info.Manufacturer,
  11335. Type: 1,
  11336. }
  11337. service.AddSigleDrugCancelStock(&cancelStock)
  11338. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11339. dealer, _ := service.GetDealerById(info.Dealer)
  11340. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11341. cancelStockInfo := models.DrugCancelStockInfo{
  11342. OrderNumber: cancelInfo.OrderNumber,
  11343. CancelStockId: cancelInfo.ID,
  11344. DrugId: info.DrugId,
  11345. Count: info.Count,
  11346. Status: 1,
  11347. Ctime: ctime,
  11348. OrgId: advice.UserOrgId,
  11349. Type: 1,
  11350. Manufacturer: manufactureName.ManufacturerName,
  11351. Dealer: dealer.DealerName,
  11352. Total: 0,
  11353. RetailPrice: info.RetailPrice,
  11354. RetailTotalPrice: info.RetailTotalPrice,
  11355. Price: info.Price,
  11356. RegisterAccount: "",
  11357. Remark: info.Remark,
  11358. BatchNumber: info.BatchNumber,
  11359. MaxUnit: info.CountUnit,
  11360. ProductDate: info.ProductDate,
  11361. ExpiryDate: info.ExpiryDate,
  11362. BatchNumberId: info.WarehouseInfoId,
  11363. }
  11364. flow := models.DrugFlow{
  11365. WarehousingId: 0,
  11366. DrugId: info.DrugId,
  11367. Number: "",
  11368. BatchNumber: info.BatchNumber,
  11369. Count: info.Count,
  11370. UserOrgId: advice.UserOrgId,
  11371. PatientId: 0,
  11372. SystemTime: ctime,
  11373. ConsumableType: 4,
  11374. IsSys: 0,
  11375. WarehousingOrder: "",
  11376. WarehouseOutId: 0,
  11377. WarehouseOutOrderNumber: "",
  11378. IsEdit: 0,
  11379. CancelStockId: cancelStock.ID,
  11380. CancelOrderNumber: cancelStock.OrderNumber,
  11381. Manufacturer: info.Manufacturer,
  11382. Dealer: info.Dealer,
  11383. Creator: advice.AdviceDoctor,
  11384. UpdateCreator: 0,
  11385. Status: 1,
  11386. Ctime: time.Now().Unix(),
  11387. Mtime: 0,
  11388. Price: info.Price,
  11389. WarehousingDetailId: 0,
  11390. WarehouseOutDetailId: 0,
  11391. CancelOutDetailId: 0,
  11392. ExpireDate: info.ExpiryDate,
  11393. ProductDate: info.ProductDate,
  11394. MaxUnit: info.CountUnit,
  11395. MinUnit: "",
  11396. }
  11397. service.CreatedCancelStock(cancelStockInfo)
  11398. service.CreateDrugFlowOne(flow)
  11399. }
  11400. }
  11401. }
  11402. return err
  11403. }
  11404. func (this *HisApiController) DeleteNCDS() {
  11405. id, _ := this.GetInt64("id", 0)
  11406. if id > 0 {
  11407. service.DeletePsnNCDSRecordById(id)
  11408. this.ServeSuccessJSON(map[string]interface{}{
  11409. "msg": "删除成功",
  11410. })
  11411. } else {
  11412. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11413. return
  11414. }
  11415. }
  11416. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11417. id, _ := c.GetInt64("id")
  11418. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11419. c.ServeSuccessJSON(map[string]interface{}{
  11420. "advice": advice,
  11421. })
  11422. return
  11423. }
  11424. func (c *HisApiController) GetHisMonthChargePatientList() {
  11425. record_date := c.GetString("record_date")
  11426. start_time := c.GetString("start_time")
  11427. end_time := c.GetString("end_time")
  11428. timeLayout := "2006-01-02"
  11429. loc, _ := time.LoadLocation("Local")
  11430. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11431. if err != nil {
  11432. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11433. return
  11434. }
  11435. if err != nil {
  11436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11437. return
  11438. }
  11439. recordDateTime := theTime.Unix()
  11440. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11441. if err != nil {
  11442. }
  11443. startRecordDateTime := startTime.Unix()
  11444. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11445. if err != nil {
  11446. }
  11447. endRecordDateTime := endTime.Unix()
  11448. adminInfo := c.GetAdminUserInfo()
  11449. var tempMonthChargePatients []*service.MonthChargePatients
  11450. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11451. for _, item := range tempPatients {
  11452. //过滤没有处方的
  11453. if len(item.HisPrescription) == 0 {
  11454. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11455. }
  11456. }
  11457. c.ServeSuccessJSON(map[string]interface{}{
  11458. "list": tempMonthChargePatients,
  11459. })
  11460. }
  11461. // PrescriptionDifference 医嘱数量差值结构体
  11462. type PrescriptionDrugDifference struct {
  11463. DrugID int64 //基础库药品id
  11464. ID int64 //医嘱id
  11465. Difference float64 //差值
  11466. Unit string //单位
  11467. }
  11468. type PrescriptionGoodDifference struct {
  11469. GoodID int64 //基础库项目耗材id
  11470. ID int64 //医嘱id
  11471. Difference int64 //差值
  11472. Unit string //单位
  11473. Type int64 //类型
  11474. }
  11475. type EditCustomData struct {
  11476. adviceList []*models.HisDoctorAdviceInfo
  11477. projectList []*models.HisPrescriptionProject
  11478. }
  11479. type SrcCustomData struct {
  11480. adviceList []*models.HisDoctorAdviceInfo
  11481. projectList []*models.HisPrescriptionProject
  11482. }
  11483. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11484. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11485. differences := make([]*PrescriptionDrugDifference, 0)
  11486. // 创建一个 map 来存储第一个切片中的药品信息
  11487. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11488. for _, advice := range firstPrescription {
  11489. firstMap[advice.DrugId] = advice
  11490. }
  11491. // 遍历第二个切片中的药品信息,并比较数量差值
  11492. for _, advice := range secondPrescription {
  11493. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11494. diff := &PrescriptionDrugDifference{
  11495. DrugID: advice.DrugId,
  11496. ID: firstAdvice.ID,
  11497. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11498. Unit: firstAdvice.PrescribingNumberUnit,
  11499. }
  11500. differences = append(differences, diff)
  11501. }
  11502. }
  11503. return differences
  11504. }
  11505. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11506. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11507. differences := make([]*PrescriptionGoodDifference, 0)
  11508. // 创建一个 map 来存储第一个切片中的耗材信息
  11509. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11510. for _, good := range firstPrescription {
  11511. firstMap[good.ProjectId] = good
  11512. }
  11513. // 遍历第二个切片中的耗材信息,并比较数量差值
  11514. for _, good := range secondPrescription {
  11515. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11516. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11517. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11518. diff := &PrescriptionGoodDifference{
  11519. GoodID: good.ProjectId,
  11520. ID: firstGood.ID,
  11521. Difference: count - firstCount,
  11522. Unit: firstGood.Unit,
  11523. Type: firstGood.Type,
  11524. }
  11525. differences = append(differences, diff)
  11526. }
  11527. }
  11528. return differences
  11529. }
  11530. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11531. var adviceList []*models.HisDoctorAdviceInfo
  11532. var projectList []*models.HisPrescriptionProject
  11533. var advice_ids []int64
  11534. var project_ids []int64
  11535. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11536. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11537. //var tempPrescription *models.HisPrescriptionProjectscription
  11538. if len(prescriptions) > 0 {
  11539. for _, item := range prescriptions {
  11540. items := item.(map[string]interface{})
  11541. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11542. advices := items["advices"].([]interface{})
  11543. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11544. groupNo := int64(0)
  11545. ctime := time.Now().Unix()
  11546. mtime := ctime
  11547. if len(advices) > 0 {
  11548. for _, advice := range advices {
  11549. var s models.HisDoctorAdviceInfo
  11550. s.AdviceType = 2
  11551. s.StopState = 2
  11552. s.ExecutionState = 2
  11553. s.Status = 1
  11554. s.Groupno = groupNo
  11555. s.CreatedTime = ctime
  11556. s.UpdatedTime = mtime
  11557. s.IsSettle = 2
  11558. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11559. //存储切片中
  11560. if s.ID > 0 {
  11561. advice_ids = append(advice_ids, s.ID)
  11562. adviceList = append(adviceList, &s)
  11563. }
  11564. }
  11565. }
  11566. }
  11567. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11568. projects := items["project"].([]interface{})
  11569. if len(projects) > 0 {
  11570. for _, project := range projects {
  11571. var p models.HisPrescriptionProject
  11572. p.Ctime = time.Now().Unix()
  11573. p.Mtime = time.Now().Unix()
  11574. p.Status = 1
  11575. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11576. if p.ID > 0 {
  11577. project_ids = append(project_ids, p.ID)
  11578. projectList = append(projectList, &p)
  11579. }
  11580. }
  11581. }
  11582. }
  11583. }
  11584. }
  11585. }
  11586. editCustomData.projectList = projectList
  11587. editCustomData.adviceList = adviceList
  11588. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11589. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11590. srcCustomData.adviceList = list
  11591. srcCustomData.projectList = list2
  11592. return
  11593. }