his_api_controller.go 237KB

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