his_api_controller.go 181KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300
  1. package sg
  2. import (
  3. "archive/zip"
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "gdyb/controllers"
  8. "gdyb/enums"
  9. "gdyb/models"
  10. "gdyb/service"
  11. "gdyb/utils"
  12. "github.com/astaxie/beego"
  13. "github.com/jinzhu/gorm"
  14. "github.com/shopspring/decimal"
  15. "io"
  16. "io/ioutil"
  17. "math/rand"
  18. "net/http"
  19. "os"
  20. "path/filepath"
  21. "strconv"
  22. "strings"
  23. "syscall"
  24. "time"
  25. "unsafe"
  26. )
  27. type HisApiController struct {
  28. controllers.BaseAuthAPIController
  29. }
  30. func HisManagerApiRegistRouters() {
  31. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  32. beego.Router("/api/diag/upload", &HisApiController{}, "get:GetUploadDiag")
  33. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  34. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  35. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  36. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  37. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  38. beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  39. beego.Router("/api/refundnumber/post", &HisApiController{}, "get:RefundNumber")
  40. beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail")
  41. beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
  42. beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
  43. //beego.Router("/api/patient/info", &HisApiController{}, "get:GetHisPatientInfo")
  44. beego.Router("/api/org/info", &HisApiController{}, "get:GetOrgInfo")
  45. //beego.Router("/api/testcard", &HisApiController{}, "get:TestGetBasBaseInfo")
  46. //beego.Router("/api/testpay", &HisApiController{}, "get:TestPay")
  47. beego.Router("/api/pre_upload/get", &HisApiController{}, "get:GetPreUploadInfo")
  48. //beego.Router("/api/settle/get", &HisApiController{}, "get:GetSettleInfo")
  49. beego.Router("/api/310", &HisApiController{}, "get:Check310")
  50. beego.Router("/api/390", &HisApiController{}, "get:Check390")
  51. beego.Router("/api/patient/info", &HisApiController{}, "get:GetPatientInfo")
  52. //备案撤销相关接口
  53. beego.Router("/api/checkcode/get", &HisApiController{}, "get:GetCheckCode")
  54. beego.Router("/api/uncheckcode/get", &HisApiController{}, "get:UnCheckCode")
  55. beego.Router("/api/psn/putonrecord", &HisApiController{}, "get:PsnPutOnRecord")
  56. beego.Router("/api/psn/unputonrecord", &HisApiController{}, "get:PsnUnPutOnRecord")
  57. beego.Router("/api/psn/ncds/putonrecord", &HisApiController{}, "get:PsnPutNCDSOnRecord")
  58. beego.Router("/api/psn/ncds/unputonrecord", &HisApiController{}, "get:PsnPutUnNCDSOnRecord")
  59. beego.Router("/api/test", &HisApiController{}, "get:TestGetBasBaseInfo")
  60. beego.Router("/api/reversal", &HisApiController{}, "get:ReversalData")
  61. beego.Router("/api/reversal/other", &HisApiController{}, "get:ReversalOtherData")
  62. //beego.Router("/api/reversal/one", &HisApiController{}, "get:ReversalOtherOneData")
  63. beego.Router("/api/settlelist/get", &HisApiController{}, "get:GetSettleList")
  64. //beego.Router("/api/settlelist/get", &HisApiController{}, "get:GetSettleList")
  65. }
  66. type CustomFundPay struct {
  67. FundPayType string `json:"fund_pay_type"`
  68. FundPayamt float64 `json:"fund_payamt"`
  69. }
  70. func (c *HisApiController) GetSettleList() {
  71. order_id, _ := c.GetInt64("order_id")
  72. admin_user_id, _ := c.GetInt64("admin_user_id")
  73. order, _ := service.GetHisOrderByIDTwo(order_id)
  74. roles, _ := service.GetDoctorListTwo(c.GetAdminUserInfo().CurrentOrgId)
  75. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  76. admin, _ := service.GetAdminUserByUserID(roles[0].AdminUserId)
  77. curRoles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  78. depart, _ := service.GetDepartMentDetail(curRoles.DepartmentId)
  79. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  80. if order.ID == 0 {
  81. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisOrderNoExistParamWrong)
  82. return
  83. }
  84. struct4101 := service.Struct4101{
  85. PsnNo: order.PsnNo,
  86. MdtrtId: order.MdtrtId,
  87. SetlId: order.SetlId,
  88. PsnName: order.PsnName,
  89. Gend: order.Gend,
  90. Brdy: his.Brdy,
  91. Age: his.Age,
  92. Naty: order.Naty,
  93. PatnCertType: "01",
  94. Certno: order.Certno,
  95. Prfs: "90",
  96. ConerName: roles[0].UserName,
  97. PatnRlts: "99",
  98. ConerAddr: miConfig.OrgName,
  99. ConerTel: admin.Mobile,
  100. HiType: order.Insutype,
  101. Insuplc: miConfig.InsuplcAdmdvs,
  102. MaindiagFlag: "1",
  103. BillCode: order.FaPiaoCode,
  104. BillNo: order.FaPiaoNumber,
  105. BizSn: order.Number,
  106. PsnSelfPay: order.PsnPartAmt,
  107. PsnOwnPay: order.PsnPartAmt,
  108. AcctPay: order.AcctPay,
  109. PsnCashpay: order.PsnCashPay,
  110. HiPaymtd: "1",
  111. Hsorg: miConfig.InsuplcAdmdvs,
  112. HsorgOpter: miConfig.InsuplcAdmdvs,
  113. MedinsFillPsn: curRoles.UserName,
  114. MedinsFillDept: depart.Name,
  115. IptMedType: "2",
  116. }
  117. if order.SettleType == 1 {
  118. t := time.Unix(int64(order.SettleAccountsDate), 0)
  119. dateStr := t.Format("2006-01-02")
  120. struct4101.SetlBegnDate = dateStr
  121. struct4101.SetlEndDate = dateStr
  122. } else {
  123. t := time.Unix(int64(order.SettleStartTime), 0)
  124. t2 := time.Unix(int64(order.SettleEndTime), 0)
  125. dateStartStr := t.Format("2006-01-02")
  126. dateEndStr := t2.Format("2006-01-02")
  127. struct4101.SetlBegnDate = dateStartStr
  128. struct4101.SetlEndDate = dateEndStr
  129. }
  130. var rf []CustomFundPay
  131. json.Unmarshal([]byte(order.SetlDetail), &rf)
  132. var tempFunPays []service.CustomStruct
  133. for _, item := range rf {
  134. var tempFunPay service.CustomStruct
  135. tempFunPay.FundPayamt = item.FundPayamt
  136. tempFunPay.FundPayType = item.FundPayType
  137. tempFunPays = append(tempFunPays, tempFunPay)
  138. }
  139. struct4101.CustomStruct = tempFunPays
  140. var tempOpspdiseinfos []service.OpspdiseinfoStruct
  141. var tempOpspdiseinfo service.OpspdiseinfoStruct
  142. var tempOpspdiseinfo2 service.OpspdiseinfoStruct
  143. sickConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  144. sickConfigTwo, _ := service.FindSickById(his.SickType)
  145. tempOpspdiseinfo.DiagCode = sickConfig.CountryCode
  146. tempOpspdiseinfo.DiagName = sickConfig.CountryContentName
  147. tempOpspdiseinfo.MaindiagFlag = "1"
  148. tempOpspdiseinfo.OprnOprtCode = ""
  149. tempOpspdiseinfo.OprnOprtName = ""
  150. tempOpspdiseinfos = append(tempOpspdiseinfos, tempOpspdiseinfo)
  151. tempOpspdiseinfo2.DiagCode = sickConfigTwo.CountryCode
  152. tempOpspdiseinfo2.DiagName = sickConfigTwo.CountryContentName
  153. tempOpspdiseinfo2.MaindiagFlag = "2"
  154. tempOpspdiseinfo2.OprnOprtCode = ""
  155. tempOpspdiseinfo2.OprnOprtName = ""
  156. tempOpspdiseinfos = append(tempOpspdiseinfos, tempOpspdiseinfo2)
  157. struct4101.OpspdiseinfoStruct = tempOpspdiseinfos
  158. var iteminfo service.IteminfoStruct
  159. var bedCostTotal float64 = 0 //床位总费
  160. var bedCostSelfTotal float64 = 0 //床位自费
  161. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  162. var operationCostTotal float64 = 0 //手术费
  163. var operationCostSelfTotal float64 = 0 //手术费
  164. var operationCostPartSelfTotal float64 = 0 //手术费
  165. var otherCostTotal float64 = 0 //其他费用
  166. var otherCostSelfTotal float64 = 0 //其他费用
  167. var otherCostPartSelfTotal float64 = 0 //其他费用
  168. var materialCostTotal float64 = 0 //材料费
  169. var materialCostSelfTotal float64 = 0 //材料费
  170. var materialCostPartSelfTotal float64 = 0 //材料费
  171. var westernMedicineCostTotal float64 = 0 //西药费
  172. var westernMedicineCostSelfTotal float64 = 0 //西药费
  173. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  174. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  175. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  176. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  177. var checkCostTotal float64 = 0 //检查费
  178. var checkCostSelfTotal float64 = 0 //检查费
  179. var checkCostPartSelfTotal float64 = 0 //检查费
  180. var laboratoryCostTotal float64 = 0 //化验费
  181. var laboratoryCostSelfTotal float64 = 0 //化验费
  182. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  183. var treatCostTotal float64 = 0 //治疗费用
  184. var treatCostSelfTotal float64 = 0 //治疗费用
  185. var treatCostPartSelfTotal float64 = 0 //治疗费用
  186. decimal.DivisionPrecision = 2
  187. var bed_fulamt_ownpay_amt float64 = 0
  188. var operation_fulamt_ownpay_amt float64 = 0
  189. var other_fulamt_ownpay_amt float64 = 0
  190. var westernMedicine_fulamt_ownpay_amt float64 = 0
  191. var chineseTraditional_fulamt_ownpay_amt float64 = 0
  192. var check_fulamt_ownpay_amt float64 = 0
  193. var material_fulamt_ownpay_amt float64 = 0
  194. var laboratory_fulamt_ownpay_amt float64 = 0
  195. var treat_fulamt_ownpay_amt float64 = 0
  196. var bed_claa_sunmfee float64 = 0
  197. var bed_clab_amt float64 = 0
  198. var bed_other_amt float64 = 0
  199. var operation_claa_sunmfee float64 = 0
  200. var operation_clab_amt float64 = 0
  201. var operation_other_amt float64 = 0
  202. var other_claa_sunmfee float64 = 0
  203. var other_clab_amt float64 = 0
  204. var other_other_amt float64 = 0
  205. var westernMedicine_claa_sunmfee float64 = 0
  206. var westernMedicine_clab_amt float64 = 0
  207. var westernMedicine_other_amt float64 = 0
  208. var chineseTraditional_claa_sunmfee float64 = 0
  209. var chineseTraditional_clab_amt float64 = 0
  210. var chineseTraditional_other_amt float64 = 0
  211. var check_claa_sunmfee float64 = 0
  212. var check_clab_amt float64 = 0
  213. var check_other_amt float64 = 0
  214. var material_claa_sunmfee float64 = 0
  215. var material_clab_amt float64 = 0
  216. var material_other_amt float64 = 0
  217. var laboratory_claa_sunmfee float64 = 0
  218. var laboratory_clab_amt float64 = 0
  219. var laboratory_other_amt float64 = 0
  220. var treat_claa_sunmfee float64 = 0
  221. var treat_clab_amt float64 = 0
  222. var treat_other_amt float64 = 0
  223. for _, item := range order.HisOrderInfo {
  224. if item.MedChrgitmType == "01" { //床位费
  225. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  226. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  227. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  228. bed_fulamt_ownpay_amt, _ = decimal.NewFromFloat(bed_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  229. if item.ChrgitmLv == "1" {
  230. bed_claa_sunmfee, _ = decimal.NewFromFloat(bed_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  231. }
  232. if item.ChrgitmLv == "2" {
  233. bed_clab_amt, _ = decimal.NewFromFloat(bed_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  234. }
  235. if item.ChrgitmLv == "3" {
  236. bed_other_amt, _ = decimal.NewFromFloat(bed_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  237. }
  238. }
  239. if item.MedChrgitmType == "03" { //检查费
  240. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  241. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  242. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  243. check_fulamt_ownpay_amt, _ = decimal.NewFromFloat(check_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  244. if item.ChrgitmLv == "1" {
  245. check_claa_sunmfee, _ = decimal.NewFromFloat(check_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  246. }
  247. if item.ChrgitmLv == "2" {
  248. check_clab_amt, _ = decimal.NewFromFloat(check_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  249. }
  250. if item.ChrgitmLv == "3" {
  251. check_other_amt, _ = decimal.NewFromFloat(check_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  252. }
  253. }
  254. if item.MedChrgitmType == "04" { //化验费
  255. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  256. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  257. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  258. laboratory_fulamt_ownpay_amt, _ = decimal.NewFromFloat(laboratory_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  259. if item.ChrgitmLv == "1" {
  260. laboratory_claa_sunmfee, _ = decimal.NewFromFloat(laboratory_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  261. }
  262. if item.ChrgitmLv == "2" {
  263. laboratory_clab_amt, _ = decimal.NewFromFloat(laboratory_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  264. }
  265. if item.ChrgitmLv == "3" {
  266. laboratory_other_amt, _ = decimal.NewFromFloat(laboratory_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  267. }
  268. }
  269. if item.MedChrgitmType == "05" { //治疗费
  270. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  271. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  272. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  273. treat_fulamt_ownpay_amt, _ = decimal.NewFromFloat(treat_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  274. if item.ChrgitmLv == "1" {
  275. treat_claa_sunmfee, _ = decimal.NewFromFloat(treat_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  276. }
  277. if item.ChrgitmLv == "2" {
  278. treat_clab_amt, _ = decimal.NewFromFloat(treat_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  279. }
  280. if item.ChrgitmLv == "3" {
  281. treat_other_amt, _ = decimal.NewFromFloat(treat_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  282. }
  283. }
  284. if item.MedChrgitmType == "06" { //手术费
  285. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  286. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  287. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  288. operation_fulamt_ownpay_amt, _ = decimal.NewFromFloat(operation_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  289. if item.ChrgitmLv == "1" {
  290. operation_claa_sunmfee, _ = decimal.NewFromFloat(operation_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  291. }
  292. if item.ChrgitmLv == "2" {
  293. operation_clab_amt, _ = decimal.NewFromFloat(operation_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  294. }
  295. if item.ChrgitmLv == "3" {
  296. operation_other_amt, _ = decimal.NewFromFloat(operation_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  297. }
  298. }
  299. if item.MedChrgitmType == "08" { //材料费
  300. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  301. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  302. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  303. material_fulamt_ownpay_amt, _ = decimal.NewFromFloat(material_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  304. if item.ChrgitmLv == "1" {
  305. material_claa_sunmfee, _ = decimal.NewFromFloat(material_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  306. }
  307. if item.ChrgitmLv == "2" {
  308. material_clab_amt, _ = decimal.NewFromFloat(material_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  309. }
  310. if item.ChrgitmLv == "3" {
  311. material_other_amt, _ = decimal.NewFromFloat(material_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  312. }
  313. }
  314. if item.MedChrgitmType == "09" { //西药费
  315. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  316. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  317. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  318. westernMedicine_fulamt_ownpay_amt, _ = decimal.NewFromFloat(westernMedicine_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  319. if item.ChrgitmLv == "1" {
  320. westernMedicine_claa_sunmfee, _ = decimal.NewFromFloat(westernMedicine_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  321. }
  322. if item.ChrgitmLv == "2" {
  323. westernMedicine_clab_amt, _ = decimal.NewFromFloat(westernMedicine_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  324. }
  325. if item.ChrgitmLv == "3" {
  326. westernMedicine_other_amt, _ = decimal.NewFromFloat(westernMedicine_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  327. }
  328. }
  329. if item.MedChrgitmType == "11" { //中成费
  330. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  331. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  332. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  333. chineseTraditional_fulamt_ownpay_amt, _ = decimal.NewFromFloat(chineseTraditional_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  334. if item.ChrgitmLv == "1" {
  335. chineseTraditional_claa_sunmfee, _ = decimal.NewFromFloat(chineseTraditional_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  336. }
  337. if item.ChrgitmLv == "2" {
  338. chineseTraditional_clab_amt, _ = decimal.NewFromFloat(chineseTraditional_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  339. }
  340. if item.ChrgitmLv == "3" {
  341. chineseTraditional_other_amt, _ = decimal.NewFromFloat(chineseTraditional_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  342. }
  343. }
  344. if item.MedChrgitmType == "14" { //其他费
  345. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  346. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  347. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  348. other_fulamt_ownpay_amt, _ = decimal.NewFromFloat(other_fulamt_ownpay_amt).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  349. if item.ChrgitmLv == "1" {
  350. other_claa_sunmfee, _ = decimal.NewFromFloat(other_claa_sunmfee).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  351. }
  352. if item.ChrgitmLv == "2" {
  353. other_clab_amt, _ = decimal.NewFromFloat(other_clab_amt).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  354. }
  355. if item.ChrgitmLv == "3" {
  356. other_other_amt, _ = decimal.NewFromFloat(other_other_amt).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  357. }
  358. }
  359. }
  360. var iteminfoStructs []service.IteminfoStruct
  361. if bedCostTotal != 0 {
  362. iteminfo.MedChrgitm = "01"
  363. iteminfo.FulamtOwnpayAmt = bed_fulamt_ownpay_amt
  364. iteminfo.Amt = bedCostTotal
  365. iteminfo.ClaaSumfee = bed_claa_sunmfee
  366. iteminfo.ClabAmt = bed_clab_amt
  367. iteminfo.OthAmt = bed_other_amt
  368. iteminfoStructs = append(iteminfoStructs, iteminfo)
  369. }
  370. if checkCostTotal != 0 {
  371. iteminfo.MedChrgitm = "03"
  372. iteminfo.FulamtOwnpayAmt = check_fulamt_ownpay_amt
  373. iteminfo.Amt = checkCostTotal
  374. iteminfo.ClaaSumfee = check_claa_sunmfee
  375. iteminfo.ClabAmt = check_clab_amt
  376. iteminfo.OthAmt = check_other_amt
  377. iteminfoStructs = append(iteminfoStructs, iteminfo)
  378. }
  379. if laboratoryCostTotal != 0 {
  380. iteminfo.MedChrgitm = "04"
  381. iteminfo.FulamtOwnpayAmt = laboratory_fulamt_ownpay_amt
  382. iteminfo.Amt = laboratoryCostTotal
  383. iteminfo.ClaaSumfee = laboratory_claa_sunmfee
  384. iteminfo.ClabAmt = laboratory_clab_amt
  385. iteminfo.OthAmt = laboratory_other_amt
  386. iteminfoStructs = append(iteminfoStructs, iteminfo)
  387. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  388. }
  389. if treatCostTotal != 0 {
  390. iteminfo.MedChrgitm = "05"
  391. iteminfo.FulamtOwnpayAmt = treat_fulamt_ownpay_amt
  392. iteminfo.Amt = treatCostTotal
  393. iteminfo.ClaaSumfee = treat_claa_sunmfee
  394. iteminfo.ClabAmt = treat_clab_amt
  395. iteminfo.OthAmt = treat_other_amt
  396. iteminfoStructs = append(iteminfoStructs, iteminfo)
  397. // (struct4101.IteminfoStruct, iteminfo)
  398. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  399. }
  400. if operationCostTotal != 0 {
  401. iteminfo.MedChrgitm = "06"
  402. iteminfo.FulamtOwnpayAmt = bed_fulamt_ownpay_amt
  403. iteminfo.Amt = operationCostTotal
  404. iteminfo.ClaaSumfee = operation_claa_sunmfee
  405. iteminfo.ClabAmt = operation_clab_amt
  406. iteminfo.OthAmt = operation_other_amt
  407. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  408. iteminfoStructs = append(iteminfoStructs, iteminfo)
  409. }
  410. if materialCostTotal != 0 {
  411. iteminfo.MedChrgitm = "08"
  412. iteminfo.FulamtOwnpayAmt = material_fulamt_ownpay_amt
  413. iteminfo.Amt = materialCostTotal
  414. iteminfo.ClaaSumfee = material_claa_sunmfee
  415. iteminfo.ClabAmt = material_clab_amt
  416. iteminfo.OthAmt = material_other_amt
  417. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  418. iteminfoStructs = append(iteminfoStructs, iteminfo)
  419. }
  420. if westernMedicineCostTotal != 0 {
  421. iteminfo.MedChrgitm = "09"
  422. iteminfo.FulamtOwnpayAmt = westernMedicine_fulamt_ownpay_amt
  423. iteminfo.Amt = westernMedicineCostTotal
  424. iteminfo.ClaaSumfee = westernMedicine_claa_sunmfee
  425. iteminfo.ClabAmt = westernMedicine_clab_amt
  426. iteminfo.OthAmt = westernMedicine_other_amt
  427. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  428. iteminfoStructs = append(iteminfoStructs, iteminfo)
  429. }
  430. if chineseTraditionalMedicineCostTotal != 0 {
  431. iteminfo.MedChrgitm = "11"
  432. iteminfo.FulamtOwnpayAmt = westernMedicine_fulamt_ownpay_amt
  433. iteminfo.Amt = westernMedicineCostTotal
  434. iteminfo.ClaaSumfee = westernMedicine_claa_sunmfee
  435. iteminfo.ClabAmt = westernMedicine_clab_amt
  436. iteminfo.OthAmt = westernMedicine_other_amt
  437. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  438. iteminfoStructs = append(iteminfoStructs, iteminfo)
  439. }
  440. if otherCostTotal != 0 {
  441. iteminfo.MedChrgitm = "14"
  442. iteminfo.FulamtOwnpayAmt = other_fulamt_ownpay_amt
  443. iteminfo.Amt = otherCostTotal
  444. iteminfo.ClaaSumfee = other_claa_sunmfee
  445. iteminfo.ClabAmt = other_clab_amt
  446. iteminfo.OthAmt = other_other_amt
  447. //struct4101.IteminfoStruct = append(struct4101.IteminfoStruct, iteminfo)
  448. iteminfoStructs = append(iteminfoStructs, iteminfo)
  449. }
  450. struct4101.IteminfoStruct = iteminfoStructs
  451. struct4101.Ntly = "中国"
  452. struct4101.AdmCaty = "A03.06"
  453. result := service.Gdyb4101(struct4101, miConfig.SecretKey, miConfig.OrgName, curRoles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  454. fmt.Println(result)
  455. var dat map[string]interface{}
  456. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  457. fmt.Println(dat)
  458. } else {
  459. fmt.Println(err)
  460. }
  461. userJSONBytes, _ := json.Marshal(dat)
  462. var res ResultSeventeen
  463. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  464. utils.ErrorLog("解析失败:%v", err)
  465. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  466. return
  467. }
  468. if res.Infcode != 0 {
  469. c.ServeSuccessJSON(map[string]interface{}{
  470. "failed_code": -10,
  471. "msg": res.ErrMsg,
  472. })
  473. return
  474. } else {
  475. hisFundSettleListResult := &models.HisFundSettleListResult{
  476. Number: res.Output.Data.SetlListId,
  477. Status: 1,
  478. Ctime: time.Now().Unix(),
  479. Mtime: time.Now().Unix(),
  480. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  481. IsUpload: 1,
  482. }
  483. service.CreateUploadRecord(hisFundSettleListResult)
  484. c.ServeSuccessJSON(map[string]interface{}{
  485. "msg": "上传成功",
  486. "result": hisFundSettleListResult,
  487. })
  488. return
  489. }
  490. }
  491. func (c *HisApiController) TestGetBasBaseInfo() {
  492. DllDef := syscall.MustLoadDLL("SSCard.dll")
  493. Iinit := DllDef.MustFindProc("Init")
  494. readCard := DllDef.MustFindProc("ReadCardBas")
  495. ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  496. if ret != 0 {
  497. fmt.Println("SSCard的报错原因:", err)
  498. fmt.Println("SSCard的运算结果为:", ret)
  499. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  500. return
  501. }
  502. result := int(ret)
  503. fmt.Println("SSCard的运算结果为1:", result)
  504. if readCard == nil {
  505. fmt.Println("readcard is nil")
  506. readCard = DllDef.MustFindProc("ReadCardBas")
  507. }
  508. if readCard == nil {
  509. fmt.Println("readcard reload is nil")
  510. return
  511. }
  512. str := make([]byte, 1024)
  513. str1 := make([]byte, 1024)
  514. cdat := len(str)
  515. cdat1 := len(str1)
  516. p := *((*int32)(unsafe.Pointer(&str[0])))
  517. p1 := *((*int32)(unsafe.Pointer(&str1[0])))
  518. ret2, _, err2 := readCard.Call(uintptr(p), uintptr(cdat), uintptr(p1), uintptr(cdat1))
  519. fmt.Println(" Add(4,5)的结果为:", ret2)
  520. str11 := prttostr(uintptr(p))
  521. str22 := prttostr(uintptr(p1))
  522. fmt.Println(" str:", str11)
  523. fmt.Println(" str1:", str22)
  524. // runtime.GC()
  525. if err2 != nil {
  526. fmt.Println("SSCard的运算结果为:", ret2)
  527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  528. return
  529. }
  530. }
  531. func prttostr(vcode uintptr) string {
  532. var vbyte []byte
  533. for i := 0; i < 10; i++ {
  534. sbyte := *((*byte)(unsafe.Pointer(vcode)))
  535. if sbyte == 0 {
  536. break
  537. }
  538. vbyte = append(vbyte, sbyte)
  539. vcode += 1
  540. }
  541. return string(vbyte)
  542. }
  543. //func (c *HisApiController) TestPay() {
  544. // DllDef2 := syscall.MustLoadDLL("SSSE32.dll")
  545. // readCards := DllDef2.MustFindProc("BankTrans")
  546. // inputData := make(map[string]interface{})
  547. // inputData["transId"] = "05"
  548. // inputData["amount"] = "0.01"
  549. // inputData["traceNo"] = "20210227093601325405377"
  550. // inputData["cardNo"] = "F36084348"
  551. // inputData["id"] = "44022919620927046X"
  552. // //jsonStr := `
  553. // // {
  554. // // "transId": "05",
  555. // // "amount":"1.00",
  556. // // "traceNo":"20210227093601325405377",
  557. // // "cardNo":"F36084348",
  558. // // "id":"44022919620927046X"
  559. // //
  560. // // }
  561. // //`
  562. //
  563. // bytes_arr, _ := json.Marshal(inputData)
  564. // str3 := make([]byte, 256)
  565. // ret4, _, err4 := readCards.Call(StrPtr(string(bytes_arr)), (uintptr)(unsafe.Pointer(&str3[0])))
  566. // fmt.Println(":", string(str3))
  567. //
  568. // if err4 != nil {
  569. // fmt.Println("SSCard的运算结果为:", ret4)
  570. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  571. // return
  572. // }
  573. //
  574. //}
  575. //func (c *HisApiController) TestGetBasBaseInfo() {
  576. //
  577. // //result := C.Init(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  578. // //fmt.Println(result)
  579. // //cs1 := C.CString("")
  580. // //cs2 := C.CString("")
  581. // //C.ReadCardBas(cs1, IntPtr(1024), cs2, IntPtr(1024))
  582. // //fmt.Println(cs1)
  583. // //fmt.Println(cs2)
  584. // //C.free(unsafe.Pointer(cs1))
  585. // //C.free(unsafe.Pointer(cs2))
  586. //
  587. // //
  588. //
  589. // DllDef := syscall.MustLoadDLL("SSCard.dll")
  590. // Iinit := DllDef.MustFindProc("Init")
  591. // readCard := DllDef.MustFindProc("ReadCardBas")
  592. // ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  593. // if ret != 0 {
  594. // fmt.Println("SSCard的报错原因:", err)
  595. // fmt.Println("SSCard的运算结果为:", ret)
  596. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  597. // return
  598. // }
  599. //
  600. // result := int(ret)
  601. // fmt.Println("SSCard的运算结果为1:", result)
  602. //
  603. // //path := ""
  604. // //bytePath := []byte( "\x00")
  605. // //bytePath2 := []byte( "\x00")
  606. // //ssss
  607. //
  608. // str := make([]byte, 256)
  609. // str1 := make([]byte, 256)
  610. // s2 := []byte(string(str))
  611. // s3 := []byte(string(str1))
  612. // ret2, _, err2 := readCard.Call((uintptr)(unsafe.Pointer(&s2[0])), IntPtr(256), (uintptr)(unsafe.Pointer(&s3[0])), IntPtr(256))
  613. // fmt.Println(" Add(4,5)的结果为:", ret2)
  614. // fmt.Println(" str:", s2)
  615. // fmt.Println(" str1:", s3)
  616. // if err2 != nil {
  617. // fmt.Println("SSCard的运算结果为:", ret2)
  618. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  619. // return
  620. // }
  621. //
  622. // //DllDef := syscall.MustLoadDLL("SSCard.dll")
  623. //
  624. //}
  625. func (c *HisApiController) GetOrgInfo() {
  626. miConfig, _ := service.FindMedicalInsuranceInfo(9919)
  627. service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
  628. }
  629. func (c *HisApiController) GetHisPatientInfo() {
  630. medical_insurance_card := c.GetString("medical_insurance_card")
  631. id_card_type, _ := c.GetInt64("id_card_type")
  632. id_card := c.GetString("id_card")
  633. adminInfo := c.GetAdminUserInfo()
  634. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  635. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  636. appRole, _ := service.GetAppRole(adminInfo.CurrentOrgId)
  637. IdCardNo := ""
  638. if id_card_type == 1 {
  639. IdCardNo = medical_insurance_card
  640. } else if id_card_type == 2 {
  641. IdCardNo = id_card
  642. }
  643. if config.IsOpen == 1 {
  644. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  645. resp, requestErr := http.Get(api)
  646. if requestErr != nil {
  647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  648. return
  649. }
  650. defer resp.Body.Close()
  651. body, ioErr := ioutil.ReadAll(resp.Body)
  652. if ioErr != nil {
  653. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  654. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  655. return
  656. }
  657. var respJSON map[string]interface{}
  658. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  659. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  660. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  661. return
  662. }
  663. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  664. userJSONBytes, _ := json.Marshal(userJSON)
  665. var res ResultTwo
  666. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  667. utils.ErrorLog("解析失败:%v", err)
  668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  669. return
  670. }
  671. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  672. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  673. infoStr := string(Iinfos)
  674. idetinfoStr := string(Idetinfos)
  675. if res.Infcode == 0 {
  676. his := models.VMHisPatient{
  677. Status: 1,
  678. Ctime: time.Now().Unix(),
  679. Mtime: time.Now().Unix(),
  680. PsnNo: res.Output.Baseinfo.PsnNo,
  681. PsnCertType: res.Output.Baseinfo.PsnCertType,
  682. Certno: res.Output.Baseinfo.Certno,
  683. PsnName: res.Output.Baseinfo.PsnName,
  684. Gend: res.Output.Baseinfo.Gend,
  685. Naty: res.Output.Baseinfo.Naty,
  686. Brdy: res.Output.Baseinfo.Brdy,
  687. Age: res.Output.Baseinfo.Age,
  688. Iinfo: infoStr,
  689. Idetinfo: idetinfoStr,
  690. UserOrgId: adminInfo.CurrentOrgId,
  691. IsReturn: 1,
  692. IdCardType: id_card_type,
  693. }
  694. c.ServeSuccessJSON(map[string]interface{}{
  695. "info": his,
  696. })
  697. } else {
  698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  699. return
  700. }
  701. }
  702. }
  703. func (c *HisApiController) Sscard() {
  704. //id_card_type, _ := c.GetInt64("id_card_type")
  705. //adminUser := c.GetAdminUserInfo()
  706. //miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  707. id_card_type := 1
  708. r := CardInit()
  709. fmt.Println(r)
  710. //if r == 0 {
  711. switch id_card_type {
  712. case 1:
  713. //defer GetBasBaseInfo()
  714. //if err != nil {
  715. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  716. // return
  717. //
  718. //} else {
  719. // fmt.Println(basStr)
  720. //
  721. // bas := strings.Split(basStr, "|")
  722. //
  723. // basNumber := bas[1]
  724. //
  725. // //basNumber := bas[2]
  726. // card_sn := bas[3]
  727. //
  728. // appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  729. //
  730. // api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + basNumber + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10) + "&card_sn=" + card_sn
  731. // resp, requestErr := http.Get(api)
  732. // if requestErr != nil {
  733. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  734. // return
  735. // }
  736. // defer resp.Body.Close()
  737. // body, ioErr := ioutil.ReadAll(resp.Body)
  738. // if ioErr != nil {
  739. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  740. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  741. // return
  742. // }
  743. // var respJSON map[string]interface{}
  744. //
  745. // if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  746. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  747. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  748. // return
  749. // }
  750. //
  751. // userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  752. // userJSONBytes, _ := json.Marshal(userJSON)
  753. // var res ResultTwo
  754. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  755. // utils.ErrorLog("解析失败:%v", err)
  756. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  757. // return
  758. // }
  759. // Iinfos, _ := json.Marshal(res.Output.Iinfo)
  760. // Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  761. // infoStr := string(Iinfos)
  762. // idetinfoStr := string(Idetinfos)
  763. //
  764. // if res.Infcode == 0 {
  765. // his := models.VMHisPatient{
  766. // Status: 1,
  767. // Ctime: time.Now().Unix(),
  768. // Mtime: time.Now().Unix(),
  769. // PsnNo: res.Output.Baseinfo.PsnNo,
  770. // PsnCertType: res.Output.Baseinfo.PsnCertType,
  771. // Certno: res.Output.Baseinfo.Certno,
  772. // PsnName: res.Output.Baseinfo.PsnName,
  773. // Gend: res.Output.Baseinfo.Gend,
  774. // Naty: res.Output.Baseinfo.Naty,
  775. // Brdy: res.Output.Baseinfo.Brdy,
  776. // Age: res.Output.Baseinfo.Age,
  777. // Iinfo: infoStr,
  778. // Idetinfo: idetinfoStr,
  779. // UserOrgId: adminUser.CurrentOrgId,
  780. // IsReturn: 1,
  781. // IdCardType: id_card_type,
  782. // }
  783. //
  784. // patient, err := service.GetPatientByNumber(basNumber, adminUser.CurrentOrgId)
  785. // if err == gorm.ErrRecordNotFound {
  786. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  787. // return
  788. //
  789. // } else if err != nil {
  790. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  791. // return
  792. //
  793. // } else {
  794. // c.ServeSuccessJSON(map[string]interface{}{
  795. // "patient": patient,
  796. // "his": his,
  797. // "number": basNumber,
  798. // })
  799. // }
  800. // } else {
  801. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  802. // return
  803. // }
  804. //
  805. //}
  806. break
  807. case 2:
  808. ////SFZStr, err := GetSFZBaseInfo()
  809. //if err != nil {
  810. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  811. // return
  812. //
  813. //} else {
  814. //
  815. // id_card_str := strings.Split(SFZStr, "^")
  816. // id_card_number := id_card_str[0]
  817. //appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  818. //
  819. //api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + id_card_number + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
  820. //resp, requestErr := http.Get(api)
  821. //if requestErr != nil {
  822. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  823. // return
  824. //}
  825. //defer resp.Body.Close()
  826. //body, ioErr := ioutil.ReadAll(resp.Body)
  827. //if ioErr != nil {
  828. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  829. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  830. // return
  831. //}
  832. //var respJSON map[string]interface{}
  833. //
  834. //if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  835. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  836. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  837. // return
  838. //}
  839. //
  840. //userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  841. //userJSONBytes, _ := json.Marshal(userJSON)
  842. //var res ResultTwo
  843. //if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  844. // utils.ErrorLog("解析失败:%v", err)
  845. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  846. // return
  847. //}
  848. //Iinfos, _ := json.Marshal(res.Output.Iinfo)
  849. //Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  850. //infoStr := string(Iinfos)
  851. //idetinfoStr := string(Idetinfos)
  852. //
  853. //if res.Infcode == 0 {
  854. // his := models.VMHisPatient{
  855. // Status: 1,
  856. // Ctime: time.Now().Unix(),
  857. // Mtime: time.Now().Unix(),
  858. // PsnNo: res.Output.Baseinfo.PsnNo,
  859. // PsnCertType: res.Output.Baseinfo.PsnCertType,
  860. // Certno: res.Output.Baseinfo.Certno,
  861. // PsnName: res.Output.Baseinfo.PsnName,
  862. // Gend: res.Output.Baseinfo.Gend,
  863. // Naty: res.Output.Baseinfo.Naty,
  864. // Brdy: res.Output.Baseinfo.Brdy,
  865. // Age: res.Output.Baseinfo.Age,
  866. // Iinfo: infoStr,
  867. // Idetinfo: idetinfoStr,
  868. // UserOrgId: adminUser.CurrentOrgId,
  869. // IsReturn: 1,
  870. // IdCardType: id_card_type,
  871. // }
  872. // patient, err := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  873. // if err == gorm.ErrRecordNotFound {
  874. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  875. // return
  876. //
  877. // } else if err != nil {
  878. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  879. // return
  880. //
  881. // } else {
  882. // c.ServeSuccessJSON(map[string]interface{}{
  883. // "patient": patient,
  884. // "number": id_card_number,
  885. // })
  886. // }
  887. //}
  888. break
  889. case 3:
  890. break
  891. }
  892. }
  893. //func GetBasBaseInfo() (jsonStr string, err error) {
  894. //
  895. // handle := syscall.NewLazyDLL("SSCard.dll")
  896. // add := handle.NewProc("ReadCardBas")
  897. // str := make([]byte, 1024)
  898. // str1 := make([]byte, 1024)
  899. // ret, _, _ := add.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  900. // fmt.Println(ConvertToString(string(str), "gbk", "utf-8"))
  901. //
  902. // fmt.Println(ConvertToString(string(str1), "gbk", "utf-8"))
  903. //
  904. // fmt.Println("> Add(4,5)的结果为:", ret)
  905. // handle.Release()
  906. //
  907. // return "", nil
  908. //
  909. //}
  910. //func GetSFZBaseInfo() (jsonStr string, err error) {
  911. // //handle := syscall.MustLoadDLL("SSCard.dll")
  912. //
  913. // str := make([]byte, 256)
  914. // str1 := make([]byte, 256)
  915. // r, _, _ := ReadIDCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  916. //
  917. // fmt.Println(r)
  918. // return string(str), nil
  919. //}
  920. //func GetQRBaseInfo() (jsonStr string, err error) {
  921. // handle := syscall.LoadDLL("SSCard.dll")
  922. // ReadCardBas := handle.FindProc("GetQRBase")
  923. //
  924. // str := make([]byte, 256)
  925. // str1 := make([]byte, 256)
  926. // r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  927. //
  928. // fmt.Println(string(str))
  929. // fmt.Println(r)
  930. // return string(str), nil
  931. //}
  932. func CardInit() int {
  933. DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  934. add := DllTestDef.MustFindProc("Init")
  935. ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  936. if err != nil {
  937. fmt.Println("SSCard的运算结果为:", ret)
  938. }
  939. result := int(ret)
  940. return result
  941. }
  942. //func CardInit() int {
  943. // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  944. // if err != nil {
  945. // fmt.Println("SSCard的运算结果为:", ret)
  946. // }
  947. // fmt.Println(err)
  948. // result := int(ret)
  949. // return result
  950. //}
  951. func IntPtr(n int) uintptr {
  952. return uintptr(n)
  953. }
  954. func StrPtr(s string) uintptr {
  955. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  956. }
  957. type ResultTwo struct {
  958. ErrMsg string `json:"err_msg"`
  959. InfRefmsgid string `json:"inf_refmsgid"`
  960. Infcode int64 `json:"infcode"`
  961. Output struct {
  962. Baseinfo struct {
  963. Age float64 `json:"age"`
  964. Brdy string `json:"brdy"`
  965. Certno string `json:"certno"`
  966. Gend string `json:"gend"`
  967. Naty string `json:"naty"`
  968. PsnCertType string `json:"psn_cert_type"`
  969. PsnName string `json:"psn_name"`
  970. PsnNo string `json:"psn_no"`
  971. } `json:"baseinfo"`
  972. Idetinfo []interface{} `json:"idetinfo"`
  973. Iinfo []struct {
  974. Balc float64 `json:"balc"`
  975. CvlservFlag string `json:"cvlserv_flag"`
  976. EmpName string `json:"emp_name"`
  977. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  978. Insutype string `json:"insutype"`
  979. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  980. PausInsuDate string `json:"paus_insu_date"`
  981. PsnInsuDate string `json:"psn_insu_date"`
  982. PsnInsuStas string `json:"psn_insu_stas"`
  983. PsnType string `json:"psn_type"`
  984. } `json:"insuinfo"`
  985. } `json:"output"`
  986. RefmsgTime string `json:"refmsg_time"`
  987. RespondTime string `json:"respond_time"`
  988. Signtype interface{} `json:"signtype"`
  989. WarnInfo interface{} `json:"warn_info"`
  990. }
  991. type ResultThree struct {
  992. Cainfo interface{} `json:"cainfo"`
  993. ErrMsg string `json:"err_msg"`
  994. InfRefmsgid string `json:"inf_refmsgid"`
  995. Infcode int64 `json:"infcode"`
  996. Output struct {
  997. Data struct {
  998. IptOtpNo string `json:"ipt_otp_no"`
  999. MdtrtID string `json:"mdtrt_id"`
  1000. PsnNo string `json:"psn_no"`
  1001. } `json:"data"`
  1002. } `json:"output"`
  1003. RefmsgTime string `json:"refmsg_time"`
  1004. RespondTime string `json:"respond_time"`
  1005. Signtype interface{} `json:"signtype"`
  1006. WarnMsg interface{} `json:"warn_msg"`
  1007. }
  1008. type ResultFour struct {
  1009. Cainfo string `json:"cainfo"`
  1010. ErrMsg string `json:"err_msg"`
  1011. InfRefmsgid string `json:"inf_refmsgid"`
  1012. Infcode int64 `json:"infcode"`
  1013. Output struct {
  1014. Result []struct {
  1015. BasMednFlag string `json:"bas_medn_flag"`
  1016. ChldMedcFlag string `json:"chld_medc_flag"`
  1017. ChrgitmLv string `json:"chrgitm_lv"`
  1018. Cnt float64 `json:"cnt"`
  1019. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  1020. DrtReimFlag string `json:"drt_reim_flag"`
  1021. FeedetlSn string `json:"feedetl_sn"`
  1022. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1023. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  1024. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1025. ListSpItemFlag string `json:"list_sp_item_flag"`
  1026. LmtUsedFlag string `json:"lmt_used_flag"`
  1027. MedChrgitmType string `json:"med_chrgitm_type"`
  1028. Memo string `json:"memo"`
  1029. OverlmtAmt float64 `json:"overlmt_amt"`
  1030. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1031. Pric float64 `json:"pric"`
  1032. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  1033. SelfpayProp float64 `json:"selfpay_prop"`
  1034. } `json:"result"`
  1035. } `json:"output"`
  1036. RefmsgTime string `json:"refmsg_time"`
  1037. RespondTime string `json:"respond_time"`
  1038. Signtype string `json:"signtype"`
  1039. WarnMsg string `json:"warn_msg"`
  1040. }
  1041. type ResultFive struct {
  1042. Balc float64 `json:"balc"`
  1043. CvlservFlag string `json:"cvlserv_flag"`
  1044. EmpName string `json:"emp_name"`
  1045. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  1046. Insutype string `json:"insutype"`
  1047. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  1048. PausInsuDate string `json:"paus_insu_date"`
  1049. PsnInsuDate string `json:"psn_insu_date"`
  1050. PsnInsuStas string `json:"psn_insu_stas"`
  1051. PsnType string `json:"psn_type"`
  1052. }
  1053. type ResultSix struct {
  1054. Cainfo interface{} `json:"cainfo"`
  1055. ErrMsg string `json:"err_msg"`
  1056. InfRefmsgid string `json:"inf_refmsgid"`
  1057. Infcode int64 `json:"infcode"`
  1058. Output struct {
  1059. } `json:"output"`
  1060. RefmsgTime string `json:"refmsg_time"`
  1061. RespondTime string `json:"respond_time"`
  1062. Signtype interface{} `json:"signtype"`
  1063. WarnMsg interface{} `json:"warn_msg"`
  1064. }
  1065. type ResultSeven struct {
  1066. Cainfo string `json:"cainfo"`
  1067. ErrMsg string `json:"err_msg"`
  1068. InfRefmsgid string `json:"inf_refmsgid"`
  1069. Infcode int64 `json:"infcode"`
  1070. Output struct {
  1071. Setldetail []interface{} `json:"setldetail"`
  1072. Setlinfo struct {
  1073. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1074. AcctPay float64 `json:"acct_pay"`
  1075. ActPayDedc float64 `json:"act_pay_dedc"`
  1076. Age float64 `json:"age"`
  1077. Balc float64 `json:"balc"`
  1078. Brdy string `json:"brdy"`
  1079. Certno string `json:"certno"`
  1080. ClrOptins string `json:"clr_optins"`
  1081. ClrType string `json:"clr_type"`
  1082. ClrWay string `json:"clr_way"`
  1083. CvlservFlag string `json:"cvlserv_flag"`
  1084. CvlservPay float64 `json:"cvlserv_pay"`
  1085. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1086. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1087. Gend string `json:"gend"`
  1088. HifesPay float64 `json:"hifes_pay"`
  1089. HifmiPay float64 `json:"hifmi_pay"`
  1090. HifpPay float64 `json:"hifp_pay"`
  1091. HospPartAmt float64 `json:"hosp_part_amt"`
  1092. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1093. Insutype string `json:"insutype"`
  1094. MafPay float64 `json:"maf_pay"`
  1095. MdtrtCertType string `json:"mdtrt_cert_type"`
  1096. HifobPay float64 `json:"hifob_pay"`
  1097. MdtrtID string `json:"mdtrt_id"`
  1098. MedType string `json:"med_type"`
  1099. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1100. MedinsSetlID string `json:"medins_setl_id"`
  1101. Naty string `json:"naty"`
  1102. OthPay float64 `json:"oth_pay"`
  1103. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1104. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1105. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1106. PsnCashPay float64 `json:"psn_cash_pay"`
  1107. PsnCertType string `json:"psn_cert_type"`
  1108. PsnName string `json:"psn_name"`
  1109. PsnNo string `json:"psn_no"`
  1110. PsnPartAmt float64 `json:"psn_part_amt"`
  1111. PsnType string `json:"psn_type"`
  1112. SetlID string `json:"setl_id"`
  1113. SetlTime string `json:"setl_time"`
  1114. } `json:"setlinfo"`
  1115. } `json:"output"`
  1116. RefmsgTime string `json:"refmsg_time"`
  1117. RespondTime string `json:"respond_time"`
  1118. Signtype interface{} `json:"signtype"`
  1119. WarnMsg interface{} `json:"warn_msg"`
  1120. }
  1121. type ResultEight struct {
  1122. Cainfo string `json:"cainfo"`
  1123. ErrMsg string `json:"err_msg"`
  1124. InfRefmsgid string `json:"inf_refmsgid"`
  1125. Infcode int64 `json:"infcode"`
  1126. Output struct {
  1127. Stmtinfo struct {
  1128. SetlOptins string `json:"setl_optins"`
  1129. StmtRslt string `json:"stmt_rslt"`
  1130. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  1131. } `json:"stmtinfo"`
  1132. } `json:"output"`
  1133. RefmsgTime string `json:"refmsg_time"`
  1134. RespondTime string `json:"respond_time"`
  1135. Signtype interface{} `json:"signtype"`
  1136. WarnMsg interface{} `json:"warn_msg"`
  1137. }
  1138. type ResultNine struct {
  1139. Cainfo string `json:"cainfo"`
  1140. ErrMsg string `json:"err_msg"`
  1141. InfRefmsgid string `json:"inf_refmsgid"`
  1142. Infcode int64 `json:"infcode"`
  1143. Output struct {
  1144. FileQuryNo string `json:"file_qury_no"`
  1145. } `json:"output"`
  1146. RefmsgTime string `json:"refmsg_time"`
  1147. RespondTime string `json:"respond_time"`
  1148. Signtype interface{} `json:"signtype"`
  1149. WarnMsg interface{} `json:"warn_msg"`
  1150. }
  1151. type ResultTen struct {
  1152. Cainfo string `json:"cainfo"`
  1153. ErrMsg string `json:"err_msg"`
  1154. InfRefmsgid string `json:"inf_refmsgid"`
  1155. Infcode int64 `json:"infcode"`
  1156. Output struct {
  1157. DldEndtime string `json:"dld_endtime"`
  1158. FileQuryNo string `json:"file_qury_no"`
  1159. Filename string `json:"filename"`
  1160. } `json:"output"`
  1161. RefmsgTime string `json:"refmsg_time"`
  1162. RespondTime string `json:"respond_time"`
  1163. Signtype interface{} `json:"signtype"`
  1164. WarnMsg interface{} `json:"warn_msg"`
  1165. }
  1166. type ResultEleven struct {
  1167. Cainfo string `json:"cainfo"`
  1168. ErrMsg string `json:"err_msg"`
  1169. InfRefmsgid string `json:"inf_refmsgid"`
  1170. Infcode int64 `json:"infcode"`
  1171. Output struct {
  1172. Setlinfo struct {
  1173. FixmedinsName string `json:"fixmedins_name"`
  1174. FixmedinsCode string `json:"fixmedins_code"`
  1175. PsnNo string `json:"psn_no"`
  1176. PsnName string `json:"psn_name"`
  1177. HifobPay float64 `json:"hifob_pay"`
  1178. Gend string `json:"gend"`
  1179. Brdy string `json:"brdy"`
  1180. PsnCertType string `json:"psn_cert_type"`
  1181. PsnType string `json:"psn_type"`
  1182. EmpName string `json:"emp_name"`
  1183. Certno string `json:"certno"`
  1184. Insutype string `json:"insutype"`
  1185. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1186. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1187. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1188. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1189. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1190. ActPayDedc float64 `json:"act_pay_dedc"`
  1191. HifpPay float64 `json:"hifp_pay"`
  1192. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1193. CvlservPay float64 `json:"cvlserv_pay"`
  1194. HifesPay float64 `json:"hifes_pay"`
  1195. HifmiPay float64 `json:"hifmi_pay"`
  1196. MafPay float64 `json:"maf_pay"`
  1197. OthPay float64 `json:"oth_pay"`
  1198. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1199. PsnPay float64 `json:"psn_pay"`
  1200. AcctPay float64 `json:"acct_pay"`
  1201. CashPayamt float64 `json:"cash_payamt"`
  1202. Balc float64 `json:"balc"`
  1203. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1204. MedinsSetlId string `json:"medins_setl_id"`
  1205. RefdSetlFlag string `json:"refd_setl_flag"`
  1206. SetlTime string `json:"setl_time"`
  1207. MedType string `json:"med_type"`
  1208. HospLv string `json:"hosp_lv"`
  1209. } `json:"setlinfo"`
  1210. } `json:"output"`
  1211. RefmsgTime string `json:"refmsg_time"`
  1212. RespondTime string `json:"respond_time"`
  1213. Signtype interface{} `json:"signtype"`
  1214. WarnMsg interface{} `json:"warn_msg"`
  1215. }
  1216. type ResultTwelve struct {
  1217. Cainfo string `json:"cainfo"`
  1218. ErrMsg string `json:"err_msg"`
  1219. InfRefmsgid string `json:"inf_refmsgid"`
  1220. Infcode int64 `json:"infcode"`
  1221. Output struct {
  1222. MdtrtId string `json:"mdtrt_id"`
  1223. ChrgBchno string `json:"chrg_bchno"`
  1224. PsnNo string `json:"psn_no"`
  1225. } `json:"output"`
  1226. RefmsgTime string `json:"refmsg_time"`
  1227. RespondTime string `json:"respond_time"`
  1228. Signtype interface{} `json:"signtype"`
  1229. WarnMsg interface{} `json:"warn_msg"`
  1230. }
  1231. type ResultThirteen struct {
  1232. ErrMsg string `json:"err_msg"`
  1233. InfRefmsgid string `json:"inf_refmsgid"`
  1234. Infcode int64 `json:"infcode"`
  1235. Output struct {
  1236. Result struct {
  1237. TrtDclaDetlSn string `json:"trt_dcla_detl_sn"`
  1238. } `json:"result"`
  1239. } `json:"output"`
  1240. RefmsgTime string `json:"refmsg_time"`
  1241. RespondTime string `json:"respond_time"`
  1242. Signtype interface{} `json:"signtype"`
  1243. WarnInfo interface{} `json:"warn_info"`
  1244. }
  1245. type ResultFourteen struct {
  1246. ErrMsg string `json:"err_msg"`
  1247. InfRefmsgid string `json:"inf_refmsgid"`
  1248. Infcode int64 `json:"infcode"`
  1249. Output struct {
  1250. } `json:"output"`
  1251. RefmsgTime string `json:"refmsg_time"`
  1252. RespondTime string `json:"respond_time"`
  1253. Signtype interface{} `json:"signtype"`
  1254. WarnInfo interface{} `json:"warn_info"`
  1255. }
  1256. type ResultSixteen struct {
  1257. Cainfo string `json:"cainfo"`
  1258. ErrMsg string `json:"err_msg"`
  1259. InfRefmsgid string `json:"inf_refmsgid"`
  1260. Infcode int64 `json:"infcode"`
  1261. Output struct {
  1262. Setldetail []interface{} `json:"setldetail"`
  1263. Setlinfo struct {
  1264. MdtrtID string `json:"mdtrt_id"`
  1265. SetlID string `json:"setl_id"`
  1266. ClrOptins string `json:"clr_optins"`
  1267. SetlTime string `json:"setl_time"`
  1268. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1269. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1270. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1271. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1272. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1273. ActPayDedc float64 `json:"act_pay_dedc"`
  1274. HifpPay float64 `json:"hifp_pay"`
  1275. PoolPropSe float64 `json:"pool_prop_selfpay"`
  1276. Lfpay float64 `json:"selfpay"`
  1277. CvlservPay float64 `json:"cvlserv_pay"`
  1278. HifesPay float64 `json:"hifes_pay"`
  1279. HifmiPay float64 `json:"hifmi_pay"`
  1280. HifobPay float64 `json:"hifob_pay"`
  1281. MafPay float64 `json:"maf_pay"`
  1282. OthPay float64 `json:"oth_pay"`
  1283. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1284. PsnPartAmt float64 `json:"psn_part_amt"`
  1285. AcctPay float64 `json:"acct_pay"`
  1286. Balc float64 `json:"balc"`
  1287. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1288. HospPartAmt float64 `json:"hosp_part_amt"`
  1289. MedinsSetlID string `json:"medins_setl_id"`
  1290. PdnCashPay string `json:"pdn_cash_pay"`
  1291. } `json:"setlinfo"`
  1292. } `json:"output"`
  1293. RefmsgTime string `json:"refmsg_time"`
  1294. RespondTime string `json:"respond_time"`
  1295. Signtype interface{} `json:"signtype"`
  1296. WarnMsg interface{} `json:"warn_msg"`
  1297. }
  1298. type ResultSeventeen struct {
  1299. ErrMsg string `json:"err_msg"`
  1300. InfRefmsgid string `json:"inf_refmsgid"`
  1301. Infcode int64 `json:"infcode"`
  1302. Output struct {
  1303. Data struct {
  1304. SetlListId string `json:"setl_list_id"`
  1305. } `json:"data"`
  1306. } `json:"output"`
  1307. RefmsgTime string `json:"refmsg_time"`
  1308. RespondTime string `json:"respond_time"`
  1309. Signtype string `json:"signtype"`
  1310. WarnInfo string `json:"warn_info"`
  1311. }
  1312. type Custom struct {
  1313. DetItemFeeSumamt string
  1314. Cut string
  1315. FeedetlSn string
  1316. Price string
  1317. MedListCodg string
  1318. Type int64
  1319. AdviceId int64
  1320. ProjectId int64
  1321. ItemId int64
  1322. }
  1323. //获取个人信息----挂号-----上传就诊信息
  1324. func (c *HisApiController) GetRegisterInfo() {
  1325. id, _ := c.GetInt64("id")
  1326. record_time := c.GetString("record_time")
  1327. settlementValue, _ := c.GetInt64("settlement_value")
  1328. medical_insurance_card := c.GetString("medical_insurance_card")
  1329. name := c.GetString("name")
  1330. id_card_type, _ := c.GetInt64("id_card_type")
  1331. certificates, _ := c.GetInt64("certificates")
  1332. medical_care, _ := c.GetInt64("medical_care")
  1333. birthday := c.GetString("birthday")
  1334. age, _ := c.GetInt64("age")
  1335. id_card := c.GetString("id_card")
  1336. register_type, _ := c.GetInt64("register")
  1337. doctor, _ := c.GetInt64("doctor")
  1338. department, _ := c.GetInt64("department")
  1339. gender, _ := c.GetInt64("sex")
  1340. phone := c.GetString("phone")
  1341. registration_fee, _ := c.GetFloat("registration_fee")
  1342. medical_expenses, _ := c.GetFloat("medical_expenses")
  1343. social_type, _ := c.GetInt64("social_type")
  1344. admin_user_id, _ := c.GetInt64("admin_user_id")
  1345. diagnosis_id, _ := c.GetInt64("diagnosis")
  1346. sick_type, _ := c.GetInt64("sick_type")
  1347. reg_type, _ := c.GetInt64("p_type")
  1348. timeLayout := "2006-01-02"
  1349. loc, _ := time.LoadLocation("Local")
  1350. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1351. birthUnix := birthdays.Unix()
  1352. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1353. if err != nil {
  1354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1355. return
  1356. }
  1357. recordDateTime := theTime.Unix()
  1358. adminInfo := c.GetAdminUserInfo()
  1359. var patient service.Patients
  1360. if id == 0 {
  1361. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  1362. } else {
  1363. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1364. }
  1365. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1366. if patientPrescription.ID == 0 {
  1367. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1368. }
  1369. //adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1370. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  1371. sickConfig, _ := service.FindSickById(sick_type)
  1372. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1373. if patient.ID == 0 {
  1374. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1375. return
  1376. }
  1377. if len(patient.IdCardNo) == 0 {
  1378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1379. return
  1380. }
  1381. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  1382. if config.IsOpen == 1 {
  1383. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&certificates=" + strconv.FormatInt(certificates, 10)
  1384. resp, requestErr := http.Get(api)
  1385. if requestErr != nil {
  1386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1387. return
  1388. }
  1389. defer resp.Body.Close()
  1390. body, ioErr := ioutil.ReadAll(resp.Body)
  1391. if ioErr != nil {
  1392. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1393. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1394. return
  1395. }
  1396. var respJSON map[string]interface{}
  1397. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1398. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1400. return
  1401. }
  1402. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1403. userJSONBytes, _ := json.Marshal(userJSON)
  1404. var res ResultTwo
  1405. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1406. utils.ErrorLog("解析失败:%v", err)
  1407. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1408. return
  1409. }
  1410. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1411. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1412. infoStr := string(Iinfos)
  1413. idetinfoStr := string(Idetinfos)
  1414. if res.Infcode == 0 {
  1415. his := models.VMHisPatient{
  1416. Name: name,
  1417. Gender: gender,
  1418. Birthday: birthUnix,
  1419. MedicalTreatmentType: medical_care,
  1420. IdType: certificates,
  1421. IdCardNo: id_card,
  1422. BalanceAccountsType: settlementValue,
  1423. SocialType: social_type,
  1424. MedicalInsuranceNumber: medical_insurance_card,
  1425. RegisterType: register_type,
  1426. RegisterCost: registration_fee,
  1427. TreatmentCost: medical_expenses,
  1428. Status: 1,
  1429. Ctime: time.Now().Unix(),
  1430. Mtime: time.Now().Unix(),
  1431. PsnNo: res.Output.Baseinfo.PsnNo,
  1432. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1433. Certno: res.Output.Baseinfo.Certno,
  1434. PsnName: res.Output.Baseinfo.PsnName,
  1435. Gend: res.Output.Baseinfo.Gend,
  1436. Naty: res.Output.Baseinfo.Naty,
  1437. Brdy: res.Output.Baseinfo.Brdy,
  1438. Age: res.Output.Baseinfo.Age,
  1439. Iinfo: infoStr,
  1440. Idetinfo: idetinfoStr,
  1441. PatientId: patient.ID,
  1442. RecordDate: theTime.Unix(),
  1443. UserOrgId: adminInfo.CurrentOrgId,
  1444. AdminUserId: admin_user_id,
  1445. IsReturn: 1,
  1446. IdCardType: id_card_type,
  1447. Doctor: doctor,
  1448. Departments: department,
  1449. SickType: sick_type,
  1450. Diagnosis: diagnosis_id,
  1451. PType: reg_type,
  1452. }
  1453. timestamp := time.Now().Unix()
  1454. tempTime := time.Unix(timestamp, 0)
  1455. timeFormat := tempTime.Format("20060102150405")
  1456. chrgBchno := rand.Intn(100000) + 10000
  1457. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1458. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  1459. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1460. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  1461. IdCardNo := ""
  1462. if id_card_type == 1 {
  1463. IdCardNo = medical_insurance_card
  1464. } else {
  1465. IdCardNo = patient.IdCardNo
  1466. }
  1467. var insutypes []string
  1468. var insutype string
  1469. var is390 int = 0
  1470. var is310 int = 0
  1471. for _, item := range res.Output.Iinfo {
  1472. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1473. insutypes = append(insutypes, item.Insutype)
  1474. }
  1475. }
  1476. if len(insutypes) == 1 {
  1477. insutype = insutypes[0]
  1478. } else {
  1479. for _, i := range insutypes {
  1480. if i == "390" {
  1481. is390 = 1
  1482. }
  1483. if i == "310" {
  1484. is310 = 1
  1485. }
  1486. }
  1487. }
  1488. if is390 == 1 {
  1489. insutype = "390"
  1490. }
  1491. if is310 == 1 {
  1492. insutype = "310"
  1493. }
  1494. if len(insutypes) == 0 {
  1495. insutype = "310"
  1496. }
  1497. if count == 1 {
  1498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1499. return
  1500. }
  1501. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + IdCardNo + "&insutype=" +
  1502. insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  1503. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  1504. "&dept=" + department.Name + "&fixmedins_code=" + miConfig.Code + "&dept_code=" + department.Number + "&doctor_id=" + doctor_id + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
  1505. resp, requestErr := http.Get(api)
  1506. if requestErr != nil {
  1507. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1508. return
  1509. }
  1510. defer resp.Body.Close()
  1511. body, ioErr := ioutil.ReadAll(resp.Body)
  1512. if ioErr != nil {
  1513. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1515. return
  1516. }
  1517. var respJSON map[string]interface{}
  1518. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1519. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1521. return
  1522. }
  1523. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1524. userJSONBytes, _ := json.Marshal(respJSON)
  1525. var res ResultThree
  1526. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1527. utils.ErrorLog("解析失败:%v", err)
  1528. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1529. return
  1530. }
  1531. if res.Infcode == -1 {
  1532. adminUser := c.GetAdminUserInfo()
  1533. errlog := &models.HisOrderError{
  1534. UserOrgId: adminUser.CurrentOrgId,
  1535. Ctime: time.Now().Unix(),
  1536. Mtime: time.Now().Unix(),
  1537. ErrMsg: res.ErrMsg,
  1538. Status: 1,
  1539. PatientId: id,
  1540. RecordTime: recordDateTime,
  1541. Stage: 2,
  1542. }
  1543. service.CreateErrMsgLog(errlog)
  1544. c.ServeSuccessJSON(map[string]interface{}{
  1545. "failed_code": -10,
  1546. "msg": res.ErrMsg,
  1547. })
  1548. return
  1549. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1550. //return
  1551. }
  1552. his.Number = res.Output.Data.MdtrtID
  1553. his.PsnNo = res.Output.Data.PsnNo
  1554. his.IptOtpNo = res.Output.Data.IptOtpNo
  1555. his.IdCardNo = patient.IdCardNo
  1556. his.PhoneNumber = patient.Phone
  1557. his.UserOrgId = adminInfo.CurrentOrgId
  1558. his.Ctime = time.Now().Unix()
  1559. his.Mtime = time.Now().Unix()
  1560. his.Status = 1
  1561. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1562. if len(lists) == 1 {
  1563. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  1564. }
  1565. if err == nil {
  1566. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  1567. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  1568. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(reg_type, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  1569. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  1570. resp2, requestErr2 := http.Get(api2)
  1571. if requestErr2 != nil {
  1572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1573. return
  1574. }
  1575. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1576. if ioErr2 != nil {
  1577. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1579. return
  1580. }
  1581. var respJSON2 map[string]interface{}
  1582. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1583. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1584. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1585. return
  1586. }
  1587. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1588. userJSONBytes2, _ := json.Marshal(respJSON2)
  1589. var res2 ResultSix
  1590. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  1591. utils.ErrorLog("解析失败:%v", err)
  1592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1593. return
  1594. }
  1595. if res2.Infcode == -1 {
  1596. adminUser := c.GetAdminUserInfo()
  1597. errlog := &models.HisOrderError{
  1598. UserOrgId: adminUser.CurrentOrgId,
  1599. Ctime: time.Now().Unix(),
  1600. Mtime: time.Now().Unix(),
  1601. ErrMsg: res2.ErrMsg,
  1602. Status: 1,
  1603. PatientId: id,
  1604. RecordTime: recordDateTime,
  1605. Stage: 3,
  1606. }
  1607. service.CreateErrMsgLog(errlog)
  1608. c.ServeSuccessJSON(map[string]interface{}{
  1609. "failed_code": -10,
  1610. "msg": res2.ErrMsg,
  1611. })
  1612. return
  1613. } else {
  1614. service.CreateHisPatientTwo(&his)
  1615. c.ServeSuccessJSON(map[string]interface{}{
  1616. "his_info": his,
  1617. })
  1618. }
  1619. } else {
  1620. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1621. return
  1622. }
  1623. } else {
  1624. adminUser := c.GetAdminUserInfo()
  1625. errlog := &models.HisOrderError{
  1626. UserOrgId: adminUser.CurrentOrgId,
  1627. Ctime: time.Now().Unix(),
  1628. Mtime: time.Now().Unix(),
  1629. ErrMsg: res.ErrMsg,
  1630. Status: 1,
  1631. PatientId: id,
  1632. RecordTime: recordDateTime,
  1633. Stage: 1,
  1634. }
  1635. service.CreateErrMsgLog(errlog)
  1636. c.ServeSuccessJSON(map[string]interface{}{
  1637. "failed_code": -10,
  1638. "msg": res.ErrMsg,
  1639. })
  1640. return
  1641. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  1642. }
  1643. } else {
  1644. timeStr := time.Now().Format("2006-01-02")
  1645. timeArr := strings.Split(timeStr, "-")
  1646. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  1647. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1648. var hisPatient models.XtHisPatient
  1649. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1650. hisPatient = models.XtHisPatient{
  1651. Name: name,
  1652. Age: age,
  1653. Gender: gender,
  1654. Birthday: birthUnix,
  1655. Phone: phone,
  1656. MedicalTreatmentType: medical_care,
  1657. IdType: certificates,
  1658. IdCardNo: id_card,
  1659. BalanceAccountsType: settlementValue,
  1660. SocialType: social_type,
  1661. MedicalInsuranceNumber: medical_insurance_card,
  1662. RegisterType: register_type,
  1663. RegisterCost: registration_fee,
  1664. TreatmentCost: medical_expenses,
  1665. AdminUserId: admin_user_id,
  1666. UserOrgId: adminInfo.CurrentOrgId,
  1667. Status: 1,
  1668. RecordDate: recordDateTime,
  1669. IsReturn: 1,
  1670. PatientId: patient.ID,
  1671. Ctime: time.Now().Unix(),
  1672. Mtime: time.Now().Unix(),
  1673. Number: str,
  1674. }
  1675. service.CreateHisPatient(&hisPatient)
  1676. }
  1677. c.ServeSuccessJSON(map[string]interface{}{
  1678. "his_info": hisPatient,
  1679. })
  1680. }
  1681. }
  1682. //上传明细----预结算----确认订单
  1683. func (c *HisApiController) GetUploadInfo() {
  1684. id, _ := c.GetInt64("id")
  1685. record_time := c.GetString("record_time")
  1686. his_patient_id, _ := c.GetInt64("his_patient_id")
  1687. pay_way, _ := c.GetInt64("pay_way")
  1688. pay_price, _ := c.GetFloat("pay_price")
  1689. pay_card_no := c.GetString("pay_card_no")
  1690. discount_price, _ := c.GetFloat("discount_price")
  1691. preferential_price, _ := c.GetFloat("preferential_price")
  1692. reality_price, _ := c.GetFloat("reality_price")
  1693. found_price, _ := c.GetFloat("found_price")
  1694. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1695. private_price, _ := c.GetFloat("private_price")
  1696. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1697. admin_user_id, _ := c.GetInt64("admin_user_id")
  1698. fapiao_code := c.GetString("fapiao_code")
  1699. fapiao_number := c.GetString("fapiao_number")
  1700. timeLayout := "2006-01-02"
  1701. loc, _ := time.LoadLocation("Local")
  1702. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1703. if err != nil {
  1704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1705. return
  1706. }
  1707. recordDateTime := theTime.Unix()
  1708. adminUser := c.GetAdminUserInfo()
  1709. var prescriptions []*models.HisPrescription
  1710. var start_time int64
  1711. var end_time int64
  1712. data := make(map[string]interface{})
  1713. if settle_accounts_type == 1 { //日结
  1714. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1715. data["pre"] = prescriptions
  1716. } else { //月结
  1717. start_time_str := c.GetString("start_time")
  1718. end_time_str := c.GetString("end_time")
  1719. timeLayout := "2006-01-02"
  1720. loc, _ := time.LoadLocation("Local")
  1721. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1722. if err != nil {
  1723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1724. return
  1725. }
  1726. recordStartTime := theStartTime.Unix()
  1727. start_time = recordStartTime
  1728. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1729. if err != nil {
  1730. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1731. return
  1732. }
  1733. recordEndTime := theEndTime.Unix()
  1734. end_time = recordEndTime
  1735. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1736. data["pre"] = prescriptions
  1737. }
  1738. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1739. fmt.Println(his_patient_id)
  1740. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1741. timestamp := time.Now().Unix()
  1742. tempTime := time.Unix(timestamp, 0)
  1743. timeFormat := tempTime.Format("20060102150405")
  1744. chrgBchno := rand.Intn(100000) + 10000
  1745. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1746. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1747. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1748. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1749. strconv.FormatInt(his.PatientId, 10)
  1750. client := &http.Client{}
  1751. data["psn_no"] = his.PsnNo
  1752. data["mdtrt_id"] = his.Number
  1753. data["chrg_bchno"] = chrg_bchno
  1754. data["org_name"] = miConfig.OrgName
  1755. data["doctor"] = roles.UserName
  1756. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1757. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1758. data["fixmedins_code"] = miConfig.Code
  1759. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  1760. data["dept_code"] = "15"
  1761. } else {
  1762. data["dept_code"] = department.Number
  1763. }
  1764. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1765. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1766. data["secret_key"] = miConfig.SecretKey
  1767. var ids []int64
  1768. for _, item := range prescriptions {
  1769. ids = append(ids, item.ID)
  1770. }
  1771. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1772. if config.IsOpen == 1 { //对接了医保,走医保流程
  1773. bytesData, _ := json.Marshal(data)
  1774. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1775. resp, _ := client.Do(req)
  1776. defer resp.Body.Close()
  1777. body, ioErr := ioutil.ReadAll(resp.Body)
  1778. if ioErr != nil {
  1779. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1781. return
  1782. }
  1783. var respJSON map[string]interface{}
  1784. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1785. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1787. return
  1788. }
  1789. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1790. userJSONBytes, _ := json.Marshal(respJSON)
  1791. var res ResultFour
  1792. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1793. utils.ErrorLog("解析失败:%v", err)
  1794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1795. return
  1796. }
  1797. if res.Infcode == 0 {
  1798. order := &models.HisOrder{
  1799. UserOrgId: adminUser.CurrentOrgId,
  1800. HisPatientId: his.ID,
  1801. PatientId: his.PatientId,
  1802. SettleAccountsDate: recordDateTime,
  1803. Ctime: time.Now().Unix(),
  1804. Mtime: time.Now().Unix(),
  1805. Status: 1,
  1806. Number: chrg_bchno,
  1807. Infcode: res.Infcode,
  1808. WarnMsg: res.WarnMsg,
  1809. Cainfo: res.Cainfo,
  1810. ErrMsg: res.ErrMsg,
  1811. RespondTime: res.RefmsgTime,
  1812. InfRefmsgid: res.InfRefmsgid,
  1813. OrderStatus: 1,
  1814. PayWay: pay_way,
  1815. PayPrice: pay_price,
  1816. PayCardNo: pay_card_no,
  1817. DiscountPrice: discount_price,
  1818. PreferentialPrice: preferential_price,
  1819. RealityPrice: reality_price,
  1820. FoundPrice: found_price,
  1821. MedicalInsurancePrice: medical_insurance_price,
  1822. PrivatePrice: private_price,
  1823. IsMedicineInsurance: 1,
  1824. SettleType: settle_accounts_type,
  1825. SettleStartTime: start_time,
  1826. SettleEndTime: end_time,
  1827. Creator: roles.AdminUserId,
  1828. Modify: roles.AdminUserId,
  1829. FaPiaoNumber: fapiao_number,
  1830. FaPiaoCode: fapiao_code,
  1831. }
  1832. err = service.CreateOrder(order)
  1833. if err != nil {
  1834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1835. return
  1836. }
  1837. for _, item := range res.Output.Result {
  1838. temp := strings.Split(item.FeedetlSn, "-")
  1839. var advice_id int64 = 0
  1840. var project_id int64 = 0
  1841. var types int64 = 0
  1842. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1843. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1844. if temp[1] == "1" {
  1845. advice_id = id
  1846. project_id = 0
  1847. } else if temp[1] == "2" {
  1848. advice_id = 0
  1849. project_id = id
  1850. }
  1851. info := &models.HisOrderInfo{
  1852. OrderNumber: order.Number,
  1853. FeedetlSn: item.FeedetlSn,
  1854. UploadDate: time.Now().Unix(),
  1855. AdviceId: advice_id,
  1856. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1857. Cnt: item.Cnt,
  1858. Pric: float64(item.Pric),
  1859. PatientId: his.PatientId,
  1860. PricUplmtAmt: item.PricUplmtAmt,
  1861. SelfpayProp: item.SelfpayProp,
  1862. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1863. OverlmtAmt: item.OverlmtAmt,
  1864. PreselfpayAmt: item.PreselfpayAmt,
  1865. BasMednFlag: item.BasMednFlag,
  1866. MedChrgitmType: item.MedChrgitmType,
  1867. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1868. Status: 1,
  1869. Memo: item.Memo,
  1870. Mtime: time.Now().Unix(),
  1871. InscpScpAmt: item.InscpScpAmt,
  1872. DrtReimFlag: item.DrtReimFlag,
  1873. Ctime: time.Now().Unix(),
  1874. ListSpItemFlag: item.ListSpItemFlag,
  1875. ChldMedcFlag: item.ChldMedcFlag,
  1876. LmtUsedFlag: item.LmtUsedFlag,
  1877. ChrgitmLv: item.ChrgitmLv,
  1878. UserOrgId: adminUser.CurrentOrgId,
  1879. HisPatientId: his.ID,
  1880. OrderId: order.ID,
  1881. ProjectId: project_id,
  1882. Type: types,
  1883. }
  1884. service.CreateOrderInfo(info)
  1885. }
  1886. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1887. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1888. var total float64
  1889. for _, item := range prescriptions {
  1890. if item.Type == 1 { //药品
  1891. for _, subItem := range item.HisDoctorAdviceInfo {
  1892. total = total + (subItem.Price * subItem.PrescribingNumber)
  1893. }
  1894. }
  1895. if item.Type == 2 { //项目
  1896. for _, subItem := range item.HisPrescriptionProject {
  1897. total = total + (subItem.Price * float64(subItem.Count))
  1898. }
  1899. }
  1900. }
  1901. for _, item := range prescriptions {
  1902. for _, subItem := range item.HisAdditionalCharge {
  1903. total = total + (subItem.Price * float64(subItem.Count))
  1904. }
  1905. }
  1906. allTotal := fmt.Sprintf("%.2f", total)
  1907. if res.Infcode == 0 {
  1908. var rf []*ResultFive
  1909. json.Unmarshal([]byte(his.Iinfo), &rf)
  1910. chrg_bchno := chrg_bchno
  1911. cert_no := his.Certno
  1912. var insutypes []string
  1913. var insutype string
  1914. var is390 int = 0
  1915. var is310 int = 0
  1916. for _, item := range rf {
  1917. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1918. insutypes = append(insutypes, item.Insutype)
  1919. }
  1920. }
  1921. if len(insutypes) == 1 {
  1922. insutype = insutypes[0]
  1923. } else {
  1924. for _, i := range insutypes {
  1925. if i == "390" {
  1926. is390 = 1
  1927. }
  1928. if i == "310" {
  1929. is310 = 1
  1930. }
  1931. }
  1932. }
  1933. if is390 == 1 {
  1934. insutype = "390"
  1935. }
  1936. if is310 == 1 {
  1937. insutype = "310"
  1938. }
  1939. if len(insutypes) == 0 {
  1940. insutype = "310"
  1941. }
  1942. if his.IdCardType == 1 {
  1943. cert_no = his.MedicalInsuranceNumber
  1944. } else {
  1945. cert_no = his.Certno
  1946. }
  1947. result, src_resquest := service.Gdyb2207(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(patientPrescription.RegisterType, 10), his.IdCardType, 0, 0, 0, 0, his.IdType)
  1948. var dat map[string]interface{}
  1949. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1950. fmt.Println(dat)
  1951. } else {
  1952. fmt.Println(err)
  1953. }
  1954. userJSONBytes, _ := json.Marshal(dat)
  1955. var res ResultSeven
  1956. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1957. utils.ErrorLog("解析失败:%v", err)
  1958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1959. return
  1960. }
  1961. if res.Infcode == -1 {
  1962. errlog := &models.HisOrderError{
  1963. UserOrgId: adminUser.CurrentOrgId,
  1964. Ctime: time.Now().Unix(),
  1965. Mtime: time.Now().Unix(),
  1966. Number: chrg_bchno,
  1967. ErrMsg: res.ErrMsg,
  1968. Status: 1,
  1969. PatientId: id,
  1970. RecordTime: recordDateTime,
  1971. Stage: 6,
  1972. }
  1973. service.CreateErrMsgLog(errlog)
  1974. c.ServeSuccessJSON(map[string]interface{}{
  1975. "failed_code": -10,
  1976. "msg": res.ErrMsg,
  1977. })
  1978. return
  1979. } else {
  1980. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1981. order.OrderStatus = 2
  1982. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1983. order.SetlId = res.Output.Setlinfo.SetlID
  1984. order.PsnNo = res.Output.Setlinfo.PsnNo
  1985. order.PsnName = res.Output.Setlinfo.PsnName
  1986. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1987. order.Certno = res.Output.Setlinfo.Certno
  1988. order.Gend = res.Output.Setlinfo.Gend
  1989. order.Naty = res.Output.Setlinfo.Naty
  1990. order.Age = res.Output.Setlinfo.Age
  1991. order.Insutype = res.Output.Setlinfo.Insutype
  1992. order.PsnType = res.Output.Setlinfo.PsnType
  1993. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1994. order.SetlTime = res.Output.Setlinfo.SetlTime
  1995. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1996. order.MedType = res.Output.Setlinfo.MedType
  1997. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1998. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1999. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2000. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2001. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2002. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2003. order.HifpPay = res.Output.Setlinfo.HifpPay
  2004. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2005. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2006. order.HifesPay = res.Output.Setlinfo.HifesPay
  2007. order.HifobPay = res.Output.Setlinfo.HifobPay
  2008. order.MafPay = res.Output.Setlinfo.MafPay
  2009. order.OthPay = res.Output.Setlinfo.OthPay
  2010. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2011. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2012. order.AcctPay = res.Output.Setlinfo.AcctPay
  2013. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2014. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2015. order.Balc = res.Output.Setlinfo.Balc
  2016. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2017. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2018. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2019. order.ClrWay = res.Output.Setlinfo.ClrWay
  2020. order.Creator = order.Creator
  2021. order.Modify = roles.AdminUserId
  2022. order.RequestLog = src_resquest
  2023. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2024. detailStr := string(setlDetail)
  2025. order.SetlDetail = detailStr
  2026. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2027. err = service.UpDateOrder(order)
  2028. if err == nil {
  2029. c.ServeSuccessJSON(map[string]interface{}{
  2030. "msg": "结算成功",
  2031. })
  2032. } else {
  2033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2034. return
  2035. }
  2036. }
  2037. } else {
  2038. adminUser := c.GetAdminUserInfo()
  2039. errlog := &models.HisOrderError{
  2040. UserOrgId: adminUser.CurrentOrgId,
  2041. Ctime: time.Now().Unix(),
  2042. Mtime: time.Now().Unix(),
  2043. ErrMsg: res.ErrMsg,
  2044. Status: 1,
  2045. PatientId: id,
  2046. RecordTime: recordDateTime,
  2047. Stage: 4,
  2048. }
  2049. service.CreateErrMsgLog(errlog)
  2050. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2051. return
  2052. }
  2053. } else {
  2054. adminUser := c.GetAdminUserInfo()
  2055. errlog := &models.HisOrderError{
  2056. UserOrgId: adminUser.CurrentOrgId,
  2057. Ctime: time.Now().Unix(),
  2058. Mtime: time.Now().Unix(),
  2059. ErrMsg: res.ErrMsg,
  2060. Status: 1,
  2061. PatientId: id,
  2062. RecordTime: recordDateTime,
  2063. Stage: 4,
  2064. }
  2065. service.CreateErrMsgLog(errlog)
  2066. c.ServeSuccessJSON(map[string]interface{}{
  2067. "failed_code": -10,
  2068. "msg": res.ErrMsg,
  2069. })
  2070. return
  2071. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2072. //return
  2073. }
  2074. } else {
  2075. var total float64
  2076. for _, item := range prescriptions {
  2077. if item.Type == 1 { //药品
  2078. for _, subItem := range item.HisDoctorAdviceInfo {
  2079. total = total + (subItem.Price * subItem.PrescribingNumber)
  2080. }
  2081. }
  2082. if item.Type == 2 { //项目
  2083. for _, subItem := range item.HisPrescriptionProject {
  2084. total = total + (subItem.Price * float64(subItem.Count))
  2085. }
  2086. }
  2087. for _, subItem := range item.HisAdditionalCharge {
  2088. total = total + (subItem.Price * float64(subItem.Count))
  2089. }
  2090. }
  2091. allTotal := fmt.Sprintf("%.2f", total)
  2092. totals, _ := strconv.ParseFloat(allTotal, 64)
  2093. order := &models.HisOrder{
  2094. UserOrgId: adminUser.CurrentOrgId,
  2095. HisPatientId: his.ID,
  2096. PatientId: id,
  2097. SettleAccountsDate: recordDateTime,
  2098. Ctime: time.Now().Unix(),
  2099. Mtime: time.Now().Unix(),
  2100. Status: 1,
  2101. OrderStatus: 2,
  2102. Number: chrg_bchno,
  2103. MedfeeSumamt: totals,
  2104. PayWay: pay_way,
  2105. PayPrice: pay_price,
  2106. PayCardNo: pay_card_no,
  2107. DiscountPrice: discount_price,
  2108. PreferentialPrice: preferential_price,
  2109. RealityPrice: reality_price,
  2110. FoundPrice: found_price,
  2111. MedicalInsurancePrice: medical_insurance_price,
  2112. PrivatePrice: private_price,
  2113. }
  2114. err = service.CreateOrder(order)
  2115. if err != nil {
  2116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2117. return
  2118. }
  2119. var customs []*Custom
  2120. for _, item := range prescriptions {
  2121. if item.Type == 1 { //药品
  2122. for _, subItem := range item.HisDoctorAdviceInfo {
  2123. cus := &Custom{
  2124. AdviceId: subItem.ID,
  2125. ProjectId: 0,
  2126. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2127. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2128. FeedetlSn: subItem.FeedetlSn,
  2129. Price: fmt.Sprintf("%.2f", subItem.Price),
  2130. MedListCodg: subItem.MedListCodg,
  2131. Type: 1,
  2132. }
  2133. customs = append(customs, cus)
  2134. }
  2135. }
  2136. if item.Type == 2 { //项目
  2137. for _, subItem := range item.HisPrescriptionProject {
  2138. cus := &Custom{
  2139. AdviceId: 0,
  2140. ProjectId: subItem.ID,
  2141. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2142. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2143. FeedetlSn: subItem.FeedetlSn,
  2144. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2145. MedListCodg: subItem.MedListCodg,
  2146. Type: 2,
  2147. }
  2148. customs = append(customs, cus)
  2149. }
  2150. }
  2151. for _, item := range item.HisAdditionalCharge {
  2152. cus := &Custom{
  2153. ItemId: item.ID,
  2154. AdviceId: 0,
  2155. ProjectId: 0,
  2156. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2157. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2158. FeedetlSn: item.FeedetlSn,
  2159. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2160. MedListCodg: item.XtHisAddtionConfig.Code,
  2161. Type: 3,
  2162. }
  2163. customs = append(customs, cus)
  2164. }
  2165. }
  2166. for _, item := range customs {
  2167. var advice_id int64 = 0
  2168. var project_id int64 = 0
  2169. var item_id int64 = 0
  2170. var types int64 = 0
  2171. if item.Type == 1 {
  2172. advice_id = item.AdviceId
  2173. project_id = 0
  2174. item_id = 0
  2175. } else if item.Type == 2 {
  2176. advice_id = 0
  2177. item_id = 0
  2178. project_id = item.ProjectId
  2179. } else if item.Type == 3 {
  2180. advice_id = 0
  2181. item_id = item.ItemId
  2182. project_id = 0
  2183. }
  2184. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2185. cut, _ := strconv.ParseFloat(item.Cut, 32)
  2186. pric, _ := strconv.ParseFloat(item.Price, 32)
  2187. info := &models.HisOrderInfo{
  2188. OrderNumber: order.Number,
  2189. UploadDate: time.Now().Unix(),
  2190. AdviceId: advice_id,
  2191. DetItemFeeSumamt: detItemFeeSumamt,
  2192. Cnt: cut,
  2193. Pric: pric,
  2194. PatientId: id,
  2195. Status: 1,
  2196. Mtime: time.Now().Unix(),
  2197. Ctime: time.Now().Unix(),
  2198. UserOrgId: adminUser.CurrentOrgId,
  2199. HisPatientId: his.ID,
  2200. OrderId: order.ID,
  2201. ProjectId: project_id,
  2202. Type: types,
  2203. ItemId: item_id,
  2204. }
  2205. service.CreateOrderInfo(info)
  2206. }
  2207. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2208. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2209. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  2210. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2211. if err == nil {
  2212. c.ServeSuccessJSON(map[string]interface{}{
  2213. "msg": "结算成功",
  2214. })
  2215. } else {
  2216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2217. return
  2218. }
  2219. }
  2220. }
  2221. func (c *HisApiController) GetPreUploadInfo() {
  2222. id, _ := c.GetInt64("id")
  2223. record_time := c.GetString("record_time")
  2224. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2225. admin_user_id, _ := c.GetInt64("admin_user_id")
  2226. timeLayout := "2006-01-02"
  2227. loc, _ := time.LoadLocation("Local")
  2228. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2229. if err != nil {
  2230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2231. return
  2232. }
  2233. recordDateTime := theTime.Unix()
  2234. adminUser := c.GetAdminUserInfo()
  2235. var prescriptions []*models.HisPrescription
  2236. var start_time int64
  2237. var end_time int64
  2238. data := make(map[string]interface{})
  2239. if settle_accounts_type == 1 { //日结
  2240. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2241. data["pre"] = prescriptions
  2242. } else { //月结
  2243. start_time_str := c.GetString("start_time")
  2244. end_time_str := c.GetString("end_time")
  2245. timeLayout := "2006-01-02"
  2246. loc, _ := time.LoadLocation("Local")
  2247. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2248. if err != nil {
  2249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2250. return
  2251. }
  2252. recordStartTime := theStartTime.Unix()
  2253. start_time = recordStartTime
  2254. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2255. if err != nil {
  2256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2257. return
  2258. }
  2259. recordEndTime := theEndTime.Unix()
  2260. end_time = recordEndTime
  2261. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2262. data["pre"] = prescriptions
  2263. }
  2264. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2265. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2266. timestamp := time.Now().Unix()
  2267. tempTime := time.Unix(timestamp, 0)
  2268. timeFormat := tempTime.Format("20060102150405")
  2269. chrgBchno := rand.Intn(100000) + 10000
  2270. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2271. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2272. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2273. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2274. strconv.FormatInt(his.PatientId, 10)
  2275. client := &http.Client{}
  2276. data["psn_no"] = his.PsnNo
  2277. data["mdtrt_id"] = his.Number
  2278. data["chrg_bchno"] = chrg_bchno
  2279. data["org_name"] = miConfig.OrgName
  2280. data["doctor"] = roles.UserName
  2281. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  2282. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  2283. data["fixmedins_code"] = miConfig.Code
  2284. data["dept_code"] = department.Number
  2285. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  2286. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2287. data["secret_key"] = miConfig.SecretKey
  2288. var ids []int64
  2289. for _, item := range prescriptions {
  2290. ids = append(ids, item.ID)
  2291. }
  2292. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2293. if config.IsOpen == 1 { //对接了医保,走医保流程
  2294. bytesData, _ := json.Marshal(data)
  2295. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  2296. resp, _ := client.Do(req)
  2297. defer resp.Body.Close()
  2298. body, ioErr := ioutil.ReadAll(resp.Body)
  2299. if ioErr != nil {
  2300. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2302. return
  2303. }
  2304. var respJSON map[string]interface{}
  2305. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2306. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2307. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2308. return
  2309. }
  2310. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2311. userJSONBytes, _ := json.Marshal(respJSON)
  2312. var res ResultFour
  2313. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2314. utils.ErrorLog("解析失败:%v", err)
  2315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2316. return
  2317. }
  2318. if res.Infcode == 0 {
  2319. order := &models.HisOrder{
  2320. UserOrgId: adminUser.CurrentOrgId,
  2321. HisPatientId: his.ID,
  2322. PatientId: his.PatientId,
  2323. SettleAccountsDate: recordDateTime,
  2324. Ctime: time.Now().Unix(),
  2325. Mtime: time.Now().Unix(),
  2326. Status: 1,
  2327. Number: chrg_bchno,
  2328. Infcode: res.Infcode,
  2329. WarnMsg: res.WarnMsg,
  2330. Cainfo: res.Cainfo,
  2331. ErrMsg: res.ErrMsg,
  2332. RespondTime: res.RefmsgTime,
  2333. InfRefmsgid: res.InfRefmsgid,
  2334. OrderStatus: 1,
  2335. IsMedicineInsurance: 1,
  2336. SettleType: settle_accounts_type,
  2337. SettleStartTime: start_time,
  2338. SettleEndTime: end_time,
  2339. Creator: roles.ID,
  2340. Modify: roles.ID,
  2341. }
  2342. err = service.CreateOrder(order)
  2343. if err != nil {
  2344. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2345. return
  2346. }
  2347. for _, item := range res.Output.Result {
  2348. temp := strings.Split(item.FeedetlSn, "-")
  2349. var advice_id int64 = 0
  2350. var project_id int64 = 0
  2351. var types int64 = 0
  2352. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2353. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2354. if temp[1] == "1" {
  2355. advice_id = id
  2356. project_id = 0
  2357. } else if temp[1] == "2" {
  2358. advice_id = 0
  2359. project_id = id
  2360. }
  2361. info := &models.HisOrderInfo{
  2362. OrderNumber: order.Number,
  2363. FeedetlSn: item.FeedetlSn,
  2364. UploadDate: time.Now().Unix(),
  2365. AdviceId: advice_id,
  2366. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2367. Cnt: item.Cnt,
  2368. Pric: float64(item.Pric),
  2369. PatientId: his.PatientId,
  2370. PricUplmtAmt: item.PricUplmtAmt,
  2371. SelfpayProp: item.SelfpayProp,
  2372. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2373. OverlmtAmt: item.OverlmtAmt,
  2374. PreselfpayAmt: item.PreselfpayAmt,
  2375. BasMednFlag: item.BasMednFlag,
  2376. MedChrgitmType: item.MedChrgitmType,
  2377. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2378. Status: 1,
  2379. Memo: item.Memo,
  2380. Mtime: time.Now().Unix(),
  2381. InscpScpAmt: item.InscpScpAmt,
  2382. DrtReimFlag: item.DrtReimFlag,
  2383. Ctime: time.Now().Unix(),
  2384. ListSpItemFlag: item.ListSpItemFlag,
  2385. ChldMedcFlag: item.ChldMedcFlag,
  2386. LmtUsedFlag: item.LmtUsedFlag,
  2387. ChrgitmLv: item.ChrgitmLv,
  2388. UserOrgId: adminUser.CurrentOrgId,
  2389. HisPatientId: his.ID,
  2390. OrderId: order.ID,
  2391. ProjectId: project_id,
  2392. Type: types,
  2393. }
  2394. service.CreateOrderInfo(info)
  2395. }
  2396. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2397. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  2398. var total float64
  2399. for _, item := range prescriptions {
  2400. if item.Type == 1 { //药品
  2401. for _, subItem := range item.HisDoctorAdviceInfo {
  2402. total = total + (subItem.Price * subItem.PrescribingNumber)
  2403. }
  2404. }
  2405. if item.Type == 2 { //项目
  2406. for _, subItem := range item.HisPrescriptionProject {
  2407. total = total + (subItem.Price * float64(subItem.Count))
  2408. }
  2409. }
  2410. }
  2411. for _, item := range prescriptions {
  2412. for _, subItem := range item.HisAdditionalCharge {
  2413. total = total + (subItem.Price * float64(subItem.Count))
  2414. }
  2415. }
  2416. allTotal := fmt.Sprintf("%.2f", total)
  2417. if res.Infcode == 0 {
  2418. var rf []*ResultFive
  2419. json.Unmarshal([]byte(his.Iinfo), &rf)
  2420. psn_no := his.PsnNo
  2421. mdtrt_id := his.Number
  2422. chrg_bchno := chrg_bchno
  2423. cert_no := his.Certno
  2424. insutype := rf[0].Insutype
  2425. if his.IdCardType == 1 {
  2426. cert_no = his.MedicalInsuranceNumber
  2427. } else {
  2428. cert_no = his.Certno
  2429. }
  2430. api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  2431. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  2432. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  2433. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  2434. resp, requestErr := http.Get(api)
  2435. if requestErr != nil {
  2436. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2437. return
  2438. }
  2439. defer resp.Body.Close()
  2440. body, ioErr := ioutil.ReadAll(resp.Body)
  2441. if ioErr != nil {
  2442. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2443. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2444. return
  2445. }
  2446. var respJSON map[string]interface{}
  2447. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2448. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2449. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2450. return
  2451. }
  2452. fmt.Println(respJSON)
  2453. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2454. userJSONBytes, _ := json.Marshal(respJSON)
  2455. var res ResultSeven
  2456. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2457. utils.ErrorLog("解析失败:%v", err)
  2458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2459. return
  2460. }
  2461. if res.Infcode == -1 {
  2462. errlog := &models.HisOrderError{
  2463. UserOrgId: adminUser.CurrentOrgId,
  2464. Ctime: time.Now().Unix(),
  2465. Mtime: time.Now().Unix(),
  2466. Number: chrg_bchno,
  2467. ErrMsg: res.ErrMsg,
  2468. Status: 1,
  2469. PatientId: id,
  2470. RecordTime: recordDateTime,
  2471. Stage: 7,
  2472. }
  2473. service.CreateErrMsgLog(errlog)
  2474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2475. return
  2476. } else {
  2477. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2478. order.OrderStatus = 1
  2479. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2480. order.SetlId = res.Output.Setlinfo.SetlID
  2481. order.PsnNo = res.Output.Setlinfo.PsnNo
  2482. order.PsnName = res.Output.Setlinfo.PsnName
  2483. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2484. order.Certno = res.Output.Setlinfo.Certno
  2485. order.Gend = res.Output.Setlinfo.Gend
  2486. order.Naty = res.Output.Setlinfo.Naty
  2487. order.Age = res.Output.Setlinfo.Age
  2488. order.Insutype = res.Output.Setlinfo.Insutype
  2489. order.PsnType = res.Output.Setlinfo.PsnType
  2490. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2491. order.SetlTime = res.Output.Setlinfo.SetlTime
  2492. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2493. order.MedType = res.Output.Setlinfo.MedType
  2494. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2495. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2496. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2497. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2498. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2499. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2500. order.HifpPay = res.Output.Setlinfo.HifpPay
  2501. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2502. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2503. order.HifesPay = res.Output.Setlinfo.HifesPay
  2504. order.HifobPay = res.Output.Setlinfo.HifobPay
  2505. order.MafPay = res.Output.Setlinfo.MafPay
  2506. order.OthPay = res.Output.Setlinfo.OthPay
  2507. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2508. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2509. order.AcctPay = res.Output.Setlinfo.AcctPay
  2510. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2511. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2512. order.Balc = res.Output.Setlinfo.Balc
  2513. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2514. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2515. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2516. order.ClrWay = res.Output.Setlinfo.ClrWay
  2517. order.Creator = order.Creator
  2518. order.Modify = roles.ID
  2519. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2520. detailStr := string(setlDetail)
  2521. order.SetlDetail = detailStr
  2522. //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2523. err = service.UpDateOrder(order)
  2524. if err == nil {
  2525. c.ServeSuccessJSON(map[string]interface{}{
  2526. "msg": "预结算成功",
  2527. })
  2528. } else {
  2529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2530. return
  2531. }
  2532. }
  2533. } else {
  2534. adminUser := c.GetAdminUserInfo()
  2535. errlog := &models.HisOrderError{
  2536. UserOrgId: adminUser.CurrentOrgId,
  2537. Ctime: time.Now().Unix(),
  2538. Mtime: time.Now().Unix(),
  2539. ErrMsg: res.ErrMsg,
  2540. Status: 1,
  2541. PatientId: id,
  2542. RecordTime: recordDateTime,
  2543. Stage: 4,
  2544. }
  2545. service.CreateErrMsgLog(errlog)
  2546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2547. return
  2548. }
  2549. } else {
  2550. adminUser := c.GetAdminUserInfo()
  2551. errlog := &models.HisOrderError{
  2552. UserOrgId: adminUser.CurrentOrgId,
  2553. Ctime: time.Now().Unix(),
  2554. Mtime: time.Now().Unix(),
  2555. ErrMsg: res.ErrMsg,
  2556. Status: 1,
  2557. PatientId: id,
  2558. RecordTime: recordDateTime,
  2559. Stage: 4,
  2560. }
  2561. service.CreateErrMsgLog(errlog)
  2562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  2563. return
  2564. }
  2565. } else {
  2566. var total float64
  2567. for _, item := range prescriptions {
  2568. if item.Type == 1 { //药品
  2569. for _, subItem := range item.HisDoctorAdviceInfo {
  2570. total = total + (subItem.Price * subItem.PrescribingNumber)
  2571. }
  2572. }
  2573. if item.Type == 2 { //项目
  2574. for _, subItem := range item.HisPrescriptionProject {
  2575. total = total + (subItem.Price * float64(subItem.Count))
  2576. }
  2577. }
  2578. for _, subItem := range item.HisAdditionalCharge {
  2579. total = total + (subItem.Price * float64(subItem.Count))
  2580. }
  2581. }
  2582. allTotal := fmt.Sprintf("%.2f", total)
  2583. totals, _ := strconv.ParseFloat(allTotal, 64)
  2584. order := &models.HisOrder{
  2585. UserOrgId: adminUser.CurrentOrgId,
  2586. HisPatientId: his.ID,
  2587. PatientId: id,
  2588. SettleAccountsDate: recordDateTime,
  2589. Ctime: time.Now().Unix(),
  2590. Mtime: time.Now().Unix(),
  2591. Status: 1,
  2592. OrderStatus: 2,
  2593. Number: chrg_bchno,
  2594. MedfeeSumamt: totals,
  2595. }
  2596. err = service.CreateOrder(order)
  2597. if err != nil {
  2598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  2599. return
  2600. }
  2601. var customs []*Custom
  2602. for _, item := range prescriptions {
  2603. if item.Type == 1 { //药品
  2604. for _, subItem := range item.HisDoctorAdviceInfo {
  2605. cus := &Custom{
  2606. AdviceId: subItem.ID,
  2607. ProjectId: 0,
  2608. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2609. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2610. FeedetlSn: subItem.FeedetlSn,
  2611. Price: fmt.Sprintf("%.2f", subItem.Price),
  2612. MedListCodg: subItem.MedListCodg,
  2613. Type: 1,
  2614. }
  2615. customs = append(customs, cus)
  2616. }
  2617. }
  2618. if item.Type == 2 { //项目
  2619. for _, subItem := range item.HisPrescriptionProject {
  2620. cus := &Custom{
  2621. AdviceId: 0,
  2622. ProjectId: subItem.ID,
  2623. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2624. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2625. FeedetlSn: subItem.FeedetlSn,
  2626. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2627. MedListCodg: subItem.MedListCodg,
  2628. Type: 2,
  2629. }
  2630. customs = append(customs, cus)
  2631. }
  2632. }
  2633. for _, item := range item.HisAdditionalCharge {
  2634. cus := &Custom{
  2635. ItemId: item.ID,
  2636. AdviceId: 0,
  2637. ProjectId: 0,
  2638. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2639. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2640. FeedetlSn: item.FeedetlSn,
  2641. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2642. MedListCodg: item.XtHisAddtionConfig.Code,
  2643. Type: 3,
  2644. }
  2645. customs = append(customs, cus)
  2646. }
  2647. }
  2648. for _, item := range customs {
  2649. var advice_id int64 = 0
  2650. var project_id int64 = 0
  2651. var item_id int64 = 0
  2652. var types int64 = 0
  2653. if item.Type == 1 {
  2654. advice_id = item.AdviceId
  2655. project_id = 0
  2656. item_id = 0
  2657. } else if item.Type == 2 {
  2658. advice_id = 0
  2659. item_id = 0
  2660. project_id = item.ProjectId
  2661. } else if item.Type == 3 {
  2662. advice_id = 0
  2663. item_id = item.ItemId
  2664. project_id = 0
  2665. }
  2666. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2667. cut, _ := strconv.ParseFloat(item.Cut, 32)
  2668. pric, _ := strconv.ParseFloat(item.Price, 32)
  2669. info := &models.HisOrderInfo{
  2670. OrderNumber: order.Number,
  2671. UploadDate: time.Now().Unix(),
  2672. AdviceId: advice_id,
  2673. DetItemFeeSumamt: detItemFeeSumamt,
  2674. Cnt: cut,
  2675. Pric: pric,
  2676. PatientId: id,
  2677. Status: 1,
  2678. Mtime: time.Now().Unix(),
  2679. Ctime: time.Now().Unix(),
  2680. UserOrgId: adminUser.CurrentOrgId,
  2681. HisPatientId: his.ID,
  2682. OrderId: order.ID,
  2683. ProjectId: project_id,
  2684. Type: types,
  2685. ItemId: item_id,
  2686. }
  2687. service.CreateOrderInfo(info)
  2688. }
  2689. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2690. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2691. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  2692. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2693. if err == nil {
  2694. c.ServeSuccessJSON(map[string]interface{}{
  2695. "msg": "结算成功",
  2696. })
  2697. } else {
  2698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2699. return
  2700. }
  2701. }
  2702. }
  2703. //func (c *HisApiController) GetSettleInfo() {
  2704. // id, _ := c.GetInt64("id")
  2705. // order_id, _ := c.GetInt64("order_id")
  2706. //
  2707. // record_time := c.GetString("record_time")
  2708. // pay_way, _ := c.GetInt64("pay_way")
  2709. // pay_price, _ := c.GetFloat("pay_price")
  2710. // pay_card_no := c.GetString("pay_card_no")
  2711. // discount_price, _ := c.GetFloat("discount_price")
  2712. // preferential_price, _ := c.GetFloat("preferential_price")
  2713. // reality_price, _ := c.GetFloat("reality_price")
  2714. // found_price, _ := c.GetFloat("found_price")
  2715. // medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2716. // private_price, _ := c.GetFloat("private_price")
  2717. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2718. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2719. //
  2720. // timeLayout := "2006-01-02"
  2721. // loc, _ := time.LoadLocation("Local")
  2722. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2723. // if err != nil {
  2724. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2725. // return
  2726. // }
  2727. // recordDateTime := theTime.Unix()
  2728. // adminUser := c.GetAdminUserInfo()
  2729. //
  2730. // var prescriptions []*models.HisPrescription
  2731. //
  2732. // data := make(map[string]interface{})
  2733. // if settle_accounts_type == 1 { //日结
  2734. // prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2735. // data["pre"] = prescriptions
  2736. //
  2737. // } else { //月结
  2738. // start_time_str := c.GetString("start_time")
  2739. // end_time_str := c.GetString("end_time")
  2740. // timeLayout := "2006-01-02"
  2741. // loc, _ := time.LoadLocation("Local")
  2742. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2743. // if err != nil {
  2744. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2745. // return
  2746. // }
  2747. // recordStartTime := theStartTime.Unix()
  2748. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2749. // if err != nil {
  2750. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2751. // return
  2752. // }
  2753. // recordEndTime := theEndTime.Unix()
  2754. // prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2755. // data["pre"] = prescriptions
  2756. //
  2757. // }
  2758. //
  2759. // roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2760. //
  2761. // his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2762. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2763. // patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2764. // strconv.FormatInt(his.PatientId, 10)
  2765. //
  2766. // order_src, _ := service.GetHisOrderByID(order_id)
  2767. //
  2768. // config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2769. // if config.IsOpen == 1 { //对接了医保,走医保流程
  2770. //
  2771. // var total float64
  2772. // for _, item := range prescriptions {
  2773. // if item.Type == 1 { //药品
  2774. // for _, subItem := range item.HisDoctorAdviceInfo {
  2775. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2776. // }
  2777. // }
  2778. // if item.Type == 2 { //项目
  2779. // for _, subItem := range item.HisPrescriptionProject {
  2780. // total = total + (subItem.Price * float64(subItem.Count))
  2781. // }
  2782. // }
  2783. // }
  2784. //
  2785. // for _, item := range prescriptions {
  2786. // for _, subItem := range item.HisAdditionalCharge {
  2787. // total = total + (subItem.Price * float64(subItem.Count))
  2788. // }
  2789. // }
  2790. //
  2791. // allTotal := fmt.Sprintf("%.2f", total)
  2792. // var rf []*ResultFive
  2793. // json.Unmarshal([]byte(his.Iinfo), &rf)
  2794. // psn_no := order_src.PsnNo
  2795. // mdtrt_id := order_src.MdtrtId
  2796. // chrg_bchno := order_src.Number
  2797. // cert_no := order_src.Certno
  2798. // insutype := rf[0].Insutype
  2799. //
  2800. // if his.IdCardType == 1 {
  2801. // cert_no = his.MedicalInsuranceNumber
  2802. // } else {
  2803. // cert_no = his.Certno
  2804. // }
  2805. //
  2806. // result, src_resquest := service.Gdyb2207(his.PsnNo, his.Number, chrg_bchno, cert_no, insutype, strconv.FormatFloat(total, 'E', -1, 64) ,miConfig.OrgName,roles.UserName,miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, strconv.FormatInt(patientPrescription.RegisterType, 10),his.IdCardType, order_src.FulamtOwnpayAmt,order_src.OverlmtSelfPay,order_src.PreselfpayAmt,order_src.InscpScpAmt)
  2807. // var dat map[string]interface{}
  2808. // if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2809. // fmt.Println(dat)
  2810. // } else {
  2811. // fmt.Println(err)
  2812. // }
  2813. //
  2814. // userJSONBytes, _ := json.Marshal(dat)
  2815. //
  2816. //
  2817. //
  2818. // var res ResultSeven
  2819. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2820. // utils.ErrorLog("解析失败:%v", err)
  2821. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2822. // return
  2823. // }
  2824. // if res.Infcode == -1 {
  2825. // errlog := &models.HisOrderError{
  2826. // UserOrgId: adminUser.CurrentOrgId,
  2827. // Ctime: time.Now().Unix(),
  2828. // Mtime: time.Now().Unix(),
  2829. // Number: chrg_bchno,
  2830. // ErrMsg: res.ErrMsg,
  2831. // Status: 1,
  2832. // PatientId: id,
  2833. // RecordTime: recordDateTime,
  2834. // Stage: 6,
  2835. // }
  2836. // service.CreateErrMsgLog(errlog)
  2837. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  2838. // return
  2839. // } else {
  2840. // order_src.OrderStatus = 2
  2841. // order_src.PayWay = pay_way
  2842. // order_src.PayPrice = pay_price
  2843. // order_src.PayCardNo = pay_card_no
  2844. // order_src.DiscountPrice = discount_price
  2845. // order_src.PreferentialPrice = preferential_price
  2846. // order_src.RealityPrice = reality_price
  2847. // order_src.FoundPrice = found_price
  2848. // order_src.MedicalInsurancePrice = medical_insurance_price
  2849. // order_src.PrivatePrice = private_price
  2850. // order_src.MdtrtId = res.Output.Setlinfo.MdtrtID
  2851. // order_src.SetlId = res.Output.Setlinfo.SetlID
  2852. // order_src.PsnNo = res.Output.Setlinfo.PsnNo
  2853. // order_src.PsnName = res.Output.Setlinfo.PsnName
  2854. // order_src.PsnCertType = res.Output.Setlinfo.PsnCertType
  2855. // order_src.Certno = res.Output.Setlinfo.Certno
  2856. // order_src.Gend = res.Output.Setlinfo.Gend
  2857. // order_src.Naty = res.Output.Setlinfo.Naty
  2858. // order_src.Age = res.Output.Setlinfo.Age
  2859. // order_src.Insutype = res.Output.Setlinfo.Insutype
  2860. // order_src.PsnType = res.Output.Setlinfo.PsnType
  2861. // order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2862. // order_src.SetlTime = res.Output.Setlinfo.SetlTime
  2863. // order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2864. // order_src.MedType = res.Output.Setlinfo.MedType
  2865. // order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2866. // order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2867. // order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2868. // order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2869. // order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2870. // order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2871. // order_src.HifpPay = res.Output.Setlinfo.HifpPay
  2872. // order_src.CvlservPay = res.Output.Setlinfo.CvlservPay
  2873. // order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2874. // order_src.HifesPay = res.Output.Setlinfo.HifesPay
  2875. // order_src.HifobPay = res.Output.Setlinfo.HifobPay
  2876. // order_src.MafPay = res.Output.Setlinfo.MafPay
  2877. // order_src.OthPay = res.Output.Setlinfo.OthPay
  2878. // order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2879. // order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2880. // order_src.AcctPay = res.Output.Setlinfo.AcctPay
  2881. // order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2882. // order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2883. // order_src.Balc = res.Output.Setlinfo.Balc
  2884. // order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2885. // order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2886. // order_src.ClrOptins = res.Output.Setlinfo.ClrOptins
  2887. // order_src.ClrWay = res.Output.Setlinfo.ClrWay
  2888. // order_src.Creator = order_src.Creator
  2889. // order_src.Modify = roles.ID
  2890. // order_src.RequestLog = src_resquest
  2891. // setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2892. // detailStr := string(setlDetail)
  2893. // order_src.SetlDetail = detailStr
  2894. // err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2895. // err = service.UpDateOrder(order_src)
  2896. //
  2897. // if err == nil {
  2898. // c.ServeSuccessJSON(map[string]interface{}{
  2899. // "msg": "结算成功",
  2900. // })
  2901. // } else {
  2902. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2903. // return
  2904. // }
  2905. // }
  2906. // }
  2907. //}
  2908. //退款
  2909. func (c *HisApiController) Refund() {
  2910. order_id, _ := c.GetInt64("order_id")
  2911. admin_user_id, _ := c.GetInt64("admin_user_id")
  2912. record_time := c.GetString("record_time")
  2913. patient_id, _ := c.GetInt64("patient_id")
  2914. timeLayout := "2006-01-02"
  2915. loc, _ := time.LoadLocation("Local")
  2916. adminUser := c.GetAdminUserInfo()
  2917. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2918. if err != nil {
  2919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2920. return
  2921. }
  2922. recordDateTime := theTime.Unix()
  2923. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2924. var order models.HisOrder
  2925. order, _ = service.GetHisOrderByID(order_id)
  2926. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2927. if order.ID == 0 {
  2928. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  2929. }
  2930. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2931. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2932. if config.IsOpen == 1 { //对接了医保,走医保流程
  2933. result, src_resquest := service.Gdyb2208(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2934. var dat map[string]interface{}
  2935. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2936. fmt.Println(dat)
  2937. } else {
  2938. fmt.Println(err)
  2939. }
  2940. userJSONBytes, _ := json.Marshal(dat)
  2941. var res ResultSixteen
  2942. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2943. utils.ErrorLog("解析失败:%v", err)
  2944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2945. return
  2946. }
  2947. if res.Infcode == 0 {
  2948. result := service.Gdyb2205(order.PsnNo, order.MdtrtId, order.Number, miConfig.OrgName, roles.UserName, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  2949. var dat map[string]interface{}
  2950. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2951. fmt.Println(dat)
  2952. } else {
  2953. fmt.Println(err)
  2954. }
  2955. userJSONBytes, _ := json.Marshal(dat)
  2956. var res2 ResultSix
  2957. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  2958. utils.ErrorLog("解析失败:%v", err)
  2959. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2960. return
  2961. }
  2962. if res2.Infcode == 0 {
  2963. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, src_resquest, result)
  2964. if err == nil {
  2965. c.ServeSuccessJSON(map[string]interface{}{
  2966. "msg": "退费成功",
  2967. })
  2968. } else {
  2969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2970. return
  2971. }
  2972. } else {
  2973. c.ServeSuccessJSON(map[string]interface{}{
  2974. "code": -10,
  2975. "msg": res2.ErrMsg,
  2976. })
  2977. }
  2978. } else {
  2979. c.ServeSuccessJSON(map[string]interface{}{
  2980. "code": -10,
  2981. "msg": res.ErrMsg,
  2982. })
  2983. }
  2984. } else {
  2985. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  2986. if err == nil {
  2987. c.ServeSuccessJSON(map[string]interface{}{
  2988. "msg": "退费成功",
  2989. })
  2990. } else {
  2991. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2992. return
  2993. }
  2994. }
  2995. }
  2996. func (c *HisApiController) RefundNumber() {
  2997. record_time := c.GetString("record_time")
  2998. patient_id, _ := c.GetInt64("patient_id")
  2999. admin_user_id, _ := c.GetInt64("admin_user_id")
  3000. //his_patient_id, _ := c.GetInt64("id")
  3001. timeLayout := "2006-01-02"
  3002. loc, _ := time.LoadLocation("Local")
  3003. adminUser := c.GetAdminUserInfo()
  3004. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3005. fmt.Println(err)
  3006. if err != nil {
  3007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3008. return
  3009. }
  3010. recordDateTime := theTime.Unix()
  3011. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3012. //his, _ := service.GetNewHisPatientRecord(adminUser.CurrentOrgId, patient_id)
  3013. //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3014. //order, _ := service.GetHisOrderByID(order_id)
  3015. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3016. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3017. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3018. if config.IsOpen == 1 { //对接了医保,走医保流程
  3019. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  3020. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + roles.UserName + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  3021. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3022. resp3, requestErr3 := http.Get(api3)
  3023. if requestErr3 != nil {
  3024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3025. return
  3026. }
  3027. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  3028. if ioErr3 != nil {
  3029. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  3030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3031. return
  3032. }
  3033. var respJSON3 map[string]interface{}
  3034. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  3035. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3036. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3037. return
  3038. }
  3039. respJSON3 = respJSON3["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3040. userJSONBytes3, _ := json.Marshal(respJSON3)
  3041. var res2 ResultSix
  3042. if err := json.Unmarshal(userJSONBytes3, &res2); err != nil {
  3043. utils.ErrorLog("解析失败:%v", err)
  3044. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3045. return
  3046. }
  3047. if res2.Infcode == 0 {
  3048. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  3049. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  3050. //err := service.UpdataRegStatus2()
  3051. if err == nil {
  3052. c.ServeSuccessJSON(map[string]interface{}{
  3053. "msg": "退号成功",
  3054. })
  3055. } else {
  3056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3057. return
  3058. }
  3059. } else {
  3060. c.ServeSuccessJSON(map[string]interface{}{
  3061. "code": -10,
  3062. "msg": res2.ErrMsg,
  3063. })
  3064. }
  3065. } else {
  3066. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  3067. //if err == nil {
  3068. // c.ServeSuccessJSON(map[string]interface{}{
  3069. // "msg": "退费成功",
  3070. // })
  3071. //} else {
  3072. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3073. // return
  3074. //}
  3075. }
  3076. }
  3077. func (c *HisApiController) RefundDetail() {
  3078. order_id, _ := c.GetInt64("order_id")
  3079. his_patient_id, _ := c.GetInt64("his_patient_id")
  3080. number := c.GetString("number")
  3081. record_time := c.GetString("record_time")
  3082. patient_id, _ := c.GetInt64("patient_id")
  3083. timeLayout := "2006-01-02"
  3084. loc, _ := time.LoadLocation("Local")
  3085. adminUser := c.GetAdminUserInfo()
  3086. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3087. fmt.Println(err)
  3088. if err != nil {
  3089. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3090. return
  3091. }
  3092. recordDateTime := theTime.Unix()
  3093. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  3094. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3095. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3096. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3097. var order models.HisOrder
  3098. order, _ = service.GetHisOrderByID(order_id)
  3099. if order.ID == 0 {
  3100. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  3101. }
  3102. if config.IsOpen == 1 { //对接了医保,走医保流程
  3103. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  3104. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  3105. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3106. resp2, requestErr2 := http.Get(api2)
  3107. if requestErr2 != nil {
  3108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3109. return
  3110. }
  3111. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  3112. if ioErr2 != nil {
  3113. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  3114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3115. return
  3116. }
  3117. var respJSON2 map[string]interface{}
  3118. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  3119. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3121. return
  3122. }
  3123. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  3124. if err == nil {
  3125. c.ServeSuccessJSON(map[string]interface{}{
  3126. "msg": "退费成功",
  3127. })
  3128. } else {
  3129. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3130. return
  3131. }
  3132. } else {
  3133. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId, "", "")
  3134. if err == nil {
  3135. c.ServeSuccessJSON(map[string]interface{}{
  3136. "msg": "退费成功",
  3137. })
  3138. } else {
  3139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3140. return
  3141. }
  3142. }
  3143. }
  3144. //对账
  3145. func (c *HisApiController) GetCheckAccount() {
  3146. start_time := c.GetString("start_time")
  3147. end_time := c.GetString("end_time")
  3148. insutype := c.GetString("insutype")
  3149. clr_type := c.GetString("clr_type")
  3150. admin_user_id, _ := c.GetInt64("admin_user_id")
  3151. adminUser := c.GetAdminUserInfo()
  3152. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3153. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3154. timeLayout := "2006-01-02"
  3155. loc, _ := time.LoadLocation("Local")
  3156. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3157. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3158. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  3159. //orders_two, _ := service.GetOrderByTimeThree(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  3160. fixmedins_setl_cnt := int64(len(orders))
  3161. //
  3162. ////撤销的算2条数据为一笔
  3163. //for _, item := range orders_two {
  3164. // if item.OrderStatus == 3 {
  3165. // fixmedins_setl_cnt = fixmedins_setl_cnt + 1
  3166. // }
  3167. //}
  3168. var medfee_sumamt float64
  3169. var acct_pay float64
  3170. var fund_pay_sumamt float64
  3171. for _, item := range orders {
  3172. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  3173. acct_pay = acct_pay + item.AcctPay
  3174. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  3175. }
  3176. var user_name string
  3177. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3178. if role.ID == 0 {
  3179. user_name = "xxx"
  3180. } else {
  3181. user_name = role.UserName
  3182. }
  3183. if config.IsOpen == 1 {
  3184. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3185. "insutype=" + insutype +
  3186. "&clr_type=" + clr_type +
  3187. "&setl_optins=" + "定点医保中心" +
  3188. "&stmt_begndate=" + start_time +
  3189. "&stm_enddate=" + end_time +
  3190. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  3191. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  3192. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  3193. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  3194. "&fixmedins_code=" + miConfig.Code +
  3195. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3196. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3197. "&secret_key=" + miConfig.SecretKey +
  3198. "&org_name=" + miConfig.OrgName +
  3199. "&doctor=" + user_name
  3200. fmt.Println(api)
  3201. resp, requestErr := http.Get(api)
  3202. if requestErr != nil {
  3203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3204. return
  3205. }
  3206. body, ioErr := ioutil.ReadAll(resp.Body)
  3207. fmt.Println(body)
  3208. if ioErr != nil {
  3209. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3211. return
  3212. }
  3213. var respJSON map[string]interface{}
  3214. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3215. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3217. return
  3218. }
  3219. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3220. userJSONBytes, _ := json.Marshal(respJSON)
  3221. var res ResultEight
  3222. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3223. utils.ErrorLog("解析失败:%v", err)
  3224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3225. return
  3226. }
  3227. if res.Infcode == 0 {
  3228. if res.Output.Stmtinfo.StmtRslt == "0" {
  3229. micc := &models.MedicalInsuranceCostCompare{
  3230. StartTime: startime.Unix(),
  3231. EndTime: endtime.Unix(),
  3232. Insutype: insutype,
  3233. CheckType: 1,
  3234. Num: fixmedins_setl_cnt,
  3235. Mtime: time.Now().Unix(),
  3236. Status: 1,
  3237. UserOrgId: adminUser.CurrentOrgId,
  3238. CostTotal: medfee_sumamt,
  3239. FuncTotal: fund_pay_sumamt,
  3240. PsnPay: acct_pay,
  3241. Creator: admin_user_id,
  3242. Ctime: time.Now().Unix(),
  3243. }
  3244. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  3245. if err == nil {
  3246. c.ServeSuccessJSON(map[string]interface{}{
  3247. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  3248. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  3249. })
  3250. } else {
  3251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3252. }
  3253. } else {
  3254. c.ServeSuccessJSON(map[string]interface{}{
  3255. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  3256. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  3257. })
  3258. }
  3259. } else {
  3260. c.ServeSuccessJSON(map[string]interface{}{
  3261. "code": -10,
  3262. "msg": res.ErrMsg,
  3263. })
  3264. }
  3265. }
  3266. }
  3267. func (c *HisApiController) Check310() {
  3268. adminUser := c.GetAdminUserInfo()
  3269. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3270. var user_name string
  3271. user_name = "xxx"
  3272. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3273. "insutype=" + "310" +
  3274. "&clr_type=" + "11" +
  3275. "&setl_optins=" + "定点医保中心" +
  3276. "&stmt_begndate=" + "2021-03-01" +
  3277. "&stm_enddate=" + "2021-03-31" +
  3278. "&medfee_sumamt=" + "11521" +
  3279. "&fund_pay_sumamt=" + "10166.66" +
  3280. "&acct_pay=" + "0" +
  3281. "&fixmedins_setl_cnt=" + "7" +
  3282. "&fixmedins_code=" + miConfig.Code +
  3283. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3284. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3285. "&secret_key=" + miConfig.SecretKey +
  3286. "&org_name=" + miConfig.OrgName +
  3287. "&doctor=" + user_name
  3288. fmt.Println(api)
  3289. resp, requestErr := http.Get(api)
  3290. if requestErr != nil {
  3291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3292. return
  3293. }
  3294. body, ioErr := ioutil.ReadAll(resp.Body)
  3295. fmt.Println(body)
  3296. if ioErr != nil {
  3297. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3299. return
  3300. }
  3301. var respJSON map[string]interface{}
  3302. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3303. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3305. return
  3306. }
  3307. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3308. userJSONBytes, _ := json.Marshal(respJSON)
  3309. var res ResultEight
  3310. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3311. utils.ErrorLog("解析失败:%v", err)
  3312. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3313. return
  3314. }
  3315. }
  3316. func (c *HisApiController) Check390() {
  3317. adminUser := c.GetAdminUserInfo()
  3318. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3319. var user_name string
  3320. user_name = "张俊杰"
  3321. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  3322. "insutype=" + "390" +
  3323. "&clr_type=" + "11" +
  3324. "&setl_optins=" + "定点医保中心" +
  3325. "&stmt_begndate=" + "2021-03-01" +
  3326. "&stm_enddate=" + "2021-03-31" +
  3327. "&medfee_sumamt=" + "209318.43" +
  3328. "&fund_pay_sumamt=" + "188029.12" +
  3329. "&acct_pay=" + "0" +
  3330. "&fixmedins_setl_cnt=" + "48" +
  3331. "&fixmedins_code=" + miConfig.Code +
  3332. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3333. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3334. "&secret_key=" + miConfig.SecretKey +
  3335. "&org_name=" + miConfig.OrgName +
  3336. "&doctor=" + user_name
  3337. fmt.Println(api)
  3338. resp, requestErr := http.Get(api)
  3339. if requestErr != nil {
  3340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3341. return
  3342. }
  3343. body, ioErr := ioutil.ReadAll(resp.Body)
  3344. fmt.Println(body)
  3345. if ioErr != nil {
  3346. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3347. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3348. return
  3349. }
  3350. var respJSON map[string]interface{}
  3351. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3352. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3354. return
  3355. }
  3356. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3357. userJSONBytes, _ := json.Marshal(respJSON)
  3358. var res ResultEight
  3359. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3360. utils.ErrorLog("解析失败:%v", err)
  3361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3362. return
  3363. }
  3364. }
  3365. //对账明细
  3366. func (c *HisApiController) GetCheckDetailAccount() {
  3367. start_time := c.GetString("start_time")
  3368. end_time := c.GetString("end_time")
  3369. admin_user_id, _ := c.GetInt64("admin_user_id")
  3370. adminUser := c.GetAdminUserInfo()
  3371. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3372. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3373. timeLayout := "2006-01-02"
  3374. loc, _ := time.LoadLocation("Local")
  3375. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3376. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3377. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  3378. Mkdir(miConfig.OrgName)
  3379. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  3380. file_name := file + ".txt"
  3381. zip_name := file + ".zip"
  3382. zip_path := miConfig.OrgName + "/" + zip_name
  3383. file_path := miConfig.OrgName + "/" + file_name
  3384. decimal.DivisionPrecision = 2
  3385. var medfee_sumamt float64
  3386. var psn_cash_pay float64
  3387. var fund_pay_sumamt float64
  3388. fixmedins_setl_cnt := int64(len(orders))
  3389. for _, item := range orders {
  3390. medfee_sumamt = medfee_sumamt + item.MedfeeSumamt
  3391. psn_cash_pay = psn_cash_pay + item.PsnCashPay
  3392. fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt
  3393. }
  3394. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  3395. defer f.Close()
  3396. if err != nil {
  3397. fmt.Println(err.Error())
  3398. } else {
  3399. for _, item := range orders {
  3400. var refd_setl_flag string
  3401. if item.OrderStatus == 2 {
  3402. refd_setl_flag = "0"
  3403. var str string
  3404. str = item.SetlId + " " +
  3405. item.MdtrtId + " " +
  3406. item.PsnNo + " " +
  3407. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  3408. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  3409. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\r\n"
  3410. _, err = f.Write([]byte(str))
  3411. }
  3412. if item.OrderStatus == 3 {
  3413. var str string
  3414. str = item.SetlId + " " +
  3415. item.MdtrtId + " " +
  3416. item.PsnNo + " " +
  3417. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  3418. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  3419. fmt.Sprintf("%.2f", item.AcctPay) + " " + "1" + "\r\n"
  3420. _, err = f.Write([]byte(str))
  3421. var str2 string
  3422. str2 = item.SetlId + " " +
  3423. item.MdtrtId + " " +
  3424. item.PsnNo + " " +
  3425. fmt.Sprintf("%.2f", 0-item.MedfeeSumamt) + " " +
  3426. fmt.Sprintf("%.2f", 0-item.FundPaySumamt) + " " +
  3427. fmt.Sprintf("%.2f", 0-item.AcctPay) + " " + "1" + "\r\n"
  3428. _, err = f.Write([]byte(str2))
  3429. }
  3430. }
  3431. }
  3432. Zip(file_path, zip_path)
  3433. fmt.Println(ReadFile(zip_path))
  3434. fmt.Println(string(ReadFile(zip_path)))
  3435. if config.IsOpen == 1 {
  3436. var user_name string
  3437. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3438. if role.ID == 0 {
  3439. user_name = "管理员"
  3440. } else {
  3441. user_name = role.UserName
  3442. }
  3443. baseParams := models.BaseParams{
  3444. SecretKey: miConfig.SecretKey,
  3445. FixmedinsCode: miConfig.Code,
  3446. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3447. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3448. OrgName: miConfig.OrgName,
  3449. Doctor: user_name,
  3450. }
  3451. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  3452. var dat map[string]interface{}
  3453. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3454. fmt.Println(dat)
  3455. } else {
  3456. fmt.Println(err)
  3457. }
  3458. userJSONBytes, _ := json.Marshal(dat)
  3459. var res ResultNine
  3460. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3461. utils.ErrorLog("解析失败:%v", err)
  3462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3463. return
  3464. }
  3465. if res.Infcode == 0 {
  3466. fileNo := res.Output.FileQuryNo
  3467. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  3468. "file_qury_no=" + fileNo +
  3469. "&setl_optins=" + "定点医保中心" +
  3470. "&stmt_begndate=" + start_time +
  3471. "&stm_enddate=" + end_time +
  3472. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  3473. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  3474. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  3475. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  3476. "&fixmedins_code=" + miConfig.Code +
  3477. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  3478. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  3479. "&secret_key=" + miConfig.SecretKey +
  3480. "&org_name=" + miConfig.OrgName +
  3481. "&doctor=" + user_name
  3482. resp, requestErr := http.Get(api)
  3483. if requestErr != nil {
  3484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3485. return
  3486. }
  3487. body, ioErr := ioutil.ReadAll(resp.Body)
  3488. if ioErr != nil {
  3489. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3491. return
  3492. }
  3493. var respJSON map[string]interface{}
  3494. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3495. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3496. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3497. return
  3498. }
  3499. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3500. userJSONBytes, _ := json.Marshal(respJSON)
  3501. var res ResultTen
  3502. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3503. utils.ErrorLog("解析失败:%v", err)
  3504. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3505. return
  3506. }
  3507. if res.Infcode == 0 {
  3508. service.Gdyb9102(baseParams, zip_name, fileNo)
  3509. micc := &models.MedicalInsuranceCostCompare{
  3510. StartTime: startime.Unix(),
  3511. EndTime: endtime.Unix(),
  3512. Insutype: "0",
  3513. CheckType: 2,
  3514. Num: fixmedins_setl_cnt,
  3515. Mtime: time.Now().Unix(),
  3516. Status: 1,
  3517. UserOrgId: adminUser.CurrentOrgId,
  3518. CostTotal: medfee_sumamt,
  3519. FuncTotal: fund_pay_sumamt,
  3520. PsnPay: psn_cash_pay,
  3521. Creator: admin_user_id,
  3522. Ctime: time.Now().Unix(),
  3523. }
  3524. service.CreateMedicalInsuranceCostCompareRecord(micc)
  3525. c.ServeSuccessJSON(map[string]interface{}{
  3526. "msg": "明细对账成功",
  3527. })
  3528. }
  3529. } else {
  3530. }
  3531. }
  3532. }
  3533. func (c *HisApiController) GetSettleAccounts() {
  3534. //id, _ := c.GetInt64("id")
  3535. //record_time := c.GetString("record_time")
  3536. order_id, _ := c.GetInt64("order_id")
  3537. admin_user_id, _ := c.GetInt64("admin_user_id")
  3538. //timeLayout := "2006-01-02"
  3539. //loc, _ := time.LoadLocation("Local")
  3540. //
  3541. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3542. //if err != nil {
  3543. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3544. // return
  3545. //}
  3546. //recordDateTime := theTime.Unix()
  3547. adminUser := c.GetAdminUserInfo()
  3548. order, _ := service.GetHisOrderByID(order_id)
  3549. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  3550. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  3551. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  3552. orderInfos = append(orderInfos, orderInfos_two...)
  3553. diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  3554. var bedCostTotal float64 = 0 //床位总费
  3555. var bedCostSelfTotal float64 = 0 //床位自费
  3556. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  3557. var operationCostTotal float64 = 0 //手术费
  3558. var operationCostSelfTotal float64 = 0 //手术费
  3559. var operationCostPartSelfTotal float64 = 0 //手术费
  3560. var otherCostTotal float64 = 0 //其他费用
  3561. var otherCostSelfTotal float64 = 0 //其他费用
  3562. var otherCostPartSelfTotal float64 = 0 //其他费用
  3563. var materialCostTotal float64 = 0 //材料费
  3564. var materialCostSelfTotal float64 = 0 //材料费
  3565. var materialCostPartSelfTotal float64 = 0 //材料费
  3566. var westernMedicineCostTotal float64 = 0 //西药费
  3567. var westernMedicineCostSelfTotal float64 = 0 //西药费
  3568. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  3569. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  3570. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  3571. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  3572. var checkCostTotal float64 = 0 //检查费
  3573. var checkCostSelfTotal float64 = 0 //检查费
  3574. var checkCostPartSelfTotal float64 = 0 //检查费
  3575. var laboratoryCostTotal float64 = 0 //化验费
  3576. var laboratoryCostSelfTotal float64 = 0 //化验费
  3577. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  3578. var treatCostTotal float64 = 0 //治疗费用
  3579. var treatCostSelfTotal float64 = 0 //治疗费用
  3580. var treatCostPartSelfTotal float64 = 0 //治疗费用
  3581. decimal.DivisionPrecision = 2
  3582. for _, item := range orderInfos {
  3583. if item.MedChrgitmType == "01" { //床位费
  3584. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3585. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3586. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3587. }
  3588. if item.MedChrgitmType == "03" { //检查费
  3589. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3590. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3591. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3592. }
  3593. if item.MedChrgitmType == "04" { //化验费
  3594. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3595. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3596. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3597. }
  3598. if item.MedChrgitmType == "05" { //治疗费
  3599. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3600. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3601. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3602. }
  3603. if item.MedChrgitmType == "06" { //手术费
  3604. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3605. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3606. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3607. }
  3608. if item.MedChrgitmType == "08" { //材料费
  3609. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3610. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3611. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3612. }
  3613. if item.MedChrgitmType == "09" { //西药费
  3614. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3615. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3616. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3617. }
  3618. if item.MedChrgitmType == "11" { //中成费
  3619. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3620. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3621. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3622. }
  3623. if item.MedChrgitmType == "14" { //其他费
  3624. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3625. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3626. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3627. }
  3628. }
  3629. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3630. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3631. var user_name string
  3632. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3633. if role.ID == 0 {
  3634. user_name = "管理员"
  3635. } else {
  3636. user_name = role.UserName
  3637. }
  3638. baseParams := models.BaseParams{
  3639. SecretKey: miConfig.SecretKey,
  3640. FixmedinsCode: miConfig.Code,
  3641. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3642. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3643. OrgName: miConfig.OrgName,
  3644. Doctor: user_name,
  3645. }
  3646. businessParams := models.BusinessParams{
  3647. PsnNo: order.PsnNo,
  3648. MdtrtId: order.MdtrtId,
  3649. SetlId: order.SetlId,
  3650. }
  3651. if config.IsOpen == 1 {
  3652. result := service.Gdyb5203(baseParams, businessParams)
  3653. var dat map[string]interface{}
  3654. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3655. fmt.Println(dat)
  3656. } else {
  3657. fmt.Println(err)
  3658. }
  3659. userJSONBytes, _ := json.Marshal(dat)
  3660. var res ResultEleven
  3661. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3662. utils.ErrorLog("解析失败:%v", err)
  3663. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3664. return
  3665. }
  3666. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3667. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  3668. if res.Infcode == 0 {
  3669. c.ServeSuccessJSON(map[string]interface{}{
  3670. "diagnosis": diagnosisConfig.CountryContentName,
  3671. "order_infos": orderInfos,
  3672. "number": order.MdtrtId,
  3673. "date": order.SettleAccountsDate,
  3674. "charge_admin": charge_admin,
  3675. "printor_admin": printor_admin,
  3676. "info": res.Output.Setlinfo,
  3677. "bedCostTotal": bedCostTotal,
  3678. "bedCostSelfTotal": bedCostSelfTotal,
  3679. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  3680. "operationCostTotal": operationCostTotal,
  3681. "operationCostSelfTotal": operationCostSelfTotal,
  3682. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  3683. "otherCostTotal": otherCostTotal,
  3684. "otherCostSelfTotal": otherCostSelfTotal,
  3685. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  3686. "materialCostTotal": materialCostTotal,
  3687. "materialCostSelfTotal": materialCostSelfTotal,
  3688. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  3689. "westernMedicineCostTotal": westernMedicineCostTotal,
  3690. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  3691. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  3692. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  3693. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  3694. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  3695. "checkCostTotal": checkCostTotal,
  3696. "checkCostSelfTotal": checkCostSelfTotal,
  3697. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  3698. "laboratoryCostTotal": laboratoryCostTotal,
  3699. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  3700. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  3701. "treatCostTotal": treatCostTotal,
  3702. "treatCostSelfTotal": treatCostSelfTotal,
  3703. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  3704. })
  3705. }
  3706. }
  3707. }
  3708. func (c *HisApiController) CheckTreatment() {
  3709. patient_id, _ := c.GetInt64("patient_id", 0)
  3710. record_time := c.GetString("record_time")
  3711. insutype := c.GetString("insutype")
  3712. timeLayout := "2006-01-02"
  3713. loc, _ := time.LoadLocation("Local")
  3714. adminUser := c.GetAdminUserInfo()
  3715. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3716. fmt.Println(err)
  3717. if err != nil {
  3718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3719. return
  3720. }
  3721. recordDateTime := theTime.Unix()
  3722. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3723. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3724. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3725. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3726. var user_name string
  3727. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  3728. if role.ID == 0 {
  3729. user_name = "xxx"
  3730. } else {
  3731. user_name = role.UserName
  3732. }
  3733. baseParams := models.BaseParams{
  3734. SecretKey: miConfig.SecretKey,
  3735. FixmedinsCode: miConfig.Code,
  3736. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  3737. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  3738. OrgName: miConfig.OrgName,
  3739. Doctor: user_name,
  3740. }
  3741. if config.IsOpen == 1 {
  3742. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  3743. var dat map[string]interface{}
  3744. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3745. fmt.Println(dat)
  3746. } else {
  3747. fmt.Println(err)
  3748. }
  3749. }
  3750. }
  3751. func (c *HisApiController) PutRecord() {
  3752. id, _ := c.GetInt64("id")
  3753. record_time := c.GetString("record_time")
  3754. timeLayout := "2006-01-02"
  3755. loc, _ := time.LoadLocation("Local")
  3756. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3757. if err != nil {
  3758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3759. return
  3760. }
  3761. recordDateTime := theTime.Unix()
  3762. adminInfo := c.GetAdminUserInfo()
  3763. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  3764. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3765. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3766. fmt.Println(miConfig.SecretKey)
  3767. if patient == nil {
  3768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3769. return
  3770. }
  3771. if len(patient.IdCardNo) == 0 {
  3772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3773. return
  3774. }
  3775. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  3776. if config.IsOpen == 1 {
  3777. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3778. resp, requestErr := http.Get(api)
  3779. if requestErr != nil {
  3780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3781. return
  3782. }
  3783. defer resp.Body.Close()
  3784. body, ioErr := ioutil.ReadAll(resp.Body)
  3785. if ioErr != nil {
  3786. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3788. return
  3789. }
  3790. var respJSON map[string]interface{}
  3791. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3792. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3794. return
  3795. }
  3796. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3797. userJSONBytes, _ := json.Marshal(userJSON)
  3798. var res ResultTwo
  3799. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3800. utils.ErrorLog("解析失败:%v", err)
  3801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3802. return
  3803. }
  3804. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3805. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3806. infoStr := string(Iinfos)
  3807. idetinfoStr := string(Idetinfos)
  3808. if res.Infcode == 0 {
  3809. his := models.VMHisPatient{
  3810. Status: 1,
  3811. Ctime: time.Now().Unix(),
  3812. Mtime: time.Now().Unix(),
  3813. PsnNo: res.Output.Baseinfo.PsnNo,
  3814. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3815. Certno: res.Output.Baseinfo.Certno,
  3816. PsnName: res.Output.Baseinfo.PsnName,
  3817. Gend: res.Output.Baseinfo.Gend,
  3818. Naty: res.Output.Baseinfo.Naty,
  3819. Brdy: res.Output.Baseinfo.Brdy,
  3820. Age: res.Output.Baseinfo.Age,
  3821. Iinfo: infoStr,
  3822. Idetinfo: idetinfoStr,
  3823. PatientId: patient.ID,
  3824. RecordDate: theTime.Unix(),
  3825. UserOrgId: adminInfo.CurrentOrgId,
  3826. AdminUserId: adminInfo.AdminUser.Id,
  3827. IsReturn: 1,
  3828. }
  3829. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  3830. result := service.Gdyb2503(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  3831. result2 := service.Gdyb5301(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  3832. var dat map[string]interface{}
  3833. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3834. fmt.Println(dat)
  3835. } else {
  3836. fmt.Println(err)
  3837. }
  3838. var dat2 map[string]interface{}
  3839. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  3840. fmt.Println(dat2)
  3841. } else {
  3842. fmt.Println(err)
  3843. }
  3844. } else {
  3845. adminUser := c.GetAdminUserInfo()
  3846. errlog := &models.HisOrderError{
  3847. UserOrgId: adminUser.CurrentOrgId,
  3848. Ctime: time.Now().Unix(),
  3849. Mtime: time.Now().Unix(),
  3850. ErrMsg: res.ErrMsg,
  3851. Status: 1,
  3852. PatientId: id,
  3853. RecordTime: recordDateTime,
  3854. Stage: 1,
  3855. }
  3856. service.CreateErrMsgLog(errlog)
  3857. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  3858. return
  3859. }
  3860. }
  3861. }
  3862. func (c *HisApiController) GetUploadDiag() {
  3863. id, _ := c.GetInt64("id")
  3864. record_time := c.GetString("record_time")
  3865. diagnosis_id, _ := c.GetInt64("diagnosis")
  3866. sick_type, _ := c.GetInt64("sick_type")
  3867. reg_type, _ := c.GetInt64("reg_type")
  3868. timeLayout := "2006-01-02"
  3869. loc, _ := time.LoadLocation("Local")
  3870. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3871. if err != nil {
  3872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3873. return
  3874. }
  3875. var patientPrescription models.HisPrescriptionInfo
  3876. recordDateTime := theTime.Unix()
  3877. adminInfo := c.GetAdminUserInfo()
  3878. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3879. if patientPrescription.ID == 0 {
  3880. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3881. }
  3882. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3883. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  3884. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  3885. sickConfig, _ := service.FindSickById(sick_type)
  3886. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  3887. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  3888. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  3889. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(reg_type, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  3890. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  3891. resp2, requestErr2 := http.Get(api2)
  3892. if requestErr2 != nil {
  3893. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3894. return
  3895. }
  3896. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  3897. if ioErr2 != nil {
  3898. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  3899. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3900. return
  3901. }
  3902. var respJSON2 map[string]interface{}
  3903. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  3904. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3906. return
  3907. }
  3908. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3909. userJSONBytes2, _ := json.Marshal(respJSON2)
  3910. var res2 ResultSix
  3911. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  3912. utils.ErrorLog("解析失败:%v", err)
  3913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3914. return
  3915. }
  3916. if res2.Infcode == -1 {
  3917. adminUser := c.GetAdminUserInfo()
  3918. errlog := &models.HisOrderError{
  3919. UserOrgId: adminUser.CurrentOrgId,
  3920. Ctime: time.Now().Unix(),
  3921. Mtime: time.Now().Unix(),
  3922. ErrMsg: res2.ErrMsg,
  3923. Status: 1,
  3924. PatientId: id,
  3925. RecordTime: recordDateTime,
  3926. Stage: 3,
  3927. }
  3928. service.CreateErrMsgLog(errlog)
  3929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  3930. return
  3931. }
  3932. c.ServeSuccessJSON(map[string]interface{}{
  3933. "msg": "上传成功",
  3934. })
  3935. }
  3936. type QueryResult struct {
  3937. ID int64
  3938. Name string
  3939. Code string
  3940. List_type_code string
  3941. }
  3942. func (c *HisApiController) GetCheckCode() {
  3943. ids_str := c.GetString("ids")
  3944. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  3945. ids_arr := strings.Split(ids_str, ",")
  3946. var queryResult []QueryResult
  3947. ids := make([]int64, 0)
  3948. for _, item := range ids_arr {
  3949. id, _ := strconv.ParseInt(item, 10, 64)
  3950. ids = append(ids, id)
  3951. }
  3952. if record_type == 1 {
  3953. drugs, _ := service.GetBatchDrugList(ids)
  3954. for _, item := range drugs {
  3955. result := QueryResult{
  3956. ID: item.ID,
  3957. Name: item.DrugName,
  3958. Code: item.MedicalInsuranceNumber,
  3959. List_type_code: "101",
  3960. }
  3961. queryResult = append(queryResult, result)
  3962. }
  3963. } else if record_type == 2 {
  3964. goods, _ := service.GetBatchGoodInformationList(ids)
  3965. for _, item := range goods {
  3966. result := QueryResult{
  3967. ID: item.ID,
  3968. Name: item.GoodName,
  3969. Code: item.MedicalInsuranceNumber,
  3970. List_type_code: "301",
  3971. }
  3972. queryResult = append(queryResult, result)
  3973. }
  3974. } else if record_type == 3 {
  3975. projects, _ := service.GetBathchMyPorjecgList(ids)
  3976. for _, item := range projects {
  3977. result := QueryResult{
  3978. ID: item.ID,
  3979. Name: item.ProjectName,
  3980. Code: item.MedicalCode,
  3981. List_type_code: "201",
  3982. }
  3983. queryResult = append(queryResult, result)
  3984. }
  3985. }
  3986. admin_user_id, _ := c.GetInt64("admin_user_id")
  3987. adminUser := c.GetAdminUserInfo()
  3988. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3989. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3990. var user_name string
  3991. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3992. if role.ID == 0 {
  3993. user_name = "xxx"
  3994. } else {
  3995. user_name = role.UserName
  3996. }
  3997. baseParams := &models.BaseParams{
  3998. SecretKey: miConfig.SecretKey,
  3999. FixmedinsCode: miConfig.Code,
  4000. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4001. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4002. OrgName: miConfig.OrgName,
  4003. Doctor: user_name,
  4004. }
  4005. if config.IsOpen == 1 {
  4006. for _, item := range queryResult {
  4007. var result string
  4008. if record_type == 1 {
  4009. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4010. } else if record_type == 2 {
  4011. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4012. } else if record_type == 3 {
  4013. result = service.Gdyb3301(baseParams, item.Name, item.Code, item.List_type_code, "2021-04-26", "", item.List_type_code)
  4014. }
  4015. var dat map[string]interface{}
  4016. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4017. fmt.Println(dat)
  4018. } else {
  4019. fmt.Println(err)
  4020. }
  4021. userJSONBytes, _ := json.Marshal(dat)
  4022. var res ResultSix
  4023. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4024. utils.ErrorLog("解析失败:%v", err)
  4025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4026. return
  4027. }
  4028. if res.Infcode == 0 {
  4029. if record_type == 1 {
  4030. service.UpdateBaseDrugById(item.ID)
  4031. } else if record_type == 2 {
  4032. service.UpdateGoodInformaitonByDetail(item.ID)
  4033. } else if record_type == 3 {
  4034. service.UpdateProjectById(item.ID)
  4035. }
  4036. c.ServeSuccessJSON(map[string]interface{}{
  4037. "failed_code": 0,
  4038. "msg": "目录对照成功",
  4039. })
  4040. } else {
  4041. c.ServeSuccessJSON(map[string]interface{}{
  4042. "failed_code": -10,
  4043. "msg": res.ErrMsg,
  4044. })
  4045. }
  4046. }
  4047. }
  4048. }
  4049. func (c *HisApiController) UnCheckCode() {
  4050. ids_str := c.GetString("ids")
  4051. record_type, _ := c.GetInt64("record_type") //1.药品 2.耗材 3.项目
  4052. admin_user_id, _ := c.GetInt64("admin_user_id")
  4053. ids_arr := strings.Split(ids_str, ",")
  4054. var queryResult []QueryResult
  4055. ids := make([]int64, 0)
  4056. for _, item := range ids_arr {
  4057. id, _ := strconv.ParseInt(item, 10, 64)
  4058. ids = append(ids, id)
  4059. }
  4060. if record_type == 1 {
  4061. drugs, _ := service.GetBatchDrugList(ids)
  4062. for _, item := range drugs {
  4063. result := QueryResult{
  4064. ID: item.ID,
  4065. Name: item.DrugName,
  4066. Code: item.MedicalInsuranceNumber,
  4067. List_type_code: "101",
  4068. }
  4069. queryResult = append(queryResult, result)
  4070. }
  4071. } else if record_type == 2 {
  4072. goods, _ := service.GetBatchGoodInformationList(ids)
  4073. for _, item := range goods {
  4074. result := QueryResult{
  4075. ID: item.ID,
  4076. Name: item.GoodName,
  4077. Code: item.MedicalInsuranceNumber,
  4078. List_type_code: "301",
  4079. }
  4080. queryResult = append(queryResult, result)
  4081. }
  4082. } else if record_type == 3 {
  4083. projects, _ := service.GetBathchMyPorjecgList(ids)
  4084. for _, item := range projects {
  4085. result := QueryResult{
  4086. ID: item.ID,
  4087. Name: item.ProjectName,
  4088. Code: item.MedicalCode,
  4089. List_type_code: "201",
  4090. }
  4091. queryResult = append(queryResult, result)
  4092. }
  4093. }
  4094. adminUser := c.GetAdminUserInfo()
  4095. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4096. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4097. var user_name string
  4098. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4099. if role.ID == 0 {
  4100. user_name = "xxx"
  4101. } else {
  4102. user_name = role.UserName
  4103. }
  4104. baseParams := &models.BaseParams{
  4105. SecretKey: miConfig.SecretKey,
  4106. FixmedinsCode: miConfig.Code,
  4107. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  4108. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  4109. OrgName: miConfig.OrgName,
  4110. Doctor: user_name,
  4111. }
  4112. if config.IsOpen == 1 {
  4113. for _, item := range queryResult {
  4114. var result string
  4115. if record_type == 1 {
  4116. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4117. } else if record_type == 2 {
  4118. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4119. } else if record_type == 3 {
  4120. result = service.Gdyb3302(baseParams, item.Name, item.Code, item.List_type_code)
  4121. }
  4122. var dat2 map[string]interface{}
  4123. if err := json.Unmarshal([]byte(result), &dat2); err == nil {
  4124. fmt.Println(dat2)
  4125. } else {
  4126. fmt.Println(err)
  4127. }
  4128. userJSONBytes, _ := json.Marshal(dat2)
  4129. var res ResultSix
  4130. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4131. utils.ErrorLog("解析失败:%v", err)
  4132. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4133. return
  4134. }
  4135. if res.Infcode == 0 {
  4136. if record_type == 1 {
  4137. service.UpdateDrugByIdDetail(item.ID)
  4138. } else if record_type == 2 {
  4139. service.UpdateGoodInfoById(item.ID)
  4140. } else if record_type == 3 {
  4141. service.UpdateMyProjectById(item.ID)
  4142. }
  4143. c.ServeSuccessJSON(map[string]interface{}{
  4144. "failed_code": 0,
  4145. "msg": "撤销目录对照成功",
  4146. })
  4147. } else {
  4148. c.ServeSuccessJSON(map[string]interface{}{
  4149. "failed_code": -10,
  4150. "msg": res.ErrMsg,
  4151. })
  4152. }
  4153. }
  4154. }
  4155. }
  4156. func (c *HisApiController) GetPatientInfo() {
  4157. id_card_no := c.GetString("id_card_no")
  4158. admin_user_id, _ := c.GetInt64("admin_user_id")
  4159. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  4160. if patient.ID == 0 {
  4161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4162. return
  4163. }
  4164. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  4165. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4166. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  4167. if config.IsOpen == 1 {
  4168. result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  4169. var dat map[string]interface{}
  4170. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4171. fmt.Println(dat)
  4172. } else {
  4173. fmt.Println(err)
  4174. }
  4175. userJSONBytes, _ := json.Marshal(dat)
  4176. var res ResultTwo
  4177. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4178. utils.ErrorLog("解析失败:%v", err)
  4179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4180. return
  4181. }
  4182. if res.Infcode == -1 {
  4183. c.ServeSuccessJSON(map[string]interface{}{
  4184. "failed_code": -10,
  4185. "msg": res.ErrMsg,
  4186. })
  4187. } else {
  4188. c.ServeSuccessJSON(map[string]interface{}{
  4189. "failed_code": 0,
  4190. "info": res,
  4191. })
  4192. }
  4193. }
  4194. }
  4195. func (c *HisApiController) PsnPutOnRecord() {
  4196. record_type, _ := c.GetInt64("type")
  4197. patient_id, _ := c.GetInt64("patient_id")
  4198. admin_user_id, _ := c.GetInt64("admin_user_id")
  4199. start_time := c.GetString("start_time")
  4200. end_time := c.GetString("end_time")
  4201. adminUser := c.GetAdminUserInfo()
  4202. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4203. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4204. var patients []*models.Patients
  4205. if record_type == 1 { //全部备案
  4206. patient, _ := service.GetAllPatient(adminUser.CurrentOrgId)
  4207. patients = append(patients, patient...)
  4208. } else { //单个备案
  4209. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  4210. patients = append(patients, patient)
  4211. }
  4212. var user_name string
  4213. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4214. if role.ID == 0 {
  4215. user_name = "xxx"
  4216. } else {
  4217. user_name = role.UserName
  4218. }
  4219. if config.IsOpen == 1 {
  4220. for _, item := range patients {
  4221. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + item.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + user_name + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  4222. resp, requestErr := http.Get(api)
  4223. if requestErr != nil {
  4224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4225. return
  4226. }
  4227. defer resp.Body.Close()
  4228. body, ioErr := ioutil.ReadAll(resp.Body)
  4229. if ioErr != nil {
  4230. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  4231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4232. return
  4233. }
  4234. var respJSON map[string]interface{}
  4235. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  4236. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  4237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4238. return
  4239. }
  4240. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  4241. userJSONBytes, _ := json.Marshal(userJSON)
  4242. var res ResultTwo
  4243. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4244. utils.ErrorLog("解析失败:%v", err)
  4245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4246. return
  4247. }
  4248. if res.Infcode == 0 {
  4249. result := service.Gdyb2505(res.Output.Baseinfo.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, start_time, end_time)
  4250. var dat map[string]interface{}
  4251. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4252. fmt.Println(dat)
  4253. } else {
  4254. fmt.Println(err)
  4255. }
  4256. userJSONBytes, _ := json.Marshal(dat)
  4257. var res2 ResultThirteen
  4258. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4259. utils.ErrorLog("解析失败:%v", err)
  4260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4261. return
  4262. }
  4263. if res2.Infcode == 0 {
  4264. psnResult := &models.GdybPsnRecord{
  4265. UserOrgId: adminUser.CurrentOrgId,
  4266. PatientId: item.ID,
  4267. PsnNo: res.Output.Baseinfo.PsnNo,
  4268. Ctime: time.Now().Unix(),
  4269. Mtime: time.Now().Unix(),
  4270. Status: 1,
  4271. IsCancel: 1,
  4272. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  4273. }
  4274. service.CreatePsnRecord(psnResult)
  4275. } else {
  4276. c.ServeSuccessJSON(map[string]interface{}{
  4277. "failed_code": -10,
  4278. "msg": res2.ErrMsg,
  4279. })
  4280. return
  4281. }
  4282. }
  4283. }
  4284. }
  4285. }
  4286. func (c *HisApiController) PsnUnPutOnRecord() {
  4287. id, _ := c.GetInt64("id")
  4288. //record_type, _ := c.GetInt64("type")
  4289. admin_user_id, _ := c.GetInt64("admin_user_id")
  4290. adminUser := c.GetAdminUserInfo()
  4291. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4292. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4293. var user_name string
  4294. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4295. if role.ID == 0 {
  4296. user_name = "xxx"
  4297. } else {
  4298. user_name = role.UserName
  4299. }
  4300. psn_record, _ := service.GetPsnRecordById(id)
  4301. if psn_record.ID == 0 {
  4302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  4303. return
  4304. }
  4305. if config.IsOpen == 1 {
  4306. result := service.Gdyb2506(psn_record.PsnNo, user_name, miConfig.OrgName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  4307. var dat map[string]interface{}
  4308. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4309. fmt.Println(dat)
  4310. } else {
  4311. fmt.Println(err)
  4312. }
  4313. userJSONBytes, _ := json.Marshal(dat)
  4314. var res ResultFourteen
  4315. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4316. utils.ErrorLog("解析失败:%v", err)
  4317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4318. return
  4319. }
  4320. if res.Infcode == 0 {
  4321. psn_record.IsCancel = 2
  4322. service.CreatePsnRecord(&psn_record)
  4323. } else {
  4324. c.ServeSuccessJSON(map[string]interface{}{
  4325. "failed_code": -10,
  4326. "msg": res.ErrMsg,
  4327. })
  4328. return
  4329. }
  4330. }
  4331. }
  4332. func (c *HisApiController) PsnPutNCDSOnRecord() {
  4333. patient_id, _ := c.GetInt64("patient_id")
  4334. insutype := c.GetString("insutype")
  4335. psn_no := c.GetString("psn_no")
  4336. doctor_id, _ := c.GetInt64("doctor_id")
  4337. sick_id, _ := c.GetInt64("sick_id")
  4338. department_id, _ := c.GetInt64("department_id")
  4339. adminUser := c.GetAdminUserInfo()
  4340. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  4341. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4342. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4343. sick, _ := service.FindSickById(sick_id)
  4344. doctor, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, doctor_id)
  4345. if config.IsOpen == 1 {
  4346. result := service.Gdyb2503(psn_no, insutype, miConfig.OrgName, doctor.UserName, miConfig.Code, strconv.FormatInt(doctor.ID, 10), miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, sick.ClassName, sick.CountryCode)
  4347. var dat map[string]interface{}
  4348. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4349. fmt.Println(dat)
  4350. } else {
  4351. fmt.Println(err)
  4352. }
  4353. userJSONBytes, _ := json.Marshal(dat)
  4354. var res2 ResultThirteen
  4355. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  4356. utils.ErrorLog("解析失败:%v", err)
  4357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4358. return
  4359. }
  4360. if res2.Infcode == 0 {
  4361. psnResult := &models.GdybPsnNcdsRecord{
  4362. UserOrgId: adminUser.CurrentOrgId,
  4363. PatientId: patient.ID,
  4364. PsnNo: psn_no,
  4365. DoctorId: doctor.AdminUserId,
  4366. DepartmentId: department_id,
  4367. SickType: sick_id,
  4368. Insutype: insutype,
  4369. Ctime: time.Now().Unix(),
  4370. Mtime: time.Now().Unix(),
  4371. Status: 1,
  4372. IsCancel: 1,
  4373. TrtDclaDetlSn: res2.Output.Result.TrtDclaDetlSn,
  4374. }
  4375. service.CreatePsnNCDSRecord(psnResult)
  4376. c.ServeSuccessJSON(map[string]interface{}{
  4377. "failed_code": 0,
  4378. "msg": "备案成功",
  4379. "result": psnResult,
  4380. })
  4381. } else {
  4382. c.ServeSuccessJSON(map[string]interface{}{
  4383. "failed_code": -10,
  4384. "msg": res2.ErrMsg,
  4385. })
  4386. return
  4387. }
  4388. }
  4389. }
  4390. func (c *HisApiController) PsnPutUnNCDSOnRecord() {
  4391. id, _ := c.GetInt64("id")
  4392. admin_user_id, _ := c.GetInt64("admin_user_id")
  4393. adminUser := c.GetAdminUserInfo()
  4394. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4395. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4396. var user_name string
  4397. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  4398. if role.ID == 0 {
  4399. user_name = "xxx"
  4400. } else {
  4401. user_name = role.UserName
  4402. }
  4403. psn_record, _ := service.GetPsnNCDSRecordById(id)
  4404. if psn_record.ID == 0 {
  4405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnRecordNoExistWrong)
  4406. return
  4407. }
  4408. if config.IsOpen == 1 {
  4409. result := service.Gdyb2504(psn_record.PsnNo, miConfig.OrgName, user_name, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, psn_record.TrtDclaDetlSn)
  4410. var dat map[string]interface{}
  4411. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  4412. fmt.Println(dat)
  4413. } else {
  4414. fmt.Println(err)
  4415. }
  4416. userJSONBytes, _ := json.Marshal(dat)
  4417. var res ResultFourteen
  4418. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  4419. utils.ErrorLog("解析失败:%v", err)
  4420. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4421. return
  4422. }
  4423. if res.Infcode == 0 {
  4424. psn_record.IsCancel = 2
  4425. service.CreatePsnNCDSRecord(&psn_record)
  4426. c.ServeSuccessJSON(map[string]interface{}{
  4427. "failed_code": 0,
  4428. "msg": "撤销备案成功",
  4429. })
  4430. } else {
  4431. c.ServeSuccessJSON(map[string]interface{}{
  4432. "failed_code": -10,
  4433. "msg": res.ErrMsg,
  4434. })
  4435. return
  4436. }
  4437. }
  4438. }
  4439. func (c *HisApiController) TestTest() {
  4440. patient, _ := service.GetHisPatientInfo(4, 456, 1619712000)
  4441. fmt.Println(patient.Iinfo)
  4442. }
  4443. type CustomData struct {
  4444. MsgId string
  4445. PsnNo string
  4446. Info string
  4447. }
  4448. func (c *HisApiController) ReversalData() {
  4449. var customData []*CustomData
  4450. custom := &CustomData{
  4451. MsgId: "H44022900158202103301714472004",
  4452. PsnNo: "44020000001101329945",
  4453. Info: "2207",
  4454. }
  4455. customData = append(customData, custom)
  4456. custom1 := &CustomData{
  4457. MsgId: "H4402290015820210330172057803",
  4458. PsnNo: "44020000001101161813",
  4459. Info: "2207",
  4460. }
  4461. customData = append(customData, custom1)
  4462. custom2 := &CustomData{
  4463. MsgId: "H44022900158202103301705198813",
  4464. PsnNo: "44190000133097375417",
  4465. Info: "2207",
  4466. }
  4467. customData = append(customData, custom2)
  4468. custom3 := &CustomData{
  4469. MsgId: "H44022900158202103301715524756",
  4470. PsnNo: "44020000001100187221",
  4471. Info: "2207",
  4472. }
  4473. customData = append(customData, custom3)
  4474. custom4 := &CustomData{
  4475. MsgId: "H44022900158202103301730376224",
  4476. PsnNo: "44020000001101959155",
  4477. Info: "2207",
  4478. }
  4479. customData = append(customData, custom4)
  4480. custom5 := &CustomData{
  4481. MsgId: "H44022900158202103301748008725",
  4482. PsnNo: "44020000001104246641",
  4483. Info: "2207",
  4484. }
  4485. customData = append(customData, custom5)
  4486. custom6 := &CustomData{
  4487. MsgId: "H44022900158202103301718096755",
  4488. PsnNo: "44020000001102211860",
  4489. Info: "2207",
  4490. }
  4491. customData = append(customData, custom6)
  4492. custom7 := &CustomData{
  4493. MsgId: "H44022900158202103301736551640",
  4494. PsnNo: "44020000001102687718",
  4495. Info: "2207",
  4496. }
  4497. customData = append(customData, custom7)
  4498. custom8 := &CustomData{
  4499. MsgId: "H44022900158202103301743097676",
  4500. PsnNo: "44020000001102127785",
  4501. Info: "2207",
  4502. }
  4503. customData = append(customData, custom8)
  4504. custom9 := &CustomData{
  4505. MsgId: "H44022900158202103301712304203",
  4506. PsnNo: "44020000001101518097",
  4507. Info: "2207",
  4508. }
  4509. customData = append(customData, custom9)
  4510. custom10 := &CustomData{
  4511. MsgId: "H44022900158202103301738448785",
  4512. PsnNo: "44020000001100500813",
  4513. Info: "2207",
  4514. }
  4515. customData = append(customData, custom10)
  4516. custom11 := &CustomData{
  4517. MsgId: "H44022900158202103301732455843",
  4518. PsnNo: "44020000001102690557",
  4519. Info: "2207",
  4520. }
  4521. customData = append(customData, custom11)
  4522. custom12 := &CustomData{
  4523. MsgId: "H44022900158202103301745421708",
  4524. PsnNo: "44020000001102211928",
  4525. Info: "2207",
  4526. }
  4527. customData = append(customData, custom12)
  4528. custom1212 := &CustomData{
  4529. MsgId: "H440229001582021033017351627",
  4530. PsnNo: "44020000001102481733",
  4531. Info: "2207",
  4532. }
  4533. customData = append(customData, custom1212)
  4534. custom13 := &CustomData{
  4535. MsgId: "H44022900158202103301740327951",
  4536. PsnNo: "44020000001103174866",
  4537. Info: "2207",
  4538. }
  4539. customData = append(customData, custom13)
  4540. custom14 := &CustomData{
  4541. MsgId: "H4402290015820210330174922668",
  4542. PsnNo: "44020000001102927272",
  4543. Info: "2207",
  4544. }
  4545. customData = append(customData, custom14)
  4546. custom15 := &CustomData{
  4547. MsgId: "H44022900158202103301752362273",
  4548. PsnNo: "44020000001102942890",
  4549. Info: "2207",
  4550. }
  4551. customData = append(customData, custom15)
  4552. custom16 := &CustomData{
  4553. MsgId: "H44022900158202103301751082917",
  4554. PsnNo: "44020000001101662162",
  4555. Info: "2207",
  4556. }
  4557. customData = append(customData, custom16)
  4558. custom17 := &CustomData{
  4559. MsgId: "H44022900158202103301754147728",
  4560. PsnNo: "44020000000229014511",
  4561. Info: "2207",
  4562. }
  4563. customData = append(customData, custom17)
  4564. adminUser := c.GetAdminUserInfo()
  4565. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4566. for _, item := range customData {
  4567. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  4568. fmt.Println(result)
  4569. }
  4570. }
  4571. func (c *HisApiController) ReversalOtherData() {
  4572. var customData []*CustomData
  4573. custom := &CustomData{
  4574. MsgId: "H44022900158202103301714472004",
  4575. PsnNo: "44020000001101329945",
  4576. Info: "2208",
  4577. }
  4578. customData = append(customData, custom)
  4579. custom1 := &CustomData{
  4580. MsgId: "H4402290015820210330172057803",
  4581. PsnNo: "44020000001101161813",
  4582. Info: "2208",
  4583. }
  4584. customData = append(customData, custom1)
  4585. custom2 := &CustomData{
  4586. MsgId: "H44022900158202103301705198813",
  4587. PsnNo: "44190000133097375417",
  4588. Info: "2208",
  4589. }
  4590. customData = append(customData, custom2)
  4591. custom3 := &CustomData{
  4592. MsgId: "H44022900158202103301715524756",
  4593. PsnNo: "44020000001100187221",
  4594. Info: "2208",
  4595. }
  4596. customData = append(customData, custom3)
  4597. custom4 := &CustomData{
  4598. MsgId: "H44022900158202103301730376224",
  4599. PsnNo: "44020000001101959155",
  4600. Info: "2208",
  4601. }
  4602. customData = append(customData, custom4)
  4603. custom5 := &CustomData{
  4604. MsgId: "H44022900158202103301748008725",
  4605. PsnNo: "44020000001104246641",
  4606. Info: "2208",
  4607. }
  4608. customData = append(customData, custom5)
  4609. custom6 := &CustomData{
  4610. MsgId: "H44022900158202103301718096755",
  4611. PsnNo: "44020000001102211860",
  4612. Info: "2208",
  4613. }
  4614. customData = append(customData, custom6)
  4615. custom7 := &CustomData{
  4616. MsgId: "H44022900158202103301736551640",
  4617. PsnNo: "44020000001102687718",
  4618. Info: "2208",
  4619. }
  4620. customData = append(customData, custom7)
  4621. custom8 := &CustomData{
  4622. MsgId: "H44022900158202103301743097676",
  4623. PsnNo: "44020000001102127785",
  4624. Info: "2208",
  4625. }
  4626. customData = append(customData, custom8)
  4627. custom9 := &CustomData{
  4628. MsgId: "H44022900158202103301712304203",
  4629. PsnNo: "44020000001101518097",
  4630. Info: "2208",
  4631. }
  4632. customData = append(customData, custom9)
  4633. custom10 := &CustomData{
  4634. MsgId: "H44022900158202103301738448785",
  4635. PsnNo: "44020000001100500813",
  4636. Info: "2208",
  4637. }
  4638. customData = append(customData, custom10)
  4639. custom11 := &CustomData{
  4640. MsgId: "H44022900158202103301732455843",
  4641. PsnNo: "44020000001102690557",
  4642. Info: "2208",
  4643. }
  4644. customData = append(customData, custom11)
  4645. custom12 := &CustomData{
  4646. MsgId: "H44022900158202103301745421708",
  4647. PsnNo: "44020000001102211928",
  4648. Info: "2208",
  4649. }
  4650. customData = append(customData, custom12)
  4651. custom1212 := &CustomData{
  4652. MsgId: "H440229001582021033017351627",
  4653. PsnNo: "44020000001102481733",
  4654. Info: "2208",
  4655. }
  4656. customData = append(customData, custom1212)
  4657. custom13 := &CustomData{
  4658. MsgId: "H44022900158202103301740327951",
  4659. PsnNo: "44020000001103174866",
  4660. Info: "2208",
  4661. }
  4662. customData = append(customData, custom13)
  4663. custom14 := &CustomData{
  4664. MsgId: "H4402290015820210330174922668",
  4665. PsnNo: "44020000001102927272",
  4666. Info: "2208",
  4667. }
  4668. customData = append(customData, custom14)
  4669. custom15 := &CustomData{
  4670. MsgId: "H44022900158202103301752362273",
  4671. PsnNo: "44020000001102942890",
  4672. Info: "2208",
  4673. }
  4674. customData = append(customData, custom15)
  4675. custom16 := &CustomData{
  4676. MsgId: "H44022900158202103301751082917",
  4677. PsnNo: "44020000001101662162",
  4678. Info: "2208",
  4679. }
  4680. customData = append(customData, custom16)
  4681. custom17 := &CustomData{
  4682. MsgId: "H44022900158202103301754147728",
  4683. PsnNo: "44020000000229014511",
  4684. Info: "2208",
  4685. }
  4686. customData = append(customData, custom17)
  4687. adminUser := c.GetAdminUserInfo()
  4688. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  4689. for _, item := range customData {
  4690. result := service.Gdyb2601(item.PsnNo, item.MsgId, item.Info, miConfig.OrgName, "张俊杰", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  4691. fmt.Println(result)
  4692. }
  4693. }
  4694. func PathExists(path string) (bool, error) {
  4695. _, err := os.Stat(path)
  4696. if err == nil {
  4697. return true, nil
  4698. }
  4699. if os.IsNotExist(err) {
  4700. return false, nil
  4701. }
  4702. return false, err
  4703. }
  4704. //创建文件夹
  4705. func Mkdir(dir string) {
  4706. // 创建文件夹
  4707. exist, err := PathExists(dir)
  4708. if err != nil {
  4709. fmt.Println(err.Error())
  4710. } else {
  4711. if exist {
  4712. fmt.Println(dir + "文件夹已存在!")
  4713. } else {
  4714. // 文件夹名称,权限
  4715. err := os.Mkdir(dir, os.ModePerm)
  4716. if err != nil {
  4717. fmt.Println(dir+"文件夹创建失败:", err.Error())
  4718. } else {
  4719. fmt.Println(dir + "文件夹创建成功!")
  4720. }
  4721. }
  4722. }
  4723. }
  4724. //压缩文件
  4725. func Zip(srcFile string, destZip string) error {
  4726. zipfile, err := os.Create(destZip)
  4727. if err != nil {
  4728. return err
  4729. }
  4730. defer zipfile.Close()
  4731. archive := zip.NewWriter(zipfile)
  4732. defer archive.Close()
  4733. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  4734. if err != nil {
  4735. return err
  4736. }
  4737. header, err := zip.FileInfoHeader(info)
  4738. if err != nil {
  4739. return err
  4740. }
  4741. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  4742. // header.Name = path
  4743. if info.IsDir() {
  4744. header.Name += "/"
  4745. } else {
  4746. header.Method = zip.Deflate
  4747. }
  4748. writer, err := archive.CreateHeader(header)
  4749. if err != nil {
  4750. return err
  4751. }
  4752. if !info.IsDir() {
  4753. file, err := os.Open(path)
  4754. if err != nil {
  4755. return err
  4756. }
  4757. defer file.Close()
  4758. _, err = io.Copy(writer, file)
  4759. }
  4760. return err
  4761. })
  4762. return err
  4763. }
  4764. func ReadFile(filePath string) []byte {
  4765. f, err := os.Open(filePath)
  4766. if err != nil {
  4767. fmt.Println("read file fail", err)
  4768. return nil
  4769. }
  4770. defer f.Close()
  4771. fd, err := ioutil.ReadAll(f)
  4772. if err != nil {
  4773. fmt.Println("read to fd fail", err)
  4774. return nil
  4775. }
  4776. return fd
  4777. }
  4778. func RemoveRepeatedCode(arr []string) (newArr []string) {
  4779. newArr = make([]string, 0)
  4780. for i := 0; i < len(arr); i++ {
  4781. repeat := false
  4782. for j := i + 1; j < len(arr); j++ {
  4783. if arr[i] == arr[j] {
  4784. repeat = true
  4785. break
  4786. }
  4787. }
  4788. if !repeat {
  4789. newArr = append(newArr, arr[i])
  4790. }
  4791. }
  4792. return
  4793. }