his_api_controller.go 243KB

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