his_api_controller.go 271KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. }
  83. func (c *PublicApiController) GetBaiLinExportData() {
  84. data := service.GetBaiLinOrderData()
  85. fmt.Println(len(data))
  86. var new_data []*models.NewCustomHisOrder
  87. for _, item := range data {
  88. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  89. new_data = append(new_data, item)
  90. }
  91. }
  92. fmt.Println(len(new_data))
  93. c.ServeSuccessJSON(map[string]interface{}{
  94. "list": new_data,
  95. })
  96. }
  97. func (c *HisApiController) GetHisUnChargePatientList() {
  98. record_date := c.GetString("record_date")
  99. timeLayout := "2006-01-02"
  100. loc, _ := time.LoadLocation("Local")
  101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  102. if err != nil {
  103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. recordDateTime := theTime.Unix()
  107. adminInfo := c.GetAdminUserInfo()
  108. var tempPatients []*service.NewTempPatients
  109. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  110. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  111. var patients []*service.NewTempPatients
  112. var patients_two []*service.NewTempPatients
  113. for _, item := range tempPatients {
  114. //过滤掉没挂号的和没开处方的
  115. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  116. patients = append(patients, item)
  117. }
  118. //过滤掉没挂号的
  119. if len(item.HisPatient) > 0 {
  120. patients_two = append(patients_two, item)
  121. }
  122. }
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "list": patients,
  125. "list_two": patients_two,
  126. })
  127. }
  128. func (c *HisApiController) GetPrivateExpensesOrder() {
  129. //id, _ := c.GetInt64("id")
  130. //record_time := c.GetString("record_time")
  131. order_id, _ := c.GetInt64("order_id")
  132. admin_user_id, _ := c.GetInt64("admin_user_id")
  133. //timeLayout := "2006-01-02"
  134. //loc, _ := time.LoadLocation("Local")
  135. //
  136. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  137. //if err != nil {
  138. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. // return
  140. //}
  141. //recordDateTime := theTime.Unix()
  142. adminUser := c.GetAdminUserInfo()
  143. order, _ := service.GetHisOrderByID(order_id)
  144. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  145. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  146. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  147. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  148. //var config []*models.HisXtDiagnoseConfig
  149. var name string
  150. if order.PType == 1 {
  151. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  152. for _, item := range diagnosis_ids {
  153. id, _ := strconv.ParseInt(item, 10, 64)
  154. diagnosisConfig, _ := service.FindDiagnoseById(id)
  155. if len(name) == 0 {
  156. name = diagnosisConfig.ClassName
  157. } else {
  158. name = name + "," + diagnosisConfig.ClassName
  159. }
  160. }
  161. } else {
  162. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  163. for _, item := range diagnosis_ids {
  164. id, _ := strconv.ParseInt(item, 10, 64)
  165. diagnosisConfig, _ := service.FindDiagnoseById(id)
  166. if len(name) == 0 {
  167. name = diagnosisConfig.ClassName
  168. } else {
  169. name = name + "," + diagnosisConfig.ClassName
  170. }
  171. }
  172. }
  173. var bedCostTotal float64 = 0 //床位总费
  174. //var bedCostSelfTotal float64 = 0 //床位自费
  175. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  176. var operationCostTotal float64 = 0 //手术费
  177. //var operationCostSelfTotal float64 = 0 //手术费
  178. var operationCostPartSelfTotal float64 = 0 //手术费
  179. var otherCostTotal float64 = 0 //其他费用
  180. //var otherCostSelfTotal float64 = 0 //其他费用
  181. var otherCostPartSelfTotal float64 = 0 //其他费用
  182. var materialCostTotal float64 = 0 //材料费
  183. //var materialCostSelfTotal float64 = 0 //材料费
  184. var materialCostPartSelfTotal float64 = 0 //材料费
  185. var westernMedicineCostTotal float64 = 0 //西药费
  186. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  187. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  188. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  189. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  190. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  191. var checkCostTotal float64 = 0 //检查费
  192. //var checkCostSelfTotal float64 = 0 //检查费
  193. var checkCostPartSelfTotal float64 = 0 //检查费
  194. var laboratoryCostTotal float64 = 0 //化验费
  195. //var laboratoryCostSelfTotal float64 = 0 //化验费
  196. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  197. var treatCostTotal float64 = 0 //治疗费用
  198. //var treatCostSelfTotal float64 = 0 //治疗费用
  199. var treatCostPartSelfTotal float64 = 0 //治疗费用
  200. var zhenChaCostTotal float64 = 0 //其他费用
  201. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  202. decimal.DivisionPrecision = 2
  203. for _, item := range orderInfos {
  204. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  205. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  206. item.MedChrgitmType = "09"
  207. }
  208. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  209. if item.HisPrescriptionProject.Type == 2 {
  210. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  211. fmt.Println("CostClassify")
  212. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  213. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  214. case 0:
  215. item.MedChrgitmType = "0"
  216. break
  217. case 1:
  218. item.MedChrgitmType = "14"
  219. break
  220. case 2:
  221. item.MedChrgitmType = "05"
  222. break
  223. case 3:
  224. item.MedChrgitmType = "03"
  225. break
  226. case 4:
  227. item.MedChrgitmType = "03"
  228. break
  229. case 5:
  230. item.MedChrgitmType = "08"
  231. break
  232. case 6:
  233. item.MedChrgitmType = "14"
  234. break
  235. case 7:
  236. item.MedChrgitmType = "14"
  237. break
  238. case 8:
  239. item.MedChrgitmType = "03"
  240. break
  241. case 9:
  242. item.MedChrgitmType = "14"
  243. break
  244. case 10:
  245. item.MedChrgitmType = "14"
  246. break
  247. case 11:
  248. item.MedChrgitmType = "06"
  249. break
  250. case 12:
  251. item.MedChrgitmType = "12"
  252. break
  253. case 13:
  254. item.MedChrgitmType = "01"
  255. break
  256. case 14:
  257. item.MedChrgitmType = "04"
  258. break
  259. case 15:
  260. item.MedChrgitmType = "14"
  261. break
  262. }
  263. } else {
  264. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  265. case 1:
  266. item.MedChrgitmType = "14"
  267. break
  268. case 2:
  269. item.MedChrgitmType = "05"
  270. break
  271. case 3:
  272. item.MedChrgitmType = "04"
  273. break
  274. case 4:
  275. item.MedChrgitmType = "14"
  276. break
  277. case 5:
  278. item.MedChrgitmType = "08"
  279. break
  280. case 6:
  281. item.MedChrgitmType = "14"
  282. break
  283. case 7:
  284. item.MedChrgitmType = "14"
  285. break
  286. case 8:
  287. item.MedChrgitmType = "03"
  288. break
  289. case 9:
  290. item.MedChrgitmType = "14"
  291. break
  292. }
  293. }
  294. } else if item.HisPrescriptionProject.Type == 3 {
  295. item.MedChrgitmType = "08"
  296. }
  297. }
  298. }
  299. order.PsnCashPay = order.MedfeeSumamt
  300. for _, item := range orderInfos {
  301. if item.MedChrgitmType == "01" { //床位费
  302. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. }
  306. if item.MedChrgitmType == "02" { //诊察费
  307. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  308. //zhenChaCostSelfTotal = zhenChaCostTotal
  309. }
  310. if item.MedChrgitmType == "03" { //检查费
  311. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  312. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  313. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "02" { //检查费
  316. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. }
  320. if item.MedChrgitmType == "04" { //化验费
  321. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  322. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  323. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  324. }
  325. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  326. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  327. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  328. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  329. }
  330. if item.MedChrgitmType == "06" { //手术费
  331. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  332. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  333. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  334. }
  335. if item.MedChrgitmType == "08" { //材料费
  336. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  337. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  338. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  339. }
  340. if item.MedChrgitmType == "09" { //西药费
  341. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  342. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  343. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  344. }
  345. if item.MedChrgitmType == "11" { //中成费
  346. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  347. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  348. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  349. }
  350. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  351. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  352. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  353. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  354. }
  355. }
  356. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  357. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  358. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  359. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  360. c.ServeSuccessJSON(map[string]interface{}{
  361. "patient": patient,
  362. "order_infos": orderInfos,
  363. "diagnosis": name,
  364. "bedCostTotal": bedCostTotal,
  365. "bedCostSelfTotal": bedCostTotal,
  366. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  367. "operationCostTotal": operationCostTotal,
  368. "operationCostSelfTotal": operationCostTotal,
  369. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  370. "otherCostTotal": otherCostTotal,
  371. "otherCostSelfTotal": otherCostTotal,
  372. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  373. "materialCostTotal": materialCostTotal,
  374. "materialCostSelfTotal": materialCostTotal,
  375. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  376. "westernMedicineCostTotal": westernMedicineCostTotal,
  377. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  378. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  379. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  380. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  381. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  382. "checkCostTotal": checkCostTotal,
  383. "checkCostSelfTotal": checkCostTotal,
  384. "zhenChaCostTotal": zhenChaCostTotal,
  385. "zhenChaCostSelfTotal": zhenChaCostTotal,
  386. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  387. "laboratoryCostTotal": laboratoryCostTotal,
  388. "laboratoryCostSelfTotal": laboratoryCostTotal,
  389. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  390. "treatCostTotal": treatCostTotal,
  391. "treatCostSelfTotal": treatCostTotal,
  392. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  393. "charge_admin": charge_admin,
  394. "printor_admin": printor_admin,
  395. "org_name": org.OrgName,
  396. "org_code": miConfig.Code,
  397. "name": patient.Name,
  398. "number": order.MdtrtId,
  399. "date": order.SettleAccountsDate,
  400. "info": order,
  401. "his_hospital": his_hospital,
  402. "his": his,
  403. })
  404. }
  405. func (c *HisApiController) RefudDetail() {
  406. order_id, _ := c.GetInt64("order_id")
  407. order, _ := service.GetHisOrderByID(order_id)
  408. adminUser := c.GetAdminUserInfo()
  409. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  410. c.ServeSuccessJSON(map[string]interface{}{
  411. "msg": "撤销成功",
  412. })
  413. }
  414. func (c *HisApiController) Sscard() {
  415. //r := CardInit()
  416. //if r == 0 {
  417. // GetBaseInfo()
  418. //}
  419. //c.ServeSuccessJSON(map[string]interface{}{
  420. // "list": "11",
  421. //})
  422. }
  423. func GetBaseInfo() error {
  424. //handle := syscall.MustLoadDLL("SSCard.dll")
  425. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  426. //
  427. //str := make([]byte, 256)
  428. //str1 := make([]byte, 256)
  429. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  430. //if ferr != nil {
  431. // fmt.Println("ReadCardBas 报错", ferr.Error())
  432. // return ferr
  433. //}
  434. //
  435. //fmt.Println(string(str))
  436. //
  437. //fmt.Println(r)
  438. return nil
  439. }
  440. func CardInit() int {
  441. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  442. //add := DllTestDef.MustFindProc("Init")
  443. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  444. //if err != nil {
  445. // fmt.Println("SSCard的运算结果为:", ret)
  446. //}
  447. //result := int(ret)
  448. return 0
  449. }
  450. func IntPtr(n int) uintptr {
  451. return uintptr(n)
  452. }
  453. func StrPtr(s string) uintptr {
  454. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  455. }
  456. func (c *HisApiController) GetHisPatientList() {
  457. //types, _ := c.GetInt64("type", 0)
  458. record_date := c.GetString("record_date")
  459. sch_type, _ := c.GetInt64("sch_type")
  460. timeLayout := "2006-01-02"
  461. loc, _ := time.LoadLocation("Local")
  462. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  463. if err != nil {
  464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  465. return
  466. }
  467. recordDateTime := theTime.Unix()
  468. adminInfo := c.GetAdminUserInfo()
  469. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  470. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  471. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  472. //获取当前用户的信息
  473. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  474. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  475. //获取所有科室信息
  476. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  477. c.ServeSuccessJSON(map[string]interface{}{
  478. "list": patients,
  479. "list_two": patients_two,
  480. "info": adminUserInfo,
  481. "doctors": doctors,
  482. "department": department,
  483. })
  484. }
  485. type CustomTemplate struct {
  486. ID int64 `gorm:"column:id" json:"id" form:"id"`
  487. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  488. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  489. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  490. Status int64 `gorm:"column:status" json:"status" form:"status"`
  491. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  492. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  493. Type int64 `gorm:"column:type" json:"type" form:"type"`
  494. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  495. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  496. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  497. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  498. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  499. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  500. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  501. }
  502. func (c *HisApiController) GetHisPatientInfo() {
  503. patient_id, _ := c.GetInt64("patient_id")
  504. his_patient_id, _ := c.GetInt64("his_patient_id")
  505. record_date := c.GetString("record_date")
  506. number := c.GetString("number")
  507. //start_time := c.GetString("start_time")
  508. //end_time := c.GetString("end_time")
  509. p_type, _ := c.GetInt64("p_type")
  510. timeLayout := "2006-01-02"
  511. loc, _ := time.LoadLocation("Local")
  512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  513. if err != nil {
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  515. return
  516. }
  517. recordDateTime := theTime.Unix()
  518. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  519. //if err != nil {
  520. //
  521. //}
  522. //startRecordDateTime := startTime.Unix()
  523. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  524. //if err != nil {
  525. //
  526. //}
  527. //endRecordDateTime := endTime.Unix()
  528. admin := c.GetAdminUserInfo()
  529. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  530. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  531. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  532. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  533. var prescriptions []*models.HisPrescription
  534. var last_prescriptions []*models.HisPrescription
  535. var sch_prescriptions []CustomTemplate
  536. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  537. if p_type == 1 { //住院
  538. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  539. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  540. } else { //门诊
  541. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  542. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  543. }
  544. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  545. if sch.ID > 0 {
  546. var week string
  547. t := time.Now()
  548. switch t.Weekday().String() {
  549. case "Monday":
  550. week = "周一"
  551. break
  552. case "Tuesday":
  553. week = "周二"
  554. break
  555. case "Wednesday":
  556. week = "周三"
  557. break
  558. case "Thursday":
  559. week = "周四"
  560. break
  561. case "Friday":
  562. week = "周五"
  563. break
  564. case "Saturday":
  565. week = "周六"
  566. break
  567. case "Sunday":
  568. week = "周日"
  569. break
  570. }
  571. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  572. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  573. //根据推送频率组装新的数组
  574. for _, item := range temp_sch_prescriptions {
  575. var cus CustomTemplate
  576. cus.ID = item.ID
  577. cus.UserOrgId = item.UserOrgId
  578. cus.PatientId = item.PatientId
  579. cus.MedType = item.MedType
  580. cus.RecordDate = item.RecordDate
  581. cus.Type = item.Type
  582. cus.PType = item.PType
  583. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  584. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  585. if subItem.FrequencyType == 1 { //每次必推
  586. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  587. }
  588. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  589. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  590. }
  591. if subItem.FrequencyType == 2 { //按照天数频率
  592. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  593. now := p.Unix()
  594. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  595. dayStr2 := "-" + dayStr
  596. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  597. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  598. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  599. if len(advices) == 0 {
  600. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  601. }
  602. }
  603. }
  604. }
  605. for _, subItem := range item.HisPrescriptionProjectTemplate {
  606. if subItem.Type == 2 {
  607. if subItem.XtHisProject.MedicalStatus != 1 {
  608. if subItem.FrequencyType == 1 {
  609. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  610. }
  611. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  612. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  613. }
  614. if subItem.FrequencyType == 2 {
  615. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  616. now := p.Unix()
  617. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  618. dayStr2 := "-" + dayStr
  619. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  620. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  621. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  622. if len(projects) == 0 {
  623. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  624. }
  625. }
  626. }
  627. } else if subItem.Type == 3 {
  628. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  629. if subItem.FrequencyType == 1 {
  630. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  631. }
  632. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  633. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  634. }
  635. if subItem.FrequencyType == 2 {
  636. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  637. now := p.Unix()
  638. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  639. dayStr2 := "-" + dayStr
  640. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  641. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  642. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  643. if len(projects) == 0 {
  644. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  645. }
  646. }
  647. }
  648. }
  649. }
  650. sch_prescriptions = append(sch_prescriptions, cus)
  651. }
  652. for _, item := range sch_prescriptions {
  653. if len(item.HisPrescriptionProjectTemplate) == 0 {
  654. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  655. }
  656. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  657. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  658. }
  659. }
  660. }
  661. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  662. if config.ID > 0 && config.IsOpen == 1 {
  663. for _, item := range sch_prescriptions {
  664. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  665. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  666. if info.RetailPrice > 0 {
  667. subItem.Drug.MinPrice = info.RetailPrice
  668. }
  669. }
  670. }
  671. }
  672. if config.ID > 0 && config.IsOpen == 1 {
  673. for _, item := range sch_prescriptions {
  674. for _, subItem := range item.HisPrescriptionProjectTemplate {
  675. if subItem.Type == 3 {
  676. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  677. if info.Price > 0 {
  678. subItem.GoodInfo.PackingPrice = info.Price
  679. }
  680. }
  681. }
  682. }
  683. }
  684. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  685. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  686. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  687. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  688. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  689. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  690. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  691. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  692. //获取所有科室信息
  693. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  694. c.ServeSuccessJSON(map[string]interface{}{
  695. "his_info": his_patient_info,
  696. "xt_info": xt_patient_info,
  697. "prescription": prescriptions,
  698. "case_history": case_history,
  699. "info": patientPrescriptionInfo,
  700. //"month_prescriptions": monthPrescriptions,
  701. "order": order,
  702. "doctors": doctors,
  703. "department": department,
  704. "sch_prescriptions": sch_prescriptions,
  705. "last_prescriptions": last_prescriptions,
  706. "schedule": sch,
  707. "count": count,
  708. "drugStockConfig": drugStockConfig,
  709. "last_info": lastPatientPrescriptionInfo,
  710. })
  711. return
  712. }
  713. func (c *HisApiController) GetHisPrescriptionConfig() {
  714. adminInfo := c.GetAdminUserInfo()
  715. //获取医嘱模版
  716. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  717. //获取所有基础药
  718. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  719. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  720. if config.ID > 0 && config.IsOpen == 1 {
  721. for _, item := range drugs {
  722. var index = 0
  723. for _, subItem := range item.OtherDrugWarehouseInfo {
  724. if index == 0 {
  725. index = index + 1
  726. if subItem.RetailPrice > 0 {
  727. item.MinPrice = subItem.RetailPrice
  728. }
  729. }
  730. }
  731. }
  732. }
  733. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  734. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  735. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  736. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  737. //获取所有科室信息
  738. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  739. //获取诊断信息
  740. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  741. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  742. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  743. c.ServeSuccessJSON(map[string]interface{}{
  744. "drugs": drugs,
  745. "advices_template": advices,
  746. "drugways": drugways,
  747. "efs": efs,
  748. "doctors": doctors,
  749. "department": department,
  750. "sick": sick,
  751. "additions": additions,
  752. "diagnose": diagnose,
  753. "manufacturers": manufacturers,
  754. })
  755. }
  756. func (c *HisApiController) CreateHisPrescription() {
  757. record_date := c.GetString("record_date")
  758. patient_id, _ := c.GetInt64("patient_id")
  759. reg_type, _ := c.GetInt64("reg_type")
  760. diagnose := c.GetString("diagnose")
  761. sick_type, _ := c.GetInt64("sick_type")
  762. sick_history := c.GetString("sick_history")
  763. doctor_id, _ := c.GetInt64("doctor", 0)
  764. department, _ := c.GetInt64("department", 0)
  765. his_patient_id, _ := c.GetInt64("his_patient_id")
  766. p_type, _ := c.GetInt64("p_type")
  767. dataBody := make(map[string]interface{}, 0)
  768. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  769. if err != nil {
  770. utils.ErrorLog(err.Error())
  771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  772. return
  773. }
  774. timeLayout := "2006-01-02"
  775. loc, _ := time.LoadLocation("Local")
  776. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  777. if err != nil {
  778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  779. return
  780. }
  781. adminInfo := c.GetAdminUserInfo()
  782. recordDateTime := theTime.Unix()
  783. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  784. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  785. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  786. if len(lists) == 1 {
  787. his_patient_id = lists[0].ID
  788. }
  789. }
  790. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  791. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  792. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  793. if drugStockConfig.IsOpen == 1 {
  794. //校验库存总量
  795. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  796. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  797. if len(prescriptions) > 0 {
  798. for _, item := range prescriptions {
  799. items := item.(map[string]interface{})
  800. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  801. advices := items["advices"].([]interface{})
  802. if len(advices) > 0 {
  803. for _, advice := range advices {
  804. var drug_id int64
  805. var prescribing_number float64
  806. var prescribingNumberUnit string
  807. var prescribingNumber string
  808. var adviceId int64
  809. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  810. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  811. }
  812. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  813. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  814. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  815. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  816. }
  817. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  818. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  819. }
  820. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  821. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  822. }
  823. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  824. if drug.ID == 0 {
  825. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  826. return
  827. }
  828. //查询药品的所有库存
  829. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId)
  830. var total_count int64
  831. for _, it := range list {
  832. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  833. }
  834. totals := strconv.FormatInt(total_count, 10)
  835. //查询该药品是否存在开药记录
  836. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  837. //新增处方
  838. if advicelist.ID == 0 {
  839. all_count, _ := strconv.ParseFloat(totals, 64)
  840. if prescribingNumberUnit == drug.MinUnit {
  841. if prescribing_number > all_count {
  842. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  843. return
  844. }
  845. } else {
  846. if prescribingNumberUnit == drug.MaxUnit {
  847. num := prescribing_number * float64(drug.MinNumber)
  848. if num > all_count {
  849. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  850. return
  851. }
  852. }
  853. }
  854. }
  855. //修改处方
  856. if advicelist.ID > 0 {
  857. var device_number int64
  858. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  859. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  860. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  861. device_number = prescribingNumberInt * drug.MinNumber
  862. }
  863. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  864. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  865. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  866. device_number = prescribingNumberInt
  867. }
  868. var number_count int64
  869. if prescribingNumberUnit == drug.MaxUnit {
  870. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  871. number_count = prescribingNumberInt * drug.MinNumber
  872. }
  873. if prescribingNumberUnit == drug.MinUnit {
  874. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  875. number_count = prescribingNumberInt
  876. }
  877. //如果修改的数量大于之前修改的数量
  878. if (number_count - device_number) > 0 {
  879. //如果修改的差数量 大于库存数量
  880. if (number_count - device_number) > total_count {
  881. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  882. return
  883. }
  884. }
  885. if device_number != number_count {
  886. // 查询该药品最后一次出库记录
  887. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  888. //回退库存
  889. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  890. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  891. }
  892. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  893. var stock_max_number int64
  894. var stock_min_number int64
  895. if number_count >= drug.MinNumber {
  896. stock_max_number = device_number / drug.MinNumber
  897. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  898. stock_min_number = device_number % drug.MinNumber
  899. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  900. } else {
  901. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  902. }
  903. }
  904. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  905. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  906. }
  907. //删除记录
  908. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  909. }
  910. }
  911. }
  912. }
  913. }
  914. }
  915. }
  916. }
  917. }
  918. if stockConfig.IsOpen == 1 {
  919. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  920. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  921. if len(prescriptions) > 0 {
  922. for _, item := range prescriptions {
  923. items := item.(map[string]interface{})
  924. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  925. projects := items["project"].([]interface{})
  926. if len(projects) > 0 {
  927. for _, project := range projects {
  928. var project_id int64
  929. var project_type int64
  930. var totals float64
  931. var project_name string
  932. var parsetotal int64
  933. var id int64
  934. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  935. id = int64(project.(map[string]interface{})["id"].(float64))
  936. }
  937. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  938. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  939. }
  940. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  941. project_type = int64(project.(map[string]interface{})["type"].(float64))
  942. }
  943. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  944. total, _ := project.(map[string]interface{})["total"].(string)
  945. totals, _ = strconv.ParseFloat(total, 64)
  946. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  947. }
  948. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  949. project_name = project.(map[string]interface{})["project_name"].(string)
  950. }
  951. if project_type == 3 {
  952. //查找该耗材的出库记录
  953. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  954. //var total_count int64
  955. //for _, it := range goodWarehouseInfo {
  956. // total_count += it.Count
  957. //}
  958. if len(goodWarehouseInfo) == 0 {
  959. //查询耗材库存
  960. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  961. var stock_count int64
  962. for _, it := range list {
  963. stock_count += it.StockCount
  964. }
  965. stock_counts := strconv.FormatInt(stock_count, 10)
  966. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  967. if totals > stock_total_count {
  968. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  969. return
  970. }
  971. //查找今日该患者已经出库的所有耗材
  972. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  973. for _, item := range goodList {
  974. //回退库存
  975. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  976. }
  977. //删除记录
  978. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  979. }
  980. if len(goodWarehouseInfo) > 0 {
  981. //查询该患者耗材的历史数据
  982. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  983. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  984. //数量发生改变
  985. if parsetotal != count {
  986. //查找今日该患者已经出库的所有耗材
  987. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  988. for _, item := range goodList {
  989. //回退库存
  990. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  991. }
  992. //删除记录
  993. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  994. }
  995. }
  996. }
  997. }
  998. }
  999. }
  1000. }
  1001. }
  1002. }
  1003. }
  1004. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1005. var hpInfo models.HisPrescriptionInfo
  1006. if info.ID == 0 {
  1007. var randNum int
  1008. randNum = rand.Intn(10000) + 1000
  1009. timestamp := time.Now().Unix()
  1010. tempTime := time.Unix(timestamp, 0)
  1011. timeFormat := tempTime.Format("20060102150405")
  1012. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1013. hpInfo = models.HisPrescriptionInfo{
  1014. HisPatientId: his_patient_id,
  1015. UserOrgId: adminInfo.CurrentOrgId,
  1016. RecordDate: theTime.Unix(),
  1017. PatientId: patient_id,
  1018. Status: 1,
  1019. Ctime: time.Now().Unix(),
  1020. Mtime: time.Now().Unix(),
  1021. Creator: adminInfo.AdminUser.Id,
  1022. Modifier: adminInfo.AdminUser.Id,
  1023. Diagnosis: diagnose,
  1024. SickHistory: sick_history,
  1025. Departments: department,
  1026. RegisterType: reg_type,
  1027. PrescriptionNumber: p_number,
  1028. PrescriptionStatus: 1,
  1029. Doctor: role.UserName,
  1030. DoctorId: doctor_id,
  1031. SickType: sick_type,
  1032. PType: p_type,
  1033. }
  1034. service.SavePatientPrescriptionInfo(hpInfo)
  1035. redis := service.RedisClient()
  1036. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1037. redis.Set(key, "", time.Second)
  1038. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1039. redis.Set(keyOne, "", time.Second)
  1040. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1041. redis.Set(keySeven, "", time.Second)
  1042. defer redis.Close()
  1043. } else {
  1044. hpInfo = models.HisPrescriptionInfo{
  1045. ID: info.ID,
  1046. UserOrgId: adminInfo.CurrentOrgId,
  1047. RecordDate: info.RecordDate,
  1048. PatientId: info.PatientId,
  1049. Status: 1,
  1050. Ctime: info.Ctime,
  1051. Mtime: time.Now().Unix(),
  1052. Creator: info.Creator,
  1053. Modifier: adminInfo.AdminUser.Id,
  1054. Diagnosis: diagnose,
  1055. SickHistory: sick_history,
  1056. Departments: department,
  1057. RegisterType: reg_type,
  1058. PrescriptionNumber: info.PrescriptionNumber,
  1059. Doctor: role.UserName,
  1060. PrescriptionStatus: info.PrescriptionStatus,
  1061. DoctorId: doctor_id,
  1062. SickType: sick_type,
  1063. PType: info.PType,
  1064. HisPatientId: info.HisPatientId,
  1065. }
  1066. service.SavePatientPrescriptionInfo(hpInfo)
  1067. redis := service.RedisClient()
  1068. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1069. redis.Set(key, "", time.Second)
  1070. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1071. redis.Set(keyOne, "", time.Second)
  1072. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1073. redis.Set(keySeven, "", time.Second)
  1074. defer redis.Close()
  1075. }
  1076. //定义切片
  1077. var adviceList []models.HisDoctorAdviceInfo
  1078. var projectList []models.HisPrescriptionProject
  1079. //var hisLis []models.HisList
  1080. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1081. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1082. var tempPrescription *models.HisPrescription
  1083. if len(prescriptions) > 0 {
  1084. for _, item := range prescriptions {
  1085. items := item.(map[string]interface{})
  1086. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1087. utils.ErrorLog("id")
  1088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1089. return
  1090. }
  1091. id := int64(items["id"].(float64))
  1092. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1093. tempPrescription = &new_prescription
  1094. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1095. utils.ErrorLog("type")
  1096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1097. return
  1098. }
  1099. types := int64(items["type"].(float64))
  1100. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1101. utils.ErrorLog("med_type")
  1102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1103. return
  1104. }
  1105. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1106. if med_type == "0" {
  1107. med_type = "14"
  1108. }
  1109. //if order_status == 0 {
  1110. // order_status = 1
  1111. //}
  1112. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  1113. utils.ErrorLog("pre_time")
  1114. }
  1115. preTime, _ := items["pre_time"].(string)
  1116. timeLayout := "2006-01-02"
  1117. loc, _ := time.LoadLocation("Local")
  1118. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  1119. if err != nil {
  1120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1121. return
  1122. }
  1123. pTime := theTime2.Unix()
  1124. ctime := time.Now().Unix()
  1125. if tempPrescription.ID == 0 {
  1126. prescription := &models.HisPrescription{
  1127. ID: 0,
  1128. PatientId: patient_id,
  1129. UserOrgId: adminInfo.CurrentOrgId,
  1130. RecordDate: recordDateTime,
  1131. Ctime: ctime,
  1132. Mtime: ctime,
  1133. Type: types,
  1134. Modifier: adminInfo.AdminUser.Id,
  1135. Creator: adminInfo.AdminUser.Id,
  1136. Status: 1,
  1137. Doctor: role.UserName,
  1138. HisPatientId: his_patient_id,
  1139. OrderStatus: 1,
  1140. BatchNumber: "",
  1141. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1142. PreTime: pTime,
  1143. PType: p_type,
  1144. MedType: med_type,
  1145. }
  1146. tempPrescription = prescription
  1147. service.SaveHisPrescription(tempPrescription)
  1148. redis := service.RedisClient()
  1149. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1150. redis.Set(key, "", time.Second)
  1151. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1152. redis.Set(keyOne, "", time.Second)
  1153. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1154. redis.Set(keySeven, "", time.Second)
  1155. defer redis.Close()
  1156. } else {
  1157. tempPrescription.ID = id
  1158. tempPrescription.Type = types
  1159. tempPrescription.Modifier = adminInfo.AdminUser.Id
  1160. tempPrescription.Mtime = time.Now().Unix()
  1161. tempPrescription.Doctor = role.UserName
  1162. //tempPrescription.OrderStatus = order_status
  1163. tempPrescription.PreTime = pTime
  1164. tempPrescription.MedType = med_type
  1165. service.SaveHisPrescription(tempPrescription)
  1166. redis := service.RedisClient()
  1167. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1168. redis.Set(key, "", time.Second)
  1169. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1170. redis.Set(keyOne, "", time.Second)
  1171. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1172. redis.Set(keySeven, "", time.Second)
  1173. defer redis.Close()
  1174. }
  1175. //service.SaveHisPrescription(prescription)
  1176. //更改患者挂号状态
  1177. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1178. fmt.Println("更改失败", err2)
  1179. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1180. advices := items["advices"].([]interface{})
  1181. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1182. groupNo := int64(0)
  1183. ctime := time.Now().Unix()
  1184. mtime := ctime
  1185. if len(advices) > 0 {
  1186. for _, advice := range advices {
  1187. var s models.HisDoctorAdviceInfo
  1188. s.PrescriptionId = tempPrescription.ID
  1189. s.AdviceType = 2
  1190. s.AdviceDoctor = doctor_id
  1191. s.StopState = 2
  1192. s.ExecutionState = 2
  1193. s.AdviceDate = recordDateTime
  1194. s.Status = 1
  1195. s.UserOrgId = adminInfo.CurrentOrgId
  1196. s.RecordDate = recordDateTime
  1197. s.StartTime = tempPrescription.PreTime
  1198. s.Groupno = groupNo
  1199. s.CreatedTime = ctime
  1200. s.UpdatedTime = mtime
  1201. s.PatientId = patient_id
  1202. s.HisPatientId = his_patient_id
  1203. s.StartTime = pTime
  1204. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  1205. if errcode > 0 {
  1206. c.ServeFailJSONWithSGJErrorCode(errcode)
  1207. return
  1208. }
  1209. s.StartTime = pTime
  1210. service.CreateHisDoctorAdvice(&s)
  1211. //存储切片中
  1212. adviceList = append(adviceList, s)
  1213. redis := service.RedisClient()
  1214. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1215. redis.Set(key, "", time.Second)
  1216. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1217. redis.Set(keyOne, "", time.Second)
  1218. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1219. redis.Set(keySeven, "", time.Second)
  1220. var randNum int
  1221. randNum = rand.Intn(10000) + 1000
  1222. timestamp := time.Now().Unix()
  1223. tempTime := time.Unix(timestamp, 0)
  1224. timeFormat := tempTime.Format("20060102150405")
  1225. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  1226. service.CreateHisDoctorAdvice(&s)
  1227. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1228. redis.Set(keySix, "", time.Second)
  1229. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1230. redis.Set(keyFive, "", time.Second)
  1231. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1232. redis.Set(keyEight, "", time.Second)
  1233. defer redis.Close()
  1234. }
  1235. }
  1236. }
  1237. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1238. projects := items["project"].([]interface{})
  1239. if len(projects) > 0 {
  1240. for _, project := range projects {
  1241. var p models.HisPrescriptionProject
  1242. p.PrescriptionId = tempPrescription.ID
  1243. p.Ctime = time.Now().Unix()
  1244. p.Mtime = time.Now().Unix()
  1245. p.PatientId = patient_id
  1246. p.RecordDate = recordDateTime
  1247. p.Doctor = doctor_id
  1248. p.UserOrgId = adminInfo.CurrentOrgId
  1249. p.HisPatientId = his_patient_id
  1250. p.Status = 1
  1251. p.StartTime = pTime
  1252. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  1253. if errcode > 0 {
  1254. c.ServeFailJSONWithSGJErrorCode(errcode)
  1255. return
  1256. }
  1257. service.CreateHisProjectTwo(&p)
  1258. projectList = append(projectList, p)
  1259. var randNum int
  1260. randNum = rand.Intn(10000) + 1000
  1261. timestamp := time.Now().Unix()
  1262. tempTime := time.Unix(timestamp, 0)
  1263. timeFormat := tempTime.Format("20060102150405")
  1264. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  1265. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  1266. //新增或者编辑项目,修改对应的标签数据
  1267. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  1268. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  1269. var label models.HisLabelPrintInfo
  1270. project, _ := service.GetProjectDetail(p.ProjectId)
  1271. if project.CostClassify == 3 { //类别为检验检查
  1272. if p.TeamId > 0 { //检验检查组套
  1273. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  1274. if tempLabel.ID == 0 {
  1275. team, _ := service.GetProjectTeamDetail(p.TeamId)
  1276. label.Number = tempPrescription.PrescriptionNumber
  1277. label.ProjectId = project.ID
  1278. label.Status = 1
  1279. label.IsPrint = 2
  1280. label.DoctorId = info.DoctorId
  1281. label.UserOrgId = p.UserOrgId
  1282. label.PatientId = patient_id
  1283. label.RecordDate = recordDateTime
  1284. label.Ctime = time.Now().Unix()
  1285. label.Mtime = time.Now().Unix()
  1286. label.ItemId = p.TeamId
  1287. label.FeedetlSn = p.FeedetlSn
  1288. label.PProjectId = p.ID
  1289. label.ProjectName = team.ProjectTeam
  1290. label.PatientName = patient.Name
  1291. service.CreateHisLabelRecord(&label)
  1292. }
  1293. } else { //单条检验检查项目
  1294. label.Number = tempPrescription.PrescriptionNumber
  1295. label.ProjectId = project.ID
  1296. label.Status = 1
  1297. label.DoctorId = info.DoctorId
  1298. label.UserOrgId = p.UserOrgId
  1299. label.PatientId = patient_id
  1300. label.RecordDate = recordDateTime
  1301. label.IsPrint = 2
  1302. label.Ctime = time.Now().Unix()
  1303. label.Mtime = time.Now().Unix()
  1304. label.FeedetlSn = p.FeedetlSn
  1305. label.PProjectId = p.ID
  1306. label.ItemId = p.TeamId
  1307. label.ProjectName = project.ProjectName
  1308. label.PatientName = patient.Name
  1309. service.CreateHisLabelRecord(&label)
  1310. }
  1311. }
  1312. }
  1313. }
  1314. service.SaveHisProjectTwo(&p)
  1315. //if p.Type == 3 { //处理透前准备耗材数量数据
  1316. // consumables, _ := service.FindHisConsumablesByID(adminInfo.CurrentOrgId, patient_id, recordDateTime, p.ProjectId)
  1317. // if consumables.ID > 0 {
  1318. // cnt, _ := strconv.ParseInt(p.Count, 10, 64)
  1319. // consumables.Count = cnt
  1320. // service.UpdateConsumables(&consumables)
  1321. // }
  1322. //}
  1323. }
  1324. }
  1325. }
  1326. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1327. // addition := items["addition"].([]interface{})
  1328. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1329. // ctime := time.Now().Unix()
  1330. // mtime := ctime
  1331. // if len(addition) > 0 {
  1332. // for _, item := range addition {
  1333. // var s models.HisAdditionalCharge
  1334. // s.PrescriptionId = tempPrescription.ID
  1335. // s.Status = 1
  1336. // s.UserOrgId = adminInfo.CurrentOrgId
  1337. // s.RecordDate = recordDateTime
  1338. // s.CreatedTime = ctime
  1339. // s.UpdatedTime = mtime
  1340. // s.PatientId = patient_id
  1341. // s.HisPatientId = his_patient_id
  1342. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1343. // if errcode > 0 {
  1344. // c.ServeFailJSONWithSGJErrorCode(errcode)
  1345. // return
  1346. // }
  1347. // service.CreateAdditionalCharge(&s)
  1348. // var randNum int
  1349. // randNum = rand.Intn(10000) + 1000
  1350. // timestamp := time.Now().Unix()
  1351. // tempTime := time.Unix(timestamp, 0)
  1352. // timeFormat := tempTime.Format("20060102150405")
  1353. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  1354. // service.CreateAdditionalCharge(&s)
  1355. //
  1356. // }
  1357. // }
  1358. //}
  1359. }
  1360. }
  1361. }
  1362. //redisClient := service.RedisClient()
  1363. //defer redisClient.Close()
  1364. //
  1365. //list := models.HisList{
  1366. // Patient_id: patient_id,
  1367. // Advice_id:0,
  1368. // Record_date: 0,
  1369. // Advice: adviceList,
  1370. // Project: nil,
  1371. //}
  1372. //hisLis = append(hisLis, list)
  1373. //
  1374. //advice_json, _ := json.Marshal(&hisLis)
  1375. //redisClient.RPush("111", advice_json).Result()
  1376. //result, _ := redisClient.RPop("111").Result()
  1377. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  1378. //
  1379. //var dat []map[string]interface{}
  1380. //json.Unmarshal([]byte(result), &dat)
  1381. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  1382. //
  1383. //for k,v:=range dat{
  1384. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  1385. //}
  1386. //project_json, _ := json.Marshal(&projectList)
  1387. //redisClient.LPush("222", project_json).Result()
  1388. if err == nil {
  1389. c.ServeSuccessJSON(map[string]interface{}{
  1390. "msg": "保存成功",
  1391. })
  1392. return
  1393. } else {
  1394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1395. return
  1396. }
  1397. }
  1398. func (c *HisApiController) EditHisPrescription() {
  1399. record_date := c.GetString("record_date")
  1400. patient_id, _ := c.GetInt64("patient_id")
  1401. reg_type, _ := c.GetInt64("reg_type")
  1402. //diagnose, _ := c.GetInt64("diagnose", 0)
  1403. diagnose := c.GetString("diagnose")
  1404. sick_type, _ := c.GetInt64("sick_type")
  1405. sick_history := c.GetString("sick_history")
  1406. doctor_id, _ := c.GetInt64("doctor", 0)
  1407. department, _ := c.GetInt64("department", 0)
  1408. his_patient_id, _ := c.GetInt64("his_patient_id")
  1409. p_type, _ := c.GetInt64("p_type")
  1410. dataBody := make(map[string]interface{}, 0)
  1411. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1412. if err != nil {
  1413. utils.ErrorLog(err.Error())
  1414. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1415. return
  1416. }
  1417. timeLayout := "2006-01-02"
  1418. loc, _ := time.LoadLocation("Local")
  1419. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1420. if err != nil {
  1421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1422. return
  1423. }
  1424. adminInfo := c.GetAdminUserInfo()
  1425. recordDateTime := theTime.Unix()
  1426. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1427. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1428. var hpInfo models.HisPrescriptionInfo
  1429. if info.ID == 0 {
  1430. var randNum int
  1431. randNum = rand.Intn(10000) + 1000
  1432. timestamp := time.Now().Unix()
  1433. tempTime := time.Unix(timestamp, 0)
  1434. timeFormat := tempTime.Format("20060102150405")
  1435. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1436. hpInfo = models.HisPrescriptionInfo{
  1437. UserOrgId: adminInfo.CurrentOrgId,
  1438. RecordDate: theTime.Unix(),
  1439. PatientId: patient_id,
  1440. Status: 1,
  1441. Ctime: time.Now().Unix(),
  1442. Mtime: time.Now().Unix(),
  1443. Creator: adminInfo.AdminUser.Id,
  1444. Modifier: adminInfo.AdminUser.Id,
  1445. Diagnosis: diagnose,
  1446. SickHistory: sick_history,
  1447. Departments: department,
  1448. RegisterType: reg_type,
  1449. PrescriptionNumber: p_number,
  1450. PrescriptionStatus: 1,
  1451. Doctor: role.UserName,
  1452. DoctorId: doctor_id,
  1453. SickType: sick_type,
  1454. PType: p_type,
  1455. }
  1456. service.SavePatientPrescriptionInfo(hpInfo)
  1457. } else {
  1458. hpInfo = models.HisPrescriptionInfo{
  1459. ID: info.ID,
  1460. UserOrgId: adminInfo.CurrentOrgId,
  1461. RecordDate: info.RecordDate,
  1462. PatientId: info.PatientId,
  1463. Status: 1,
  1464. Ctime: info.Ctime,
  1465. Mtime: time.Now().Unix(),
  1466. Creator: info.Creator,
  1467. Modifier: adminInfo.AdminUser.Id,
  1468. Diagnosis: diagnose,
  1469. SickHistory: sick_history,
  1470. Departments: department,
  1471. RegisterType: reg_type,
  1472. PrescriptionNumber: info.PrescriptionNumber,
  1473. Doctor: role.UserName,
  1474. PrescriptionStatus: info.PrescriptionStatus,
  1475. DoctorId: doctor_id,
  1476. SickType: sick_type,
  1477. PType: info.PType,
  1478. }
  1479. service.SavePatientPrescriptionInfo(hpInfo)
  1480. }
  1481. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1482. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1483. if len(prescriptions) > 0 {
  1484. for _, item := range prescriptions {
  1485. items := item.(map[string]interface{})
  1486. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1487. utils.ErrorLog("id")
  1488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1489. return
  1490. }
  1491. id := int64(items["id"].(float64))
  1492. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1493. utils.ErrorLog("type")
  1494. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1495. return
  1496. }
  1497. types := int64(items["type"].(float64))
  1498. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1499. utils.ErrorLog("med_type")
  1500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1501. return
  1502. }
  1503. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1504. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  1505. ctime := time.Now().Unix()
  1506. prescription := &models.HisPrescription{
  1507. ID: id,
  1508. PatientId: patient_id,
  1509. UserOrgId: adminInfo.CurrentOrgId,
  1510. RecordDate: recordDateTime,
  1511. Ctime: ctime,
  1512. Mtime: ctime,
  1513. Type: types,
  1514. Modifier: adminInfo.AdminUser.Id,
  1515. Creator: adminInfo.AdminUser.Id,
  1516. Status: 1,
  1517. Doctor: role.UserName,
  1518. HisPatientId: his_patient_id,
  1519. OrderStatus: 1,
  1520. BatchNumber: "",
  1521. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1522. PType: hpInfo.PType,
  1523. MedType: med_type,
  1524. }
  1525. if historyPrescription.ID > 0 {
  1526. prescription.PreTime = historyPrescription.PreTime
  1527. }
  1528. service.SaveHisPrescription(prescription)
  1529. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1530. advices := items["advices"].([]interface{})
  1531. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1532. groupNo := int64(0)
  1533. ctime := time.Now().Unix()
  1534. mtime := ctime
  1535. if len(advices) > 0 {
  1536. for _, advice := range advices {
  1537. var s models.HisDoctorAdviceInfo
  1538. s.PrescriptionId = prescription.ID
  1539. s.AdviceType = 2
  1540. s.AdviceDoctor = adminInfo.AdminUser.Id
  1541. s.StopState = 2
  1542. s.ExecutionState = 2
  1543. s.AdviceDate = recordDateTime
  1544. s.Status = 1
  1545. s.UserOrgId = adminInfo.CurrentOrgId
  1546. s.RecordDate = recordDateTime
  1547. s.StartTime = prescription.PreTime
  1548. s.Groupno = groupNo
  1549. s.CreatedTime = ctime
  1550. s.UpdatedTime = mtime
  1551. s.PatientId = patient_id
  1552. s.HisPatientId = his_patient_id
  1553. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  1554. if errcode > 0 {
  1555. c.ServeFailJSONWithSGJErrorCode(errcode)
  1556. return
  1557. }
  1558. service.CreateHisDoctorAdvice(&s)
  1559. redis := service.RedisClient()
  1560. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1561. redis.Set(key, "", time.Second)
  1562. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1563. fmt.Println("keyOne", keyOne)
  1564. redis.Set(keyOne, "", time.Second)
  1565. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1566. redis.Set(keySeven, "", time.Second)
  1567. redis.Close()
  1568. }
  1569. }
  1570. }
  1571. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1572. projects := items["project"].([]interface{})
  1573. if len(projects) > 0 {
  1574. for _, project := range projects {
  1575. var p models.HisPrescriptionProject
  1576. p.PrescriptionId = prescription.ID
  1577. p.Ctime = time.Now().Unix()
  1578. p.Mtime = time.Now().Unix()
  1579. p.PatientId = patient_id
  1580. p.RecordDate = recordDateTime
  1581. p.UserOrgId = adminInfo.CurrentOrgId
  1582. p.HisPatientId = his_patient_id
  1583. p.Status = 1
  1584. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  1585. if errcode > 0 {
  1586. c.ServeFailJSONWithSGJErrorCode(errcode)
  1587. return
  1588. }
  1589. service.CreateHisProjectTwo(&p)
  1590. }
  1591. }
  1592. }
  1593. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1594. addition := items["addition"].([]interface{})
  1595. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1596. ctime := time.Now().Unix()
  1597. mtime := ctime
  1598. if len(addition) > 0 {
  1599. for _, item := range addition {
  1600. var s models.HisAdditionalCharge
  1601. s.PrescriptionId = prescription.ID
  1602. s.Status = 1
  1603. s.UserOrgId = adminInfo.CurrentOrgId
  1604. s.RecordDate = recordDateTime
  1605. s.CreatedTime = ctime
  1606. s.UpdatedTime = mtime
  1607. s.PatientId = patient_id
  1608. s.HisPatientId = his_patient_id
  1609. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1610. if errcode > 0 {
  1611. c.ServeFailJSONWithSGJErrorCode(errcode)
  1612. return
  1613. }
  1614. service.CreateAdditionalCharge(&s)
  1615. }
  1616. }
  1617. }
  1618. }
  1619. }
  1620. }
  1621. if err == nil {
  1622. c.ServeSuccessJSON(map[string]interface{}{
  1623. "msg": "保存成功",
  1624. })
  1625. return
  1626. } else {
  1627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1628. return
  1629. }
  1630. }
  1631. func (c *HisApiController) DeletePrescription() {
  1632. prescription_id, _ := c.GetInt64("id")
  1633. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  1634. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  1635. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1636. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1637. if len(projects) > 0 {
  1638. for _, item := range projects {
  1639. service.DeletePrintInfo(item.ID) //删除打印信息
  1640. if stockConfig.IsOpen == 1 {
  1641. if item.Type == 3 {
  1642. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  1643. f_count, _ := strconv.ParseFloat(item.Count, 64)
  1644. good.Total = good.Total + f_count
  1645. service.UpdateGoodInfo(&good)
  1646. operation_time := time.Now().Unix()
  1647. creater := c.GetAdminUserInfo().AdminUser.Id
  1648. //创建退库单
  1649. timeStr := time.Now().Format("2006-01-02")
  1650. timeArr := strings.Split(timeStr, "-")
  1651. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  1652. total = total + 1
  1653. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1654. cancelStock := models.CancelStock{
  1655. OrderNumber: orderNumber,
  1656. OperaTime: operation_time,
  1657. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1658. Creater: creater,
  1659. Ctime: time.Now().Unix(),
  1660. Status: 1,
  1661. ReturnTime: item.RecordDate,
  1662. Type: 1,
  1663. }
  1664. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  1665. if msgerrkonde == gorm.ErrRecordNotFound {
  1666. service.AddSigleCancelStock(&cancelStock)
  1667. }
  1668. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  1669. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  1670. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1671. //查询该耗材是否出库
  1672. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  1673. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  1674. deaerler, _ := service.GetDealerById(info.Dealer)
  1675. if info.ID > 0 {
  1676. cancelStockInfo := models.CancelStockInfo{
  1677. GoodId: item.ProjectId,
  1678. CancelStockId: cancel.ID,
  1679. GoodTypeId: good.GoodTypeId,
  1680. Count: prescribingNumber,
  1681. Price: info.Price,
  1682. Total: 0,
  1683. ProductDate: info.ProductDate,
  1684. ExpiryDate: info.ExpiryDate,
  1685. Ctime: time.Now().Unix(),
  1686. Status: 1,
  1687. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1688. OrderNumber: cancel.OrderNumber,
  1689. Type: 0,
  1690. Dealer: deaerler.DealerName,
  1691. Manufacturer: manufacturer.ManufacturerName,
  1692. Number: info.Number,
  1693. RegisterAccount: "",
  1694. Remark: "",
  1695. WarehouseInfoId: info.WarehouseInfotId,
  1696. PatientId: info.PatientId,
  1697. RecordDate: info.SysRecordTime,
  1698. }
  1699. service.CreateCancelStockInfoOne(&cancelStockInfo)
  1700. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  1701. flow := models.VmStockFlow{
  1702. WarehousingId: 0,
  1703. GoodId: item.ProjectId,
  1704. Number: info.Number,
  1705. LicenseNumber: info.LicenseNumber,
  1706. Count: prescribingNumber,
  1707. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1708. PatientId: item.PatientId,
  1709. SystemTime: info.SysRecordTime,
  1710. ConsumableType: 7,
  1711. IsSys: 0,
  1712. WarehousingOrder: "",
  1713. WarehouseOutId: 0,
  1714. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1715. IsEdit: 0,
  1716. CancelStockId: cancel.ID,
  1717. CancelOrderNumber: cancel.OrderNumber,
  1718. Manufacturer: manufacturer.ID,
  1719. Dealer: 0,
  1720. Creator: c.GetAdminUserInfo().CurrentOrgId,
  1721. UpdateCreator: 0,
  1722. Status: 1,
  1723. Ctime: time.Now().Unix(),
  1724. Mtime: 0,
  1725. Price: info.Price,
  1726. WarehousingDetailId: info.WarehouseInfotId,
  1727. WarehouseOutDetailId: 0,
  1728. CancelOutDetailId: cancelInfo.ID,
  1729. ProductDate: info.ProductDate,
  1730. ExpireDate: info.ExpiryDate,
  1731. }
  1732. service.CreateStockFlowOne(flow)
  1733. //删除出库表
  1734. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  1735. //查询今日该患者开了多少耗材
  1736. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1737. var total_count int64
  1738. var cha_count int64
  1739. for _, item := range projectList {
  1740. count, _ := strconv.ParseInt(item.Count, 10, 64)
  1741. total_count += count
  1742. }
  1743. //回退库存
  1744. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  1745. //查询今日该耗材退库数量
  1746. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1747. var cancel_Count int64
  1748. for _, items := range cancelInfoOne {
  1749. cancel_Count += items.Count
  1750. }
  1751. cha_count = total_count - cancel_Count
  1752. if total_count > cancel_Count {
  1753. out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  1754. if err == gorm.ErrRecordNotFound {
  1755. //没有记录,则创建出库单
  1756. timeStr := time.Now().Format("2006-01-02")
  1757. timeArr := strings.Split(timeStr, "-")
  1758. total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  1759. total = total + 1
  1760. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1761. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1762. number = number + total
  1763. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1764. warehouseOut := models.WarehouseOut{
  1765. WarehouseOutOrderNumber: warehousing_out_order,
  1766. OperationTime: time.Now().Unix(),
  1767. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1768. Creater: creater,
  1769. Ctime: time.Now().Unix(),
  1770. Status: 1,
  1771. WarehouseOutTime: info.SysRecordTime,
  1772. Dealer: 0,
  1773. Manufacturer: 0,
  1774. Type: 1,
  1775. IsSys: 1,
  1776. }
  1777. err := service.AddSigleWarehouseOut(&warehouseOut)
  1778. if err != nil {
  1779. utils.TraceLog("创建出库单失败 err = %v", err)
  1780. return
  1781. }
  1782. prepare := &models.DialysisBeforePrepare{
  1783. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1784. PatientId: info.PatientId,
  1785. RecordDate: info.SysRecordTime,
  1786. GoodId: item.ProjectId,
  1787. GoodTypeId: info.GoodTypeId,
  1788. Count: cha_count,
  1789. }
  1790. //出库
  1791. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  1792. } else if err == nil {
  1793. prepare := &models.DialysisBeforePrepare{
  1794. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1795. PatientId: info.PatientId,
  1796. RecordDate: info.SysRecordTime,
  1797. GoodId: item.ProjectId,
  1798. GoodTypeId: info.GoodTypeId,
  1799. Count: cha_count,
  1800. }
  1801. //出库
  1802. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  1803. }
  1804. }
  1805. }
  1806. }
  1807. }
  1808. }
  1809. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1810. fmt.Println(err)
  1811. }
  1812. if drugStockConfig.IsOpen == 1 {
  1813. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1814. fmt.Println(err)
  1815. if len(advices) > 0 {
  1816. for _, item := range advices {
  1817. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
  1818. redis := service.RedisClient()
  1819. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1820. redis.Set(keyFive, "", time.Second)
  1821. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1822. redis.Set(keyOne, "", time.Second)
  1823. redis.Close()
  1824. //查询该药品是否存在出库记录
  1825. info, errcode := service.GetDrugAutoWarehouseOutSeven(item.PatientId, item.AdviceDate, item.DrugId, item.ID)
  1826. if errcode == gorm.ErrRecordNotFound {
  1827. } else if errcode == nil {
  1828. if item.PrescribingNumberUnit == drug.MinUnit {
  1829. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1830. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1831. //退库
  1832. warehouseInfo := models.DrugWarehouseInfo{
  1833. StockMinNumber: prescribingNumber,
  1834. }
  1835. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  1836. adminUserInfo := c.GetAdminUserInfo()
  1837. operation_time := time.Now().Unix()
  1838. creater := adminUserInfo.AdminUser.Id
  1839. ctime := time.Now().Unix()
  1840. timeStr := time.Now().Format("2006-01-02")
  1841. timeArr := strings.Split(timeStr, "-")
  1842. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1843. total = total + 1
  1844. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1845. cancelStock := models.DrugCancelStock{
  1846. OrderNumber: orderNumber,
  1847. OperaTime: operation_time,
  1848. OrgId: adminUserInfo.CurrentOrgId,
  1849. Creater: creater,
  1850. Ctime: ctime,
  1851. Status: 1,
  1852. ReturnTime: item.AdviceDate,
  1853. Dealer: info.Dealer,
  1854. Manufacturer: info.Manufacturer,
  1855. Type: 1,
  1856. }
  1857. service.AddSigleDrugCancelStock(&cancelStock)
  1858. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1859. dealer, _ := service.GetDealerById(info.Dealer)
  1860. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1861. cancelStockInfo := models.DrugCancelStockInfo{
  1862. OrderNumber: cancelInfo.OrderNumber,
  1863. CancelStockId: cancelInfo.ID,
  1864. DrugId: info.DrugId,
  1865. Count: prescribingNumber,
  1866. Status: 1,
  1867. Ctime: ctime,
  1868. OrgId: adminUserInfo.CurrentOrgId,
  1869. Type: 1,
  1870. Manufacturer: manufactureName.ManufacturerName,
  1871. Dealer: dealer.DealerName,
  1872. Total: 0,
  1873. RetailPrice: info.RetailPrice,
  1874. RetailTotalPrice: info.RetailTotalPrice,
  1875. Price: info.Price,
  1876. RegisterAccount: "",
  1877. Remark: info.Remark,
  1878. BatchNumber: info.BatchNumber,
  1879. MaxUnit: info.CountUnit,
  1880. ProductDate: info.ProductDate,
  1881. ExpiryDate: info.ExpiryDate,
  1882. BatchNumberId: info.WarehouseInfoId,
  1883. }
  1884. flow := models.DrugFlow{
  1885. WarehousingId: 0,
  1886. DrugId: info.DrugId,
  1887. Number: "",
  1888. BatchNumber: info.BatchNumber,
  1889. Count: prescribingNumber,
  1890. UserOrgId: adminUserInfo.CurrentOrgId,
  1891. PatientId: 0,
  1892. SystemTime: info.SysRecordTime,
  1893. ConsumableType: 7,
  1894. IsSys: 0,
  1895. WarehousingOrder: "",
  1896. WarehouseOutId: 0,
  1897. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1898. IsEdit: 0,
  1899. CancelStockId: cancelStock.ID,
  1900. CancelOrderNumber: cancelStock.OrderNumber,
  1901. Manufacturer: info.Manufacturer,
  1902. Dealer: info.Dealer,
  1903. Creator: adminUserInfo.AdminUser.Id,
  1904. UpdateCreator: 0,
  1905. Status: 1,
  1906. Ctime: time.Now().Unix(),
  1907. Mtime: 0,
  1908. Price: info.Price,
  1909. WarehousingDetailId: 0,
  1910. WarehouseOutDetailId: 0,
  1911. CancelOutDetailId: 0,
  1912. ExpireDate: info.ExpiryDate,
  1913. ProductDate: info.ProductDate,
  1914. MaxUnit: info.CountUnit,
  1915. MinUnit: "",
  1916. AdviceId: info.AdviceId,
  1917. }
  1918. service.CreatedCancelStock(cancelStockInfo)
  1919. service.CreateDrugFlowOne(flow)
  1920. //删除出库记录
  1921. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  1922. //删除流水
  1923. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  1924. } else {
  1925. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1926. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1927. if item.PrescribingNumberUnit == drug.MaxUnit {
  1928. warehouseInfo := models.DrugWarehouseInfo{
  1929. StockMaxNumber: prescribingNumber,
  1930. }
  1931. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  1932. }
  1933. adminUserInfo := c.GetAdminUserInfo()
  1934. operation_time := time.Now().Unix()
  1935. creater := adminUserInfo.AdminUser.Id
  1936. ctime := time.Now().Unix()
  1937. timeStr := time.Now().Format("2006-01-02")
  1938. timeArr := strings.Split(timeStr, "-")
  1939. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1940. total = total + 1
  1941. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1942. cancelStock := models.DrugCancelStock{
  1943. OrderNumber: orderNumber,
  1944. OperaTime: operation_time,
  1945. OrgId: adminUserInfo.CurrentOrgId,
  1946. Creater: creater,
  1947. Ctime: ctime,
  1948. Status: 1,
  1949. ReturnTime: item.AdviceDate,
  1950. Dealer: info.Dealer,
  1951. Manufacturer: info.Manufacturer,
  1952. Type: 1,
  1953. }
  1954. service.AddSigleDrugCancelStock(&cancelStock)
  1955. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1956. dealer, _ := service.GetDealerById(info.Dealer)
  1957. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1958. cancelStockInfo := models.DrugCancelStockInfo{
  1959. OrderNumber: cancelInfo.OrderNumber,
  1960. CancelStockId: cancelInfo.ID,
  1961. DrugId: info.DrugId,
  1962. // Count: info.Count,
  1963. Count: prescribingNumber,
  1964. Status: 1,
  1965. Ctime: ctime,
  1966. OrgId: adminUserInfo.CurrentOrgId,
  1967. Type: 1,
  1968. Manufacturer: manufactureName.ManufacturerName,
  1969. Dealer: dealer.DealerName,
  1970. Total: 0,
  1971. RetailPrice: info.RetailPrice,
  1972. RetailTotalPrice: info.RetailTotalPrice,
  1973. Price: info.Price,
  1974. RegisterAccount: "",
  1975. Remark: info.Remark,
  1976. BatchNumber: info.BatchNumber,
  1977. MaxUnit: info.CountUnit,
  1978. ProductDate: info.ProductDate,
  1979. ExpiryDate: info.ExpiryDate,
  1980. BatchNumberId: info.WarehouseInfoId,
  1981. }
  1982. flow := models.DrugFlow{
  1983. WarehousingId: 0,
  1984. DrugId: info.DrugId,
  1985. Number: "",
  1986. BatchNumber: info.BatchNumber,
  1987. //Count: info.Count,
  1988. Count: prescribingNumber,
  1989. UserOrgId: adminUserInfo.CurrentOrgId,
  1990. PatientId: 0,
  1991. SystemTime: info.SysRecordTime,
  1992. ConsumableType: 7,
  1993. IsSys: 0,
  1994. WarehousingOrder: "",
  1995. WarehouseOutId: 0,
  1996. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1997. IsEdit: 0,
  1998. CancelStockId: cancelStock.ID,
  1999. CancelOrderNumber: cancelStock.OrderNumber,
  2000. Manufacturer: info.Manufacturer,
  2001. Dealer: info.Dealer,
  2002. Creator: adminUserInfo.AdminUser.Id,
  2003. UpdateCreator: 0,
  2004. Status: 1,
  2005. Ctime: time.Now().Unix(),
  2006. Mtime: 0,
  2007. Price: info.Price,
  2008. WarehousingDetailId: 0,
  2009. WarehouseOutDetailId: 0,
  2010. CancelOutDetailId: 0,
  2011. ExpireDate: info.ExpiryDate,
  2012. ProductDate: info.ProductDate,
  2013. MaxUnit: info.CountUnit,
  2014. MinUnit: "",
  2015. AdviceId: info.AdviceId,
  2016. }
  2017. service.CreatedCancelStock(cancelStockInfo)
  2018. service.CreateDrugFlowOne(flow)
  2019. //删除出库记录
  2020. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  2021. //删除流水
  2022. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  2023. }
  2024. }
  2025. if item.PrescribingNumberUnit == drug.MinUnit {
  2026. drug.Total = drug.Total + item.PrescribingNumber
  2027. service.UpdateBaseDrugLib(&drug)
  2028. } else {
  2029. if item.PrescribingNumberUnit == drug.MaxUnit {
  2030. item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
  2031. drug.Total = drug.Total + item.PrescribingNumber
  2032. service.UpdateBaseDrugLib(&drug)
  2033. }
  2034. }
  2035. }
  2036. }
  2037. }
  2038. c.ServeSuccessJSON(map[string]interface{}{
  2039. "msg": "删除成功",
  2040. })
  2041. return
  2042. }
  2043. func (c *HisApiController) DeleteDoctorAdvice() {
  2044. id, _ := c.GetInt64("id")
  2045. advice, _ := service.GetHisDoctorAdvicesById(id)
  2046. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2047. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  2048. redis := service.RedisClient()
  2049. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2050. redis.Set(keyFive, "", time.Second)
  2051. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2052. redis.Set(keyOne, "", time.Second)
  2053. defer redis.Close()
  2054. if err == nil {
  2055. if drugStockConfig.IsOpen == 1 {
  2056. //判断该医嘱是否执行了
  2057. if advice.ExecutionState == 1 {
  2058. //查询该病人该药品是否有库存记录
  2059. info, errcode := service.GetDrugAutoWarehouseOutSeven(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  2060. if errcode == gorm.ErrRecordNotFound {
  2061. } else {
  2062. //退库
  2063. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
  2064. if advice.PrescribingNumberUnit == drug.MinUnit {
  2065. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  2066. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2067. //退库
  2068. warehouseInfo := models.DrugWarehouseInfo{
  2069. StockMinNumber: prescribingNumber,
  2070. }
  2071. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  2072. adminUserInfo := c.GetAdminUserInfo()
  2073. operation_time := time.Now().Unix()
  2074. creater := adminUserInfo.AdminUser.Id
  2075. ctime := time.Now().Unix()
  2076. timeStr := time.Now().Format("2006-01-02")
  2077. timeArr := strings.Split(timeStr, "-")
  2078. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2079. total = total + 1
  2080. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2081. cancelStock := models.DrugCancelStock{
  2082. OrderNumber: orderNumber,
  2083. OperaTime: operation_time,
  2084. OrgId: adminUserInfo.CurrentOrgId,
  2085. Creater: creater,
  2086. Ctime: ctime,
  2087. Status: 1,
  2088. ReturnTime: advice.AdviceDate,
  2089. Dealer: info.Dealer,
  2090. Manufacturer: info.Manufacturer,
  2091. Type: 1,
  2092. }
  2093. service.AddSigleDrugCancelStock(&cancelStock)
  2094. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2095. dealer, _ := service.GetDealerById(info.Dealer)
  2096. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2097. cancelStockInfo := models.DrugCancelStockInfo{
  2098. OrderNumber: cancelInfo.OrderNumber,
  2099. CancelStockId: cancelInfo.ID,
  2100. DrugId: info.DrugId,
  2101. Count: info.Count,
  2102. Status: 1,
  2103. Ctime: ctime,
  2104. OrgId: adminUserInfo.CurrentOrgId,
  2105. Type: 1,
  2106. Manufacturer: manufactureName.ManufacturerName,
  2107. Dealer: dealer.DealerName,
  2108. Total: 0,
  2109. RetailPrice: info.RetailPrice,
  2110. RetailTotalPrice: info.RetailTotalPrice,
  2111. Price: info.Price,
  2112. RegisterAccount: "",
  2113. Remark: info.Remark,
  2114. BatchNumber: info.BatchNumber,
  2115. MaxUnit: info.CountUnit,
  2116. ProductDate: info.ProductDate,
  2117. ExpiryDate: info.ExpiryDate,
  2118. BatchNumberId: info.WarehouseInfoId,
  2119. }
  2120. flow := models.DrugFlow{
  2121. WarehousingId: 0,
  2122. DrugId: info.DrugId,
  2123. Number: "",
  2124. BatchNumber: info.BatchNumber,
  2125. Count: info.Count,
  2126. UserOrgId: adminUserInfo.CurrentOrgId,
  2127. PatientId: 0,
  2128. SystemTime: info.SysRecordTime,
  2129. ConsumableType: 7,
  2130. IsSys: 0,
  2131. WarehousingOrder: "",
  2132. WarehouseOutId: 0,
  2133. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2134. IsEdit: 0,
  2135. CancelStockId: cancelStock.ID,
  2136. CancelOrderNumber: cancelStock.OrderNumber,
  2137. Manufacturer: info.Manufacturer,
  2138. Dealer: info.Dealer,
  2139. Creator: adminUserInfo.AdminUser.Id,
  2140. UpdateCreator: 0,
  2141. Status: 1,
  2142. Ctime: time.Now().Unix(),
  2143. Mtime: 0,
  2144. Price: info.Price,
  2145. WarehousingDetailId: 0,
  2146. WarehouseOutDetailId: 0,
  2147. CancelOutDetailId: 0,
  2148. ExpireDate: info.ExpiryDate,
  2149. ProductDate: info.ProductDate,
  2150. MaxUnit: info.CountUnit,
  2151. MinUnit: "",
  2152. AdviceId: info.AdviceId,
  2153. }
  2154. service.CreatedCancelStock(cancelStockInfo)
  2155. service.CreateDrugFlowOne(flow)
  2156. //删除出库记录
  2157. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2158. //删除流水
  2159. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2160. } else {
  2161. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  2162. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2163. if advice.PrescribingNumberUnit == drug.MaxUnit {
  2164. warehouseInfo := models.DrugWarehouseInfo{
  2165. StockMaxNumber: prescribingNumber,
  2166. }
  2167. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  2168. }
  2169. adminUserInfo := c.GetAdminUserInfo()
  2170. operation_time := time.Now().Unix()
  2171. creater := adminUserInfo.AdminUser.Id
  2172. ctime := time.Now().Unix()
  2173. timeStr := time.Now().Format("2006-01-02")
  2174. timeArr := strings.Split(timeStr, "-")
  2175. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  2176. total = total + 1
  2177. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2178. cancelStock := models.DrugCancelStock{
  2179. OrderNumber: orderNumber,
  2180. OperaTime: operation_time,
  2181. OrgId: adminUserInfo.CurrentOrgId,
  2182. Creater: creater,
  2183. Ctime: ctime,
  2184. Status: 1,
  2185. ReturnTime: advice.AdviceDate,
  2186. Dealer: info.Dealer,
  2187. Manufacturer: info.Manufacturer,
  2188. Type: 1,
  2189. }
  2190. service.AddSigleDrugCancelStock(&cancelStock)
  2191. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2192. dealer, _ := service.GetDealerById(info.Dealer)
  2193. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2194. cancelStockInfo := models.DrugCancelStockInfo{
  2195. OrderNumber: cancelInfo.OrderNumber,
  2196. CancelStockId: cancelInfo.ID,
  2197. DrugId: info.DrugId,
  2198. Count: info.Count,
  2199. Status: 1,
  2200. Ctime: ctime,
  2201. OrgId: adminUserInfo.CurrentOrgId,
  2202. Type: 1,
  2203. Manufacturer: manufactureName.ManufacturerName,
  2204. Dealer: dealer.DealerName,
  2205. Total: 0,
  2206. RetailPrice: info.RetailPrice,
  2207. RetailTotalPrice: info.RetailTotalPrice,
  2208. Price: info.Price,
  2209. RegisterAccount: "",
  2210. Remark: info.Remark,
  2211. BatchNumber: info.BatchNumber,
  2212. MaxUnit: info.CountUnit,
  2213. ProductDate: info.ProductDate,
  2214. ExpiryDate: info.ExpiryDate,
  2215. BatchNumberId: info.WarehouseInfoId,
  2216. }
  2217. flow := models.DrugFlow{
  2218. WarehousingId: 0,
  2219. DrugId: info.DrugId,
  2220. Number: "",
  2221. BatchNumber: info.BatchNumber,
  2222. Count: info.Count,
  2223. UserOrgId: adminUserInfo.CurrentOrgId,
  2224. PatientId: 0,
  2225. SystemTime: info.SysRecordTime,
  2226. ConsumableType: 7,
  2227. IsSys: 0,
  2228. WarehousingOrder: "",
  2229. WarehouseOutId: 0,
  2230. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2231. IsEdit: 0,
  2232. CancelStockId: cancelStock.ID,
  2233. CancelOrderNumber: cancelStock.OrderNumber,
  2234. Manufacturer: info.Manufacturer,
  2235. Dealer: info.Dealer,
  2236. Creator: adminUserInfo.AdminUser.Id,
  2237. UpdateCreator: 0,
  2238. Status: 1,
  2239. Ctime: time.Now().Unix(),
  2240. Mtime: 0,
  2241. Price: info.Price,
  2242. WarehousingDetailId: 0,
  2243. WarehouseOutDetailId: 0,
  2244. CancelOutDetailId: 0,
  2245. ExpireDate: info.ExpiryDate,
  2246. ProductDate: info.ProductDate,
  2247. MaxUnit: info.CountUnit,
  2248. MinUnit: "",
  2249. AdviceId: info.AdviceId,
  2250. }
  2251. service.CreatedCancelStock(cancelStockInfo)
  2252. service.CreateDrugFlowOne(flow)
  2253. //删除出库记录
  2254. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2255. //删除流水
  2256. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2257. }
  2258. }
  2259. }
  2260. }
  2261. c.ServeSuccessJSON(map[string]interface{}{
  2262. "msg": "删除成功",
  2263. })
  2264. return
  2265. } else {
  2266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2267. return
  2268. }
  2269. }
  2270. func (c *HisApiController) DeleteProject() {
  2271. id, _ := c.GetInt64("id")
  2272. adminInfo := c.GetAdminUserInfo()
  2273. project, _ := service.GetHisProjectByID(id)
  2274. // var consumable models.DialysisBeforePrepare
  2275. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2276. service.DeletePrintInfo(id)
  2277. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  2278. label.Status = 0
  2279. service.CreateHisLabelRecord(&label)
  2280. if stockConfig.IsOpen == 1 {
  2281. if project.Type == 2 {
  2282. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2283. fmt.Println(err)
  2284. }
  2285. if project.Type == 3 {
  2286. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2287. f_count, _ := strconv.ParseFloat(project.Count, 64)
  2288. good.Total = good.Total + f_count
  2289. service.UpdateGoodInfo(&good)
  2290. operation_time := time.Now().Unix()
  2291. creater := adminInfo.AdminUser.Id
  2292. //创建退库单
  2293. timeStr := time.Now().Format("2006-01-02")
  2294. timeArr := strings.Split(timeStr, "-")
  2295. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  2296. total = total + 1
  2297. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2298. cancelStock := models.CancelStock{
  2299. OrderNumber: orderNumber,
  2300. OperaTime: operation_time,
  2301. OrgId: adminInfo.CurrentOrgId,
  2302. Creater: creater,
  2303. Ctime: time.Now().Unix(),
  2304. Status: 1,
  2305. ReturnTime: project.RecordDate,
  2306. Type: 1,
  2307. }
  2308. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  2309. if msgerrkonde == gorm.ErrRecordNotFound {
  2310. service.AddSigleCancelStock(&cancelStock)
  2311. }
  2312. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  2313. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2314. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2315. //获取该耗材有库存的第一条数据
  2316. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  2317. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2318. deaerler, _ := service.GetDealerById(info.Dealer)
  2319. if info.ID > 0 {
  2320. cancelStockInfo := models.CancelStockInfo{
  2321. GoodId: project.ProjectId,
  2322. CancelStockId: cancel.ID,
  2323. GoodTypeId: good.GoodTypeId,
  2324. Count: prescribingNumber,
  2325. Price: info.Price,
  2326. Total: 0,
  2327. ProductDate: info.ProductDate,
  2328. ExpiryDate: info.ExpiryDate,
  2329. Ctime: time.Now().Unix(),
  2330. Status: 1,
  2331. OrgId: adminInfo.CurrentOrgId,
  2332. OrderNumber: cancel.OrderNumber,
  2333. Type: 0,
  2334. Dealer: deaerler.DealerName,
  2335. Manufacturer: manufacturer.ManufacturerName,
  2336. Number: info.Number,
  2337. RegisterAccount: "",
  2338. Remark: "",
  2339. WarehouseInfoId: info.WarehouseInfotId,
  2340. PatientId: info.PatientId,
  2341. RecordDate: info.SysRecordTime,
  2342. }
  2343. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2344. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  2345. flow := models.VmStockFlow{
  2346. WarehousingId: 0,
  2347. GoodId: project.ProjectId,
  2348. Number: info.Number,
  2349. LicenseNumber: info.LicenseNumber,
  2350. Count: prescribingNumber,
  2351. UserOrgId: adminInfo.CurrentOrgId,
  2352. PatientId: project.PatientId,
  2353. SystemTime: time.Now().Unix(),
  2354. ConsumableType: 7,
  2355. IsSys: 0,
  2356. WarehousingOrder: "",
  2357. WarehouseOutId: 0,
  2358. WarehouseOutOrderNumber: "",
  2359. IsEdit: 0,
  2360. CancelStockId: cancel.ID,
  2361. CancelOrderNumber: cancel.OrderNumber,
  2362. Manufacturer: manufacturer.ID,
  2363. Dealer: 0,
  2364. Creator: adminInfo.AdminUser.Id,
  2365. UpdateCreator: 0,
  2366. Status: 1,
  2367. Ctime: time.Now().Unix(),
  2368. Mtime: 0,
  2369. Price: info.Price,
  2370. WarehousingDetailId: info.WarehouseInfotId,
  2371. WarehouseOutDetailId: 0,
  2372. CancelOutDetailId: cancelInfo.ID,
  2373. ProductDate: info.ProductDate,
  2374. ExpireDate: info.ExpiryDate,
  2375. }
  2376. service.CreateStockFlowOne(flow)
  2377. //删除出库表
  2378. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  2379. //查询今日该患者开了多少耗材
  2380. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2381. var total_count int64
  2382. var cha_count int64
  2383. for _, item := range projectList {
  2384. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2385. total_count += count
  2386. }
  2387. //回退库存
  2388. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  2389. //查询今日该耗材退库数量
  2390. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2391. var cancel_count int64
  2392. for _, items := range cancelInfoOne {
  2393. cancel_count += items.Count
  2394. }
  2395. cha_count = total_count - cancel_count
  2396. if total_count > cancel_count {
  2397. out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  2398. if err == gorm.ErrRecordNotFound {
  2399. //没有记录,则创建出库单
  2400. timeStr := time.Now().Format("2006-01-02")
  2401. timeArr := strings.Split(timeStr, "-")
  2402. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2403. total = total + 1
  2404. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2405. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2406. number = number + total
  2407. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2408. warehouseOut := models.WarehouseOut{
  2409. WarehouseOutOrderNumber: warehousing_out_order,
  2410. OperationTime: time.Now().Unix(),
  2411. OrgId: adminInfo.CurrentOrgId,
  2412. Creater: creater,
  2413. Ctime: time.Now().Unix(),
  2414. Status: 1,
  2415. WarehouseOutTime: info.SysRecordTime,
  2416. Dealer: 0,
  2417. Manufacturer: 0,
  2418. Type: 1,
  2419. IsSys: 1,
  2420. }
  2421. err := service.AddSigleWarehouseOut(&warehouseOut)
  2422. if err != nil {
  2423. utils.TraceLog("创建出库单失败 err = %v", err)
  2424. return
  2425. }
  2426. prepare := &models.DialysisBeforePrepare{
  2427. UserOrgId: adminInfo.CurrentOrgId,
  2428. PatientId: info.PatientId,
  2429. RecordDate: info.SysRecordTime,
  2430. GoodId: project.ProjectId,
  2431. GoodTypeId: info.GoodTypeId,
  2432. Count: cha_count,
  2433. }
  2434. //出库
  2435. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2436. } else if err == nil {
  2437. prepare := &models.DialysisBeforePrepare{
  2438. UserOrgId: adminInfo.CurrentOrgId,
  2439. PatientId: info.PatientId,
  2440. RecordDate: info.SysRecordTime,
  2441. GoodId: project.ProjectId,
  2442. GoodTypeId: info.GoodTypeId,
  2443. Count: cha_count,
  2444. }
  2445. //出库
  2446. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2447. }
  2448. }
  2449. }
  2450. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2451. fmt.Println(err)
  2452. }
  2453. }
  2454. c.ServeSuccessJSON(map[string]interface{}{
  2455. "msg": "删除成功",
  2456. })
  2457. return
  2458. }
  2459. func (c *HisApiController) CreateHisAdditionalCharge() {
  2460. his_patient_id, _ := c.GetInt64("his_patient_id")
  2461. patient_id, _ := c.GetInt64("patient_id")
  2462. record_date := c.GetString("record_date")
  2463. timeLayout := "2006-01-02"
  2464. loc, _ := time.LoadLocation("Local")
  2465. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2466. if err != nil {
  2467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2468. return
  2469. }
  2470. adminInfo := c.GetAdminUserInfo()
  2471. recordDateTime := theTime.Unix()
  2472. dataBody := make(map[string]interface{}, 0)
  2473. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2474. if err != nil {
  2475. utils.ErrorLog(err.Error())
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2477. return
  2478. }
  2479. var additions []*models.HisAdditionalCharge
  2480. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  2481. additions, _ := dataBody["addition"].([]interface{})
  2482. if len(additions) > 0 {
  2483. for _, item := range additions {
  2484. items := item.(map[string]interface{})
  2485. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  2486. utils.ErrorLog("item_id")
  2487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2488. return
  2489. }
  2490. item_id := int64(items["item_id"].(float64))
  2491. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  2492. utils.ErrorLog("item_name")
  2493. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2494. return
  2495. }
  2496. item_name := items["item_name"].(string)
  2497. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2498. utils.ErrorLog("price")
  2499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2500. return
  2501. }
  2502. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2503. ctime := time.Now().Unix()
  2504. additional := &models.HisAdditionalCharge{
  2505. PatientId: patient_id,
  2506. HisPatientId: his_patient_id,
  2507. UserOrgId: adminInfo.CurrentOrgId,
  2508. RecordDate: recordDateTime,
  2509. CreatedTime: ctime,
  2510. UpdatedTime: ctime,
  2511. Modifier: adminInfo.AdminUser.Id,
  2512. Creator: adminInfo.AdminUser.Id,
  2513. Price: price,
  2514. ItemName: item_name,
  2515. ItemId: item_id,
  2516. Status: 1,
  2517. }
  2518. additions = append(additions, additional)
  2519. }
  2520. }
  2521. }
  2522. for _, item := range additions {
  2523. service.CreateAddtionalCharge(item)
  2524. }
  2525. c.ServeSuccessJSON(map[string]interface{}{
  2526. "msg": "创建成功",
  2527. })
  2528. }
  2529. func (c *HisApiController) CreateHisPatientCaseHistory() {
  2530. blood_fat := c.GetString("blood_fat")
  2531. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  2532. blood_sugar := c.GetString("blood_sugar")
  2533. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  2534. chief_conplaint := c.GetString("chief_conplaint")
  2535. dbp := c.GetString("dbp")
  2536. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  2537. delivery_way, _ := c.GetInt64("delivery_way")
  2538. diagnostic := c.GetString("diagnostic")
  2539. family_history := c.GetString("family_history")
  2540. height := c.GetString("height")
  2541. history_of_present_illness := c.GetString("history_of_present_illness")
  2542. is_infect, _ := c.GetInt64("is_infect")
  2543. past_history := c.GetString("past_history")
  2544. patient_id, _ := c.GetInt64("patient_id")
  2545. his_patient_id, _ := c.GetInt64("his_patient_id")
  2546. personal_history := c.GetString("personal_history")
  2547. pulse := c.GetString("pulse")
  2548. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  2549. sbp := c.GetString("sbp")
  2550. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  2551. heightfloat, _ := strconv.ParseFloat(height, 64)
  2552. sicktype := c.GetString("sick_type")
  2553. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  2554. symptom := c.GetString("symptom")
  2555. sick_date := c.GetString("sick_date")
  2556. temperatures := c.GetString("temperature")
  2557. temperature, _ := strconv.ParseFloat(temperatures, 64)
  2558. record_date := c.GetString("record_date")
  2559. breathing := c.GetString("breathing")
  2560. doctor_advice := c.GetString("doctor_advice")
  2561. remark := c.GetString("remark")
  2562. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  2563. sick, _ := c.GetInt64("sick")
  2564. diagnose, _ := c.GetInt64("diagnose")
  2565. id, _ := c.GetInt64("id")
  2566. timeLayout := "2006-01-02"
  2567. loc, _ := time.LoadLocation("Local")
  2568. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2569. allergic_history := c.GetString("allergic_history")
  2570. if err != nil {
  2571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2572. return
  2573. }
  2574. recordDateTime := theTime.Unix()
  2575. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  2576. if err != nil {
  2577. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2578. return
  2579. }
  2580. sickTimes := sickTime.Unix()
  2581. ctime := time.Now().Unix()
  2582. caseHistory := models.HisPatientCaseHistory{
  2583. HisPatientId: his_patient_id,
  2584. PatientId: patient_id,
  2585. Temperature: temperature,
  2586. BloodSugar: bloodsugarfloat,
  2587. Pulse: pulsefloat,
  2588. Sbp: sbpfloat,
  2589. Dbp: dbpfloat,
  2590. Height: heightfloat,
  2591. BloodFat: bloodfatfloat,
  2592. SickType: sick_type,
  2593. Symptom: symptom,
  2594. SickDate: sickTimes,
  2595. IsInfect: is_infect,
  2596. HistoryOfPresentIllness: history_of_present_illness,
  2597. PastHistory: past_history,
  2598. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  2599. ChiefConplaint: chief_conplaint,
  2600. PersonalHistory: personal_history,
  2601. FamilyHistory: family_history,
  2602. Diagnostic: diagnostic,
  2603. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2604. Status: 1,
  2605. Ctime: ctime,
  2606. Mtime: ctime,
  2607. RecordDate: recordDateTime,
  2608. DeliveryWay: delivery_way,
  2609. Breathing: breathingfloat,
  2610. DoctorAdvice: doctor_advice,
  2611. Remark: remark,
  2612. Sick: sick,
  2613. Diagnose: diagnose,
  2614. AllergicHistory: allergic_history,
  2615. }
  2616. //查询该患者是否有病历
  2617. _, errcodes := service.GetHisPatientCaseHistoryById(id)
  2618. if errcodes == gorm.ErrRecordNotFound {
  2619. err = service.SaveHisPatientCaseHistory(&caseHistory)
  2620. if err != nil {
  2621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2622. return
  2623. }
  2624. c.ServeSuccessJSON(map[string]interface{}{
  2625. "caseHistory": caseHistory,
  2626. })
  2627. return
  2628. } else if errcodes == nil {
  2629. err := service.UpdatePatientCaseHistory(id, &caseHistory)
  2630. if err != nil {
  2631. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2632. return
  2633. }
  2634. c.ServeSuccessJSON(map[string]interface{}{
  2635. "caseHistory": caseHistory,
  2636. })
  2637. }
  2638. //查询该患者是否有病历
  2639. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  2640. //if errcode == gorm.ErrRecordNotFound {
  2641. // err = service.SaveHisPatientCaseHistory(caseHistory)
  2642. // if err != nil {
  2643. // c.ServeSuccessJSON(map[string]interface{}{
  2644. // "msg": "保存成功",
  2645. // })
  2646. // }
  2647. //} else if errcode == nil {
  2648. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2649. // return
  2650. //}
  2651. }
  2652. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  2653. patient_id, _ := c.GetInt64("patient_id", 0)
  2654. adminUser := c.GetAdminUserInfo()
  2655. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  2656. c.ServeSuccessJSON(map[string]interface{}{
  2657. "list": caseHistorys,
  2658. })
  2659. }
  2660. func (c *HisApiController) GetHisPatientCaseHistory() {
  2661. record_date, _ := c.GetInt64("record_date", 0)
  2662. patient_id, _ := c.GetInt64("patient_id", 0)
  2663. admin := c.GetAdminUserInfo()
  2664. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  2665. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  2666. c.ServeSuccessJSON(map[string]interface{}{
  2667. "info": info,
  2668. "case_history": case_history,
  2669. })
  2670. }
  2671. func (c *HisApiController) CreateCaseHistoryTemplate() {
  2672. template_name := c.GetString("template_name")
  2673. template_remark := c.GetString("template_remark")
  2674. doctor := c.GetAdminUserInfo().AdminUser.Id
  2675. diagnostic := c.GetString("diagnostic")
  2676. chief_conplaint := c.GetString("chief_conplain")
  2677. history_of_present_illness := c.GetString("history_of_present_illness")
  2678. past_history := c.GetString("past_history")
  2679. personal_history := c.GetString("personal_history")
  2680. family_history := c.GetString("family_history")
  2681. user_name := c.GetString("user_name")
  2682. doctor_advice := c.GetString("doctor_advice")
  2683. remark := c.GetString("remark")
  2684. //record_date := c.GetString("record_date")
  2685. //fmt.Println("record_date--------",record_date)
  2686. //timeLayout := "2006-01-02"
  2687. //loc, _ := time.LoadLocation("Local")
  2688. //
  2689. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2690. //if err != nil {
  2691. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2692. // return
  2693. //}
  2694. //recordDateTime := theTime.Unix()
  2695. ctime := time.Now().Unix()
  2696. template := models.HisCaseHistoryTemplate{
  2697. HistoryOfPresentIllness: history_of_present_illness,
  2698. PastHistory: past_history,
  2699. ChiefConplaint: chief_conplaint,
  2700. PersonalHistory: personal_history,
  2701. FamilyHistory: family_history,
  2702. Diagnostic: diagnostic,
  2703. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2704. Status: 1,
  2705. Ctime: ctime,
  2706. Mtime: ctime,
  2707. RecordDate: time.Now().Unix(),
  2708. TemplateName: template_name,
  2709. TemplateRemark: template_remark,
  2710. Creator: doctor,
  2711. Modifier: doctor,
  2712. UserName: user_name,
  2713. DoctorAdvice: doctor_advice,
  2714. Remark: remark,
  2715. }
  2716. err := service.SaveHisPatientCaseHistoryTemplate(template)
  2717. if err == nil {
  2718. c.ServeSuccessJSON(map[string]interface{}{
  2719. "msg": "保存成功",
  2720. })
  2721. } else {
  2722. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2723. return
  2724. }
  2725. }
  2726. func (c *HisApiController) GetCaseHistoryTemplate() {
  2727. timeLayout := "2006-01-02"
  2728. loc, _ := time.LoadLocation("Local")
  2729. keyword := c.GetString("keyword")
  2730. start_time := c.GetString("start_time")
  2731. end_time := c.GetString("end_time")
  2732. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2733. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2734. admin := c.GetAdminUserInfo()
  2735. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  2736. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  2737. c.ServeSuccessJSON(map[string]interface{}{
  2738. "template": template,
  2739. //"history": history,
  2740. })
  2741. }
  2742. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2743. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2744. utils.ErrorLog("drug_name")
  2745. return enums.ErrorCodeParamWrong
  2746. }
  2747. adviceName, _ := json["drug_name"].(string)
  2748. if len(adviceName) == 0 {
  2749. utils.ErrorLog("len(advice_name) == 0")
  2750. return enums.ErrorCodeParamWrong
  2751. }
  2752. advice.AdviceName = adviceName
  2753. adviceDesc, _ := json["advice_desc"].(string)
  2754. advice.AdviceDesc = adviceDesc
  2755. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2756. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2757. advice.DrugSpec = drugSpec
  2758. }
  2759. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2760. remark, _ := json["remark"].(string)
  2761. advice.Remark = remark
  2762. }
  2763. if json["id"] == nil {
  2764. advice.DrugId = 0
  2765. } else {
  2766. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2767. drug_id := int64(json["id"].(float64))
  2768. advice.DrugId = drug_id
  2769. }
  2770. }
  2771. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  2772. advice_id := int64(json["advice_id"].(float64))
  2773. advice.ID = advice_id
  2774. if advice.ID > 0 {
  2775. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  2776. if err == nil {
  2777. if hisAdvice.ID > 0 {
  2778. advice.ExecutionTime = hisAdvice.ExecutionTime
  2779. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  2780. advice.ExecutionState = hisAdvice.ExecutionState
  2781. advice.CheckTime = hisAdvice.CheckTime
  2782. advice.Checker = hisAdvice.Checker
  2783. advice.CheckState = hisAdvice.CheckState
  2784. advice.StartTime = hisAdvice.StartTime
  2785. advice.FeedetlSn = hisAdvice.FeedetlSn
  2786. }
  2787. }
  2788. }
  2789. }
  2790. //
  2791. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  2792. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  2793. // advice.ExecutionTime = execution_time
  2794. //}
  2795. //
  2796. //
  2797. //
  2798. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  2799. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  2800. // advice.ExecutionStaff = execution_staff
  2801. //}
  2802. //
  2803. //
  2804. //
  2805. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  2806. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  2807. // advice.ExecutionState = execution_state
  2808. //}
  2809. //
  2810. //
  2811. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  2812. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  2813. // advice.CheckTime = check_time
  2814. //}
  2815. //
  2816. //
  2817. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  2818. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  2819. // advice.CheckState = check_state
  2820. //}
  2821. //
  2822. //
  2823. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  2824. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  2825. // advice.Checker = checker
  2826. //}
  2827. //
  2828. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  2829. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  2830. // advice.StartTime = start_time
  2831. //}
  2832. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2833. drugSpecUnit, _ := json["min_unit"].(string)
  2834. advice.DrugSpecUnit = drugSpecUnit
  2835. }
  2836. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2837. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2838. advice.SingleDose = singleDose
  2839. }
  2840. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2841. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2842. advice.SingleDoseUnit = singleDoseUnit
  2843. }
  2844. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2845. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2846. advice.PrescribingNumber = prescribingNumber
  2847. }
  2848. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2849. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2850. advice.PrescribingNumberUnit = prescribingNumberUnit
  2851. }
  2852. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2853. deliveryWay, _ := json["delivery_way"].(string)
  2854. advice.DeliveryWay = deliveryWay
  2855. }
  2856. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2857. executionFrequency, _ := json["execution_frequency"].(string)
  2858. advice.ExecutionFrequency = executionFrequency
  2859. }
  2860. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2861. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2862. advice.Price = price
  2863. }
  2864. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2865. med_list_codg, _ := json["medical_insurance_number"].(string)
  2866. advice.MedListCodg = med_list_codg
  2867. }
  2868. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2869. day := int64(json["day"].(float64))
  2870. advice.Day = day
  2871. }
  2872. return 0
  2873. }
  2874. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  2875. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2876. id := int64(json["id"].(float64))
  2877. project.ID = id
  2878. historyProject, _ := service.GetHisProjectByID(id)
  2879. project.FeedetlSn = historyProject.FeedetlSn
  2880. }
  2881. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  2882. project_id := int64(json["project_id"].(float64))
  2883. project.ProjectId = project_id
  2884. }
  2885. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2886. // price := int64(json["price"].(float64))
  2887. // formatInt_price := strconv.FormatInt(price, 10)
  2888. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2889. // project.Price = float_price
  2890. // }
  2891. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2892. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2893. project.Price = price
  2894. }
  2895. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  2896. total, _ := json["total"].(string)
  2897. project.Count = total
  2898. }
  2899. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  2900. medical_code, _ := json["medical_code"].(string)
  2901. project.MedListCodg = medical_code
  2902. }
  2903. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2904. single_dose, _ := json["single_dose"].(string)
  2905. project.SingleDose = single_dose
  2906. }
  2907. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2908. delivery_way, _ := json["delivery_way"].(string)
  2909. project.DeliveryWay = delivery_way
  2910. }
  2911. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2912. execution_frequency, _ := json["execution_frequency"].(string)
  2913. project.ExecutionFrequency = execution_frequency
  2914. }
  2915. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2916. remark, _ := json["remark"].(string)
  2917. project.Remark = remark
  2918. }
  2919. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  2920. day, _ := json["number_days"].(string)
  2921. project.Day = day
  2922. }
  2923. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  2924. unit, _ := json["unit"].(string)
  2925. project.Unit = unit
  2926. }
  2927. return 0
  2928. }
  2929. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  2930. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2931. id := int64(json["id"].(float64))
  2932. historyAddtions, _ := service.GetHisAdditionByID(id)
  2933. additionalCharge.ID = id
  2934. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  2935. }
  2936. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  2937. item_id := int64(json["item_id"].(float64))
  2938. additionalCharge.ItemId = item_id
  2939. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  2940. if config.ID > 0 {
  2941. if len(config.Code) > 0 {
  2942. additionalCharge.MedListCodg = config.Code
  2943. }
  2944. }
  2945. }
  2946. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2947. // price := int64(json["price"].(float64))
  2948. // formatInt_price := strconv.FormatInt(price, 10)
  2949. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2950. // additionalCharge.Price = float_price
  2951. // }
  2952. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2953. // price := int64(json["price"].(float64))
  2954. // formatInt_price := strconv.FormatInt(price, 10)
  2955. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2956. // additionalCharge.Price = float_price
  2957. //}
  2958. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2959. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2960. additionalCharge.Price = price
  2961. }
  2962. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  2963. count, _ := json["count"].(string)
  2964. counts, _ := strconv.ParseInt(count, 10, 64)
  2965. additionalCharge.Count = counts
  2966. }
  2967. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  2968. item_name, _ := json["item_name"].(string)
  2969. additionalCharge.ItemName = item_name
  2970. }
  2971. return 0
  2972. }
  2973. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2974. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2975. utils.ErrorLog("drug_name")
  2976. return enums.ErrorCodeParamWrong
  2977. }
  2978. adviceName, _ := json["drug_name"].(string)
  2979. if len(adviceName) == 0 {
  2980. utils.ErrorLog("len(advice_name) == 0")
  2981. return enums.ErrorCodeParamWrong
  2982. }
  2983. advice.AdviceName = adviceName
  2984. adviceDesc, _ := json["advice_desc"].(string)
  2985. advice.AdviceDesc = adviceDesc
  2986. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2987. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2988. advice.DrugSpec = drugSpec
  2989. }
  2990. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2991. remark, _ := json["remark"].(string)
  2992. advice.Remark = remark
  2993. }
  2994. if json["id"] == nil {
  2995. advice.DrugId = 0
  2996. } else {
  2997. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2998. drug_id := int64(json["id"].(float64))
  2999. advice.DrugId = drug_id
  3000. }
  3001. }
  3002. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  3003. groupno := int64(json["groupno"].(float64))
  3004. advice.Groupno = groupno
  3005. }
  3006. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  3007. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  3008. advice.HospApprFlag = hosp_appr_flag
  3009. }
  3010. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3011. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3012. advice.PrescribingNumber = prescribingNumber
  3013. }
  3014. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3015. // frequency_type := int64(json["frequency_type"].(float64))
  3016. // advice.FrequencyType = frequency_type
  3017. //}
  3018. //
  3019. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3020. // day_count := int64(json["day_count"].(float64))
  3021. // advice.DayCount = day_count
  3022. //}
  3023. //
  3024. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3025. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3026. // week_day, _ := json["week_day"].(string)
  3027. // advice.WeekDay = week_day
  3028. //}
  3029. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3030. drugSpecUnit, _ := json["min_unit"].(string)
  3031. advice.DrugSpecUnit = drugSpecUnit
  3032. }
  3033. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3034. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3035. advice.SingleDose = singleDose
  3036. }
  3037. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3038. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3039. advice.SingleDoseUnit = singleDoseUnit
  3040. }
  3041. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3042. deliveryWay, _ := json["delivery_way"].(string)
  3043. advice.DeliveryWay = deliveryWay
  3044. }
  3045. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3046. executionFrequency, _ := json["execution_frequency"].(string)
  3047. advice.ExecutionFrequency = executionFrequency
  3048. }
  3049. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3050. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3051. advice.Price = price
  3052. }
  3053. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3054. med_list_codg, _ := json["medical_insurance_number"].(string)
  3055. advice.MedListCodg = med_list_codg
  3056. }
  3057. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3058. day := int64(json["day"].(float64))
  3059. advice.Day = day
  3060. }
  3061. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3062. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3063. advice.PrescribingNumberUnit = prescribingNumberUnit
  3064. }
  3065. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3066. advice_id := int64(json["advice_id"].(float64))
  3067. advice.ID = advice_id
  3068. if advice.ID > 0 {
  3069. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3070. if err == nil {
  3071. if hisAdvice.ID > 0 {
  3072. advice.ExecutionTime = hisAdvice.ExecutionTime
  3073. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3074. advice.ExecutionState = hisAdvice.ExecutionState
  3075. advice.CheckTime = hisAdvice.CheckTime
  3076. advice.Checker = hisAdvice.Checker
  3077. advice.CheckState = hisAdvice.CheckState
  3078. advice.StartTime = hisAdvice.StartTime
  3079. advice.HospApprFlag = hisAdvice.HospApprFlag
  3080. if hisAdvice.UserOrgId == 10028 {
  3081. 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 {
  3082. advice.ExecutionTime = 0
  3083. advice.ExecutionStaff = 0
  3084. advice.ExecutionState = 2
  3085. advice.CheckTime = 0
  3086. advice.Checker = 0
  3087. advice.CheckState = 2
  3088. }
  3089. } else {
  3090. 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 {
  3091. advice.ExecutionTime = 0
  3092. advice.ExecutionStaff = 0
  3093. advice.ExecutionState = 2
  3094. advice.CheckTime = 0
  3095. advice.Checker = 0
  3096. advice.CheckState = 2
  3097. }
  3098. }
  3099. //advice.Groupno = hisAdvice.Groupno
  3100. }
  3101. }
  3102. }
  3103. }
  3104. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  3105. //
  3106. //if drugStockConfig.IsOpen == 1 {
  3107. //
  3108. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  3109. // if advice.ID == 0 { //医嘱不存在
  3110. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  3111. // drug.Total = drug.Total - advice.PrescribingNumber
  3112. // service.UpdateBaseDrugLib(&drug)
  3113. //
  3114. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  3115. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  3116. // drug.Total = drug.Total - num
  3117. // service.UpdateBaseDrugLib(&drug)
  3118. // }
  3119. //
  3120. // } else if advice.ID > 0 { //医嘱存在
  3121. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  3122. // var num float64
  3123. //
  3124. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  3125. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  3126. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  3127. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  3128. // drug.Total = drug.Total + num
  3129. // service.UpdateBaseDrugLib(&drug)
  3130. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  3131. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  3132. // drug.Total = drug.Total - num
  3133. // service.UpdateBaseDrugLib(&drug)
  3134. // }
  3135. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  3136. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3137. // if num2 > advice.PrescribingNumber {
  3138. // num = num2 - advice.PrescribingNumber
  3139. // drug.Total = drug.Total + num
  3140. // service.UpdateBaseDrugLib(&drug)
  3141. // } else if num2 < advice.PrescribingNumber {
  3142. // num = advice.PrescribingNumber - num2
  3143. // drug.Total = drug.Total - num
  3144. // service.UpdateBaseDrugLib(&drug)
  3145. // }
  3146. //
  3147. // }
  3148. //
  3149. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  3150. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  3151. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3152. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3153. // if num1 > num2 {
  3154. // num = num1 - num2
  3155. // drug.Total = drug.Total + num
  3156. // service.UpdateBaseDrugLib(&drug)
  3157. // } else if num1 < num2 {
  3158. // num = num2 - num1
  3159. // drug.Total = drug.Total - num
  3160. // service.UpdateBaseDrugLib(&drug)
  3161. // }
  3162. //
  3163. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  3164. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3165. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  3166. // if hisAdvice.PrescribingNumber > num2 {
  3167. // num = hisAdvice.PrescribingNumber - num2
  3168. // drug.Total = drug.Total + num
  3169. // service.UpdateBaseDrugLib(&drug)
  3170. // } else if num2 < advice.PrescribingNumber {
  3171. // num = num2 - hisAdvice.PrescribingNumber
  3172. // drug.Total = drug.Total - num
  3173. // service.UpdateBaseDrugLib(&drug)
  3174. // }
  3175. //
  3176. // }
  3177. // }
  3178. // }
  3179. //}
  3180. //
  3181. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3182. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3183. // advice.ExecutionTime = execution_time
  3184. //}
  3185. //
  3186. //
  3187. //
  3188. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3189. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3190. // advice.ExecutionStaff = execution_staff
  3191. //}
  3192. //
  3193. //
  3194. //
  3195. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3196. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3197. // advice.ExecutionState = execution_state
  3198. //}
  3199. //
  3200. //
  3201. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3202. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3203. // advice.CheckTime = check_time
  3204. //}
  3205. //
  3206. //
  3207. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3208. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3209. // advice.CheckState = check_state
  3210. //}
  3211. //
  3212. //
  3213. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3214. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3215. // advice.Checker = checker
  3216. //}
  3217. //
  3218. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3219. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3220. // advice.StartTime = start_time
  3221. //}
  3222. return 0
  3223. }
  3224. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3225. project.ExecutionStaff = 0
  3226. project.ExecutionState = 2
  3227. project.ExecutionTime = 0
  3228. project.Checker = 0
  3229. project.CheckState = 2
  3230. project.CheckTime = 0
  3231. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3232. id := int64(json["id"].(float64))
  3233. project.ID = id
  3234. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  3235. project.ExecutionStaff = temp_project.ExecutionStaff
  3236. project.ExecutionState = temp_project.ExecutionState
  3237. project.ExecutionTime = temp_project.ExecutionTime
  3238. project.Checker = temp_project.Checker
  3239. project.CheckState = temp_project.CheckState
  3240. project.CheckTime = temp_project.CheckTime
  3241. project.TeamId = temp_project.TeamId
  3242. }
  3243. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3244. types := int64(json["type"].(float64))
  3245. project.Type = types
  3246. }
  3247. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3248. project_id := int64(json["project_id"].(float64))
  3249. project.ProjectId = project_id
  3250. }
  3251. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  3252. team_id := int64(json["team_id"].(float64))
  3253. project.TeamId = team_id
  3254. }
  3255. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3256. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3257. project.Price = price
  3258. }
  3259. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3260. total, _ := json["total"].(string)
  3261. //totals, _ := strconv.ParseInt(total, 10, 64)
  3262. project.Count = total
  3263. }
  3264. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3265. medical_code, _ := json["medical_code"].(string)
  3266. project.MedListCodg = medical_code
  3267. }
  3268. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3269. single_dose, _ := json["single_dose"].(string)
  3270. project.SingleDose = single_dose
  3271. }
  3272. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3273. delivery_way, _ := json["delivery_way"].(string)
  3274. project.DeliveryWay = delivery_way
  3275. }
  3276. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3277. execution_frequency, _ := json["execution_frequency"].(string)
  3278. project.ExecutionFrequency = execution_frequency
  3279. }
  3280. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3281. remark, _ := json["remark"].(string)
  3282. project.Remark = remark
  3283. }
  3284. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3285. day, _ := json["number_days"].(string)
  3286. project.Day = day
  3287. }
  3288. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3289. unit, _ := json["unit"].(string)
  3290. project.Unit = unit
  3291. }
  3292. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3293. // frequency_type := int64(json["frequency_type"].(float64))
  3294. // project.FrequencyType = frequency_type
  3295. //}
  3296. //
  3297. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3298. // day_count := int64(json["day_count"].(float64))
  3299. // project.DayCount = day_count
  3300. //}
  3301. //
  3302. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3303. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3304. // week_day, _ := json["week_day"].(string)
  3305. // project.WeekDay = week_day
  3306. //}
  3307. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  3308. //
  3309. //if project.ID == 0 {
  3310. // if stockConfig.IsOpen == 1 {
  3311. // if project.Type == 3 {
  3312. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3313. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  3314. // good.Total = good.Total - f_count
  3315. // service.UpdateGoodInfo(&good)
  3316. // }
  3317. // }
  3318. //
  3319. //} else {
  3320. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  3321. //
  3322. // if stockConfig.IsOpen == 1 {
  3323. // if project.Type == 3 {
  3324. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3325. // if project.Count < temp_project.Count {
  3326. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3327. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3328. //
  3329. // other_count := f_count_two - f_count_one
  3330. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3331. // good.Total = good.Total + other_count_two
  3332. // service.UpdateGoodInfo(&good)
  3333. // } else if project.Count > temp_project.Count {
  3334. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3335. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3336. //
  3337. // other_count := f_count_one - f_count_two
  3338. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3339. // good.Total = good.Total - other_count_two
  3340. // service.UpdateGoodInfo(&good)
  3341. // }
  3342. //
  3343. // }
  3344. // }
  3345. //
  3346. //}
  3347. return 0
  3348. }
  3349. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3350. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3351. id := int64(json["id"].(float64))
  3352. additionalCharge.ID = id
  3353. }
  3354. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3355. item_id := int64(json["item_id"].(float64))
  3356. additionalCharge.ItemId = item_id
  3357. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3358. if config.ID > 0 {
  3359. if len(config.Code) > 0 {
  3360. additionalCharge.MedListCodg = config.Code
  3361. }
  3362. }
  3363. }
  3364. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3365. // price := int64(json["price"].(float64))
  3366. // formatInt_price := strconv.FormatInt(price, 10)
  3367. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3368. // additionalCharge.Price = float_price
  3369. // }
  3370. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3371. // price := int64(json["price"].(float64))
  3372. // formatInt_price := strconv.FormatInt(price, 10)
  3373. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3374. // additionalCharge.Price = float_price
  3375. //}
  3376. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3377. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3378. additionalCharge.Price = price
  3379. }
  3380. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3381. count, _ := json["count"].(string)
  3382. counts, _ := strconv.ParseInt(count, 10, 64)
  3383. additionalCharge.Count = counts
  3384. }
  3385. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3386. item_name, _ := json["item_name"].(string)
  3387. additionalCharge.ItemName = item_name
  3388. }
  3389. return 0
  3390. }
  3391. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  3392. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3393. utils.ErrorLog("drug_name")
  3394. return enums.ErrorCodeParamWrong
  3395. }
  3396. adviceName, _ := json["drug_name"].(string)
  3397. if len(adviceName) == 0 {
  3398. utils.ErrorLog("len(advice_name) == 0")
  3399. return enums.ErrorCodeParamWrong
  3400. }
  3401. advice.AdviceName = adviceName
  3402. adviceDesc, _ := json["advice_desc"].(string)
  3403. advice.AdviceDesc = adviceDesc
  3404. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3405. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3406. advice.DrugSpec = drugSpec
  3407. }
  3408. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3409. remark, _ := json["remark"].(string)
  3410. advice.Remark = remark
  3411. }
  3412. if json["id"] == nil {
  3413. advice.DrugId = 0
  3414. } else {
  3415. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3416. drug_id := int64(json["id"].(float64))
  3417. advice.DrugId = drug_id
  3418. }
  3419. }
  3420. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3421. drugSpecUnit, _ := json["min_unit"].(string)
  3422. advice.DrugSpecUnit = drugSpecUnit
  3423. }
  3424. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3425. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3426. advice.SingleDose = singleDose
  3427. }
  3428. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3429. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3430. advice.SingleDoseUnit = singleDoseUnit
  3431. }
  3432. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3433. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3434. advice.PrescribingNumber = prescribingNumber
  3435. }
  3436. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3437. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3438. advice.PrescribingNumberUnit = prescribingNumberUnit
  3439. }
  3440. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3441. deliveryWay, _ := json["delivery_way"].(string)
  3442. advice.DeliveryWay = deliveryWay
  3443. }
  3444. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3445. executionFrequency, _ := json["execution_frequency"].(string)
  3446. advice.ExecutionFrequency = executionFrequency
  3447. }
  3448. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3449. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3450. advice.Price = price
  3451. }
  3452. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3453. med_list_codg, _ := json["medical_insurance_number"].(string)
  3454. advice.MedListCodg = med_list_codg
  3455. }
  3456. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3457. day := int64(json["day"].(float64))
  3458. advice.Day = day
  3459. }
  3460. return 0
  3461. }
  3462. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  3463. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3464. types := int64(json["type"].(float64))
  3465. project.Type = types
  3466. }
  3467. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3468. project_id := int64(json["project_id"].(float64))
  3469. project.ProjectId = project_id
  3470. }
  3471. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3472. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3473. project.Price = price
  3474. }
  3475. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3476. total, _ := json["total"].(string)
  3477. //totals, _ := strconv.ParseInt(total, 10, 64)
  3478. project.Count = total
  3479. }
  3480. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3481. medical_code, _ := json["medical_code"].(string)
  3482. project.MedListCodg = medical_code
  3483. }
  3484. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3485. single_dose, _ := json["single_dose"].(string)
  3486. project.SingleDose = single_dose
  3487. }
  3488. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3489. delivery_way, _ := json["delivery_way"].(string)
  3490. project.DeliveryWay = delivery_way
  3491. }
  3492. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3493. execution_frequency, _ := json["execution_frequency"].(string)
  3494. project.ExecutionFrequency = execution_frequency
  3495. }
  3496. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3497. remark, _ := json["remark"].(string)
  3498. project.Remark = remark
  3499. }
  3500. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3501. day, _ := json["number_days"].(string)
  3502. project.Day = day
  3503. }
  3504. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3505. unit, _ := json["unit"].(string)
  3506. project.Unit = unit
  3507. }
  3508. return 0
  3509. }
  3510. func (c *HisApiController) GetHisOrderList() {
  3511. page, _ := c.GetInt64("page", -1)
  3512. limit, _ := c.GetInt64("limit", -1)
  3513. start_time := c.GetString("start_time")
  3514. end_time := c.GetString("end_time")
  3515. types, _ := c.GetInt64("type", 0)
  3516. keywords := c.GetString("keywords")
  3517. p_type, _ := c.GetInt64("p_type", 0)
  3518. sort_type, _ := c.GetInt64("sort_type", 0)
  3519. timeLayout := "2006-01-02"
  3520. loc, _ := time.LoadLocation("Local")
  3521. var startTime int64
  3522. if len(start_time) > 0 {
  3523. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3524. if err != nil {
  3525. fmt.Println(err)
  3526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3527. return
  3528. }
  3529. startTime = theTime.Unix()
  3530. }
  3531. var endTime int64
  3532. if len(end_time) > 0 {
  3533. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3534. if err != nil {
  3535. utils.ErrorLog(err.Error())
  3536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3537. return
  3538. }
  3539. endTime = theTime.Unix()
  3540. }
  3541. adminUser := c.GetAdminUserInfo()
  3542. org_id := adminUser.CurrentOrgId
  3543. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time)
  3544. for _, item := range order {
  3545. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  3546. item.DoctorName = info.Doctor
  3547. item.DepartmentName = info.XtHisDepartment.Name
  3548. }
  3549. if err == nil {
  3550. c.ServeSuccessJSON(map[string]interface{}{
  3551. "order": order,
  3552. "total": total,
  3553. })
  3554. } else {
  3555. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3556. return
  3557. }
  3558. }
  3559. func (c *HisApiController) GetHisOrder() {
  3560. patient_id, _ := c.GetInt64("patient_id", 0)
  3561. number := c.GetString("number")
  3562. adminInfo := c.GetAdminUserInfo()
  3563. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  3564. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  3565. if err == nil {
  3566. c.ServeSuccessJSON(map[string]interface{}{
  3567. "order": order,
  3568. "prescription": prescriptions,
  3569. })
  3570. } else {
  3571. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3572. return
  3573. }
  3574. }
  3575. func (c *HisApiController) GetHisPrescriptionList() {
  3576. record_date := c.GetString("record_date")
  3577. keywords := c.GetString("keywords")
  3578. page, _ := c.GetInt64("page")
  3579. limit, _ := c.GetInt64("limit")
  3580. timeLayout := "2006-01-02"
  3581. loc, _ := time.LoadLocation("Local")
  3582. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3583. if err != nil {
  3584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3585. return
  3586. }
  3587. recordDateTime := theTime.Unix()
  3588. adminInfo := c.GetAdminUserInfo()
  3589. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  3590. //adminInfo := c.GetAdminUserInfo()
  3591. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  3592. //fmt.Println(prescriptionOrder)
  3593. if err == nil {
  3594. c.ServeSuccessJSON(map[string]interface{}{
  3595. "order": prescriptionOrder,
  3596. "total": total,
  3597. })
  3598. } else {
  3599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3600. return
  3601. }
  3602. }
  3603. func (c *HisApiController) GetHisPrescriptionInfo() {
  3604. id, _ := c.GetInt64("id")
  3605. adminInfo := c.GetAdminUserInfo()
  3606. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  3607. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  3608. if err == nil {
  3609. c.ServeSuccessJSON(map[string]interface{}{
  3610. "order": prescriptionOrder,
  3611. "prescription": prescription,
  3612. })
  3613. } else {
  3614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3615. return
  3616. }
  3617. }
  3618. func (c *HisApiController) GetMedicalInsuranceConfig() {
  3619. adminUser := c.GetAdminUserInfo()
  3620. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3621. c.ServeSuccessJSON(map[string]interface{}{
  3622. "config": config,
  3623. })
  3624. }
  3625. type ResultTwo struct {
  3626. ErrMsg interface{} `json:"err_msg"`
  3627. InfRefmsgid string `json:"inf_refmsgid"`
  3628. Infcode int64 `json:"infcode"`
  3629. Output struct {
  3630. Baseinfo struct {
  3631. Age float64 `json:"age"`
  3632. Brdy string `json:"brdy"`
  3633. Certno string `json:"certno"`
  3634. Gend string `json:"gend"`
  3635. Naty string `json:"naty"`
  3636. PsnCertType string `json:"psn_cert_type"`
  3637. PsnName string `json:"psn_name"`
  3638. PsnNo string `json:"psn_no"`
  3639. } `json:"baseinfo"`
  3640. Idetinfo []interface{} `json:"idetinfo"`
  3641. Iinfo []struct {
  3642. Balc float64 `json:"balc"`
  3643. CvlservFlag string `json:"cvlserv_flag"`
  3644. EmpName string `json:"emp_name"`
  3645. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  3646. Insutype string `json:"insutype"`
  3647. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  3648. PausInsuDate interface{} `json:"paus_insu_date"`
  3649. PsnInsuDate string `json:"psn_insu_date"`
  3650. PsnInsuStas string `json:"psn_insu_stas"`
  3651. PsnType string `json:"psn_type"`
  3652. } `json:"insuinfo"`
  3653. } `json:"output"`
  3654. RefmsgTime string `json:"refmsg_time"`
  3655. RespondTime string `json:"respond_time"`
  3656. Signtype interface{} `json:"signtype"`
  3657. WarnInfo interface{} `json:"warn_info"`
  3658. }
  3659. type ResultThree struct {
  3660. Cainfo interface{} `json:"cainfo"`
  3661. ErrMsg interface{} `json:"err_msg"`
  3662. InfRefmsgid string `json:"inf_refmsgid"`
  3663. Infcode int64 `json:"infcode"`
  3664. Output struct {
  3665. Data struct {
  3666. IptOtpNo string `json:"ipt_otp_no"`
  3667. MdtrtID string `json:"mdtrt_id"`
  3668. PsnNo string `json:"psn_no"`
  3669. } `json:"data"`
  3670. } `json:"output"`
  3671. RefmsgTime string `json:"refmsg_time"`
  3672. RespondTime string `json:"respond_time"`
  3673. Signtype interface{} `json:"signtype"`
  3674. WarnMsg interface{} `json:"warn_msg"`
  3675. }
  3676. type ResultFour struct {
  3677. Cainfo string `json:"cainfo"`
  3678. ErrMsg string `json:"err_msg"`
  3679. InfRefmsgid string `json:"inf_refmsgid"`
  3680. Infcode int64 `json:"infcode"`
  3681. Output struct {
  3682. Result []struct {
  3683. BasMednFlag string `json:"bas_medn_flag"`
  3684. ChldMedcFlag string `json:"chld_medc_flag"`
  3685. ChrgitmLv string `json:"chrgitm_lv"`
  3686. Cnt float64 `json:"cnt"`
  3687. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  3688. DrtReimFlag string `json:"drt_reim_flag"`
  3689. FeedetlSn string `json:"feedetl_sn"`
  3690. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3691. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  3692. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3693. ListSpItemFlag string `json:"list_sp_item_flag"`
  3694. LmtUsedFlag string `json:"lmt_used_flag"`
  3695. MedChrgitmType string `json:"med_chrgitm_type"`
  3696. Memo string `json:"memo"`
  3697. OverlmtAmt float64 `json:"overlmt_amt"`
  3698. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3699. Pric float64 `json:"pric"`
  3700. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  3701. SelfpayProp float64 `json:"selfpay_prop"`
  3702. } `json:"result"`
  3703. } `json:"output"`
  3704. RefmsgTime string `json:"refmsg_time"`
  3705. RespondTime string `json:"respond_time"`
  3706. Signtype string `json:"signtype"`
  3707. WarnMsg string `json:"warn_msg"`
  3708. }
  3709. type ResultFive struct {
  3710. Insutype string `json:"insutype"`
  3711. }
  3712. type ResultSix struct {
  3713. Cainfo interface{} `json:"cainfo"`
  3714. ErrMsg interface{} `json:"err_msg"`
  3715. InfRefmsgid string `json:"inf_refmsgid"`
  3716. Infcode int64 `json:"infcode"`
  3717. Output struct {
  3718. } `json:"output"`
  3719. RefmsgTime string `json:"refmsg_time"`
  3720. RespondTime string `json:"respond_time"`
  3721. Signtype interface{} `json:"signtype"`
  3722. WarnMsg interface{} `json:"warn_msg"`
  3723. }
  3724. type ResultSeven struct {
  3725. Cainfo string `json:"cainfo"`
  3726. ErrMsg string `json:"err_msg"`
  3727. InfRefmsgid string `json:"inf_refmsgid"`
  3728. Infcode int64 `json:"infcode"`
  3729. Output struct {
  3730. Setldetail []interface{} `json:"setldetail"`
  3731. Setlinfo struct {
  3732. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3733. AcctPay float64 `json:"acct_pay"`
  3734. ActPayDedc float64 `json:"act_pay_dedc"`
  3735. Age float64 `json:"age"`
  3736. Balc float64 `json:"balc"`
  3737. Brdy string `json:"brdy"`
  3738. Certno string `json:"certno"`
  3739. ClrOptins string `json:"clr_optins"`
  3740. ClrType string `json:"clr_type"`
  3741. ClrWay string `json:"clr_way"`
  3742. CvlservFlag string `json:"cvlserv_flag"`
  3743. CvlservPay float64 `json:"cvlserv_pay"`
  3744. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3745. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3746. Gend string `json:"gend"`
  3747. HifesPay float64 `json:"hifes_pay"`
  3748. HifmiPay float64 `json:"hifmi_pay"`
  3749. HifobPay float64 `json:"hifob_pay"`
  3750. HifpPay float64 `json:"hifp_pay"`
  3751. HospPartAmt float64 `json:"hosp_part_amt"`
  3752. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3753. Insutype string `json:"insutype"`
  3754. MafPay float64 `json:"maf_pay"`
  3755. MdtrtCertType string `json:"mdtrt_cert_type"`
  3756. MdtrtID string `json:"mdtrt_id"`
  3757. MedType string `json:"med_type"`
  3758. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3759. MedinsSetlID string `json:"medins_setl_id"`
  3760. Naty string `json:"naty"`
  3761. OthPay float64 `json:"oth_pay"`
  3762. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3763. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3764. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3765. PsnCashPay float64 `json:"psn_cash_pay"`
  3766. PsnCertType string `json:"psn_cert_type"`
  3767. PsnName string `json:"psn_name"`
  3768. PsnNo string `json:"psn_no"`
  3769. PsnPartAmt float64 `json:"psn_part_amt"`
  3770. PsnType string `json:"psn_type"`
  3771. SetlID string `json:"setl_id"`
  3772. SetlTime string `json:"setl_time"`
  3773. } `json:"setlinfo"`
  3774. } `json:"output"`
  3775. RefmsgTime string `json:"refmsg_time"`
  3776. RespondTime string `json:"respond_time"`
  3777. Signtype interface{} `json:"signtype"`
  3778. WarnMsg interface{} `json:"warn_msg"`
  3779. }
  3780. type ResultEight struct {
  3781. Cainfo string `json:"cainfo"`
  3782. ErrMsg string `json:"err_msg"`
  3783. InfRefmsgid string `json:"inf_refmsgid"`
  3784. Infcode int64 `json:"infcode"`
  3785. Output struct {
  3786. Stmtinfo struct {
  3787. SetlOptins string `json:"setl_optins"`
  3788. StmtRslt string `json:"stmt_rslt"`
  3789. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  3790. } `json:"stmtinfo"`
  3791. } `json:"output"`
  3792. RefmsgTime string `json:"refmsg_time"`
  3793. RespondTime string `json:"respond_time"`
  3794. Signtype interface{} `json:"signtype"`
  3795. WarnMsg interface{} `json:"warn_msg"`
  3796. }
  3797. type ResultNine struct {
  3798. Cainfo string `json:"cainfo"`
  3799. ErrMsg string `json:"err_msg"`
  3800. InfRefmsgid string `json:"inf_refmsgid"`
  3801. Infcode int64 `json:"infcode"`
  3802. Output struct {
  3803. FileQuryNo string `json:"file_qury_no"`
  3804. } `json:"output"`
  3805. RefmsgTime string `json:"refmsg_time"`
  3806. RespondTime string `json:"respond_time"`
  3807. Signtype interface{} `json:"signtype"`
  3808. WarnMsg interface{} `json:"warn_msg"`
  3809. }
  3810. type ResultTen struct {
  3811. Cainfo string `json:"cainfo"`
  3812. ErrMsg string `json:"err_msg"`
  3813. InfRefmsgid string `json:"inf_refmsgid"`
  3814. Infcode int64 `json:"infcode"`
  3815. Output struct {
  3816. DldEndtime string `json:"dld_endtime"`
  3817. FileQuryNo string `json:"file_qury_no"`
  3818. Filename string `json:"filename"`
  3819. } `json:"output"`
  3820. RefmsgTime string `json:"refmsg_time"`
  3821. RespondTime string `json:"respond_time"`
  3822. Signtype interface{} `json:"signtype"`
  3823. WarnMsg interface{} `json:"warn_msg"`
  3824. }
  3825. type ResultEleven struct {
  3826. Cainfo string `json:"cainfo"`
  3827. ErrMsg string `json:"err_msg"`
  3828. InfRefmsgid string `json:"inf_refmsgid"`
  3829. Infcode int64 `json:"infcode"`
  3830. Output struct {
  3831. Setlinfo struct {
  3832. FixmedinsName string `json:"fixmedins_name"`
  3833. FixmedinsCode string `json:"fixmedins_code"`
  3834. PsnNo string `json:"psn_no"`
  3835. PsnName string `json:"psn_name"`
  3836. HifobPay float64 `json:"hifob_pay"`
  3837. Gend string `json:"gend"`
  3838. Brdy string `json:"brdy"`
  3839. PsnCertType string `json:"psn_cert_type"`
  3840. PsnType string `json:"psn_type"`
  3841. EmpName string `json:"emp_name"`
  3842. Certno string `json:"certno"`
  3843. Insutype string `json:"insutype"`
  3844. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3845. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3846. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3847. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3848. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3849. ActPayDedc float64 `json:"act_pay_dedc"`
  3850. HifpPay float64 `json:"hifp_pay"`
  3851. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3852. CvlservPay float64 `json:"cvlserv_pay"`
  3853. HifesPay float64 `json:"hifes_pay"`
  3854. HifmiPay float64 `json:"hifmi_pay"`
  3855. MafPay float64 `json:"maf_pay"`
  3856. OthPay float64 `json:"oth_pay"`
  3857. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3858. PsnPay float64 `json:"psn_pay"`
  3859. AcctPay float64 `json:"acct_pay"`
  3860. CashPayamt float64 `json:"cash_payamt"`
  3861. Balc float64 `json:"balc"`
  3862. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3863. MedinsSetlId string `json:"medins_setl_id"`
  3864. RefdSetlFlag string `json:"refd_setl_flag"`
  3865. SetlTime string `json:"setl_time"`
  3866. MedType string `json:"med_type"`
  3867. } `json:"setlinfo"`
  3868. } `json:"output"`
  3869. RefmsgTime string `json:"refmsg_time"`
  3870. RespondTime string `json:"respond_time"`
  3871. Signtype interface{} `json:"signtype"`
  3872. WarnMsg interface{} `json:"warn_msg"`
  3873. }
  3874. type Custom struct {
  3875. DetItemFeeSumamt string
  3876. Cut string
  3877. FeedetlSn string
  3878. Price string
  3879. MedListCodg string
  3880. Type int64
  3881. AdviceId int64
  3882. ProjectId int64
  3883. ItemId int64
  3884. }
  3885. //获取个人信息----挂号-----上传就诊信息
  3886. func (c *HisApiController) GetRegisterInfo() {
  3887. id, _ := c.GetInt64("id")
  3888. record_time := c.GetString("record_time")
  3889. settlementValue, _ := c.GetInt64("settlement_value")
  3890. medical_insurance_card := c.GetString("medical_insurance_card")
  3891. name := c.GetString("name")
  3892. id_card_type, _ := c.GetInt64("id_card_type")
  3893. certificates, _ := c.GetInt64("certificates")
  3894. medical_care, _ := c.GetInt64("medical_care")
  3895. birthday := c.GetString("birthday")
  3896. age, _ := c.GetInt64("age")
  3897. id_card := c.GetString("id_card")
  3898. register_type, _ := c.GetInt64("register")
  3899. doctor, _ := c.GetInt64("doctor")
  3900. department, _ := c.GetInt64("department")
  3901. gender, _ := c.GetInt64("sex")
  3902. phone := c.GetString("phone")
  3903. registration_fee, _ := c.GetFloat("registration_fee")
  3904. medical_expenses, _ := c.GetFloat("medical_expenses")
  3905. social_type, _ := c.GetInt64("social_type")
  3906. //diagnosis_id, _ := c.GetInt64("diagnosis")
  3907. diagnosis_ids := c.GetString("diagnosis")
  3908. sick_type, _ := c.GetInt64("sick_type")
  3909. reg_type := c.GetString("p_type")
  3910. timeLayout := "2006-01-02"
  3911. loc, _ := time.LoadLocation("Local")
  3912. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  3913. birthUnix := birthdays.Unix()
  3914. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3915. if err != nil {
  3916. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3917. return
  3918. }
  3919. recordDateTime := theTime.Unix()
  3920. adminInfo := c.GetAdminUserInfo()
  3921. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  3922. if tempPatient.ID == 0 {
  3923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  3924. return
  3925. }
  3926. var patient service.Patients
  3927. if id == 0 {
  3928. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  3929. } else {
  3930. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  3931. }
  3932. if patient.ID == 0 {
  3933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3934. return
  3935. }
  3936. if len(patient.IdCardNo) == 0 {
  3937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3938. return
  3939. }
  3940. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  3941. if len(his) >= 1 {
  3942. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  3943. if len(his) >= 1 && order.ID == 0 {
  3944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  3945. return
  3946. }
  3947. }
  3948. timeStr := time.Now().Format("2006-01-02 15:04:05")
  3949. fmt.Println(timeStr)
  3950. timeArr := strings.Split(timeStr, " ")
  3951. fmt.Println(timeArr)
  3952. timeArrTwo := strings.Split(timeArr[0], "-")
  3953. timeArrThree := strings.Split(timeArr[1], ":")
  3954. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  3955. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  3956. if len(lists) == 0 {
  3957. var hisPatient models.XtHisPatient
  3958. hisPatient = models.XtHisPatient{
  3959. Name: name,
  3960. Age: age,
  3961. Gender: gender,
  3962. Birthday: birthUnix,
  3963. Phone: phone,
  3964. MedicalTreatmentType: medical_care,
  3965. IdType: certificates,
  3966. IdCardNo: id_card,
  3967. BalanceAccountsType: settlementValue,
  3968. SocialType: social_type,
  3969. MedicalInsuranceNumber: medical_insurance_card,
  3970. RegisterType: register_type,
  3971. RegisterCost: registration_fee,
  3972. TreatmentCost: medical_expenses,
  3973. AdminUserId: adminInfo.AdminUser.Id,
  3974. UserOrgId: adminInfo.CurrentOrgId,
  3975. Status: 1,
  3976. RecordDate: recordDateTime,
  3977. IsReturn: 1,
  3978. PatientId: patient.ID,
  3979. Ctime: time.Now().Unix(),
  3980. Mtime: time.Now().Unix(),
  3981. Number: str,
  3982. IdCardType: id_card_type,
  3983. Departments: department,
  3984. Doctor: doctor,
  3985. PType: reg_type,
  3986. Diagnosis: diagnosis_ids,
  3987. SickType: sick_type,
  3988. }
  3989. service.CreateHisPatient(&hisPatient)
  3990. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  3991. c.ServeSuccessJSON(map[string]interface{}{
  3992. "his_info": hisPatient,
  3993. })
  3994. } else {
  3995. //chrgBchno := rand.Intn(1000000) + 10000
  3996. var hisPatient models.XtHisPatient
  3997. hisPatient = models.XtHisPatient{
  3998. Name: name,
  3999. Age: age,
  4000. Gender: gender,
  4001. Birthday: birthUnix,
  4002. Phone: phone,
  4003. MedicalTreatmentType: medical_care,
  4004. IdType: certificates,
  4005. IdCardNo: id_card,
  4006. BalanceAccountsType: settlementValue,
  4007. SocialType: social_type,
  4008. MedicalInsuranceNumber: medical_insurance_card,
  4009. RegisterType: register_type,
  4010. RegisterCost: registration_fee,
  4011. TreatmentCost: medical_expenses,
  4012. AdminUserId: adminInfo.AdminUser.Id,
  4013. UserOrgId: adminInfo.CurrentOrgId,
  4014. Status: 1,
  4015. RecordDate: recordDateTime,
  4016. IsReturn: 1,
  4017. PatientId: patient.ID,
  4018. Ctime: time.Now().Unix(),
  4019. Mtime: time.Now().Unix(),
  4020. Number: str,
  4021. IdCardType: id_card_type,
  4022. Departments: department,
  4023. Doctor: doctor,
  4024. PType: reg_type,
  4025. Diagnosis: diagnosis_ids,
  4026. SickType: sick_type,
  4027. }
  4028. service.CreateHisPatient(&hisPatient)
  4029. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4030. c.ServeSuccessJSON(map[string]interface{}{
  4031. "his_info": hisPatient,
  4032. })
  4033. }
  4034. }
  4035. //上传明细----结算
  4036. func (c *HisApiController) GetUploadInfo() {
  4037. id, _ := c.GetInt64("id")
  4038. record_time := c.GetString("record_time")
  4039. his_patient_id, _ := c.GetInt64("his_patient_id")
  4040. pay_way, _ := c.GetInt64("pay_way")
  4041. pay_price, _ := c.GetFloat("pay_price")
  4042. pay_card_no := c.GetString("pay_card_no")
  4043. discount_price, _ := c.GetFloat("discount_price")
  4044. preferential_price, _ := c.GetFloat("preferential_price")
  4045. reality_price, _ := c.GetFloat("reality_price")
  4046. found_price, _ := c.GetFloat("found_price")
  4047. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  4048. private_price, _ := c.GetFloat("private_price")
  4049. timeLayout := "2006-01-02"
  4050. loc, _ := time.LoadLocation("Local")
  4051. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  4052. fapiao_code := c.GetString("fapiao_code")
  4053. fapiao_number := c.GetString("fapiao_number")
  4054. diagnosis_id := c.GetString("diagnosis")
  4055. sick_type, _ := c.GetInt64("sick_type")
  4056. reg_type, _ := c.GetInt64("p_type")
  4057. order_id, _ := c.GetInt64("order_id")
  4058. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  4059. tempOrder, _ := service.GetHisOrderByID(order_id)
  4060. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4061. if err != nil {
  4062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4063. return
  4064. }
  4065. recordDateTime := theTime.Unix()
  4066. adminUser := c.GetAdminUserInfo()
  4067. var prescriptions []*models.HisPrescription
  4068. var start_time int64
  4069. var end_time int64
  4070. ids_str := c.GetString("ids")
  4071. ids_arr := strings.Split(ids_str, ",")
  4072. if tempOrder.ID == 0 {
  4073. if settle_accounts_type == 1 { //日结
  4074. fmt.Println(reg_type)
  4075. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  4076. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  4077. } else {
  4078. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  4079. }
  4080. } else { //月结
  4081. start_time_str := c.GetString("start_time")
  4082. end_time_str := c.GetString("end_time")
  4083. timeLayout := "2006-01-02"
  4084. loc, _ := time.LoadLocation("Local")
  4085. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  4086. if err != nil {
  4087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4088. return
  4089. }
  4090. recordStartTime := theStartTime.Unix()
  4091. start_time = recordStartTime
  4092. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  4093. if err != nil {
  4094. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4095. return
  4096. }
  4097. recordEndTime := theEndTime.Unix()
  4098. end_time = recordEndTime
  4099. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  4100. }
  4101. timestamp := time.Now().Unix()
  4102. tempTime := time.Unix(timestamp, 0)
  4103. timeFormat := tempTime.Format("20060102150405")
  4104. chrgBchno := rand.Intn(100000) + 10000
  4105. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  4106. strconv.FormatInt(his.PatientId, 10)
  4107. var ids []int64
  4108. for _, item := range prescriptions {
  4109. ids = append(ids, item.ID)
  4110. }
  4111. var total float64
  4112. for _, item := range prescriptions {
  4113. fmt.Println(item)
  4114. if item.Type == 1 { //药品
  4115. for _, subItem := range item.HisDoctorAdviceInfo {
  4116. total = total + (subItem.Price * subItem.PrescribingNumber)
  4117. }
  4118. }
  4119. if item.Type == 2 { //项目
  4120. for _, subItem := range item.HisPrescriptionProject {
  4121. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4122. total = total + (subItem.Price * cnt)
  4123. }
  4124. }
  4125. for _, subItem := range item.HisAdditionalCharge {
  4126. total = total + (subItem.Price * float64(subItem.Count))
  4127. }
  4128. }
  4129. if reg_type == 1111 || reg_type == 1112 {
  4130. reg_type = 11
  4131. }
  4132. tm := time.Unix(time.Now().Unix(), 0)
  4133. allTotal := fmt.Sprintf("%.4f", total)
  4134. totals, _ := strconv.ParseFloat(allTotal, 64)
  4135. order := &models.HisOrder{
  4136. UserOrgId: adminUser.CurrentOrgId,
  4137. HisPatientId: his.ID,
  4138. PatientId: id,
  4139. SettleAccountsDate: recordDateTime,
  4140. Ctime: time.Now().Unix(),
  4141. Mtime: time.Now().Unix(),
  4142. Status: 1,
  4143. OrderStatus: 2,
  4144. MdtrtId: his.Number,
  4145. Number: chrg_bchno,
  4146. MedfeeSumamt: totals,
  4147. PayWay: pay_way,
  4148. PayPrice: pay_price,
  4149. MedType: strconv.Itoa(int(reg_type)),
  4150. PayCardNo: pay_card_no,
  4151. DiscountPrice: discount_price,
  4152. PreferentialPrice: preferential_price,
  4153. RealityPrice: reality_price,
  4154. FoundPrice: found_price,
  4155. MedicalInsurancePrice: medical_insurance_price,
  4156. PrivatePrice: private_price,
  4157. SettleEndTime: end_time,
  4158. SettleStartTime: start_time,
  4159. SettleType: settle_accounts_type,
  4160. FaPiaoCode: fapiao_code,
  4161. FaPiaoNumber: fapiao_number,
  4162. Diagnosis: diagnosis_id,
  4163. PType: 2,
  4164. SetlTime: tm.Format("2006-01-02 15:04:05"),
  4165. }
  4166. err = service.CreateOrder(order)
  4167. if err != nil {
  4168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4169. return
  4170. }
  4171. var customs []*Custom
  4172. for _, item := range prescriptions {
  4173. if item.Type == 1 { //药品
  4174. for _, subItem := range item.HisDoctorAdviceInfo {
  4175. cus := &Custom{
  4176. AdviceId: subItem.ID,
  4177. ProjectId: 0,
  4178. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  4179. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  4180. FeedetlSn: subItem.FeedetlSn,
  4181. Price: fmt.Sprintf("%.2f", subItem.Price),
  4182. MedListCodg: subItem.MedListCodg,
  4183. Type: 1,
  4184. }
  4185. customs = append(customs, cus)
  4186. }
  4187. }
  4188. if item.Type == 2 { //项目
  4189. for _, subItem := range item.HisPrescriptionProject {
  4190. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4191. cus := &Custom{
  4192. AdviceId: 0,
  4193. ProjectId: subItem.ID,
  4194. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  4195. Cut: fmt.Sprintf("%.4f", cnt),
  4196. FeedetlSn: subItem.FeedetlSn,
  4197. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  4198. MedListCodg: subItem.MedListCodg,
  4199. Type: 2,
  4200. }
  4201. customs = append(customs, cus)
  4202. }
  4203. }
  4204. for _, item := range item.HisAdditionalCharge {
  4205. cus := &Custom{
  4206. ItemId: item.ID,
  4207. AdviceId: 0,
  4208. ProjectId: 0,
  4209. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  4210. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  4211. FeedetlSn: item.FeedetlSn,
  4212. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  4213. MedListCodg: item.XtHisAddtionConfig.Code,
  4214. Type: 3,
  4215. }
  4216. customs = append(customs, cus)
  4217. }
  4218. }
  4219. for _, item := range customs {
  4220. var advice_id int64 = 0
  4221. var project_id int64 = 0
  4222. var item_id int64 = 0
  4223. var types int64 = 0
  4224. if item.Type == 1 {
  4225. advice_id = item.AdviceId
  4226. project_id = 0
  4227. item_id = 0
  4228. } else if item.Type == 2 {
  4229. advice_id = 0
  4230. item_id = 0
  4231. project_id = item.ProjectId
  4232. } else if item.Type == 3 {
  4233. advice_id = 0
  4234. item_id = item.ItemId
  4235. project_id = 0
  4236. }
  4237. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4238. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4239. pric, _ := strconv.ParseFloat(item.Price, 32)
  4240. info := &models.HisOrderInfo{
  4241. OrderNumber: order.Number,
  4242. UploadDate: time.Now().Unix(),
  4243. AdviceId: advice_id,
  4244. DetItemFeeSumamt: detItemFeeSumamt,
  4245. Cnt: cut,
  4246. Pric: pric,
  4247. PatientId: id,
  4248. Status: 1,
  4249. Mtime: time.Now().Unix(),
  4250. Ctime: time.Now().Unix(),
  4251. UserOrgId: adminUser.CurrentOrgId,
  4252. HisPatientId: his.ID,
  4253. OrderId: order.ID,
  4254. ProjectId: project_id,
  4255. Type: types,
  4256. ItemId: item_id,
  4257. }
  4258. service.CreateOrderInfo(info)
  4259. }
  4260. his.Diagnosis = diagnosis_id
  4261. his.SickType = sick_type
  4262. his.RegisterType = reg_type
  4263. his.MedicalTreatmentType = reg_type
  4264. service.UpdataHisPateint(&his)
  4265. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  4266. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  4267. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  4268. if err == nil {
  4269. c.ServeSuccessJSON(map[string]interface{}{
  4270. "msg": "结算成功",
  4271. })
  4272. }
  4273. } else {
  4274. if tempOrder.IsPre > 0 {
  4275. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  4276. totals, _ := strconv.ParseFloat(allTotal, 64)
  4277. tempOrder.OrderStatus = 2
  4278. tempOrder.PayWay = pay_way
  4279. tempOrder.PayPrice = pay_price
  4280. tempOrder.PayCardNo = pay_card_no
  4281. tempOrder.DiscountPrice = discount_price
  4282. tempOrder.PreferentialPrice = preferential_price
  4283. tempOrder.RealityPrice = reality_price
  4284. tempOrder.FoundPrice = found_price
  4285. tempOrder.MedicalInsurancePrice = medical_insurance_price
  4286. tempOrder.PrivatePrice = private_price
  4287. tempOrder.FaPiaoCode = fapiao_code
  4288. tempOrder.FaPiaoNumber = fapiao_number
  4289. tempOrder.PType = 2
  4290. tempOrder.MedfeeSumamt = totals
  4291. tempOrder.Diagnosis = diagnosis_id
  4292. err = service.SaveHisOrder(&tempOrder)
  4293. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  4294. if err != nil {
  4295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4296. return
  4297. }
  4298. if err == nil {
  4299. c.ServeSuccessJSON(map[string]interface{}{
  4300. "msg": "结算成功",
  4301. })
  4302. }
  4303. }
  4304. }
  4305. }
  4306. //退款
  4307. func (c *HisApiController) Refund() {
  4308. order_id, _ := c.GetInt64("order_id")
  4309. order, _ := service.GetHisOrderByID(order_id)
  4310. adminUser := c.GetAdminUserInfo()
  4311. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  4312. if err == nil {
  4313. c.ServeSuccessJSON(map[string]interface{}{
  4314. "msg": "退费成功",
  4315. })
  4316. } else {
  4317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4318. return
  4319. }
  4320. }
  4321. func (c *HisApiController) RefundNumber() {
  4322. his_patient_id, _ := c.GetInt64("id")
  4323. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4324. info.Status = 0
  4325. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  4326. if count > 0 {
  4327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  4328. return
  4329. }
  4330. err := service.SaveHisPatient(info)
  4331. if err == nil {
  4332. c.ServeSuccessJSON(map[string]interface{}{
  4333. "msg": "退号成功",
  4334. })
  4335. } else {
  4336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4337. return
  4338. }
  4339. }
  4340. func (this *HisApiController) AdditionalCharge() {
  4341. dataBody := make(map[string]interface{}, 0)
  4342. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4343. fmt.Println(err)
  4344. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  4345. patient_id := int64(dataBody["patient_id"].(float64))
  4346. medicineData, _ := dataBody["medicineData"].([]interface{})
  4347. adminUserInfo := this.GetAdminUserInfo()
  4348. orgId := adminUserInfo.CurrentOrgId
  4349. admin_user_id := adminUserInfo.AdminUser.Id
  4350. timeStr := time.Now().Format("2006-01-02")
  4351. timeLayout := "2006-01-02 15:04:05"
  4352. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  4353. timenow := timeStringToTime.Unix()
  4354. var additionalCharges []*models.HisAdditionalCharge
  4355. for _, item := range medicineData {
  4356. var randNum int
  4357. randNum = rand.Intn(10000) + 1000
  4358. timestamp := time.Now().Unix()
  4359. tempTime := time.Unix(timestamp, 0)
  4360. timeFormat := tempTime.Format("20060102150405")
  4361. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4362. items := item.(map[string]interface{})
  4363. money := items["price"].(string)
  4364. item_id_str := items["item_id"].(string)
  4365. name := items["name"].(string)
  4366. id_str := items["id"].(string)
  4367. moneys, _ := strconv.ParseInt(money, 10, 64)
  4368. monStr := strconv.FormatInt(moneys, 10)
  4369. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  4370. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  4371. id, _ := strconv.ParseInt(id_str, 10, 64)
  4372. additionalCharge := &models.HisAdditionalCharge{
  4373. ID: id,
  4374. HisPatientId: his_patient_id,
  4375. UserOrgId: orgId,
  4376. PatientId: patient_id,
  4377. RecordDate: timenow,
  4378. Price: monneyStr,
  4379. Status: 1,
  4380. ItemName: name,
  4381. ItemId: item_id,
  4382. AdminUserId: admin_user_id,
  4383. CreatedTime: time.Now().Unix(),
  4384. OrderStatus: 0,
  4385. PrescriptionNumber: "",
  4386. BatchNumber: "",
  4387. FeedetlSn: p_number,
  4388. }
  4389. service.CreateAdditionalCharge(additionalCharge)
  4390. additionalCharges = append(additionalCharges, additionalCharge)
  4391. }
  4392. this.ServeSuccessJSON(map[string]interface{}{
  4393. "msg": "添加成功",
  4394. "additional_charges": additionalCharges,
  4395. })
  4396. }
  4397. func (this *HisApiController) DeleteAddition() {
  4398. id, _ := this.GetInt64("id")
  4399. //TODO 需要判断是否已经结算
  4400. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  4401. if err == nil {
  4402. this.ServeSuccessJSON(map[string]interface{}{
  4403. "msg": "删除成功",
  4404. })
  4405. return
  4406. } else {
  4407. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4408. return
  4409. }
  4410. }
  4411. func (this *HisApiController) GetAdminUsers() {
  4412. adminUser := this.GetAdminUserInfo()
  4413. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  4414. this.ServeSuccessJSON(map[string]interface{}{
  4415. "doctors": doctors,
  4416. })
  4417. }
  4418. func (this *HisApiController) GetLastOrNextHisPrescription() {
  4419. change_type, _ := this.GetInt64("type", 0)
  4420. record_date := this.GetString("record_time")
  4421. patient_id, _ := this.GetInt64("patient_id", 0)
  4422. p_type, _ := this.GetInt64("p_type", 0)
  4423. timeLayout := "2006-01-02"
  4424. loc, _ := time.LoadLocation("Local")
  4425. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4426. record_time := theAdviceRecordTime.Unix()
  4427. adminUserInfo := this.GetAdminUserInfo()
  4428. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  4429. if err == nil {
  4430. if len(prescriptions) == 0 {
  4431. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4432. return
  4433. } else {
  4434. this.ServeSuccessJSON(map[string]interface{}{
  4435. "prescriptions": prescriptions,
  4436. })
  4437. return
  4438. }
  4439. } else {
  4440. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4441. return
  4442. }
  4443. }
  4444. func (this *HisApiController) GetCallHisPrescription() {
  4445. patient_id, _ := this.GetInt64("patient_id", 0)
  4446. timeLayout := "2006-01-02"
  4447. loc, _ := time.LoadLocation("Local")
  4448. start_time := this.GetString("start_time")
  4449. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4450. end_time := this.GetString("end_time")
  4451. p_type, _ := this.GetInt64("p_type")
  4452. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4453. adminUserInfo := this.GetAdminUserInfo()
  4454. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  4455. if err == nil {
  4456. this.ServeSuccessJSON(map[string]interface{}{
  4457. "prescriptions": prescriptions,
  4458. })
  4459. return
  4460. } else {
  4461. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4462. return
  4463. }
  4464. }
  4465. func (this *HisApiController) GetHisDayPrescription() {
  4466. timeLayout := "2006-01-02"
  4467. loc, _ := time.LoadLocation("Local")
  4468. start_time := this.GetString("start_time")
  4469. patient_id, _ := this.GetInt64("patient_id", 0)
  4470. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4471. end_time := this.GetString("end_time")
  4472. p_type, _ := this.GetInt64("p_type")
  4473. order_status, _ := this.GetInt64("type")
  4474. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4475. adminUserInfo := this.GetAdminUserInfo()
  4476. var dayHisPrescription []*models.HisPrescription
  4477. var err error
  4478. if order_status == 1 || order_status == 0 {
  4479. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4480. } else if order_status == 2 {
  4481. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4482. }
  4483. var settle_total float64
  4484. for _, item := range dayHisPrescription {
  4485. if len(item.HisPrescriptionProject) > 0 {
  4486. for _, subItem := range item.HisPrescriptionProject {
  4487. count, _ := strconv.ParseFloat(subItem.Count, 64)
  4488. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  4489. settle_total = settle_total + total
  4490. }
  4491. }
  4492. if len(item.HisDoctorAdviceInfo) > 0 {
  4493. for _, subItem := range item.HisDoctorAdviceInfo {
  4494. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  4495. settle_total = settle_total + total
  4496. }
  4497. }
  4498. }
  4499. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  4500. if err == nil {
  4501. this.ServeSuccessJSON(map[string]interface{}{
  4502. "day_prescription": dayHisPrescription,
  4503. "settle_total": settle_total,
  4504. })
  4505. return
  4506. } else {
  4507. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4508. return
  4509. }
  4510. }
  4511. func (c *HisApiController) GetHisChargePatientList() {
  4512. record_date := c.GetString("record_date")
  4513. order_status, _ := c.GetInt64("type")
  4514. timeLayout := "2006-01-02"
  4515. loc, _ := time.LoadLocation("Local")
  4516. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4517. if err != nil {
  4518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4519. return
  4520. }
  4521. recordDateTime := theTime.Unix()
  4522. adminInfo := c.GetAdminUserInfo()
  4523. var tempPatients []*service.NewTempPatients
  4524. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4525. if order_status != 2 {
  4526. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4527. } else {
  4528. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4529. }
  4530. var patients []*service.NewTempPatients
  4531. var patients_two []*service.NewTempPatients
  4532. for _, item := range tempPatients {
  4533. //过滤掉没挂号的和没开处方的
  4534. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  4535. patients = append(patients, item)
  4536. }
  4537. //过滤掉没挂号的
  4538. if len(item.HisPatient) > 0 {
  4539. patients_two = append(patients_two, item)
  4540. }
  4541. }
  4542. c.ServeSuccessJSON(map[string]interface{}{
  4543. "list": patients,
  4544. "list_two": patients_two,
  4545. })
  4546. }
  4547. func (c *HisApiController) GetHisUnRegisterPatientList() {
  4548. record_date := c.GetString("record_date")
  4549. timeLayout := "2006-01-02"
  4550. loc, _ := time.LoadLocation("Local")
  4551. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4552. if err != nil {
  4553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4554. return
  4555. }
  4556. recordDateTime := theTime.Unix()
  4557. adminUser := c.GetAdminUserInfo()
  4558. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  4559. var patients []*service.Patients
  4560. for _, item := range tempPatients {
  4561. if item.HisPatient.ID == 0 {
  4562. patients = append(patients, item)
  4563. }
  4564. }
  4565. c.ServeSuccessJSON(map[string]interface{}{
  4566. "list": patients,
  4567. //"list_two": patients_two,
  4568. })
  4569. }
  4570. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  4571. newArr = make([]*service.Patients, 0)
  4572. for i := 0; i < len(patient); i++ {
  4573. repeat := false
  4574. for j := i + 1; j < len(patient); j++ {
  4575. if patient[i].ID == patient[j].ID {
  4576. repeat = true
  4577. break
  4578. }
  4579. }
  4580. if !repeat {
  4581. newArr = append(newArr, patient[i])
  4582. }
  4583. }
  4584. return
  4585. }
  4586. func (c *HisApiController) GetHisChargePatientInfo() {
  4587. patient_id, _ := c.GetInt64("patient_id")
  4588. his_patient_id, _ := c.GetInt64("his_patient_id")
  4589. record_date := c.GetString("record_date")
  4590. //start_time := c.GetString("start_time")
  4591. //end_time := c.GetString("end_time")
  4592. order_status, _ := c.GetInt64("type", 0)
  4593. p_type, _ := c.GetInt64("p_type", 0)
  4594. order_id, _ := c.GetInt64("order_id", 0)
  4595. timeLayout := "2006-01-02"
  4596. loc, _ := time.LoadLocation("Local")
  4597. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4598. if err != nil {
  4599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4600. return
  4601. }
  4602. recordDateTime := theTime.Unix()
  4603. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4604. //if err != nil {
  4605. //
  4606. //}
  4607. //startRecordDateTime := startTime.Unix()
  4608. //
  4609. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4610. //if err != nil {
  4611. //
  4612. //}
  4613. //endRecordDateTime := endTime.Unix()
  4614. admin := c.GetAdminUserInfo()
  4615. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4616. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4617. var prescriptions []*models.HisPrescription
  4618. //var unChargeMonthPrescriptions []*models.HisPrescription
  4619. order, _ := service.GetHisOrderByID(order_id)
  4620. if order_status == 1 || order_status == 0 {
  4621. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  4622. } else if order_status == 2 {
  4623. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4624. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4625. }
  4626. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  4627. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4628. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4629. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  4630. //获取所有科室信息
  4631. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  4632. c.ServeSuccessJSON(map[string]interface{}{
  4633. "his_info": his_patient_info,
  4634. "xt_info": xt_patient_info,
  4635. "prescription": prescriptions,
  4636. "case_history": case_history,
  4637. "info": patientPrescriptionInfo,
  4638. "last_info": lastPatientPrescriptionInfo,
  4639. "order": order,
  4640. "doctors": doctors,
  4641. "department": department,
  4642. })
  4643. return
  4644. }
  4645. func (c *HisApiController) GetAllOrderDetail() {
  4646. order_id, _ := c.GetInt64("id", 0)
  4647. order, _ := service.GetHisOrderByID(order_id)
  4648. if order.ID == 0 {
  4649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4650. return
  4651. }
  4652. org_id := c.GetAdminUserInfo().CurrentOrgId
  4653. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4654. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4655. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4656. c.ServeSuccessJSON(map[string]interface{}{
  4657. "order": order,
  4658. "order_info": order_info,
  4659. "patient": patient,
  4660. "admin_info": adminInfo,
  4661. })
  4662. return
  4663. }
  4664. func (c *HisApiController) GetAllOrderDetailCollect() {
  4665. order_id, _ := c.GetInt64("id", 0)
  4666. order, _ := service.GetHisOrderByID(order_id)
  4667. if order.ID == 0 {
  4668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4669. return
  4670. }
  4671. org_id := c.GetAdminUserInfo().CurrentOrgId
  4672. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4673. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4674. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4675. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  4676. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  4677. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  4678. var bedCostTotal float64 = 0 //床位总费
  4679. //var bedCostSelfTotal float64 = 0 //床位自费
  4680. var operationCostTotal float64 = 0 //手术费
  4681. //var operationCostSelfTotal float64 = 0 //手术费
  4682. var otherCostTotal float64 = 0 //其他费用
  4683. //var otherCostSelfTotal float64 = 0 //其他费用
  4684. var materialCostTotal float64 = 0 //材料费
  4685. //var materialCostSelfTotal float64 = 0 //材料费
  4686. var westernMedicineCostTotal float64 = 0 //西药费
  4687. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  4688. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4689. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4690. var checkCostTotal float64 = 0 //检查费
  4691. //var checkCostSelfTotal float64 = 0 //检查费
  4692. var laboratoryCostTotal float64 = 0 //化验费
  4693. //var laboratoryCostSelfTotal float64 = 0 //化验费
  4694. var treatCostTotal float64 = 0 //治疗费用
  4695. //var treatCostSelfTotal float64 = 0 //治疗费用
  4696. var zhenChaCostTotal float64 = 0 //其他费用
  4697. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  4698. decimal.DivisionPrecision = 2
  4699. if his.BalanceAccountsType != 2 {
  4700. for _, item := range order_info {
  4701. if item.MedChrgitmType == "01" { //床位费
  4702. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4703. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4704. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4705. }
  4706. if item.MedChrgitmType == "02" { //诊察费
  4707. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4708. //zhenChaCostSelfTotal = zhenChaCostTotal
  4709. }
  4710. if item.MedChrgitmType == "03" { //检查费
  4711. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4712. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4713. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4714. }
  4715. if item.MedChrgitmType == "02" { //检查费
  4716. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4717. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4718. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4719. }
  4720. if item.MedChrgitmType == "04" { //化验费
  4721. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4722. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4723. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4724. }
  4725. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4726. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4727. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4728. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4729. }
  4730. if item.MedChrgitmType == "06" { //手术费
  4731. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4732. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4733. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4734. }
  4735. if item.MedChrgitmType == "08" { //材料费
  4736. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4737. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4738. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4739. }
  4740. if item.MedChrgitmType == "09" { //西药费
  4741. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4742. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4743. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4744. }
  4745. if item.MedChrgitmType == "11" { //中成费
  4746. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4747. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4748. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4749. }
  4750. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  4751. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4752. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4753. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4754. }
  4755. }
  4756. c.ServeSuccessJSON(map[string]interface{}{
  4757. "order": order,
  4758. "order_info": order_info,
  4759. "patient": patient,
  4760. "admin_info": adminInfo,
  4761. "his_hospital": record,
  4762. "bedCostTotal": bedCostTotal,
  4763. "operationCostTotal": operationCostTotal,
  4764. "otherCostTotal": otherCostTotal,
  4765. "materialCostTotal": materialCostTotal,
  4766. "westernMedicineCostTotal": westernMedicineCostTotal,
  4767. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4768. "checkCostTotal": checkCostTotal,
  4769. "zhenChaCostTotal": zhenChaCostTotal,
  4770. "laboratoryCostTotal": laboratoryCostTotal,
  4771. "treatCostTotal": treatCostTotal,
  4772. })
  4773. } else {
  4774. for _, item := range order_info {
  4775. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  4776. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  4777. item.MedChrgitmType = "09"
  4778. }
  4779. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  4780. if item.HisPrescriptionProject.Type == 2 {
  4781. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  4782. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  4783. case 0:
  4784. item.MedChrgitmType = "0"
  4785. break
  4786. case 1:
  4787. item.MedChrgitmType = "14"
  4788. break
  4789. case 2:
  4790. item.MedChrgitmType = "05"
  4791. break
  4792. case 3:
  4793. item.MedChrgitmType = "03"
  4794. break
  4795. case 4:
  4796. item.MedChrgitmType = "03"
  4797. break
  4798. case 5:
  4799. item.MedChrgitmType = "08"
  4800. break
  4801. case 6:
  4802. item.MedChrgitmType = "14"
  4803. break
  4804. case 7:
  4805. item.MedChrgitmType = "14"
  4806. break
  4807. case 8:
  4808. item.MedChrgitmType = "03"
  4809. break
  4810. case 9:
  4811. item.MedChrgitmType = "14"
  4812. break
  4813. case 10:
  4814. item.MedChrgitmType = "14"
  4815. break
  4816. case 11:
  4817. item.MedChrgitmType = "06"
  4818. break
  4819. case 12:
  4820. item.MedChrgitmType = "12"
  4821. break
  4822. case 13:
  4823. item.MedChrgitmType = "01"
  4824. break
  4825. case 14:
  4826. item.MedChrgitmType = "04"
  4827. break
  4828. case 15:
  4829. item.MedChrgitmType = "14"
  4830. break
  4831. }
  4832. } else {
  4833. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  4834. case 1:
  4835. item.MedChrgitmType = "14"
  4836. break
  4837. case 2:
  4838. item.MedChrgitmType = "05"
  4839. break
  4840. case 3:
  4841. item.MedChrgitmType = "04"
  4842. break
  4843. case 4:
  4844. item.MedChrgitmType = "14"
  4845. break
  4846. case 5:
  4847. item.MedChrgitmType = "08"
  4848. break
  4849. case 6:
  4850. item.MedChrgitmType = "14"
  4851. break
  4852. case 7:
  4853. item.MedChrgitmType = "14"
  4854. break
  4855. case 8:
  4856. item.MedChrgitmType = "03"
  4857. break
  4858. case 9:
  4859. item.MedChrgitmType = "14"
  4860. break
  4861. }
  4862. }
  4863. } else if item.HisPrescriptionProject.Type == 3 {
  4864. item.MedChrgitmType = "08"
  4865. }
  4866. }
  4867. }
  4868. c.ServeSuccessJSON(map[string]interface{}{
  4869. "order": order,
  4870. "order_info": order_info,
  4871. "patient": patient,
  4872. "admin_info": adminInfo,
  4873. "his_hospital": record,
  4874. "bedCostTotal": bedCostTotal,
  4875. "operationCostTotal": operationCostTotal,
  4876. "otherCostTotal": otherCostTotal,
  4877. "materialCostTotal": materialCostTotal,
  4878. "westernMedicineCostTotal": westernMedicineCostTotal,
  4879. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4880. "checkCostTotal": checkCostTotal,
  4881. "zhenChaCostTotal": zhenChaCostTotal,
  4882. "laboratoryCostTotal": laboratoryCostTotal,
  4883. "treatCostTotal": treatCostTotal,
  4884. })
  4885. }
  4886. }
  4887. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  4888. page, _ := c.GetInt64("page")
  4889. limit, _ := c.GetInt64("limit")
  4890. keywords := c.GetString("keywords")
  4891. start_time := c.GetString("start_time")
  4892. end_time := c.GetString("end_time")
  4893. //clr_type := c.GetString("clr_type")
  4894. insutype := c.GetString("insutype")
  4895. timeLayout := "2006-01-02"
  4896. loc, _ := time.LoadLocation("Local")
  4897. var theStartTIme int64
  4898. if len(start_time) > 0 {
  4899. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4900. theStartTIme = theTime.Unix()
  4901. }
  4902. var theEndtTIme int64
  4903. if len(end_time) > 0 {
  4904. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4905. theEndtTIme = theTime.Unix()
  4906. }
  4907. if page <= 0 {
  4908. page = 1
  4909. }
  4910. if limit <= 0 {
  4911. limit = 10
  4912. }
  4913. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  4914. c.ServeSuccessJSON(map[string]interface{}{
  4915. "total": total,
  4916. "list": list,
  4917. })
  4918. return
  4919. }
  4920. func (c *HisApiController) GetPutOnRecordList() {
  4921. page, _ := c.GetInt64("page")
  4922. limit, _ := c.GetInt64("limit")
  4923. keywords := c.GetString("keywords")
  4924. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  4925. if page <= 0 {
  4926. page = 1
  4927. }
  4928. if limit <= 0 {
  4929. limit = 10
  4930. }
  4931. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  4932. c.ServeSuccessJSON(map[string]interface{}{
  4933. "total": total,
  4934. "list": list,
  4935. })
  4936. return
  4937. }
  4938. func (c *HisApiController) GetCompareData() {
  4939. start_time := c.GetString("start_time")
  4940. end_time := c.GetString("end_time")
  4941. insutype := c.GetString("insutype")
  4942. clr_type := c.GetString("clr_type")
  4943. timeLayout := "2006-01-02"
  4944. loc, _ := time.LoadLocation("Local")
  4945. var theStartTIme int64
  4946. if len(start_time) > 0 {
  4947. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4948. if err != nil {
  4949. theStartTIme = 0
  4950. }
  4951. theStartTIme = theTime.Unix()
  4952. }
  4953. var theEndtTIme int64
  4954. if len(end_time) > 0 {
  4955. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4956. if err != nil {
  4957. theEndtTIme = 0
  4958. }
  4959. theEndtTIme = theTime.Unix()
  4960. }
  4961. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  4962. fmt.Println(err)
  4963. if err == nil {
  4964. c.ServeSuccessJSON(map[string]interface{}{
  4965. "list": formData,
  4966. })
  4967. } else {
  4968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4969. return
  4970. }
  4971. }
  4972. func (c *HisApiController) GetFaPiaoData() {
  4973. order_id, _ := c.GetInt64("order_id")
  4974. patient_id, _ := c.GetInt64("patient_id")
  4975. number := c.GetString("number")
  4976. adminUser := c.GetAdminUserInfo()
  4977. order, _ := service.GetHisOrderByID(order_id)
  4978. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4979. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  4980. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4981. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  4982. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  4983. //prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
  4984. var bedCostTotal float64 = 0 //床位总费
  4985. var bedCostSelfTotal float64 = 0 //床位自费
  4986. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  4987. var operationCostTotal float64 = 0 //手术费
  4988. var operationCostSelfTotal float64 = 0 //手术费
  4989. var operationCostPartSelfTotal float64 = 0 //手术费
  4990. var otherCostTotal float64 = 0 //其他费用
  4991. var otherCostSelfTotal float64 = 0 //其他费用
  4992. var otherCostPartSelfTotal float64 = 0 //其他费用
  4993. var materialCostTotal float64 = 0 //材料费
  4994. var materialCostSelfTotal float64 = 0 //材料费
  4995. var materialCostPartSelfTotal float64 = 0 //材料费
  4996. var westernMedicineCostTotal float64 = 0 //西药费
  4997. var westernMedicineCostSelfTotal float64 = 0 //西药费
  4998. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  4999. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  5000. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  5001. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  5002. var checkCostTotal float64 = 0 //检查费
  5003. var checkCostSelfTotal float64 = 0 //检查费
  5004. var checkCostPartSelfTotal float64 = 0 //检查费
  5005. var laboratoryCostTotal float64 = 0 //化验费
  5006. var laboratoryCostSelfTotal float64 = 0 //化验费
  5007. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  5008. var treatCostTotal float64 = 0 //治疗费用
  5009. var treatCostSelfTotal float64 = 0 //治疗费用
  5010. var treatCostPartSelfTotal float64 = 0 //治疗费用
  5011. var zhenChaCostTotal float64 = 0 //其他费用
  5012. var zhenChaCostSelfTotal float64 = 0 //其他费用
  5013. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  5014. decimal.DivisionPrecision = 2
  5015. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5016. var balanceAccountsType int64
  5017. if his.ID > 0 {
  5018. balanceAccountsType = his.BalanceAccountsType
  5019. } else {
  5020. balanceAccountsType = his_hospital_record.BalanceAccountsType
  5021. }
  5022. if balanceAccountsType == 2 {
  5023. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5024. for _, item := range orderInfos_two {
  5025. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  5026. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  5027. item.MedChrgitmType = "09"
  5028. }
  5029. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  5030. if item.HisPrescriptionProject.Type == 2 {
  5031. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5032. fmt.Println("CostClassify")
  5033. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  5034. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5035. case 0:
  5036. item.MedChrgitmType = "0"
  5037. break
  5038. case 1:
  5039. item.MedChrgitmType = "14"
  5040. break
  5041. case 2:
  5042. item.MedChrgitmType = "05"
  5043. break
  5044. case 3:
  5045. item.MedChrgitmType = "03"
  5046. break
  5047. case 4:
  5048. item.MedChrgitmType = "03"
  5049. break
  5050. case 5:
  5051. item.MedChrgitmType = "08"
  5052. break
  5053. case 6:
  5054. item.MedChrgitmType = "14"
  5055. break
  5056. case 7:
  5057. item.MedChrgitmType = "14"
  5058. break
  5059. case 8:
  5060. item.MedChrgitmType = "03"
  5061. break
  5062. case 9:
  5063. item.MedChrgitmType = "14"
  5064. break
  5065. case 10:
  5066. item.MedChrgitmType = "14"
  5067. break
  5068. case 11:
  5069. item.MedChrgitmType = "06"
  5070. break
  5071. case 12:
  5072. item.MedChrgitmType = "12"
  5073. break
  5074. case 13:
  5075. item.MedChrgitmType = "01"
  5076. break
  5077. case 14:
  5078. item.MedChrgitmType = "04"
  5079. break
  5080. case 15:
  5081. item.MedChrgitmType = "02"
  5082. break
  5083. }
  5084. } else {
  5085. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5086. case 1:
  5087. item.MedChrgitmType = "14"
  5088. break
  5089. case 2:
  5090. item.MedChrgitmType = "05"
  5091. break
  5092. case 3:
  5093. item.MedChrgitmType = "03"
  5094. break
  5095. case 4:
  5096. item.MedChrgitmType = "03"
  5097. break
  5098. case 5:
  5099. item.MedChrgitmType = "08"
  5100. break
  5101. case 6:
  5102. item.MedChrgitmType = "14"
  5103. break
  5104. case 7:
  5105. item.MedChrgitmType = "14"
  5106. break
  5107. case 8:
  5108. item.MedChrgitmType = "03"
  5109. break
  5110. case 9:
  5111. item.MedChrgitmType = "14"
  5112. break
  5113. }
  5114. }
  5115. } else if item.HisPrescriptionProject.Type == 3 {
  5116. item.MedChrgitmType = "08"
  5117. }
  5118. }
  5119. }
  5120. for _, item := range orderInfos_two {
  5121. fmt.Println(item.MedChrgitmType)
  5122. if item.MedChrgitmType == "01" { //床位费
  5123. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5124. bedCostSelfTotal = bedCostTotal
  5125. }
  5126. if item.MedChrgitmType == "02" { //诊察费
  5127. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5128. zhenChaCostSelfTotal = zhenChaCostTotal
  5129. }
  5130. if item.MedChrgitmType == "03" { //检查费
  5131. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5132. checkCostSelfTotal = checkCostTotal
  5133. }
  5134. if item.MedChrgitmType == "04" { //化验费
  5135. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5136. laboratoryCostSelfTotal = laboratoryCostTotal
  5137. }
  5138. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  5139. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5140. treatCostSelfTotal = treatCostTotal
  5141. }
  5142. if item.MedChrgitmType == "06" { //手术费
  5143. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5144. operationCostSelfTotal = treatCostTotal
  5145. }
  5146. if item.MedChrgitmType == "08" { //材料费
  5147. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5148. materialCostSelfTotal = materialCostTotal
  5149. }
  5150. if item.MedChrgitmType == "09" { //西药费
  5151. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5152. westernMedicineCostSelfTotal = westernMedicineCostTotal
  5153. }
  5154. if item.MedChrgitmType == "11" { //中成费
  5155. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5156. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  5157. }
  5158. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5159. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5160. otherCostSelfTotal = otherCostTotal
  5161. }
  5162. }
  5163. } else {
  5164. for _, item := range orderInfos {
  5165. if item.MedChrgitmType == "01" { //床位费
  5166. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5167. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5168. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5169. }
  5170. if item.MedChrgitmType == "02" { //诊察费
  5171. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5172. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5173. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5174. }
  5175. if item.MedChrgitmType == "03" { //检查费
  5176. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5177. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5178. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5179. }
  5180. if item.MedChrgitmType == "04" { //化验费
  5181. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5182. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5183. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5184. }
  5185. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5186. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5187. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5188. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5189. }
  5190. if item.MedChrgitmType == "06" { //手术费
  5191. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5192. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5193. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5194. }
  5195. if item.MedChrgitmType == "08" { //材料费
  5196. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5197. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5198. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5199. }
  5200. if item.MedChrgitmType == "09" { //西药费
  5201. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5202. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5203. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5204. }
  5205. if item.MedChrgitmType == "11" { //中成费
  5206. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5207. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5208. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5209. }
  5210. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5211. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5212. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5213. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5214. }
  5215. }
  5216. }
  5217. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  5218. c.ServeSuccessJSON(map[string]interface{}{
  5219. "order_number": order.Number, //业务流水号
  5220. "id_card_no": his.IdCardNo, //社会保障号
  5221. "department_name": department.Name, //科室
  5222. "number": his.Number, //门诊号
  5223. "date": order.SettleAccountsDate, //结算日期
  5224. "name": order.PsnName, //姓名
  5225. "gender": order.Gend, //性别
  5226. "psn_cash_money": order.PsnCashPay, //个人支付
  5227. "pay_way": "门诊", //结算方式
  5228. "medfee_sumamt": order.MedfeeSumamt, //总费用
  5229. "admin_user_name": admin.UserName, //收款员
  5230. "order": order,
  5231. "order_info": orderInfos_two,
  5232. "his": his,
  5233. "bedCostTotal": bedCostTotal,
  5234. "bedCostSelfTotal": bedCostSelfTotal,
  5235. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  5236. "operationCostTotal": operationCostTotal,
  5237. "operationCostSelfTotal": operationCostSelfTotal,
  5238. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  5239. "otherCostTotal": otherCostTotal,
  5240. "otherCostSelfTotal": otherCostSelfTotal,
  5241. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  5242. "materialCostTotal": materialCostTotal,
  5243. "materialCostSelfTotal": materialCostSelfTotal,
  5244. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  5245. "westernMedicineCostTotal": westernMedicineCostTotal,
  5246. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  5247. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  5248. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5249. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  5250. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  5251. "checkCostTotal": checkCostTotal,
  5252. "checkCostSelfTotal": checkCostSelfTotal,
  5253. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  5254. "laboratoryCostTotal": laboratoryCostTotal,
  5255. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  5256. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  5257. "treatCostTotal": treatCostTotal,
  5258. "treatCostSelfTotal": treatCostSelfTotal,
  5259. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  5260. "zhenChaCostTotal": zhenChaCostTotal,
  5261. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  5262. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  5263. "his_hospital_record": his_hospital_record,
  5264. })
  5265. }
  5266. func (this *HisApiController) GetIncomeStatisticsData() {
  5267. start_time := this.GetString("start_time")
  5268. end_time := this.GetString("end_time")
  5269. key_words := this.GetString("key_words")
  5270. limit, _ := this.GetInt64("limit")
  5271. page, _ := this.GetInt64("page")
  5272. if page <= 0 {
  5273. page = 1
  5274. }
  5275. if limit <= 0 {
  5276. limit = 10
  5277. }
  5278. statistics_type, _ := this.GetInt64("statistics_type")
  5279. admin := this.GetAdminUserInfo()
  5280. timeLayout := "2006-01-02"
  5281. loc, _ := time.LoadLocation("Local")
  5282. var theStartTIme int64
  5283. if len(start_time) > 0 {
  5284. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5285. if err != nil {
  5286. theStartTIme = 0
  5287. }
  5288. theStartTIme = theTime.Unix()
  5289. }
  5290. var theEndtTIme int64
  5291. if len(end_time) > 0 {
  5292. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5293. if err != nil {
  5294. theEndtTIme = 0
  5295. }
  5296. theEndtTIme = theTime.Unix()
  5297. }
  5298. if statistics_type == 1 {
  5299. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5300. this.ServeSuccessJSON(map[string]interface{}{
  5301. "list": list,
  5302. "total": total,
  5303. })
  5304. } else {
  5305. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5306. this.ServeSuccessJSON(map[string]interface{}{
  5307. "list": list,
  5308. "total": total,
  5309. })
  5310. }
  5311. }
  5312. func (c *HisApiController) PostProjectInformation() {
  5313. adminUser := c.GetAdminUserInfo()
  5314. orgId := adminUser.CurrentOrgId
  5315. dataBody := make(map[string]interface{}, 0)
  5316. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5317. if err != nil {
  5318. utils.ErrorLog(err.Error())
  5319. return
  5320. }
  5321. utils.ErrorLog("%v", dataBody)
  5322. var projectList []*models.HisProject
  5323. var total_goods []interface{}
  5324. tempProjects := dataBody["projects"].([]interface{})
  5325. total_goods = tempProjects
  5326. for index, projectMap := range tempProjects {
  5327. projectM := projectMap.(map[string]interface{})
  5328. var project models.HisProject
  5329. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  5330. utils.ErrorLog("project_name")
  5331. return
  5332. }
  5333. project_name, _ := projectM["project_name"].(string)
  5334. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  5335. err_log := models.ExportErrLog{
  5336. LogType: 6,
  5337. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5338. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  5339. Status: 1,
  5340. CreateTime: time.Now().Unix(),
  5341. UpdateTime: time.Now().Unix(),
  5342. ExportTime: time.Now().Unix(),
  5343. }
  5344. service.CreateExportErrLog(&err_log)
  5345. continue
  5346. }
  5347. project.ProjectName = project_name
  5348. prices := projectM["price"].(string)
  5349. price, _ := strconv.ParseFloat(prices, 64)
  5350. if price <= 0 { //名字为空则生成一条导入错误日志
  5351. err_log := models.ExportErrLog{
  5352. LogType: 6,
  5353. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5354. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  5355. Status: 1,
  5356. CreateTime: time.Now().Unix(),
  5357. UpdateTime: time.Now().Unix(),
  5358. ExportTime: time.Now().Unix(),
  5359. }
  5360. service.CreateExportErrLog(&err_log)
  5361. continue
  5362. }
  5363. project.Price = price
  5364. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  5365. utils.ErrorLog("unit_id")
  5366. return
  5367. }
  5368. unit := projectM["unit"].(string)
  5369. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  5370. err_log := models.ExportErrLog{
  5371. LogType: 6,
  5372. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5373. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  5374. Status: 1,
  5375. CreateTime: time.Now().Unix(),
  5376. UpdateTime: time.Now().Unix(),
  5377. ExportTime: time.Now().Unix(),
  5378. }
  5379. service.CreateExportErrLog(&err_log)
  5380. continue
  5381. }
  5382. project.Unit = unit
  5383. cost_classify := projectM["cost_classify"].(string)
  5384. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  5385. err_log := models.ExportErrLog{
  5386. LogType: 6,
  5387. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5388. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5389. Status: 1,
  5390. CreateTime: time.Now().Unix(),
  5391. UpdateTime: time.Now().Unix(),
  5392. ExportTime: time.Now().Unix(),
  5393. }
  5394. service.CreateExportErrLog(&err_log)
  5395. continue
  5396. }
  5397. var costClassify = "费用类别"
  5398. var cost_classify_id int64
  5399. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  5400. if len(cost_classify) != 0 {
  5401. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  5402. if errcode == gorm.ErrRecordNotFound {
  5403. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  5404. dataconfig := models.DictDataconfig{
  5405. ParentId: costClassifyConfig.ID,
  5406. Module: "system",
  5407. OrgId: orgId,
  5408. Name: cost_classify,
  5409. FieldName: "",
  5410. Value: costConfig.Value + 1,
  5411. CreatedTime: "",
  5412. UpdatedTime: "",
  5413. CreateUserId: adminUser.AdminUser.Id,
  5414. Status: 1,
  5415. Remark: "",
  5416. DeleteIdSystem: 0,
  5417. Title: "",
  5418. Content: "",
  5419. Order: 0,
  5420. Code: "",
  5421. }
  5422. service.CreatedDicConfig(&dataconfig)
  5423. }
  5424. }
  5425. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  5426. for _, it := range costClassList {
  5427. if cost_classify == it.Name {
  5428. cost_classify_id = int64(it.Value)
  5429. }
  5430. }
  5431. project.CostClassify = cost_classify_id
  5432. executive_section := projectM["executive_section"].(string)
  5433. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  5434. err_log := models.ExportErrLog{
  5435. LogType: 6,
  5436. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5437. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  5438. Status: 1,
  5439. CreateTime: time.Now().Unix(),
  5440. UpdateTime: time.Now().Unix(),
  5441. ExportTime: time.Now().Unix(),
  5442. }
  5443. service.CreateExportErrLog(&err_log)
  5444. continue
  5445. }
  5446. if len(executive_section) != 0 {
  5447. //查找科室是否有内容
  5448. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  5449. if errcodedepart == gorm.ErrRecordNotFound {
  5450. department := models.XtHisDepartment{
  5451. Name: executive_section,
  5452. Status: 1,
  5453. UserOrgId: adminUser.CurrentOrgId,
  5454. CreatedTime: time.Now().Unix(),
  5455. }
  5456. service.CreateDePartment(&department)
  5457. }
  5458. }
  5459. var executive_section_id int64
  5460. departMentList, _ := service.GetAllDepartMent(orgId)
  5461. for _, it := range departMentList {
  5462. if executive_section == it.Name {
  5463. executive_section_id = it.ID
  5464. }
  5465. }
  5466. project.ExecutiveSection = executive_section_id
  5467. medical_coverage := projectM["medical_coverage"].(string)
  5468. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  5469. err_log := models.ExportErrLog{
  5470. LogType: 6,
  5471. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5472. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5473. Status: 1,
  5474. CreateTime: time.Now().Unix(),
  5475. UpdateTime: time.Now().Unix(),
  5476. ExportTime: time.Now().Unix(),
  5477. }
  5478. service.CreateExportErrLog(&err_log)
  5479. continue
  5480. }
  5481. var medicalCoverage = "医保等级"
  5482. var medical_coverage_id int64
  5483. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  5484. if len(medical_coverage) != 0 {
  5485. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  5486. if errormedicalcoverage == gorm.ErrRecordNotFound {
  5487. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  5488. dataconfig := models.DictDataconfig{
  5489. ParentId: medicalCoverageConfig.ID,
  5490. Module: "system",
  5491. OrgId: orgId,
  5492. Name: medical_coverage,
  5493. FieldName: "",
  5494. Value: medicalCoverageConfig.Value + 1,
  5495. CreatedTime: "",
  5496. UpdatedTime: "",
  5497. CreateUserId: adminUser.AdminUser.Id,
  5498. Status: 1,
  5499. Remark: "",
  5500. DeleteIdSystem: 0,
  5501. Title: "",
  5502. Content: "",
  5503. Order: 0,
  5504. Code: "",
  5505. }
  5506. service.CreatedDicConfig(&dataconfig)
  5507. }
  5508. }
  5509. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  5510. for _, it := range medicalCoverageList {
  5511. if medical_coverage == it.Name {
  5512. medical_coverage_id = int64(it.Value)
  5513. }
  5514. }
  5515. project.MedicalCoverage = medical_coverage_id
  5516. pinyin := projectM["pinyin"].(string)
  5517. project.Pinyin = pinyin
  5518. wubi := projectM["wubi"].(string)
  5519. project.Wubi = wubi
  5520. statistical_classification := projectM["statistical_classification"].(string)
  5521. var statisticalClassification = "统计分类"
  5522. var statistical_classification_id int64
  5523. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  5524. if len(statistical_classification) != 0 {
  5525. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  5526. if classificationerrcodes == gorm.ErrRecordNotFound {
  5527. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  5528. dataconfig := models.DictDataconfig{
  5529. ParentId: classiFication.ID,
  5530. Module: "system",
  5531. OrgId: orgId,
  5532. Name: statistical_classification,
  5533. FieldName: "",
  5534. Value: classiFicationConfig.Value + 1,
  5535. CreatedTime: "",
  5536. UpdatedTime: "",
  5537. CreateUserId: adminUser.AdminUser.Id,
  5538. Status: 1,
  5539. Remark: "",
  5540. DeleteIdSystem: 0,
  5541. Title: "",
  5542. Content: "",
  5543. Order: 0,
  5544. Code: "",
  5545. }
  5546. service.CreatedDicConfig(&dataconfig)
  5547. }
  5548. }
  5549. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  5550. for _, it := range classiFicationList {
  5551. if statistical_classification == it.Name {
  5552. statistical_classification_id = int64(it.Value)
  5553. }
  5554. }
  5555. project.StatisticalClassification = statistical_classification_id
  5556. disease_directory := int64(projectM["disease_directory"].(float64))
  5557. project.DiseaseDirectory = disease_directory
  5558. is_record := int64(projectM["is_record"].(float64))
  5559. project.IsRecord = is_record
  5560. medical_code := projectM["medical_code"].(string)
  5561. project.MedicalCode = medical_code
  5562. tube_color := projectM["tube_color"].(string)
  5563. var tubeColor = "试管颜色"
  5564. var tube_color_id int64
  5565. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  5566. if len(tube_color) != 0 {
  5567. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  5568. if errcodetube == gorm.ErrRecordNotFound {
  5569. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  5570. dataconfig := models.DictDataconfig{
  5571. ParentId: tubeColorConfig.ID,
  5572. Module: "system",
  5573. OrgId: orgId,
  5574. Name: tube_color,
  5575. FieldName: "",
  5576. Value: tubeConfig.Value + 1,
  5577. CreatedTime: "",
  5578. UpdatedTime: "",
  5579. CreateUserId: adminUser.AdminUser.Id,
  5580. Status: 1,
  5581. Remark: "",
  5582. DeleteIdSystem: 0,
  5583. Title: "",
  5584. Content: "",
  5585. Order: 0,
  5586. Code: "",
  5587. }
  5588. service.CreatedDicConfig(&dataconfig)
  5589. }
  5590. }
  5591. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  5592. for _, it := range tubeColorList {
  5593. if tube_color == it.Name {
  5594. tube_color_id = int64(it.Value)
  5595. }
  5596. }
  5597. project.TubeColor = tube_color_id
  5598. single_dose := projectM["single_dose"].(string)
  5599. project.SingleDose = single_dose
  5600. execution_frequency := projectM["execution_frequency"].(string)
  5601. project.ExecutionFrequency = execution_frequency
  5602. delivery_way := projectM["delivery_way"].(string)
  5603. project.DeliveryWay = delivery_way
  5604. number_days := projectM["number_days"].(string)
  5605. project.NumberDays = number_days
  5606. total := projectM["total"].(string)
  5607. project.Total = total
  5608. medical_status := int64(projectM["medical_status"].(float64))
  5609. project.MedicalStatus = medical_status
  5610. category := int64(projectM["category"].(float64))
  5611. project.Category = category
  5612. specail_project := int64(projectM["specail_project"].(float64))
  5613. project.SpecailProject = specail_project
  5614. social_security_directory_code := projectM["social_security_directory_code"].(string)
  5615. project.SocialSecurityDirectoryCode = social_security_directory_code
  5616. remark := projectM["remark"].(string)
  5617. project.Remark = remark
  5618. record_date := projectM["record_date"].(string)
  5619. timeLayout := "2006-01-02"
  5620. loc, _ := time.LoadLocation("Local")
  5621. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5622. project.RecordDate = theTime.Unix()
  5623. projectList = append(projectList, &project)
  5624. }
  5625. export_time := time.Now().Unix()
  5626. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5627. if len(projectList) > 0 {
  5628. for _, item := range projectList {
  5629. project := models.HisProject{
  5630. ProjectName: item.ProjectName,
  5631. Price: item.Price,
  5632. Unit: item.Unit,
  5633. CostClassify: item.CostClassify,
  5634. ExecutiveSection: item.ExecutiveSection,
  5635. MedicalCoverage: item.MedicalCoverage,
  5636. UserOrgId: orgId,
  5637. Status: 1,
  5638. CreatedTime: time.Now().Unix(),
  5639. Pinyin: item.Pinyin,
  5640. Wubi: item.Wubi,
  5641. StatisticalClassification: item.StatisticalClassification,
  5642. DiseaseDirectory: item.DiseaseDirectory,
  5643. IsRecord: item.IsRecord,
  5644. MedicalCode: item.MedicalCode,
  5645. TubeColor: item.TubeColor,
  5646. SingleDose: item.SingleDose,
  5647. DeliveryWay: item.DeliveryWay,
  5648. NumberDays: item.NumberDays,
  5649. Total: item.Total,
  5650. Category: item.Category,
  5651. MedicalStatus: item.MedicalStatus,
  5652. SpecailProject: item.SpecailProject,
  5653. RecordDate: item.RecordDate,
  5654. Remark: item.Remark,
  5655. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5656. ExecutionFrequency: item.ExecutionFrequency,
  5657. }
  5658. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  5659. if errcodeproject == gorm.ErrRecordNotFound {
  5660. service.CreateProjectInfomation(&project)
  5661. } else if errcodeproject == nil {
  5662. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  5663. }
  5664. log := models.ExportLog{
  5665. LogType: 6,
  5666. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5667. TotalNum: int64(len(total_goods)),
  5668. FailNum: int64(len(errLogs)),
  5669. SuccessNum: int64(len(projectList)),
  5670. CreateTime: time.Now().Unix(),
  5671. UpdateTime: time.Now().Unix(),
  5672. ExportTime: export_time,
  5673. Status: 1,
  5674. }
  5675. service.CreateExportLog(&log)
  5676. c.ServeSuccessJSON(map[string]interface{}{
  5677. "msg": "导入成功",
  5678. "total_num": len(total_goods),
  5679. "success_num": len(projectList),
  5680. "fail_num": int64(len(errLogs)),
  5681. })
  5682. }
  5683. } else {
  5684. log := models.ExportLog{
  5685. LogType: 6,
  5686. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5687. TotalNum: int64(len(total_goods)),
  5688. FailNum: int64(len(errLogs)),
  5689. SuccessNum: int64(len(projectList)),
  5690. CreateTime: time.Now().Unix(),
  5691. UpdateTime: time.Now().Unix(),
  5692. ExportTime: export_time,
  5693. Status: 1,
  5694. }
  5695. service.CreateExportLog(&log)
  5696. c.ServeSuccessJSON(map[string]interface{}{
  5697. "msg": "导入成功",
  5698. "total_num": len(total_goods),
  5699. "success_num": len(projectList),
  5700. "fail_num": int64(len(errLogs)),
  5701. })
  5702. }
  5703. }
  5704. //func (this *HisApiController) EditProjectInformation(){
  5705. //
  5706. // id, _ := this.GetInt64("id")
  5707. // project_team := this.GetString("project_team")
  5708. // price := this.GetString("price")
  5709. // price_float, _ := strconv.ParseFloat(price, 64)
  5710. // pinyin := this.GetString("pinyin")
  5711. // wubi := this.GetString("wubi")
  5712. // tube_color, _ := this.GetInt64("tube_color")
  5713. // team_type, _ := this.GetInt64("team_type")
  5714. // remark := this.GetString("remark")
  5715. // ids := this.GetString("ids")
  5716. // item_id := this.GetString("item_id")
  5717. // projectTeam := models.XtHisProjectTeam{
  5718. // ProjectTeam: project_team,
  5719. // Price: price_float,
  5720. // Pinyin: pinyin,
  5721. // Wubi: wubi,
  5722. // TubeColor: tube_color,
  5723. // TeamType: team_type,
  5724. // Remark: remark,
  5725. // ProjectId: ids,
  5726. // ItemId: item_id,
  5727. // }
  5728. //
  5729. //
  5730. // dataBody := make(map[string]interface{}, 0)
  5731. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5732. // if err != nil {
  5733. // utils.ErrorLog(err.Error())
  5734. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5735. // return
  5736. // }
  5737. //
  5738. // err = service.UpdatedProjectTeam(id, &projectTeam)
  5739. //
  5740. //
  5741. // if err != nil {
  5742. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5743. // return
  5744. // }
  5745. //
  5746. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  5747. // infos, _ := dataBody["info"].([]interface{})
  5748. // if len(infos) > 0 {
  5749. // var ids []string
  5750. //
  5751. // for _, item := range infos {
  5752. // items := item.(map[string]interface{})
  5753. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5754. // utils.ErrorLog("id")
  5755. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5756. // return
  5757. // }
  5758. // id := int64(items["id"].(float64))
  5759. //
  5760. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5761. // utils.ErrorLog("type")
  5762. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5763. // return
  5764. // }
  5765. // types := int64(items["type"].(float64))
  5766. //
  5767. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5768. // utils.ErrorLog("number")
  5769. // }
  5770. //
  5771. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  5772. //
  5773. // projectList := models.XtHisProjectList{
  5774. // Number: number,
  5775. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  5776. // ProjectId: id,
  5777. // Status: 1,
  5778. // CreatedTime: time.Now().Unix(),
  5779. // UpdatedTime: time.Now().Unix(),
  5780. // TeamId: projectTeam.ID,
  5781. // Type: types,
  5782. // }
  5783. // list := projectList
  5784. //
  5785. // service.CreateProjectList(&list)
  5786. //
  5787. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  5788. //
  5789. // }
  5790. // ids_str := strings.Join(ids, ",")
  5791. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  5792. // service.SaveProjectTeam(&projectTeam)
  5793. // this.ServeSuccessJSON(map[string]interface{}{
  5794. // "projectTeam": projectTeam,
  5795. // })
  5796. // }
  5797. // }
  5798. //}
  5799. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  5800. name := c.GetString("name")
  5801. mode_id, _ := c.GetInt64("mode", 0)
  5802. types, _ := c.GetInt64("type", 0)
  5803. patient_id, _ := c.GetInt64("patient_id", 0)
  5804. types = 1
  5805. adminInfo := c.GetAdminUserInfo()
  5806. template := &models.HisPrescriptionTemplate{
  5807. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5808. PatientId: patient_id,
  5809. Type: types,
  5810. Status: 1,
  5811. Ctime: time.Now().Unix(),
  5812. Mtime: time.Now().Unix(),
  5813. Name: name,
  5814. Mode: mode_id,
  5815. }
  5816. dataBody := make(map[string]interface{}, 0)
  5817. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5818. if err != nil {
  5819. utils.ErrorLog(err.Error())
  5820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5821. return
  5822. }
  5823. err = service.CreateHisPrescriptionTemplate(template)
  5824. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5825. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5826. if len(prescriptions) > 0 {
  5827. for _, item := range prescriptions {
  5828. items := item.(map[string]interface{})
  5829. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5830. utils.ErrorLog("type")
  5831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5832. return
  5833. }
  5834. types := int64(items["type"].(float64))
  5835. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5836. utils.ErrorLog("med_type")
  5837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5838. return
  5839. }
  5840. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5841. ctime := time.Now().Unix()
  5842. prescription := &models.HisPrescriptionInfoTemplate{
  5843. PatientId: patient_id,
  5844. UserOrgId: adminInfo.CurrentOrgId,
  5845. Ctime: ctime,
  5846. Mtime: ctime,
  5847. Type: types,
  5848. Modifier: adminInfo.AdminUser.Id,
  5849. Creator: adminInfo.AdminUser.Id,
  5850. Status: 1,
  5851. PTemplateId: template.ID,
  5852. MedType: med_type,
  5853. }
  5854. service.CreateHisPrescriptionInfoTemplate(prescription)
  5855. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5856. advices := items["advices"].([]interface{})
  5857. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5858. ctime := time.Now().Unix()
  5859. mtime := ctime
  5860. if len(advices) > 0 {
  5861. for _, advice := range advices {
  5862. var s models.HisPrescriptionAdviceTemplate
  5863. s.PrescriptionId = prescription.ID
  5864. s.AdviceType = 2
  5865. s.StopState = 2
  5866. s.ExecutionState = 2
  5867. s.Status = 1
  5868. s.UserOrgId = adminInfo.CurrentOrgId
  5869. s.CreatedTime = ctime
  5870. s.UpdatedTime = mtime
  5871. s.PatientId = patient_id
  5872. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  5873. if errcode > 0 {
  5874. c.ServeFailJSONWithSGJErrorCode(errcode)
  5875. return
  5876. }
  5877. service.CreateHisPrescriptionAdviceTemplate(&s)
  5878. }
  5879. }
  5880. }
  5881. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5882. projects := items["project"].([]interface{})
  5883. if len(projects) > 0 {
  5884. for _, project := range projects {
  5885. var p models.HisPrescriptionProjectTemplate
  5886. p.PrescriptionId = prescription.ID
  5887. p.Ctime = time.Now().Unix()
  5888. p.Mtime = time.Now().Unix()
  5889. p.PatientId = patient_id
  5890. p.UserOrgId = adminInfo.CurrentOrgId
  5891. p.Status = 1
  5892. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  5893. if errcode > 0 {
  5894. c.ServeFailJSONWithSGJErrorCode(errcode)
  5895. return
  5896. }
  5897. service.CreateHisPrescriptionProjectTemplate(&p)
  5898. }
  5899. }
  5900. }
  5901. }
  5902. c.ServeSuccessJSON(map[string]interface{}{
  5903. "msg": "创建成功",
  5904. })
  5905. }
  5906. }
  5907. }
  5908. func (c *HisApiController) PreSettle() {
  5909. id, _ := c.GetInt64("id")
  5910. record_time := c.GetString("record_time")
  5911. his_patient_id, _ := c.GetInt64("his_patient_id")
  5912. timeLayout := "2006-01-02"
  5913. loc, _ := time.LoadLocation("Local")
  5914. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5915. diagnosis_id := c.GetString("diagnosis")
  5916. sick_type, _ := c.GetInt64("sick_type")
  5917. reg_type, _ := c.GetInt64("p_type")
  5918. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  5919. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5920. if err != nil {
  5921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5922. return
  5923. }
  5924. recordDateTime := theTime.Unix()
  5925. adminUser := c.GetAdminUserInfo()
  5926. var prescriptions []*models.HisPrescription
  5927. var start_time int64
  5928. var end_time int64
  5929. ids_str := c.GetString("ids")
  5930. ids_arr := strings.Split(ids_str, ",")
  5931. fmt.Println(reg_type)
  5932. if settle_accounts_type == 1 { //日结
  5933. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5934. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  5935. } else {
  5936. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  5937. }
  5938. fmt.Println(prescriptions)
  5939. } else { //月结
  5940. start_time_str := c.GetString("start_time")
  5941. end_time_str := c.GetString("end_time")
  5942. timeLayout := "2006-01-02"
  5943. loc, _ := time.LoadLocation("Local")
  5944. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5945. if err != nil {
  5946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5947. return
  5948. }
  5949. recordStartTime := theStartTime.Unix()
  5950. start_time = recordStartTime
  5951. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5952. if err != nil {
  5953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5954. return
  5955. }
  5956. recordEndTime := theEndTime.Unix()
  5957. end_time = recordEndTime
  5958. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  5959. }
  5960. if reg_type == 1111 || reg_type == 1112 {
  5961. reg_type = 11
  5962. }
  5963. timestamp := time.Now().Unix()
  5964. tempTime := time.Unix(timestamp, 0)
  5965. timeFormat := tempTime.Format("20060102150405")
  5966. chrgBchno := rand.Intn(100000) + 10000
  5967. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  5968. strconv.FormatInt(his.PatientId, 10)
  5969. var ids []int64
  5970. for _, item := range prescriptions {
  5971. ids = append(ids, item.ID)
  5972. }
  5973. fmt.Println(ids)
  5974. var total float64
  5975. for _, item := range prescriptions {
  5976. fmt.Println(item)
  5977. if item.Type == 1 { //药品
  5978. for _, subItem := range item.HisDoctorAdviceInfo {
  5979. total = total + (subItem.Price * subItem.PrescribingNumber)
  5980. }
  5981. }
  5982. if item.Type == 2 { //项目
  5983. for _, subItem := range item.HisPrescriptionProject {
  5984. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5985. total = total + (subItem.Price * cnt)
  5986. }
  5987. }
  5988. for _, subItem := range item.HisAdditionalCharge {
  5989. total = total + (subItem.Price * float64(subItem.Count))
  5990. }
  5991. }
  5992. allTotal := fmt.Sprintf("%.2f", total)
  5993. totals, _ := strconv.ParseFloat(allTotal, 64)
  5994. order := &models.HisOrder{
  5995. UserOrgId: adminUser.CurrentOrgId,
  5996. HisPatientId: his.ID,
  5997. PatientId: id,
  5998. SettleAccountsDate: recordDateTime,
  5999. Ctime: time.Now().Unix(),
  6000. Mtime: time.Now().Unix(),
  6001. Status: 1,
  6002. OrderStatus: 1,
  6003. MdtrtId: his.Number,
  6004. Number: chrg_bchno,
  6005. MedfeeSumamt: totals,
  6006. SettleEndTime: end_time,
  6007. SettleStartTime: start_time,
  6008. SettleType: settle_accounts_type,
  6009. PType: 2,
  6010. IsPre: 1,
  6011. MedType: strconv.Itoa(int(reg_type)),
  6012. Diagnosis: diagnosis_id,
  6013. }
  6014. err = service.CreateOrder(order)
  6015. if err != nil {
  6016. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6017. return
  6018. }
  6019. var customs []*Custom
  6020. for _, item := range prescriptions {
  6021. fmt.Println(item.Type)
  6022. if item.Type == 1 { //药品
  6023. for _, subItem := range item.HisDoctorAdviceInfo {
  6024. cus := &Custom{
  6025. AdviceId: subItem.ID,
  6026. ProjectId: 0,
  6027. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  6028. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  6029. FeedetlSn: subItem.FeedetlSn,
  6030. Price: fmt.Sprintf("%.2f", subItem.Price),
  6031. MedListCodg: subItem.MedListCodg,
  6032. Type: 1,
  6033. }
  6034. customs = append(customs, cus)
  6035. }
  6036. }
  6037. if item.Type == 2 { //项目
  6038. for _, subItem := range item.HisPrescriptionProject {
  6039. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6040. cus := &Custom{
  6041. AdviceId: 0,
  6042. ProjectId: subItem.ID,
  6043. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  6044. Cut: fmt.Sprintf("%.2f", cnt),
  6045. FeedetlSn: subItem.FeedetlSn,
  6046. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  6047. MedListCodg: subItem.MedListCodg,
  6048. Type: 2,
  6049. }
  6050. customs = append(customs, cus)
  6051. }
  6052. }
  6053. for _, item := range item.HisAdditionalCharge {
  6054. cus := &Custom{
  6055. ItemId: item.ID,
  6056. AdviceId: 0,
  6057. ProjectId: 0,
  6058. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  6059. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  6060. FeedetlSn: item.FeedetlSn,
  6061. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  6062. MedListCodg: item.XtHisAddtionConfig.Code,
  6063. Type: 3,
  6064. }
  6065. customs = append(customs, cus)
  6066. }
  6067. }
  6068. fmt.Println(customs)
  6069. for _, item := range customs {
  6070. var advice_id int64 = 0
  6071. var project_id int64 = 0
  6072. var item_id int64 = 0
  6073. var types int64 = 0
  6074. if item.Type == 1 {
  6075. advice_id = item.AdviceId
  6076. project_id = 0
  6077. item_id = 0
  6078. } else if item.Type == 2 {
  6079. advice_id = 0
  6080. item_id = 0
  6081. project_id = item.ProjectId
  6082. } else if item.Type == 3 {
  6083. advice_id = 0
  6084. item_id = item.ItemId
  6085. project_id = 0
  6086. }
  6087. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6088. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6089. pric, _ := strconv.ParseFloat(item.Price, 32)
  6090. info := &models.HisOrderInfo{
  6091. OrderNumber: order.Number,
  6092. UploadDate: time.Now().Unix(),
  6093. AdviceId: advice_id,
  6094. DetItemFeeSumamt: detItemFeeSumamt,
  6095. Cnt: cut,
  6096. Pric: pric,
  6097. PatientId: id,
  6098. Status: 1,
  6099. Mtime: time.Now().Unix(),
  6100. Ctime: time.Now().Unix(),
  6101. UserOrgId: adminUser.CurrentOrgId,
  6102. HisPatientId: his.ID,
  6103. OrderId: order.ID,
  6104. ProjectId: project_id,
  6105. Type: types,
  6106. ItemId: item_id,
  6107. }
  6108. service.CreateOrderInfo(info)
  6109. }
  6110. his.SickType = sick_type
  6111. service.UpdataHisPateint(&his)
  6112. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  6113. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  6114. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  6115. if err == nil {
  6116. c.ServeSuccessJSON(map[string]interface{}{
  6117. "msg": "结算成功",
  6118. })
  6119. }
  6120. }
  6121. type CustomOrderInfo struct {
  6122. Name string
  6123. Spec string
  6124. Unit string
  6125. Count float64
  6126. Price float64
  6127. Total float64
  6128. }
  6129. func (c *HisApiController) GetPrivateExpensesInfo() {
  6130. order_id, _ := c.GetInt64("id", 0)
  6131. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  6132. order, _ := service.GetHisOrderByID(order_id)
  6133. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  6134. if order.ID == 0 {
  6135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6136. return
  6137. }
  6138. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6139. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6140. org_id := c.GetAdminUserInfo().CurrentOrgId
  6141. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6142. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6143. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  6144. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  6145. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  6146. var orderInfos_four []*models.HisOrderInfoTwo
  6147. for _, item := range orderInfos_three {
  6148. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  6149. item.HisPrescriptionProject.IsCheckTeam = 1
  6150. orderInfos_four = append(orderInfos_four, item)
  6151. }
  6152. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  6153. item.HisPrescriptionProject.IsCheckTeam = 2
  6154. orderInfos_two = append(orderInfos_two, item)
  6155. }
  6156. }
  6157. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  6158. var cus_slice []CustomOrderInfo
  6159. for _, item := range new_order_info {
  6160. var cus CustomOrderInfo
  6161. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  6162. cus.Unit = ""
  6163. cus.Spec = ""
  6164. var total float64
  6165. for _, subItem := range orderInfos_four {
  6166. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  6167. total = total + subItem.DetItemFeeSumamt
  6168. fmt.Println(subItem.DetItemFeeSumamt)
  6169. }
  6170. }
  6171. cus.Count = 1
  6172. cus.Total = total
  6173. cus_slice = append(cus_slice, cus)
  6174. }
  6175. orderInfos = append(orderInfos, orderInfos_two...)
  6176. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  6177. orderInfos = append(orderInfos, orderInfos_three...)
  6178. }
  6179. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6180. c.ServeSuccessJSON(map[string]interface{}{
  6181. "order": order,
  6182. "order_info": orderInfos,
  6183. "patient": patient,
  6184. "admin_info": adminInfo,
  6185. "his": his,
  6186. "current_admin": role,
  6187. "org_config": miConfig,
  6188. "new_order_info": cus_slice,
  6189. })
  6190. }
  6191. func (this *HisApiController) ChangeMedType() {
  6192. med_type := this.GetString("med_type")
  6193. old_med_type := this.GetString("old_med_type")
  6194. ids := this.GetString("ids")
  6195. settle_type, _ := this.GetInt64("settle_type")
  6196. start_time := this.GetString("start_time")
  6197. end_time := this.GetString("end_time")
  6198. ids_arr := strings.Split(ids, ",")
  6199. if settle_type == 1 { //日结
  6200. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  6201. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  6202. prescription.MedType = med_type
  6203. err := service.SaveHisPrescription(&prescription)
  6204. if err == nil {
  6205. this.ServeSuccessJSON(map[string]interface{}{
  6206. "msg": "修改成功",
  6207. })
  6208. } else {
  6209. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6210. return
  6211. }
  6212. } else if settle_type == 2 {
  6213. timeLayout := "2006-01-02"
  6214. loc, _ := time.LoadLocation("Local")
  6215. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6216. if err != nil {
  6217. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6218. return
  6219. }
  6220. recordStartTime := theStartTime.Unix()
  6221. start_time_timestamp := recordStartTime
  6222. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6223. if err != nil {
  6224. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6225. return
  6226. }
  6227. recordEndTime := theEndTime.Unix()
  6228. end_time_timestamp := recordEndTime
  6229. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  6230. if updateErr == nil {
  6231. this.ServeSuccessJSON(map[string]interface{}{
  6232. "msg": "修改成功",
  6233. })
  6234. } else {
  6235. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6236. return
  6237. }
  6238. }
  6239. }
  6240. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  6241. patient_id, _ := c.GetInt64("patient_id")
  6242. his_patient_id, _ := c.GetInt64("his_patient_id")
  6243. record_date := c.GetString("record_date")
  6244. start_time := c.GetString("start_time")
  6245. end_time := c.GetString("end_time")
  6246. order_status, _ := c.GetInt64("type", 0)
  6247. p_type, _ := c.GetInt64("p_type", 0)
  6248. order_id, _ := c.GetInt64("order_id", 0)
  6249. timeLayout := "2006-01-02"
  6250. loc, _ := time.LoadLocation("Local")
  6251. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6252. if err != nil {
  6253. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6254. return
  6255. }
  6256. recordDateTime := theTime.Unix()
  6257. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6258. if err != nil {
  6259. }
  6260. startRecordDateTime := startTime.Unix()
  6261. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6262. if err != nil {
  6263. }
  6264. endRecordDateTime := endTime.Unix()
  6265. admin := c.GetAdminUserInfo()
  6266. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6267. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6268. order, _ := service.GetHisOrderByID(order_id)
  6269. var monthPrescriptions []*models.HisPrescription
  6270. if order_status == 1 || order_status == 0 {
  6271. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6272. } else if order_status == 2 {
  6273. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6274. }
  6275. var settle_total float64
  6276. for _, item := range monthPrescriptions {
  6277. if len(item.HisPrescriptionProject) > 0 {
  6278. for _, subItem := range item.HisPrescriptionProject {
  6279. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6280. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6281. settle_total = settle_total + total
  6282. }
  6283. }
  6284. if len(item.HisDoctorAdviceInfo) > 0 {
  6285. for _, subItem := range item.HisDoctorAdviceInfo {
  6286. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6287. settle_total = settle_total + total
  6288. }
  6289. }
  6290. }
  6291. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6292. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6293. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6294. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6295. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6296. //获取所有科室信息
  6297. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6298. c.ServeSuccessJSON(map[string]interface{}{
  6299. "his_info": his_patient_info,
  6300. "xt_info": xt_patient_info,
  6301. "case_history": case_history,
  6302. "info": patientPrescriptionInfo,
  6303. "last_info": lastPatientPrescriptionInfo,
  6304. "month_prescriptions": monthPrescriptions,
  6305. "order": order,
  6306. "doctors": doctors,
  6307. "department": department,
  6308. "settle_total": settle_total,
  6309. })
  6310. return
  6311. }
  6312. func (c *HisApiController) GetHisMonthPatientInfo() {
  6313. patient_id, _ := c.GetInt64("patient_id")
  6314. his_patient_id, _ := c.GetInt64("his_patient_id")
  6315. record_date := c.GetString("record_date")
  6316. number := c.GetString("number")
  6317. start_time := c.GetString("start_time")
  6318. end_time := c.GetString("end_time")
  6319. p_type, _ := c.GetInt64("p_type")
  6320. timeLayout := "2006-01-02"
  6321. loc, _ := time.LoadLocation("Local")
  6322. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6323. if err != nil {
  6324. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6325. return
  6326. }
  6327. recordDateTime := theTime.Unix()
  6328. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6329. if err != nil {
  6330. }
  6331. startRecordDateTime := startTime.Unix()
  6332. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6333. if err != nil {
  6334. }
  6335. endRecordDateTime := endTime.Unix()
  6336. admin := c.GetAdminUserInfo()
  6337. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  6338. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6339. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  6340. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6341. var settle_total float64
  6342. for _, item := range monthPrescriptions {
  6343. if len(item.HisPrescriptionProject) > 0 {
  6344. for _, subItem := range item.HisPrescriptionProject {
  6345. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6346. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6347. settle_total = settle_total + total
  6348. }
  6349. }
  6350. if len(item.HisDoctorAdviceInfo) > 0 {
  6351. for _, subItem := range item.HisDoctorAdviceInfo {
  6352. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6353. settle_total = settle_total + total
  6354. }
  6355. }
  6356. }
  6357. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6358. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6359. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6360. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6361. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  6362. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6363. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  6364. //获取所有科室信息
  6365. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6366. c.ServeSuccessJSON(map[string]interface{}{
  6367. "his_info": his_patient_info,
  6368. "xt_info": xt_patient_info,
  6369. "case_history": case_history,
  6370. "info": patientPrescriptionInfo,
  6371. "month_prescriptions": monthPrescriptions,
  6372. "order": order,
  6373. "doctors": doctors,
  6374. "department": department,
  6375. "count": count,
  6376. "drugStockConfig": drugStockConfig,
  6377. "last_info": lastPatientPrescriptionInfo,
  6378. "settle_total": settle_total,
  6379. })
  6380. return
  6381. }
  6382. func (c *HisApiController) GetAllOrder() {
  6383. org_id := c.GetAdminUserInfo().CurrentOrgId
  6384. orders, _ := service.GetNewHisOrderList(org_id)
  6385. c.ServeSuccessJSON(map[string]interface{}{
  6386. "order": orders,
  6387. })
  6388. return
  6389. }
  6390. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  6391. newArr = make([]*models.HisOrderInfoTwo, 0)
  6392. for i := 0; i < len(arr); i++ {
  6393. repeat := false
  6394. for j := i + 1; j < len(arr); j++ {
  6395. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  6396. repeat = true
  6397. break
  6398. }
  6399. }
  6400. if !repeat {
  6401. newArr = append(newArr, arr[i])
  6402. }
  6403. }
  6404. return
  6405. }
  6406. //修改处方退库操作 参数传修改之前的处方数据
  6407. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  6408. if advice.ExecutionState == 1 {
  6409. //查询该病人该药品是否有库存记录
  6410. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  6411. if errcode == gorm.ErrRecordNotFound {
  6412. } else {
  6413. //退库
  6414. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6415. if advice.PrescribingNumberUnit == drug.MinUnit {
  6416. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6417. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6418. //退库
  6419. warehouseInfo := models.DrugWarehouseInfo{
  6420. StockMinNumber: prescribingNumber,
  6421. }
  6422. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  6423. operation_time := time.Now().Unix()
  6424. creater := advice.AdviceDoctor
  6425. ctime := time.Now().Unix()
  6426. timeStr := time.Now().Format("2006-01-02")
  6427. timeArr := strings.Split(timeStr, "-")
  6428. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6429. total = total + 1
  6430. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6431. cancelStock := models.DrugCancelStock{
  6432. OrderNumber: orderNumber,
  6433. OperaTime: operation_time,
  6434. OrgId: advice.UserOrgId,
  6435. Creater: creater,
  6436. Ctime: ctime,
  6437. Status: 1,
  6438. ReturnTime: advice.AdviceDate,
  6439. Dealer: info.Dealer,
  6440. Manufacturer: info.Manufacturer,
  6441. Type: 1,
  6442. }
  6443. service.AddSigleDrugCancelStock(&cancelStock)
  6444. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6445. dealer, _ := service.GetDealerById(info.Dealer)
  6446. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6447. cancelStockInfo := models.DrugCancelStockInfo{
  6448. OrderNumber: cancelInfo.OrderNumber,
  6449. CancelStockId: cancelInfo.ID,
  6450. DrugId: info.DrugId,
  6451. Count: info.Count,
  6452. Status: 1,
  6453. Ctime: ctime,
  6454. OrgId: advice.UserOrgId,
  6455. Type: 1,
  6456. Manufacturer: manufactureName.ManufacturerName,
  6457. Dealer: dealer.DealerName,
  6458. Total: 0,
  6459. RetailPrice: info.RetailPrice,
  6460. RetailTotalPrice: info.RetailTotalPrice,
  6461. Price: info.Price,
  6462. RegisterAccount: "",
  6463. Remark: info.Remark,
  6464. BatchNumber: info.BatchNumber,
  6465. MaxUnit: info.CountUnit,
  6466. ProductDate: info.ProductDate,
  6467. ExpiryDate: info.ExpiryDate,
  6468. BatchNumberId: info.WarehouseInfoId,
  6469. }
  6470. flow := models.DrugFlow{
  6471. WarehousingId: 0,
  6472. DrugId: info.DrugId,
  6473. Number: "",
  6474. BatchNumber: info.BatchNumber,
  6475. Count: info.Count,
  6476. UserOrgId: advice.UserOrgId,
  6477. PatientId: 0,
  6478. SystemTime: ctime,
  6479. ConsumableType: 4,
  6480. IsSys: 0,
  6481. WarehousingOrder: "",
  6482. WarehouseOutId: 0,
  6483. WarehouseOutOrderNumber: "",
  6484. IsEdit: 0,
  6485. CancelStockId: cancelStock.ID,
  6486. CancelOrderNumber: cancelStock.OrderNumber,
  6487. Manufacturer: info.Manufacturer,
  6488. Dealer: info.Dealer,
  6489. Creator: advice.UserOrgId,
  6490. UpdateCreator: 0,
  6491. Status: 1,
  6492. Ctime: time.Now().Unix(),
  6493. Mtime: 0,
  6494. Price: info.Price,
  6495. WarehousingDetailId: 0,
  6496. WarehouseOutDetailId: 0,
  6497. CancelOutDetailId: 0,
  6498. ExpireDate: info.ExpiryDate,
  6499. ProductDate: info.ProductDate,
  6500. MaxUnit: info.CountUnit,
  6501. MinUnit: "",
  6502. }
  6503. service.CreatedCancelStock(cancelStockInfo)
  6504. service.CreateDrugFlowOne(flow)
  6505. } else {
  6506. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6507. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6508. if advice.PrescribingNumberUnit == drug.MaxUnit {
  6509. warehouseInfo := models.DrugWarehouseInfo{
  6510. StockMinNumber: prescribingNumber,
  6511. }
  6512. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  6513. }
  6514. operation_time := time.Now().Unix()
  6515. creater := advice.AdviceDoctor
  6516. ctime := time.Now().Unix()
  6517. timeStr := time.Now().Format("2006-01-02")
  6518. timeArr := strings.Split(timeStr, "-")
  6519. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6520. total = total + 1
  6521. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6522. cancelStock := models.DrugCancelStock{
  6523. OrderNumber: orderNumber,
  6524. OperaTime: operation_time,
  6525. OrgId: advice.UserOrgId,
  6526. Creater: creater,
  6527. Ctime: ctime,
  6528. Status: 1,
  6529. ReturnTime: advice.AdviceDate,
  6530. Dealer: info.Dealer,
  6531. Manufacturer: info.Manufacturer,
  6532. Type: 1,
  6533. }
  6534. service.AddSigleDrugCancelStock(&cancelStock)
  6535. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6536. dealer, _ := service.GetDealerById(info.Dealer)
  6537. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6538. cancelStockInfo := models.DrugCancelStockInfo{
  6539. OrderNumber: cancelInfo.OrderNumber,
  6540. CancelStockId: cancelInfo.ID,
  6541. DrugId: info.DrugId,
  6542. Count: info.Count,
  6543. Status: 1,
  6544. Ctime: ctime,
  6545. OrgId: advice.UserOrgId,
  6546. Type: 1,
  6547. Manufacturer: manufactureName.ManufacturerName,
  6548. Dealer: dealer.DealerName,
  6549. Total: 0,
  6550. RetailPrice: info.RetailPrice,
  6551. RetailTotalPrice: info.RetailTotalPrice,
  6552. Price: info.Price,
  6553. RegisterAccount: "",
  6554. Remark: info.Remark,
  6555. BatchNumber: info.BatchNumber,
  6556. MaxUnit: info.CountUnit,
  6557. ProductDate: info.ProductDate,
  6558. ExpiryDate: info.ExpiryDate,
  6559. BatchNumberId: info.WarehouseInfoId,
  6560. }
  6561. flow := models.DrugFlow{
  6562. WarehousingId: 0,
  6563. DrugId: info.DrugId,
  6564. Number: "",
  6565. BatchNumber: info.BatchNumber,
  6566. Count: info.Count,
  6567. UserOrgId: advice.UserOrgId,
  6568. PatientId: 0,
  6569. SystemTime: ctime,
  6570. ConsumableType: 4,
  6571. IsSys: 0,
  6572. WarehousingOrder: "",
  6573. WarehouseOutId: 0,
  6574. WarehouseOutOrderNumber: "",
  6575. IsEdit: 0,
  6576. CancelStockId: cancelStock.ID,
  6577. CancelOrderNumber: cancelStock.OrderNumber,
  6578. Manufacturer: info.Manufacturer,
  6579. Dealer: info.Dealer,
  6580. Creator: advice.AdviceDoctor,
  6581. UpdateCreator: 0,
  6582. Status: 1,
  6583. Ctime: time.Now().Unix(),
  6584. Mtime: 0,
  6585. Price: info.Price,
  6586. WarehousingDetailId: 0,
  6587. WarehouseOutDetailId: 0,
  6588. CancelOutDetailId: 0,
  6589. ExpireDate: info.ExpiryDate,
  6590. ProductDate: info.ProductDate,
  6591. MaxUnit: info.CountUnit,
  6592. MinUnit: "",
  6593. }
  6594. service.CreatedCancelStock(cancelStockInfo)
  6595. service.CreateDrugFlowOne(flow)
  6596. }
  6597. }
  6598. }
  6599. return err
  6600. }
  6601. func (this *HisApiController) DeleteNCDS() {
  6602. id, _ := this.GetInt64("id", 0)
  6603. if id > 0 {
  6604. service.DeletePsnNCDSRecordById(id)
  6605. this.ServeSuccessJSON(map[string]interface{}{
  6606. "msg": "删除成功",
  6607. })
  6608. } else {
  6609. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  6610. return
  6611. }
  6612. }
  6613. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  6614. id, _ := c.GetInt64("id")
  6615. advice, _ := service.GetHisDoctorAdviceInfo(id)
  6616. c.ServeSuccessJSON(map[string]interface{}{
  6617. "advice": advice,
  6618. })
  6619. return
  6620. }
  6621. func (c *HisApiController) GetHisMonthChargePatientList() {
  6622. record_date := c.GetString("record_date")
  6623. start_time := c.GetString("start_time")
  6624. end_time := c.GetString("end_time")
  6625. timeLayout := "2006-01-02"
  6626. loc, _ := time.LoadLocation("Local")
  6627. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6628. if err != nil {
  6629. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6630. return
  6631. }
  6632. if err != nil {
  6633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6634. return
  6635. }
  6636. recordDateTime := theTime.Unix()
  6637. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6638. if err != nil {
  6639. }
  6640. startRecordDateTime := startTime.Unix()
  6641. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6642. if err != nil {
  6643. }
  6644. endRecordDateTime := endTime.Unix()
  6645. adminInfo := c.GetAdminUserInfo()
  6646. var tempMonthChargePatients []*service.MonthChargePatients
  6647. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  6648. for _, item := range tempPatients {
  6649. //过滤没有处方的
  6650. if len(item.HisPrescription) == 0 {
  6651. tempMonthChargePatients = append(tempMonthChargePatients, item)
  6652. }
  6653. }
  6654. c.ServeSuccessJSON(map[string]interface{}{
  6655. "list": tempMonthChargePatients,
  6656. })
  6657. }