zh_his_api_controller.go 159KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708
  1. package zh
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "fmt"
  6. "gdyb/controllers"
  7. "gdyb/enums"
  8. "gdyb/models"
  9. "gdyb/service"
  10. "gdyb/utils"
  11. "github.com/astaxie/beego"
  12. "github.com/axgle/mahonia"
  13. "github.com/jinzhu/gorm"
  14. "io/ioutil"
  15. "math"
  16. "math/rand"
  17. "net/http"
  18. "os"
  19. "regexp"
  20. "strconv"
  21. "strings"
  22. "syscall"
  23. "time"
  24. "unsafe"
  25. )
  26. type ZHHisApiController struct {
  27. controllers.BaseAuthAPIController
  28. }
  29. type ResultSix struct {
  30. Cainfo interface{} `json:"cainfo"`
  31. ErrMsg string `json:"err_msg"`
  32. InfRefmsgid string `json:"inf_refmsgid"`
  33. Infcode int64 `json:"infcode"`
  34. Output struct {
  35. } `json:"output"`
  36. RefmsgTime string `json:"refmsg_time"`
  37. RespondTime string `json:"respond_time"`
  38. Signtype interface{} `json:"signtype"`
  39. WarnMsg interface{} `json:"warn_msg"`
  40. }
  41. type ResultTwo struct {
  42. ErrMsg string `json:"err_msg"`
  43. InfRefmsgid string `json:"inf_refmsgid"`
  44. Infcode int64 `json:"infcode"`
  45. Output struct {
  46. Baseinfo struct {
  47. Age float64 `json:"age"`
  48. Brdy string `json:"brdy"`
  49. Certno string `json:"certno"`
  50. Gend string `json:"gend"`
  51. Naty string `json:"naty"`
  52. PsnCertType string `json:"psn_cert_type"`
  53. PsnName string `json:"psn_name"`
  54. PsnNo string `json:"psn_no"`
  55. } `json:"baseinfo"`
  56. Idetinfo []interface{} `json:"idetinfo"`
  57. Iinfo []struct {
  58. Balc float64 `json:"balc"`
  59. CvlservFlag string `json:"cvlserv_flag"`
  60. EmpName string `json:"emp_name"`
  61. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  62. Insutype string `json:"insutype"`
  63. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  64. PausInsuDate string `json:"paus_insu_date"`
  65. PsnInsuDate string `json:"psn_insu_date"`
  66. PsnInsuStas string `json:"psn_insu_stas"`
  67. PsnType string `json:"psn_type"`
  68. } `json:"insuinfo"`
  69. } `json:"output"`
  70. RefmsgTime string `json:"refmsg_time"`
  71. RespondTime string `json:"respond_time"`
  72. Signtype interface{} `json:"signtype"`
  73. WarnInfo interface{} `json:"warn_info"`
  74. }
  75. type ResultTwo10265 struct {
  76. ErrMsg string `json:"err_msg"`
  77. InfRefmsgid string `json:"inf_refmsgid"`
  78. Infcode string `json:"infcode"`
  79. Output struct {
  80. Baseinfo struct {
  81. Age float64 `json:"age"`
  82. Brdy string `json:"brdy"`
  83. Certno string `json:"certno"`
  84. Gend string `json:"gend"`
  85. Naty string `json:"naty"`
  86. PsnCertType string `json:"psn_cert_type"`
  87. PsnName string `json:"psn_name"`
  88. PsnNo string `json:"psn_no"`
  89. } `json:"baseinfo"`
  90. Idetinfo []interface{} `json:"idetinfo"`
  91. Iinfo []struct {
  92. Balc float64 `json:"balc"`
  93. CvlservFlag string `json:"cvlserv_flag"`
  94. EmpName string `json:"emp_name"`
  95. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  96. Insutype string `json:"insutype"`
  97. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  98. PausInsuDate string `json:"paus_insu_date"`
  99. PsnInsuDate string `json:"psn_insu_date"`
  100. PsnInsuStas string `json:"psn_insu_stas"`
  101. PsnType string `json:"psn_type"`
  102. } `json:"insuinfo"`
  103. } `json:"output"`
  104. RefmsgTime string `json:"refmsg_time"`
  105. RespondTime string `json:"respond_time"`
  106. Signtype interface{} `json:"signtype"`
  107. WarnInfo interface{} `json:"warn_info"`
  108. }
  109. type ResultThree struct {
  110. Cainfo interface{} `json:"cainfo"`
  111. ErrMsg string `json:"err_msg"`
  112. InfRefmsgid string `json:"inf_refmsgid"`
  113. Infcode int64 `json:"infcode"`
  114. Output struct {
  115. Result struct {
  116. MdtrtID string `json:"mdtrt_id"`
  117. } `json:"result"`
  118. } `json:"output"`
  119. RefmsgTime string `json:"refmsg_time"`
  120. RespondTime string `json:"respond_time"`
  121. Signtype interface{} `json:"signtype"`
  122. WarnMsg interface{} `json:"warn_msg"`
  123. }
  124. type ResultThree10265 struct {
  125. Cainfo interface{} `json:"cainfo"`
  126. ErrMsg string `json:"err_msg"`
  127. InfRefmsgid string `json:"inf_refmsgid"`
  128. Infcode string `json:"infcode"`
  129. Output struct {
  130. Result struct {
  131. MdtrtID string `json:"mdtrt_id"`
  132. } `json:"result"`
  133. } `json:"output"`
  134. RefmsgTime string `json:"refmsg_time"`
  135. RespondTime string `json:"respond_time"`
  136. Signtype interface{} `json:"signtype"`
  137. WarnMsg interface{} `json:"warn_msg"`
  138. }
  139. type ResultFour struct {
  140. Cainfo string `json:"cainfo"`
  141. ErrMsg string `json:"err_msg"`
  142. InfRefmsgid string `json:"inf_refmsgid"`
  143. Infcode int64 `json:"infcode"`
  144. Output struct {
  145. Result []struct {
  146. BasMednFlag string `json:"bas_medn_flag"`
  147. ChldMedcFlag string `json:"chld_medc_flag"`
  148. ChrgitmLv string `json:"chrgitm_lv"`
  149. Cnt float64 `json:"cnt"`
  150. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  151. DrtReimFlag string `json:"drt_reim_flag"`
  152. FeedetlSn string `json:"feedetl_sn"`
  153. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  154. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  155. InscpScpAmt float64 `json:"inscp_scp_amt"`
  156. ListSpItemFlag string `json:"list_sp_item_flag"`
  157. LmtUsedFlag string `json:"lmt_used_flag"`
  158. MedChrgitmType string `json:"med_chrgitm_type"`
  159. Memo string `json:"memo"`
  160. OverlmtAmt float64 `json:"overlmt_amt"`
  161. PreselfpayAmt float64 `json:"preselfpay_amt"`
  162. Pric float64 `json:"pric"`
  163. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  164. SelfpayProp float64 `json:"selfpay_prop"`
  165. } `json:"result"`
  166. } `json:"output"`
  167. RefmsgTime string `json:"refmsg_time"`
  168. RespondTime string `json:"respond_time"`
  169. Signtype string `json:"signtype"`
  170. WarnMsg string `json:"warn_msg"`
  171. }
  172. type ResultFour10265 struct {
  173. Cainfo string `json:"cainfo"`
  174. ErrMsg string `json:"err_msg"`
  175. InfRefmsgid string `json:"inf_refmsgid"`
  176. Infcode string `json:"infcode"`
  177. Output struct {
  178. Result []struct {
  179. BasMednFlag string `json:"bas_medn_flag"`
  180. ChldMedcFlag string `json:"chld_medc_flag"`
  181. ChrgitmLv string `json:"chrgitm_lv"`
  182. Cnt float64 `json:"cnt"`
  183. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  184. DrtReimFlag string `json:"drt_reim_flag"`
  185. FeedetlSn string `json:"feedetl_sn"`
  186. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  187. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  188. InscpScpAmt float64 `json:"inscp_scp_amt"`
  189. ListSpItemFlag string `json:"list_sp_item_flag"`
  190. LmtUsedFlag string `json:"lmt_used_flag"`
  191. MedChrgitmType string `json:"med_chrgitm_type"`
  192. Memo string `json:"memo"`
  193. OverlmtAmt float64 `json:"overlmt_amt"`
  194. PreselfpayAmt float64 `json:"preselfpay_amt"`
  195. Pric float64 `json:"pric"`
  196. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  197. SelfpayProp float64 `json:"selfpay_prop"`
  198. } `json:"result"`
  199. } `json:"output"`
  200. RefmsgTime string `json:"refmsg_time"`
  201. RespondTime string `json:"respond_time"`
  202. Signtype string `json:"signtype"`
  203. WarnMsg string `json:"warn_msg"`
  204. }
  205. type ResultFive struct {
  206. Balc float64 `json:"balc"`
  207. CvlservFlag string `json:"cvlserv_flag"`
  208. EmpName string `json:"emp_name"`
  209. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  210. Insutype string `json:"insutype"`
  211. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  212. PausInsuDate string `json:"paus_insu_date"`
  213. PsnInsuDate string `json:"psn_insu_date"`
  214. PsnInsuStas string `json:"psn_insu_stas"`
  215. PsnType string `json:"psn_type"`
  216. }
  217. type ResultSeven struct {
  218. Cainfo string `json:"cainfo"`
  219. ErrMsg string `json:"err_msg"`
  220. InfRefmsgid string `json:"inf_refmsgid"`
  221. Infcode int64 `json:"infcode"`
  222. Output struct {
  223. Setldetail []interface{} `json:"setldetail"`
  224. Setlinfo struct {
  225. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  226. AcctPay float64 `json:"acct_pay"`
  227. ActPayDedc float64 `json:"act_pay_dedc"`
  228. Age float64 `json:"age"`
  229. Balc float64 `json:"balc"`
  230. Brdy string `json:"brdy"`
  231. Certno string `json:"certno"`
  232. ClrOptins string `json:"clr_optins"`
  233. ClrType string `json:"clr_type"`
  234. ClrWay string `json:"clr_way"`
  235. CvlservFlag string `json:"cvlserv_flag"`
  236. CvlservPay float64 `json:"cvlserv_pay"`
  237. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  238. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  239. Gend string `json:"gend"`
  240. HifesPay float64 `json:"hifes_pay"`
  241. HifmiPay float64 `json:"hifmi_pay"`
  242. HifpPay float64 `json:"hifp_pay"`
  243. HospPartAmt float64 `json:"hosp_part_amt"`
  244. InscpScpAmt float64 `json:"inscp_scp_amt"`
  245. Insutype string `json:"insutype"`
  246. MafPay float64 `json:"maf_pay"`
  247. MdtrtCertType string `json:"mdtrt_cert_type"`
  248. HifobPay float64 `json:"hifob_pay"`
  249. MdtrtID string `json:"mdtrt_id"`
  250. MedType string `json:"med_type"`
  251. MedfeeSumamt float64 `json:"medfee_sumamt"`
  252. MedinsSetlID string `json:"medins_setl_id"`
  253. Naty string `json:"naty"`
  254. OthPay float64 `json:"oth_pay"`
  255. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  256. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  257. PreselfpayAmt float64 `json:"preselfpay_amt"`
  258. PsnCashPay float64 `json:"psn_cash_pay"`
  259. PsnCertType string `json:"psn_cert_type"`
  260. PsnName string `json:"psn_name"`
  261. PsnNo string `json:"psn_no"`
  262. PsnPartAmt float64 `json:"psn_part_amt"`
  263. PsnType string `json:"psn_type"`
  264. SetlID string `json:"setl_id"`
  265. SetlTime string `json:"setl_time"`
  266. } `json:"setlinfo"`
  267. } `json:"output"`
  268. RefmsgTime string `json:"refmsg_time"`
  269. RespondTime string `json:"respond_time"`
  270. Signtype interface{} `json:"signtype"`
  271. WarnMsg interface{} `json:"warn_msg"`
  272. }
  273. type ResultSeven10265 struct {
  274. Cainfo string `json:"cainfo"`
  275. ErrMsg string `json:"err_msg"`
  276. InfRefmsgid string `json:"inf_refmsgid"`
  277. Infcode string `json:"infcode"`
  278. Output struct {
  279. Setldetail []interface{} `json:"setldetail"`
  280. Setlinfo struct {
  281. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  282. AcctPay float64 `json:"acct_pay"`
  283. ActPayDedc float64 `json:"act_pay_dedc"`
  284. Age float64 `json:"age"`
  285. Balc float64 `json:"balc"`
  286. Brdy string `json:"brdy"`
  287. Certno string `json:"certno"`
  288. ClrOptins string `json:"clr_optins"`
  289. ClrType string `json:"clr_type"`
  290. ClrWay string `json:"clr_way"`
  291. CvlservFlag string `json:"cvlserv_flag"`
  292. CvlservPay float64 `json:"cvlserv_pay"`
  293. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  294. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  295. Gend string `json:"gend"`
  296. HifesPay float64 `json:"hifes_pay"`
  297. HifmiPay float64 `json:"hifmi_pay"`
  298. HifpPay float64 `json:"hifp_pay"`
  299. HospPartAmt float64 `json:"hosp_part_amt"`
  300. InscpScpAmt float64 `json:"inscp_scp_amt"`
  301. Insutype string `json:"insutype"`
  302. MafPay float64 `json:"maf_pay"`
  303. MdtrtCertType string `json:"mdtrt_cert_type"`
  304. HifobPay float64 `json:"hifob_pay"`
  305. MdtrtID string `json:"mdtrt_id"`
  306. MedType string `json:"med_type"`
  307. MedfeeSumamt float64 `json:"medfee_sumamt"`
  308. MedinsSetlID string `json:"medins_setl_id"`
  309. Naty string `json:"naty"`
  310. OthPay float64 `json:"oth_pay"`
  311. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  312. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  313. PreselfpayAmt float64 `json:"preselfpay_amt"`
  314. PsnCashPay float64 `json:"psn_cash_pay"`
  315. PsnCertType string `json:"psn_cert_type"`
  316. PsnName string `json:"psn_name"`
  317. PsnNo string `json:"psn_no"`
  318. PsnPartAmt float64 `json:"psn_part_amt"`
  319. PsnType string `json:"psn_type"`
  320. SetlID string `json:"setl_id"`
  321. SetlTime string `json:"setl_time"`
  322. } `json:"setlinfo"`
  323. } `json:"output"`
  324. RefmsgTime string `json:"refmsg_time"`
  325. RespondTime string `json:"respond_time"`
  326. Signtype interface{} `json:"signtype"`
  327. WarnMsg interface{} `json:"warn_msg"`
  328. }
  329. type ResultSixteen struct {
  330. Cainfo string `json:"cainfo"`
  331. ErrMsg string `json:"err_msg"`
  332. InfRefmsgid string `json:"inf_refmsgid"`
  333. Infcode int64 `json:"infcode"`
  334. Output struct {
  335. Setldetail []interface{} `json:"setldetail"`
  336. Setlinfo struct {
  337. MdtrtID string `json:"mdtrt_id"`
  338. SetlID string `json:"setl_id"`
  339. ClrOptins string `json:"clr_optins"`
  340. SetlTime string `json:"setl_time"`
  341. MedfeeSumamt float64 `json:"medfee_sumamt"`
  342. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  343. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  344. PreselfpayAmt float64 `json:"preselfpay_amt"`
  345. InscpScpAmt float64 `json:"inscp_scp_amt"`
  346. ActPayDedc float64 `json:"act_pay_dedc"`
  347. HifpPay float64 `json:"hifp_pay"`
  348. PoolPropSe float64 `json:"pool_prop_selfpay"`
  349. Lfpay float64 `json:"selfpay"`
  350. CvlservPay float64 `json:"cvlserv_pay"`
  351. HifesPay float64 `json:"hifes_pay"`
  352. HifmiPay float64 `json:"hifmi_pay"`
  353. HifobPay float64 `json:"hifob_pay"`
  354. MafPay float64 `json:"maf_pay"`
  355. OthPay float64 `json:"oth_pay"`
  356. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  357. PsnPartAmt float64 `json:"psn_part_amt"`
  358. AcctPay float64 `json:"acct_pay"`
  359. Balc float64 `json:"balc"`
  360. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  361. HospPartAmt float64 `json:"hosp_part_amt"`
  362. MedinsSetlID string `json:"medins_setl_id"`
  363. PdnCashPay string `json:"pdn_cash_pay"`
  364. } `json:"setlinfo"`
  365. } `json:"output"`
  366. RefmsgTime string `json:"refmsg_time"`
  367. RespondTime string `json:"respond_time"`
  368. Signtype interface{} `json:"signtype"`
  369. WarnMsg interface{} `json:"warn_msg"`
  370. }
  371. type ResultSixteen10265 struct {
  372. Cainfo string `json:"cainfo"`
  373. ErrMsg string `json:"err_msg"`
  374. InfRefmsgid string `json:"inf_refmsgid"`
  375. Infcode string `json:"infcode"`
  376. Output struct {
  377. Setldetail []interface{} `json:"setldetail"`
  378. Setlinfo struct {
  379. MdtrtID string `json:"mdtrt_id"`
  380. SetlID string `json:"setl_id"`
  381. ClrOptins string `json:"clr_optins"`
  382. SetlTime string `json:"setl_time"`
  383. MedfeeSumamt float64 `json:"medfee_sumamt"`
  384. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  385. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  386. PreselfpayAmt float64 `json:"preselfpay_amt"`
  387. InscpScpAmt float64 `json:"inscp_scp_amt"`
  388. ActPayDedc float64 `json:"act_pay_dedc"`
  389. HifpPay float64 `json:"hifp_pay"`
  390. PoolPropSe float64 `json:"pool_prop_selfpay"`
  391. Lfpay float64 `json:"selfpay"`
  392. CvlservPay float64 `json:"cvlserv_pay"`
  393. HifesPay float64 `json:"hifes_pay"`
  394. HifmiPay float64 `json:"hifmi_pay"`
  395. HifobPay float64 `json:"hifob_pay"`
  396. MafPay float64 `json:"maf_pay"`
  397. OthPay float64 `json:"oth_pay"`
  398. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  399. PsnPartAmt float64 `json:"psn_part_amt"`
  400. AcctPay float64 `json:"acct_pay"`
  401. Balc float64 `json:"balc"`
  402. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  403. HospPartAmt float64 `json:"hosp_part_amt"`
  404. MedinsSetlID string `json:"medins_setl_id"`
  405. PdnCashPay string `json:"pdn_cash_pay"`
  406. } `json:"setlinfo"`
  407. } `json:"output"`
  408. RefmsgTime string `json:"refmsg_time"`
  409. RespondTime string `json:"respond_time"`
  410. Signtype interface{} `json:"signtype"`
  411. WarnMsg interface{} `json:"warn_msg"`
  412. }
  413. type Custom struct {
  414. DetItemFeeSumamt string
  415. Cut string
  416. FeedetlSn string
  417. Price string
  418. MedListCodg string
  419. Type int64
  420. AdviceId int64
  421. ProjectId int64
  422. ItemId int64
  423. }
  424. type ResultEmpty struct {
  425. Cainfo interface{} `json:"cainfo"`
  426. ErrMsg string `json:"err_msg"`
  427. InfRefmsgid string `json:"inf_refmsgid"`
  428. Infcode int64 `json:"infcode"`
  429. Output struct {
  430. } `json:"output"`
  431. RefmsgTime string `json:"refmsg_time"`
  432. RespondTime string `json:"respond_time"`
  433. Signtype interface{} `json:"signtype"`
  434. WarnMsg interface{} `json:"warn_msg"`
  435. }
  436. type ResultEmpty10265 struct {
  437. Cainfo interface{} `json:"cainfo"`
  438. ErrMsg string `json:"err_msg"`
  439. InfRefmsgid string `json:"inf_refmsgid"`
  440. Infcode string `json:"infcode"`
  441. Output struct {
  442. } `json:"output"`
  443. RefmsgTime string `json:"refmsg_time"`
  444. RespondTime string `json:"respond_time"`
  445. Signtype interface{} `json:"signtype"`
  446. WarnMsg interface{} `json:"warn_msg"`
  447. }
  448. type CustomResult struct {
  449. BasMednFlag string `json:"bas_medn_flag"`
  450. ChldMedcFlag string `json:"chld_medc_flag"`
  451. ChrgitmLv string `json:"chrgitm_lv"`
  452. Cnt float64 `json:"cnt"`
  453. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  454. DrtReimFlag string `json:"drt_reim_flag"`
  455. FeedetlSn string `json:"feedetl_sn"`
  456. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  457. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  458. InscpScpAmt float64 `json:"inscp_scp_amt"`
  459. ListSpItemFlag string `json:"list_sp_item_flag"`
  460. LmtUsedFlag string `json:"lmt_used_flag"`
  461. MedChrgitmType string `json:"med_chrgitm_type"`
  462. Memo string `json:"memo"`
  463. OverlmtAmt float64 `json:"overlmt_amt"`
  464. PreselfpayAmt float64 `json:"preselfpay_amt"`
  465. Pric float64 `json:"pric"`
  466. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  467. SelfpayProp float64 `json:"selfpay_prop"`
  468. }
  469. func ZHHisManagerApiRegistRouters() {
  470. beego.Router("/zh/api/inhopitalcheck/get", &ZHHisApiController{}, "get:GetZHInHospitalCheck")
  471. beego.Router("/zh/api/outhopitalcheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalCheck")
  472. beego.Router("/zh/api/uploadinfo/get", &ZHHisApiController{}, "get:GetUploadInfo")
  473. beego.Router("/zh/api/presettle/get", &ZHHisApiController{}, "get:GetPreSettleInfo")
  474. beego.Router("/zh/api/settle/get", &ZHHisApiController{}, "get:GetSettleInfo")
  475. beego.Router("/zh/api/inthopitaluncheck/get", &ZHHisApiController{}, "get:GetZHInHospitalUnCheck")
  476. beego.Router("/zh/api/outhopitaluncheck/get", &ZHHisApiController{}, "get:GetZHOutHospitalUnCheck")
  477. beego.Router("/zh/api/refund", &ZHHisApiController{}, "get:ZHRefund")
  478. beego.Router("/zh/api/refunddetail", &ZHHisApiController{}, "get:ZHRefundDetail")
  479. beego.Router("/zh/api/patient/info", &ZHHisApiController{}, "get:GetZHPatientInfo")
  480. beego.Router("/zh/api/readcard", &ZHHisApiController{}, "get:ReadCard")
  481. beego.Router("/zh/api/clearsettle", &ZHHisApiController{}, "get:ClearSettle")
  482. beego.Router("/zh/api/readelecard", &ZHHisApiController{}, "get:ReadEleCard")
  483. //beego.Router("/zh/api/readelecard", &ZHHisApiController{}, "get:ReadEleCard")
  484. beego.Router("/zh/api/lingbao/upload", &ZHHisApiController{}, "get:UploadLingBao")
  485. beego.Router("/zh/api/lingbao/refund", &ZHHisApiController{}, "get:RefundLingBao")
  486. beego.Router("/zh/api/lingbao/get", &ZHHisApiController{}, "get:GetLingBao")
  487. beego.Router("/api/token/get", &ZHHisApiController{}, "post:GetToken")
  488. beego.Router("/api/ele/info", &ZHHisApiController{}, "post:GetEleInfo")
  489. beego.Router("/api/4102", &ZHHisApiController{}, "get:Get4102")
  490. beego.Router("/api/4103", &ZHHisApiController{}, "get:Get4103")
  491. beego.Router("/api/cardstatus", &ZHHisApiController{}, "get:GetCardStatus")
  492. }
  493. func (c *ZHHisApiController) GetCardStatus() {
  494. //patient_id, _ := c.GetInt64("patient_id")
  495. //record_date, _ := c.GetInt64("record_date")
  496. //psn, _ := service.GetPsnByPatientIdtWO(patient_id,record_date)
  497. //if len(psn.VerifyNumber) > 0{
  498. // c.ServeSuccessJSON(map[string]interface{}{
  499. // "msg": "读卡成功",
  500. // })
  501. //} else{
  502. // c.ServeSuccessJSON(map[string]interface{}{
  503. // "msg": "",
  504. // })
  505. //}
  506. }
  507. func (c *ZHHisApiController) GetEleInfo() {
  508. body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
  509. var respJSON map[string]interface{}
  510. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  511. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  512. return
  513. }
  514. token := respJSON["token"].(string)
  515. respJSON = respJSON["result"].(map[string]interface{})
  516. result_byte, _ := json.Marshal(respJSON)
  517. result := string(result_byte)
  518. fmt.Println("token")
  519. fmt.Println(token)
  520. fmt.Println("result")
  521. fmt.Println(result)
  522. var res ResultTwo
  523. var res10265 ResultTwo10265 //1101结果
  524. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  525. utils.ErrorLog("解析失败:%v", err)
  526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  527. return
  528. }
  529. res.ErrMsg = res10265.ErrMsg
  530. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  531. res.Infcode = infocode
  532. res.Output = res10265.Output
  533. res.InfRefmsgid = res10265.InfRefmsgid
  534. if res.Infcode == 0 {
  535. patient, err := service.GetPatientByNumber(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  536. if err == gorm.ErrRecordNotFound {
  537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  538. return
  539. } else if err != nil {
  540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  541. return
  542. } else {
  543. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  544. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  545. infoStr := string(Iinfos)
  546. idetinfoStr := string(Idetinfos)
  547. psn := &models.HisPsn{
  548. PsnNo: res.Output.Baseinfo.PsnNo,
  549. Age: res.Output.Baseinfo.Age,
  550. PatientId: patient.ID,
  551. Certno: res.Output.Baseinfo.Certno,
  552. Brdy: res.Output.Baseinfo.Brdy,
  553. Gend: res.Output.Baseinfo.Gend,
  554. Naty: res.Output.Baseinfo.Naty,
  555. PsnCertType: res.Output.Baseinfo.PsnCertType,
  556. PsnName: res.Output.Baseinfo.PsnName,
  557. Idetinfo: idetinfoStr,
  558. Insuinfo: infoStr,
  559. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  560. CardInfo: "",
  561. VerifyNumber: token,
  562. }
  563. service.CreateHisPsn(psn)
  564. c.ServeSuccessJSON(map[string]interface{}{
  565. "patient": patient,
  566. "number": token,
  567. })
  568. }
  569. } else {
  570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  571. return
  572. }
  573. }
  574. func (c *ZHHisApiController) GetToken() {
  575. body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
  576. var respJSON map[string]interface{}
  577. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  578. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  579. return
  580. }
  581. token := respJSON["token"].(string)
  582. id_card_no := respJSON["id_card_no"].(string)
  583. fmt.Println("token")
  584. fmt.Println(token)
  585. fmt.Println("result")
  586. fmt.Println(id_card_no)
  587. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  588. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  589. var api string
  590. api = "http://172.16.13.254:9532/" + "api/eleinfo?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName +
  591. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&url=" + miConfig.Url + "&cainfo=" + miConfig.Cainfo + "&token=" + token + "&user_name=" + patient.Name + "&id_card_no=" + patient.IdCardNo
  592. resp, requestErr := http.Get(api)
  593. if requestErr != nil {
  594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  595. return
  596. }
  597. body, ioErr := ioutil.ReadAll(resp.Body)
  598. if ioErr != nil {
  599. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  601. return
  602. }
  603. c.ServeSuccessJSON(map[string]interface{}{
  604. "msg": "读卡成功",
  605. })
  606. }
  607. func (c *ZHHisApiController) UploadLingBao() {
  608. id, _ := c.GetInt64("id")
  609. record_time := c.GetString("record_time")
  610. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  611. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  612. admin_user_id, _ := c.GetInt64("admin_user_id")
  613. timeLayout := "2006-01-02"
  614. loc, _ := time.LoadLocation("Local")
  615. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  616. if err != nil {
  617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  618. return
  619. }
  620. recordDateTime := theTime.Unix()
  621. adminUser := c.GetAdminUserInfo()
  622. var prescriptions []*models.HisPrescription
  623. data := make(map[string]interface{})
  624. if settle_accounts_type == 1 { //日结
  625. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  626. } else { //月结
  627. start_time_str := c.GetString("start_time")
  628. end_time_str := c.GetString("end_time")
  629. timeLayout := "2006-01-02"
  630. loc, _ := time.LoadLocation("Local")
  631. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  632. if err != nil {
  633. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  634. return
  635. }
  636. recordStartTime := theStartTime.Unix()
  637. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  638. if err != nil {
  639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  640. return
  641. }
  642. recordEndTime := theEndTime.Unix()
  643. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  644. }
  645. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  646. record, _ := service.GetInHospitalRecord(in_hospital_id)
  647. if record.ID == 0 {
  648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  649. return
  650. }
  651. timestamp := time.Now().Unix()
  652. tempTime := time.Unix(timestamp, 0)
  653. timeFormat := tempTime.Format("20060102150405")
  654. chrgBchno := rand.Intn(100000) + 10000
  655. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  656. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  657. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  658. department, _ := service.GetDepartMentDetail(record.Departments)
  659. strconv.FormatInt(record.PatientId, 10)
  660. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, record.Doctor)
  661. //client := &http.Client{}
  662. data["psn_no"] = record.PsnNo
  663. data["mdtrt_id"] = record.Number
  664. data["chrg_bchno"] = chrg_bchno
  665. data["org_name"] = miConfig.OrgName
  666. data["doctor"] = roles.UserName
  667. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  668. data["dept"] = strconv.FormatInt(department.ID, 10)
  669. data["fixmedins_code"] = miConfig.Code
  670. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  671. data["dept_code"] = "15"
  672. } else {
  673. data["dept_code"] = department.Number
  674. }
  675. if miConfig.Code == "H15049901371" {
  676. if record.MedType == 14 {
  677. if record.InsutypeType == "390" {
  678. data["med_type"] = "9933"
  679. } else if record.InsutypeType == "310" {
  680. data["med_type"] = "990502"
  681. }
  682. } else if record.MedType == 11 {
  683. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  684. }
  685. } else {
  686. if record.MedType == 1112 {
  687. data["med_type"] = strconv.FormatInt(11, 10)
  688. } else {
  689. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  690. }
  691. }
  692. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  693. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  694. data["secret_key"] = miConfig.SecretKey
  695. var ids []int64
  696. fmt.Println(data)
  697. for _, item := range prescriptions {
  698. ids = append(ids, item.ID)
  699. }
  700. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  701. if config.IsOpen == 1 { //对接了医保,走医保流程
  702. var pagesize int = 100
  703. var start int = 1
  704. var stop int
  705. var pagecount int
  706. var curpage int
  707. var isSuccess bool = true
  708. var customs []*models.NewCustom
  709. for _, item := range prescriptions {
  710. tm := time.Unix(item.PreTime, 0)
  711. if item.Type == 1 { //药品
  712. for _, subItem := range item.HisDoctorAdviceInfo {
  713. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  714. //var randNum int
  715. //randNum = rand.Intn(10000) + 1000
  716. cus := &models.NewCustom{
  717. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  718. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  719. FeedetlSn: subItem.FeedetlSn,
  720. Price: fmt.Sprintf("%.4f", subItem.Price),
  721. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  722. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  723. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  724. }
  725. customs = append(customs, cus)
  726. }
  727. }
  728. }
  729. if item.Type == 2 { //项目
  730. for _, subItem := range item.HisPrescriptionProject {
  731. //var randNum int
  732. //randNum = rand.Intn(10000) + 1000
  733. if subItem.Type == 2 {
  734. if len(subItem.HisProject.MedicalCode) > 0 {
  735. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  736. cus := &models.NewCustom{
  737. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  738. Cut: fmt.Sprintf("%.4f", cnt),
  739. FeedetlSn: subItem.FeedetlSn,
  740. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  741. MedListCodg: subItem.HisProject.MedicalCode,
  742. HospApprFlag: -1,
  743. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  744. }
  745. customs = append(customs, cus)
  746. }
  747. } else if subItem.Type == 3 {
  748. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  749. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  750. cus := &models.NewCustom{
  751. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  752. Cut: fmt.Sprintf("%.4f", cnt),
  753. FeedetlSn: subItem.FeedetlSn,
  754. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  755. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  756. HospApprFlag: -1,
  757. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  758. }
  759. customs = append(customs, cus)
  760. }
  761. }
  762. }
  763. }
  764. }
  765. //总页数,向上取整,注意除之前要先转换类型为float64
  766. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  767. var ress []*ResultFour
  768. for curpage = 1; curpage <= pagecount; curpage++ {
  769. if curpage == 1 {
  770. start = 1
  771. } else {
  772. start = (curpage-1)*pagesize + 1
  773. }
  774. stop = curpage * pagesize
  775. if stop > len(customs) {
  776. stop = len(customs)
  777. }
  778. var result string
  779. var requestLog string
  780. if miConfig.MdtrtareaAdmvs == "150499" {
  781. data := make(map[string]interface{})
  782. if record.MedType == 14 {
  783. if record.InsutypeType == "390" {
  784. data["med_type"] = "9933"
  785. } else if record.InsutypeType == "310" {
  786. data["med_type"] = "990502"
  787. }
  788. } else if record.MedType == 11 {
  789. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  790. }
  791. data["psn_no"] = record.PsnNo
  792. data["number"] = record.Number
  793. data["customs"] = customs[start-1 : stop]
  794. data["chrg_bchno"] = chrg_bchno
  795. data["dept"] = strconv.FormatInt(department.ID, 10)
  796. data["dept_code"] = department.Number
  797. data["doctor_code"] = doctor_info.DoctorNumber
  798. data["doctor_name"] = doctor_info.UserName
  799. data["org_name"] = miConfig.OrgName
  800. data["opertor"] = roles.UserName
  801. data["fixmedins_code"] = miConfig.Code
  802. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  803. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  804. data["secret_key"] = miConfig.SecretKey
  805. var req *http.Request
  806. bytesData, _ := json.Marshal(data)
  807. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2301", bytes.NewReader(bytesData))
  808. client := &http.Client{}
  809. resp, _ := client.Do(req)
  810. defer resp.Body.Close()
  811. body, ioErr := ioutil.ReadAll(resp.Body)
  812. if ioErr != nil {
  813. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  815. return
  816. }
  817. var respJSON map[string]interface{}
  818. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  819. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  821. return
  822. }
  823. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  824. result_byte, _ := json.Marshal(respJSON)
  825. result = string(result_byte)
  826. } else {
  827. result, requestLog = service.ZHGdyb2301(record.PsnNo, record.Number, customs[start-1:stop], chrg_bchno, miConfig.OrgName, roles.UserName, strconv.FormatInt(department.ID, 10), miConfig.Code, department.Number, strconv.FormatInt(roles.AdminUserId, 10), record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, data["med_type"].(string), doctor_info.DoctorNumber, doctor_info.UserName)
  828. saveLog(result, requestLog, "2301", "上传明细")
  829. }
  830. var dat map[string]interface{}
  831. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  832. fmt.Println(dat)
  833. } else {
  834. fmt.Println(err)
  835. }
  836. userJSONBytes, _ := json.Marshal(dat)
  837. var res ResultFour
  838. var resFour10265 ResultFour10265
  839. if miConfig.Code == "H15049901371" {
  840. if err := json.Unmarshal(userJSONBytes, &resFour10265); err != nil {
  841. utils.ErrorLog("解析失败:%v", err)
  842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  843. return
  844. }
  845. res.WarnMsg = resFour10265.WarnMsg
  846. res.Output = resFour10265.Output
  847. res.ErrMsg = resFour10265.ErrMsg
  848. res.RespondTime = resFour10265.RespondTime
  849. res.InfRefmsgid = resFour10265.InfRefmsgid
  850. Infcode, _ := strconv.ParseInt(resFour10265.Infcode, 10, 64)
  851. res.Infcode = Infcode
  852. } else {
  853. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  854. utils.ErrorLog("解析失败:%v", err)
  855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  856. return
  857. }
  858. }
  859. if res.Infcode == 0 {
  860. ress = append(ress, &res)
  861. } else {
  862. isSuccess = false
  863. errlog := &models.HisOrderError{
  864. UserOrgId: adminUser.CurrentOrgId,
  865. Ctime: time.Now().Unix(),
  866. Mtime: time.Now().Unix(),
  867. Number: chrg_bchno,
  868. ErrMsg: "",
  869. Status: 1,
  870. PatientId: id,
  871. RecordTime: recordDateTime,
  872. Stage: 4,
  873. }
  874. service.CreateErrMsgLog(errlog)
  875. c.ServeSuccessJSON(map[string]interface{}{
  876. "failed_code": -10,
  877. "msg": "上传明细错误,请联系his厂商",
  878. })
  879. return
  880. }
  881. }
  882. if isSuccess == true {
  883. if settle_accounts_type == 1 {
  884. for _, subItem := range ress {
  885. for _, item := range subItem.Output.Result {
  886. temp := strings.Split(item.FeedetlSn, "-")
  887. var advice_id int64 = 0
  888. var project_id int64 = 0
  889. var types int64 = 0
  890. id, _ := strconv.ParseInt(temp[2], 10, 64)
  891. types, _ = strconv.ParseInt(temp[1], 10, 64)
  892. if temp[1] == "1" {
  893. advice_id = id
  894. project_id = 0
  895. } else if temp[1] == "2" {
  896. advice_id = 0
  897. project_id = id
  898. }
  899. info := &models.HisOrderInfo{
  900. OrderNumber: record.Number,
  901. FeedetlSn: item.FeedetlSn,
  902. UploadDate: recordDateTime,
  903. AdviceId: advice_id,
  904. DetItemFeeSumamt: item.DetItemFeeSumamt,
  905. Cnt: item.Cnt,
  906. Pric: float64(item.Pric),
  907. PatientId: record.PatientId,
  908. PricUplmtAmt: item.PricUplmtAmt,
  909. SelfpayProp: item.SelfpayProp,
  910. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  911. OverlmtAmt: item.OverlmtAmt,
  912. PreselfpayAmt: item.PreselfpayAmt,
  913. BasMednFlag: item.BasMednFlag,
  914. MedChrgitmType: item.MedChrgitmType,
  915. HiNegoDrugFlag: item.HiNegoDrugFlag,
  916. Status: 1,
  917. Memo: item.Memo,
  918. Mtime: time.Now().Unix(),
  919. InscpScpAmt: item.InscpScpAmt,
  920. DrtReimFlag: item.DrtReimFlag,
  921. Ctime: time.Now().Unix(),
  922. ListSpItemFlag: item.ListSpItemFlag,
  923. ChldMedcFlag: item.ChldMedcFlag,
  924. LmtUsedFlag: item.LmtUsedFlag,
  925. ChrgitmLv: item.ChrgitmLv,
  926. UserOrgId: adminUser.CurrentOrgId,
  927. HisPatientId: record.ID,
  928. OrderId: 0,
  929. ProjectId: project_id,
  930. Type: types,
  931. SettleType: settle_accounts_type,
  932. }
  933. service.CreateOrderInfo(info)
  934. }
  935. }
  936. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  937. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  938. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  939. if err == nil {
  940. c.ServeSuccessJSON(map[string]interface{}{
  941. "msg": "上传费用明细成功",
  942. })
  943. return
  944. } else {
  945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  946. return
  947. }
  948. } else {
  949. for _, subItem := range ress {
  950. for _, item := range subItem.Output.Result {
  951. temp := strings.Split(item.FeedetlSn, "-")
  952. var advice_id int64 = 0
  953. var project_id int64 = 0
  954. var types int64 = 0
  955. id, _ := strconv.ParseInt(temp[2], 10, 64)
  956. types, _ = strconv.ParseInt(temp[1], 10, 64)
  957. if temp[1] == "1" {
  958. advice_id = id
  959. project_id = 0
  960. } else if temp[1] == "2" {
  961. advice_id = 0
  962. project_id = id
  963. }
  964. info := &models.HisOrderInfo{
  965. OrderNumber: record.Number,
  966. FeedetlSn: item.FeedetlSn,
  967. UploadDate: time.Now().Unix(),
  968. AdviceId: advice_id,
  969. DetItemFeeSumamt: item.DetItemFeeSumamt,
  970. Cnt: item.Cnt,
  971. Pric: float64(item.Pric),
  972. PatientId: record.PatientId,
  973. PricUplmtAmt: item.PricUplmtAmt,
  974. SelfpayProp: item.SelfpayProp,
  975. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  976. OverlmtAmt: item.OverlmtAmt,
  977. PreselfpayAmt: item.PreselfpayAmt,
  978. BasMednFlag: item.BasMednFlag,
  979. MedChrgitmType: item.MedChrgitmType,
  980. HiNegoDrugFlag: item.HiNegoDrugFlag,
  981. Status: 1,
  982. Memo: item.Memo,
  983. Mtime: time.Now().Unix(),
  984. InscpScpAmt: item.InscpScpAmt,
  985. DrtReimFlag: item.DrtReimFlag,
  986. Ctime: time.Now().Unix(),
  987. ListSpItemFlag: item.ListSpItemFlag,
  988. ChldMedcFlag: item.ChldMedcFlag,
  989. LmtUsedFlag: item.LmtUsedFlag,
  990. ChrgitmLv: item.ChrgitmLv,
  991. UserOrgId: adminUser.CurrentOrgId,
  992. HisPatientId: record.ID,
  993. ProjectId: project_id,
  994. Type: types,
  995. SettleType: settle_accounts_type,
  996. }
  997. service.CreateOrderInfo(info)
  998. }
  999. }
  1000. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  1001. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  1002. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  1003. c.ServeSuccessJSON(map[string]interface{}{
  1004. "msg": "上传费用明细成功",
  1005. })
  1006. }
  1007. }
  1008. }
  1009. }
  1010. func (c *ZHHisApiController) RefundLingBao() {
  1011. }
  1012. func (c *ZHHisApiController) GetLingBao() {
  1013. }
  1014. func (c *ZHHisApiController) ReadEleCard() {
  1015. id_card_type, _ := c.GetInt64("id_card_type")
  1016. admin_user_id, _ := c.GetInt64("admin_user_id")
  1017. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1018. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1019. var api string
  1020. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  1021. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&url=" + miConfig.Url + "&cainfo=" + miConfig.Cainfo + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&operator_id=" + strconv.FormatInt(admin_user_id, 10) + "&operator=" + roles.UserName
  1022. fmt.Println(api)
  1023. resp, requestErr := http.Get(api)
  1024. if requestErr != nil {
  1025. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1026. return
  1027. }
  1028. body, ioErr := ioutil.ReadAll(resp.Body)
  1029. if ioErr != nil {
  1030. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1032. return
  1033. }
  1034. var respJSON map[string]interface{}
  1035. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1036. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1038. return
  1039. }
  1040. var status string
  1041. status = respJSON["data"].(map[string]interface{})["status"].(string)
  1042. //card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  1043. var token string
  1044. var res ResultTwo //1101结果
  1045. var res10265 ResultTwo10265 //1101结果
  1046. if status == "0" { //读卡成功
  1047. token = respJSON["data"].(map[string]interface{})["token"].(string)
  1048. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  1049. result, _ := json.Marshal(respJSON)
  1050. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  1051. utils.ErrorLog("解析失败:%v", err)
  1052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1053. return
  1054. }
  1055. res.ErrMsg = res10265.ErrMsg
  1056. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  1057. res.Infcode = infocode
  1058. res.Output = res10265.Output
  1059. res.InfRefmsgid = res10265.InfRefmsgid
  1060. if res.Infcode == 0 {
  1061. c.ServeSuccessJSON(map[string]interface{}{
  1062. "number": token,
  1063. })
  1064. }
  1065. } else {
  1066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  1067. return
  1068. }
  1069. }
  1070. func (c *ZHHisApiController) ClearSettle() {
  1071. order_id, _ := c.GetInt64("order_id")
  1072. admin_user_id, _ := c.GetInt64("admin_user_id")
  1073. adminUser := c.GetAdminUserInfo()
  1074. var order models.HisOrder
  1075. order, _ = service.GetHisOrderByID(order_id)
  1076. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  1077. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1078. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1079. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1080. if config.IsOpen == 1 { //对接了医保,走医保流程
  1081. var result string
  1082. var requestLog string
  1083. result, requestLog = service.Gdyb90306(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  1084. saveLog(result, requestLog, "90306", "撤销结算清单")
  1085. var dat map[string]interface{}
  1086. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1087. fmt.Println(dat)
  1088. } else {
  1089. fmt.Println(err)
  1090. }
  1091. userJSONBytes, _ := json.Marshal(dat)
  1092. var res ResultSix
  1093. //var resSixteen ResultSixteen10265
  1094. if miConfig.Code == "H15049901371" {
  1095. //if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  1096. // utils.ErrorLog("解析失败:%v", err)
  1097. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1098. // return
  1099. //}
  1100. //res.Cainfo = resSixteen.Cainfo
  1101. //res.WarnMsg = resSixteen.WarnMsg
  1102. //res.Output = resSixteen.Output
  1103. //res.ErrMsg = resSixteen.ErrMsg
  1104. //res.RespondTime = resSixteen.RespondTime
  1105. //Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  1106. //res.Infcode = Infcode
  1107. } else {
  1108. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1109. utils.ErrorLog("解析失败:%v", err)
  1110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1111. return
  1112. }
  1113. }
  1114. if res.Infcode == 0 {
  1115. record, _ := service.GetUploadRecord(order_id)
  1116. record.Status = 0
  1117. service.UpdateRecord(&record)
  1118. c.ServeSuccessJSON(map[string]interface{}{
  1119. "msg": "撤销成功",
  1120. })
  1121. } else {
  1122. c.ServeSuccessJSON(map[string]interface{}{
  1123. "code": -10,
  1124. "msg": res.ErrMsg,
  1125. })
  1126. }
  1127. }
  1128. }
  1129. func (c *ZHHisApiController) GetZHPatientInfo() {
  1130. id_card_no := c.GetString("id_card_no")
  1131. admin_user_id, _ := c.GetInt64("admin_user_id")
  1132. patient, _ := service.GetPatientByIDCard(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  1133. if patient.ID == 0 {
  1134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1135. return
  1136. }
  1137. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  1138. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  1139. config, _ := service.GetMedicalInsuranceConfig(c.GetAdminUserInfo().CurrentOrgId)
  1140. if config.IsOpen == 1 {
  1141. var result string
  1142. var request_log string
  1143. var result_log string
  1144. if miConfig.MdtrtareaAdmvs == "150499" {
  1145. var insuplc_admdvs string
  1146. if len(patient.InsuplcAdmdvs) > 0 {
  1147. insuplc_admdvs = patient.InsuplcAdmdvs
  1148. } else {
  1149. insuplc_admdvs = miConfig.InsuplcAdmdvs
  1150. }
  1151. //请求内网数据
  1152. api := "http://172.16.13.254:9532/" + "nmyb/1101?cert_no=" + patient.IdCardNo +
  1153. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  1154. "&insuplc_admdvs=" + insuplc_admdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(2, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(1, 10) + "&name=" + patient.Name
  1155. resp, requestErr := http.Get(api)
  1156. if requestErr != nil {
  1157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1158. return
  1159. }
  1160. body, ioErr := ioutil.ReadAll(resp.Body)
  1161. if ioErr != nil {
  1162. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1164. return
  1165. }
  1166. var respJSON map[string]interface{}
  1167. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1168. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1170. return
  1171. }
  1172. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1173. result_byte, _ := json.Marshal(respJSON)
  1174. result = string(result_byte)
  1175. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1176. } else {
  1177. result, request_log, result_log = service.ZHGdyb1101(patient.IdCardNo, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 2, "", 1, patient.Name)
  1178. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1179. }
  1180. //result := service.Gdyb1101A(id_card_no, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, patient.Name)
  1181. var dat map[string]interface{}
  1182. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1183. fmt.Println(dat)
  1184. } else {
  1185. fmt.Println(err)
  1186. }
  1187. userJSONBytes, _ := json.Marshal(dat)
  1188. var res ResultTwo
  1189. var resTwo10265 ResultTwo10265
  1190. if miConfig.Code == "H15049901371" {
  1191. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  1192. utils.ErrorLog("解析失败:%v", err)
  1193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1194. return
  1195. }
  1196. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  1197. res.Infcode = Infcode
  1198. res.ErrMsg = resTwo10265.ErrMsg
  1199. res.Output = resTwo10265.Output
  1200. res.InfRefmsgid = resTwo10265.InfRefmsgid
  1201. res.RespondTime = resTwo10265.RespondTime
  1202. res.WarnInfo = resTwo10265.WarnInfo
  1203. } else {
  1204. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1205. utils.ErrorLog("解析失败:%v", err)
  1206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1207. return
  1208. }
  1209. }
  1210. var insutypes []string
  1211. var insutype string
  1212. var is390 int = 0
  1213. var is310 int = 0
  1214. for _, item := range res.Output.Iinfo {
  1215. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1216. insutypes = append(insutypes, item.Insutype)
  1217. }
  1218. }
  1219. if len(insutypes) == 1 {
  1220. insutype = insutypes[0]
  1221. } else {
  1222. for _, i := range insutypes {
  1223. if i == "390" {
  1224. is390 = 1
  1225. }
  1226. if i == "310" {
  1227. is310 = 1
  1228. }
  1229. }
  1230. }
  1231. if is390 == 1 {
  1232. insutype = "390"
  1233. }
  1234. if is310 == 1 {
  1235. insutype = "310"
  1236. }
  1237. if len(insutypes) == 0 {
  1238. insutype = "310"
  1239. }
  1240. if res.Infcode != 0 {
  1241. c.ServeSuccessJSON(map[string]interface{}{
  1242. "failed_code": -10,
  1243. "msg": res.ErrMsg,
  1244. })
  1245. } else {
  1246. c.ServeSuccessJSON(map[string]interface{}{
  1247. "failed_code": 0,
  1248. "info": res,
  1249. "insutype": insutype,
  1250. })
  1251. }
  1252. }
  1253. }
  1254. func (c *ZHHisApiController) GetZHInHospitalCheck() {
  1255. id, _ := c.GetInt64("id")
  1256. record_time := c.GetString("record_time")
  1257. name := c.GetString("name")
  1258. phone := c.GetString("phone")
  1259. id_card_type, _ := c.GetInt64("id_card_type")
  1260. certificates, _ := c.GetInt64("certificates")
  1261. id_card_no := c.GetString("id_card_no")
  1262. doctor, _ := c.GetInt64("doctor")
  1263. admin_user_id, _ := c.GetInt64("admin_user_id")
  1264. department, _ := c.GetInt64("department")
  1265. adm_bed, _ := c.GetInt64("adm_bed")
  1266. diagnosis_ids := c.GetString("diagnosis")
  1267. sick_type, _ := c.GetInt64("sick_type")
  1268. start_time := c.GetString("start_time")
  1269. insuplc_admdvs := c.GetString("insuplc_admdvs")
  1270. balance_accounts_type, _ := c.GetInt64("balance_accounts_type")
  1271. social_type, _ := c.GetInt64("social_type")
  1272. psn_type, _ := c.GetInt64("psn_type")
  1273. //reg_type, _ := c.GetInt64("p_type")
  1274. med_type, _ := c.GetInt64("med_type")
  1275. diagnosis_ids_arr := strings.Split(diagnosis_ids, "-")
  1276. timeLayout := "2006-01-02"
  1277. loc, _ := time.LoadLocation("Local")
  1278. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1279. if err != nil {
  1280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1281. return
  1282. }
  1283. recordDateTime := theTime.Unix()
  1284. adminInfo := c.GetAdminUserInfo()
  1285. record, _ := service.GetLastHospitalRecord(id, adminInfo.CurrentOrgId)
  1286. if record.ID != 0 {
  1287. if record.InHospitalStatus == 1 && record.OutHospitalStatus != 1 {
  1288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalExistDataException)
  1289. return
  1290. }
  1291. }
  1292. var patient service.Patients
  1293. if id == 0 {
  1294. patient, _ = service.GetPatientByIDCard(id_card_no, adminInfo.CurrentOrgId)
  1295. } else {
  1296. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1297. }
  1298. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  1299. sickConfig, _ := service.FindSickById(sick_type)
  1300. departmentInfo, _ := service.GetDepartMentDetail(department)
  1301. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1302. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1303. var result string
  1304. var request_log string
  1305. var result_log string
  1306. var res2 ResultTwo
  1307. var resTwo10265 ResultTwo10265
  1308. psn_info, _ := service.GetPsnByPatientId(patient.ID)
  1309. if miConfig.MdtrtareaAdmvs == "150499" {
  1310. if id_card_type == 2 {
  1311. mdtrt_cert_no := ""
  1312. card_sn := ""
  1313. if record.IdCardType == 1 {
  1314. bas := strings.Split(psn_info.CardInfo, "|")
  1315. cardNumber := bas[2]
  1316. mdtrt_cert_no = cardNumber
  1317. card_sn = bas[3]
  1318. } else {
  1319. mdtrt_cert_no = id_card_no
  1320. }
  1321. //请求内网数据
  1322. api := "http://172.16.13.254:9532/" + "nmyb/1101?cert_no=" + mdtrt_cert_no +
  1323. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  1324. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&card_sn=" + card_sn + "&certificates=" + strconv.FormatInt(certificates, 10) + "&name=" + patient.Name
  1325. resp, requestErr := http.Get(api)
  1326. if requestErr != nil {
  1327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1328. return
  1329. }
  1330. body, ioErr := ioutil.ReadAll(resp.Body)
  1331. if ioErr != nil {
  1332. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1334. return
  1335. }
  1336. var respJSON map[string]interface{}
  1337. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1338. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1340. return
  1341. }
  1342. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1343. result_byte, _ := json.Marshal(respJSON)
  1344. result = string(result_byte)
  1345. var dat map[string]interface{}
  1346. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1347. fmt.Println(dat)
  1348. } else {
  1349. fmt.Println(err)
  1350. }
  1351. userJSONBytes, _ := json.Marshal(dat)
  1352. if err := json.Unmarshal(userJSONBytes, &resTwo10265); err != nil {
  1353. utils.ErrorLog("解析失败:%v", err)
  1354. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1355. return
  1356. }
  1357. Infcode, _ := strconv.ParseInt(resTwo10265.Infcode, 10, 64)
  1358. res2.Infcode = Infcode
  1359. res2.ErrMsg = resTwo10265.ErrMsg
  1360. res2.Output = resTwo10265.Output
  1361. res2.InfRefmsgid = resTwo10265.InfRefmsgid
  1362. res2.RespondTime = resTwo10265.RespondTime
  1363. res2.WarnInfo = resTwo10265.WarnInfo
  1364. } else {
  1365. res2.Infcode = 0
  1366. res2.Output.Baseinfo.PsnNo = psn_info.PsnNo
  1367. res2.Output.Baseinfo.Certno = patient.IdCardNo
  1368. }
  1369. } else {
  1370. result, request_log, result_log = service.ZHGdyb1101(patient.IdCardNo, miConfig.OrgName, role.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, "", certificates, name)
  1371. saveLog(result_log, request_log, "1101", "人员基本信息获取")
  1372. }
  1373. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor)
  1374. deviceNumber, _ := service.GetDeviceNumberByID(adm_bed, adminInfo.CurrentOrgId)
  1375. if miConfig.MdtrtareaAdmvs != "150499" {
  1376. var dat map[string]interface{}
  1377. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1378. fmt.Println(dat)
  1379. } else {
  1380. fmt.Println(err)
  1381. }
  1382. userJSONBytes, _ := json.Marshal(dat)
  1383. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  1384. utils.ErrorLog("解析失败:%v", err)
  1385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1386. return
  1387. }
  1388. }
  1389. var infoStr string
  1390. if miConfig.MdtrtareaAdmvs == "150499" {
  1391. if id_card_type == 2 {
  1392. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  1393. infoStr = string(Iinfos)
  1394. } else {
  1395. infoStr = psn_info.Insuinfo
  1396. }
  1397. } else {
  1398. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  1399. infoStr = string(Iinfos)
  1400. }
  1401. var rf []*ResultFive
  1402. json.Unmarshal([]byte(infoStr), &rf)
  1403. var insutypes []*ResultFive
  1404. var insutype string
  1405. var is390 int = 0
  1406. var is310 int = 0
  1407. for _, item := range rf {
  1408. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1409. insutypes = append(insutypes, item)
  1410. }
  1411. }
  1412. if len(insutypes) == 1 {
  1413. insutype = insutypes[0].Insutype
  1414. //insuplc_admdvs = insutypes[0].InsuplcAdmdvs
  1415. } else {
  1416. for _, i := range insutypes {
  1417. if i.Insutype == "390" {
  1418. is390 = 1
  1419. }
  1420. if i.Insutype == "310" {
  1421. is310 = 1
  1422. }
  1423. }
  1424. }
  1425. if is390 == 1 {
  1426. insutype = "390"
  1427. }
  1428. if is310 == 1 {
  1429. insutype = "310"
  1430. }
  1431. if len(insutypes) == 0 {
  1432. insutype = "310"
  1433. }
  1434. if len(insutypes) == 2 {
  1435. insutype = strconv.FormatInt(social_type, 10)
  1436. }
  1437. //for _, item := range rf {
  1438. // if item.Insutype == insutype {
  1439. // insuplc_admdvs = item.InsuplcAdmdvs
  1440. // }
  1441. //}
  1442. if res2.Infcode == 0 {
  1443. //var insutypes []string
  1444. //
  1445. //var insutype string
  1446. //var is390 int = 0
  1447. //var is310 int = 0
  1448. //for _, item := range res2.Output.Iinfo {
  1449. // if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  1450. // insutypes = append(insutypes, item.Insutype)
  1451. // }
  1452. //}
  1453. //if len(insutypes) == 1 {
  1454. // insutype = insutypes[0]
  1455. //} else {
  1456. // for _, i := range insutypes {
  1457. // if i == "390" {
  1458. // is390 = 1
  1459. // }
  1460. //
  1461. // if i == "310" {
  1462. // is310 = 1
  1463. // }
  1464. // }
  1465. //}
  1466. //if is390 == 1 {
  1467. // insutype = "390"
  1468. //}
  1469. //if is310 == 1 {
  1470. // insutype = "310"
  1471. //}
  1472. //
  1473. //if len(insutypes) == 0 {
  1474. // insutype = "310"
  1475. //}
  1476. if len(insuplc_admdvs) == 0 {
  1477. insuplc_admdvs = miConfig.InsuplcAdmdvs
  1478. }
  1479. timestamp := time.Now().Unix()
  1480. tempTime := time.Unix(timestamp, 0)
  1481. timeFormat := tempTime.Format("20060102150405")
  1482. chrgBchno := rand.Intn(100000) + 10000
  1483. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(id, 10)
  1484. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  1485. var struct2401 service.Struct2401
  1486. struct2401.PsnNo = res2.Output.Baseinfo.PsnNo
  1487. //insutype = "310"
  1488. struct2401.Insutype = insutype
  1489. psn_info, _ := service.GetPsnByPatientId(patient.ID)
  1490. if id_card_type == 1 {
  1491. struct2401.MdtrtCertType = "03"
  1492. bas := strings.Split(psn_info.CardInfo, "|")
  1493. cardNumber := bas[2]
  1494. struct2401.MdtrtCertNo = cardNumber
  1495. } else {
  1496. struct2401.MdtrtCertType = "02"
  1497. struct2401.MdtrtCertNo = res2.Output.Baseinfo.Certno
  1498. }
  1499. if miConfig.Code == "H15049901371" {
  1500. if med_type == 14 {
  1501. if insutype == "390" {
  1502. struct2401.MedType = "9933"
  1503. } else if insutype == "310" {
  1504. struct2401.MedType = "990502"
  1505. }
  1506. } else if med_type == 11 {
  1507. struct2401.MedType = "21"
  1508. }
  1509. } else {
  1510. if med_type == 11 {
  1511. struct2401.MedType = "21"
  1512. } else {
  1513. struct2401.MedType = strconv.FormatInt(int64(med_type), 10)
  1514. }
  1515. }
  1516. struct2401.IptNo = ipt_otp_no
  1517. struct2401.AtddrNo = doctorInfo.DoctorNumber
  1518. struct2401.ChfpdrName = doctorInfo.UserName
  1519. struct2401.AdmDiagDscr = diagnosisConfig[0].ClassName
  1520. struct2401.AdmDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  1521. struct2401.AdmDeptName = departmentInfo.Name
  1522. struct2401.AdmBed = deviceNumber.Number
  1523. struct2401.AdmBed = "待定"
  1524. struct2401.DscgMaindiagName = diagnosisConfig[0].ClassName
  1525. struct2401.DscgMaindiagCode = diagnosisConfig[0].CountryCode
  1526. struct2401.Begntime = start_time
  1527. struct2401.DiseCodg = sickConfig.CountryCode
  1528. struct2401.DiseName = sickConfig.ClassName
  1529. var dises []service.DiseinfoStruct
  1530. for index, item := range diagnosisConfig {
  1531. var dise service.DiseinfoStruct
  1532. dise.PsnNo = res2.Output.Baseinfo.PsnNo
  1533. dise.DiagType = "1"
  1534. if index == 0 {
  1535. dise.MaindiagFlag = "1"
  1536. } else {
  1537. dise.MaindiagFlag = "2"
  1538. }
  1539. dise.DiagSrtNo = strconv.FormatInt(int64(index), 10)
  1540. dise.DiseDorName = doctorInfo.UserName
  1541. dise.DiagCode = item.CountryCode
  1542. dise.DiagName = item.ClassName
  1543. dise.DiagDept = departmentInfo.Name
  1544. dise.DiseDorNo = doctorInfo.DoctorNumber
  1545. dise.DiagTime = timeFormatOne
  1546. dises = append(dises, dise)
  1547. }
  1548. struct2401.Diseinfo = dises
  1549. var result string
  1550. var request_log string
  1551. if miConfig.MdtrtareaAdmvs == "150499" {
  1552. data := make(map[string]interface{})
  1553. data["org_name"] = miConfig.OrgName
  1554. data["doctor"] = role.UserName
  1555. data["fixmedins_code"] = miConfig.Code
  1556. data["insuplc_admdvs"] = insuplc_admdvs
  1557. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1558. data["secret_key"] = miConfig.SecretKey
  1559. data["struct_2401"] = struct2401
  1560. var req *http.Request
  1561. bytesData, _ := json.Marshal(data)
  1562. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2401", bytes.NewReader(bytesData))
  1563. client := &http.Client{}
  1564. resp, _ := client.Do(req)
  1565. defer resp.Body.Close()
  1566. body, ioErr := ioutil.ReadAll(resp.Body)
  1567. if ioErr != nil {
  1568. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1570. return
  1571. }
  1572. var respJSON map[string]interface{}
  1573. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1574. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1575. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1576. return
  1577. }
  1578. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1579. result_byte, _ := json.Marshal(respJSON)
  1580. result = string(result_byte)
  1581. } else {
  1582. result, request_log = service.ZHGdyb2401(struct2401, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, insuplc_admdvs, miConfig.MdtrtareaAdmvs)
  1583. saveLog(result, request_log, "2401", "入院登记")
  1584. }
  1585. var dat map[string]interface{}
  1586. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1587. fmt.Println(dat)
  1588. } else {
  1589. fmt.Println(err)
  1590. }
  1591. userJSONBytes, _ := json.Marshal(dat)
  1592. var res ResultThree
  1593. var resThree10265 ResultThree10265
  1594. if miConfig.Code == "H15049901371" {
  1595. if err := json.Unmarshal(userJSONBytes, &resThree10265); err != nil {
  1596. utils.ErrorLog("解析失败:%v", err)
  1597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1598. return
  1599. }
  1600. Infcode, _ := strconv.ParseInt(resThree10265.Infcode, 10, 64)
  1601. res.Infcode = Infcode
  1602. res.ErrMsg = resThree10265.ErrMsg
  1603. res.Output = resThree10265.Output
  1604. res.InfRefmsgid = resThree10265.InfRefmsgid
  1605. res.RespondTime = resThree10265.RespondTime
  1606. } else {
  1607. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1608. utils.ErrorLog("解析失败:%v", err)
  1609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1610. return
  1611. }
  1612. }
  1613. if res.Infcode == 0 {
  1614. //result2 := service.Gdyb5301Two(res2.Output.Baseinfo.PsnNo, miConfig.OrgName, role.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey)
  1615. //fmt.Println(result2)
  1616. Iinfos, _ := json.Marshal(res2.Output.Iinfo)
  1617. Idetinfos, _ := json.Marshal(res2.Output.Idetinfo)
  1618. infoStr := string(Iinfos)
  1619. idetinfoStr := string(Idetinfos)
  1620. inHospital := &models.HisHospitalCheckRecord{
  1621. PatientId: id,
  1622. Name: name,
  1623. MedicalTreatmentType: med_type,
  1624. RecordDate: recordDateTime,
  1625. IdCardNo: id_card_no,
  1626. AdminUserId: admin_user_id,
  1627. Departments: department,
  1628. UserOrgId: adminInfo.CurrentOrgId,
  1629. Status: 1,
  1630. Ctime: time.Now().Unix(),
  1631. Mtime: time.Now().Unix(),
  1632. Number: res.Output.Result.MdtrtID,
  1633. Doctor: doctor,
  1634. PsnNo: res2.Output.Baseinfo.PsnNo,
  1635. PsnCertType: res2.Output.Baseinfo.PsnCertType,
  1636. Certno: res2.Output.Baseinfo.Certno,
  1637. PsnName: res2.Output.Baseinfo.PsnName,
  1638. Gend: res2.Output.Baseinfo.Gend,
  1639. Naty: res2.Output.Baseinfo.Naty,
  1640. MedType: med_type,
  1641. InsutypeType: insutype,
  1642. Brdy: res2.Output.Baseinfo.Brdy,
  1643. Iinfo: infoStr,
  1644. Idetinfo: idetinfoStr,
  1645. IptOtpNo: ipt_otp_no,
  1646. AdmBed: adm_bed,
  1647. IdCardType: id_card_type,
  1648. Diagnosis: diagnosis_ids,
  1649. SickType: sick_type,
  1650. MdtrtCertType: "02",
  1651. InHosptialTime: start_time,
  1652. OutHosptialTime: "",
  1653. InHospitalStatus: 1,
  1654. Certificates: certificates,
  1655. Phone: phone,
  1656. BalanceAccountsType: balance_accounts_type,
  1657. PsnType: psn_type,
  1658. InsuplcAdmdvs: insuplc_admdvs,
  1659. }
  1660. service.CreateHospitalRecord(inHospital)
  1661. c.ServeSuccessJSON(map[string]interface{}{
  1662. "msg": "办理入院成功",
  1663. "info": inHospital,
  1664. })
  1665. } else {
  1666. c.ServeSuccessJSON(map[string]interface{}{
  1667. "failed_code": -10,
  1668. "msg": res.ErrMsg,
  1669. })
  1670. }
  1671. } else {
  1672. c.ServeSuccessJSON(map[string]interface{}{
  1673. "failed_code": -10,
  1674. "msg": res2.ErrMsg,
  1675. })
  1676. return
  1677. }
  1678. }
  1679. func (this *ZHHisApiController) GetZHOutHospitalCheck() {
  1680. id, _ := this.GetInt64("id")
  1681. patient_id, _ := this.GetInt64("patient_id")
  1682. admin_user_id, _ := this.GetInt64("admin_user_id")
  1683. record_time := this.GetString("record_time")
  1684. out_time := this.GetString("out_time")
  1685. adminInfo := this.GetAdminUserInfo()
  1686. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1687. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  1688. record, _ := service.GetInHospitalRecord(id)
  1689. if record.ID == 0 {
  1690. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  1691. return
  1692. }
  1693. timeLayout := "2006-01-02"
  1694. loc, _ := time.LoadLocation("Local")
  1695. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1696. if err != nil {
  1697. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1698. return
  1699. }
  1700. recordDateTime := theTime.Unix()
  1701. var patient service.Patients
  1702. if patient_id == 0 {
  1703. patient, _ = service.GetPatientByIDCard(record.IdCardNo, adminInfo.CurrentOrgId)
  1704. } else {
  1705. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  1706. }
  1707. fmt.Println(patient)
  1708. diagnosis_ids_arr := strings.Split(record.Diagnosis, "-")
  1709. diagnosisConfig, _ := service.FindDiagnoseByIds(diagnosis_ids_arr)
  1710. departmentInfo, _ := service.GetDepartMentDetail(record.Departments)
  1711. doctorInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, record.Doctor)
  1712. //deviceNumber, _ := service.GetDeviceNumberByID(record.AdmBed, adminInfo.CurrentOrgId)
  1713. sickConfig, _ := service.FindSickById(record.SickType)
  1714. var struct2402 service.Struct2402
  1715. timestamp := time.Now().Unix()
  1716. tempTime := time.Unix(timestamp, 0)
  1717. //timeFormat := tempTime.Format("20060102150405")
  1718. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  1719. struct2402.PsnNo = record.PsnNo
  1720. struct2402.Insutype = record.InsutypeType
  1721. struct2402.DscgWay = "1"
  1722. struct2402.Endtime = out_time
  1723. struct2402.DscgDeptName = departmentInfo.Number
  1724. struct2402.DscgDeptCodg = strconv.FormatInt(int64(departmentInfo.ID), 10)
  1725. struct2402.MdtrtId = record.Number
  1726. var dises []service.Diseinfo2402Struct
  1727. for index, item := range diagnosisConfig {
  1728. var dise service.Diseinfo2402Struct
  1729. dise.PsnNo = record.PsnNo
  1730. dise.DiagType = "1"
  1731. if index == 0 {
  1732. dise.MaindiagFlag = "1"
  1733. } else {
  1734. dise.MaindiagFlag = "2"
  1735. }
  1736. dise.MdtrtId = record.Number
  1737. dise.DiagSrtNo = strconv.FormatInt(int64(item.ID), 10)
  1738. dise.DiseDorName = doctorInfo.UserName
  1739. dise.DiagCode = item.CountryCode
  1740. dise.DiagName = item.ClassName
  1741. dise.DiagDept = departmentInfo.Name
  1742. dise.DiseDorNo = doctorInfo.DoctorNumber
  1743. dise.DiagTime = timeFormatOne
  1744. dises = append(dises, dise)
  1745. }
  1746. struct2402.Diseinfo = dises
  1747. struct2402.DiseName = sickConfig.ClassName
  1748. struct2402.DiseCode = sickConfig.CountryCode
  1749. var result string
  1750. var request_log string
  1751. if miConfig.MdtrtareaAdmvs == "150499" {
  1752. data := make(map[string]interface{})
  1753. data["org_name"] = miConfig.OrgName
  1754. data["doctor"] = role.UserName
  1755. data["fixmedins_code"] = miConfig.Code
  1756. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  1757. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1758. data["secret_key"] = miConfig.SecretKey
  1759. data["struct_2402"] = struct2402
  1760. var req *http.Request
  1761. bytesData, _ := json.Marshal(data)
  1762. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2402", bytes.NewReader(bytesData))
  1763. client := &http.Client{}
  1764. resp, _ := client.Do(req)
  1765. defer resp.Body.Close()
  1766. body, ioErr := ioutil.ReadAll(resp.Body)
  1767. if ioErr != nil {
  1768. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1769. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1770. return
  1771. }
  1772. var respJSON map[string]interface{}
  1773. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1774. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1775. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1776. return
  1777. }
  1778. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1779. result_byte, _ := json.Marshal(respJSON)
  1780. result = string(result_byte)
  1781. } else {
  1782. result, request_log = service.ZHGdyb2402(struct2402, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code)
  1783. saveLog(result, request_log, "2402", "出院")
  1784. }
  1785. var dat map[string]interface{}
  1786. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1787. fmt.Println(dat)
  1788. } else {
  1789. fmt.Println(err)
  1790. }
  1791. userJSONBytes, _ := json.Marshal(dat)
  1792. var res ResultEmpty
  1793. var resEmpty10265 ResultEmpty10265
  1794. if miConfig.Code == "H15049901371" {
  1795. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  1796. utils.ErrorLog("解析失败:%v", err)
  1797. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1798. return
  1799. }
  1800. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  1801. res.Infcode = Infcode
  1802. res.RespondTime = resEmpty10265.RespondTime
  1803. res.ErrMsg = resEmpty10265.ErrMsg
  1804. res.Output = resEmpty10265.Output
  1805. res.WarnMsg = resEmpty10265.WarnMsg
  1806. } else {
  1807. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1808. utils.ErrorLog("解析失败:%v", err)
  1809. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1810. return
  1811. }
  1812. }
  1813. if res.Infcode == 0 {
  1814. record.OutHospitalStatus = 1
  1815. record.OutHosptialTime = struct2402.Endtime
  1816. record.OutWay = 1
  1817. service.CreateHospitalRecord(&record)
  1818. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  1819. var total float64
  1820. for _, item := range orders {
  1821. total = total + item.DetItemFeeSumamt
  1822. }
  1823. order := &models.HisOrder{
  1824. UserOrgId: adminInfo.CurrentOrgId,
  1825. HisPatientId: record.ID,
  1826. PatientId: record.PatientId,
  1827. SettleAccountsDate: recordDateTime,
  1828. Ctime: time.Now().Unix(),
  1829. Mtime: time.Now().Unix(),
  1830. Status: 1,
  1831. Number: record.Number,
  1832. Infcode: 0,
  1833. WarnMsg: "",
  1834. Cainfo: "",
  1835. ErrMsg: "",
  1836. RespondTime: "",
  1837. InfRefmsgid: "",
  1838. OrderStatus: 1,
  1839. MdtrtId: record.Number,
  1840. IsMedicineInsurance: 1,
  1841. PType: 1,
  1842. MedfeeSumamt: total,
  1843. }
  1844. err = service.CreateOrder(order)
  1845. if err != nil {
  1846. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1847. return
  1848. }
  1849. this.ServeSuccessJSON(map[string]interface{}{
  1850. "msg": "出院成功",
  1851. })
  1852. } else {
  1853. this.ServeSuccessJSON(map[string]interface{}{
  1854. "failed_code": -10,
  1855. "msg": res.ErrMsg,
  1856. })
  1857. }
  1858. }
  1859. func (c *ZHHisApiController) Get4102() {
  1860. order_id, _ := c.GetInt64("order_id")
  1861. admin_user_id, _ := c.GetInt64("admin_user_id")
  1862. stas_type := c.GetString("stas_type")
  1863. adminUser := c.GetAdminUserInfo()
  1864. order, _ := service.GetHisOrderByID(order_id)
  1865. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1866. var user_name string
  1867. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1868. if role.ID == 0 {
  1869. user_name = "管理员"
  1870. } else {
  1871. user_name = role.UserName
  1872. }
  1873. baseParams := models.BaseParams{
  1874. SecretKey: miConfig.SecretKey,
  1875. FixmedinsCode: miConfig.Code,
  1876. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1877. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1878. OrgName: miConfig.OrgName,
  1879. Doctor: user_name,
  1880. RequestUrl: miConfig.Url,
  1881. AccessKey: miConfig.AccessKey,
  1882. }
  1883. businessParams := models.BusinessParams{
  1884. PsnNo: order.PsnNo,
  1885. MdtrtId: order.MdtrtId,
  1886. SetlId: order.SetlId,
  1887. StasType: stas_type,
  1888. }
  1889. api := "http://172.16.13.254:9532/" + "nmyb/4102?psn_no=" + businessParams.PsnNo + "&mdtrt_id=" + businessParams.MdtrtId + "&setl_id=" + businessParams.SetlId +
  1890. "&org_name=" + miConfig.OrgName + "&doctor=" + baseParams.Doctor + "&fixmedins_code=" + miConfig.Code +
  1891. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&stas_type=" + stas_type
  1892. resp, requestErr := http.Get(api)
  1893. if requestErr != nil {
  1894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1895. return
  1896. }
  1897. body, ioErr := ioutil.ReadAll(resp.Body)
  1898. if ioErr != nil {
  1899. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1901. return
  1902. }
  1903. var respJSON map[string]interface{}
  1904. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1905. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1907. return
  1908. }
  1909. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1910. result, _ := json.Marshal(respJSON)
  1911. fmt.Println("log")
  1912. fmt.Println(string(result))
  1913. var res2 ResultSix
  1914. var resEmpty10265 ResultEmpty10265
  1915. if err := json.Unmarshal(result, &resEmpty10265); err != nil {
  1916. utils.ErrorLog("解析失败:%v", err)
  1917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1918. return
  1919. }
  1920. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  1921. res2.Infcode = Infcode
  1922. res2.RespondTime = resEmpty10265.RespondTime
  1923. res2.ErrMsg = resEmpty10265.ErrMsg
  1924. res2.Output = resEmpty10265.Output
  1925. res2.WarnMsg = resEmpty10265.WarnMsg
  1926. if res2.Infcode == 0 {
  1927. c.ServeSuccessJSON(map[string]interface{}{
  1928. "msg": "确认成功",
  1929. })
  1930. } else {
  1931. c.ServeSuccessJSON(map[string]interface{}{
  1932. "failed_code": -10,
  1933. "msg": res2.ErrMsg,
  1934. })
  1935. }
  1936. }
  1937. func (c *ZHHisApiController) Get4103() {
  1938. order_id, _ := c.GetInt64("order_id")
  1939. admin_user_id, _ := c.GetInt64("admin_user_id")
  1940. stas_type := c.GetString("stas_type")
  1941. adminUser := c.GetAdminUserInfo()
  1942. order, _ := service.GetHisOrderByID(order_id)
  1943. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1944. var user_name string
  1945. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1946. if role.ID == 0 {
  1947. user_name = "管理员"
  1948. } else {
  1949. user_name = role.UserName
  1950. }
  1951. baseParams := models.BaseParams{
  1952. SecretKey: miConfig.SecretKey,
  1953. FixmedinsCode: miConfig.Code,
  1954. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1955. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1956. OrgName: miConfig.OrgName,
  1957. Doctor: user_name,
  1958. RequestUrl: miConfig.Url,
  1959. AccessKey: miConfig.AccessKey,
  1960. }
  1961. businessParams := models.BusinessParams{
  1962. PsnNo: order.PsnNo,
  1963. MdtrtId: order.MdtrtId,
  1964. SetlId: order.SetlId,
  1965. StasType: stas_type,
  1966. }
  1967. api := "http://172.16.13.254:9532/" + "nmyb/4103?psn_no=" + businessParams.PsnNo + "&mdtrt_id=" + businessParams.MdtrtId + "&setl_id=" + businessParams.SetlId +
  1968. "&org_name=" + miConfig.OrgName + "&doctor=" + baseParams.Doctor + "&fixmedins_code=" + miConfig.Code +
  1969. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&stas_type=" + stas_type
  1970. resp, requestErr := http.Get(api)
  1971. if requestErr != nil {
  1972. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1973. return
  1974. }
  1975. body, ioErr := ioutil.ReadAll(resp.Body)
  1976. if ioErr != nil {
  1977. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1978. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1979. return
  1980. }
  1981. var respJSON map[string]interface{}
  1982. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1983. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1985. return
  1986. }
  1987. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1988. result, _ := json.Marshal(respJSON)
  1989. fmt.Println("log")
  1990. fmt.Println(string(result))
  1991. var res2 ResultSix
  1992. var resEmpty10265 ResultEmpty10265
  1993. if err := json.Unmarshal(result, &resEmpty10265); err != nil {
  1994. utils.ErrorLog("解析失败:%v", err)
  1995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1996. return
  1997. }
  1998. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  1999. res2.Infcode = Infcode
  2000. res2.RespondTime = resEmpty10265.RespondTime
  2001. res2.ErrMsg = resEmpty10265.ErrMsg
  2002. res2.Output = resEmpty10265.Output
  2003. res2.WarnMsg = resEmpty10265.WarnMsg
  2004. if res2.Infcode == 0 {
  2005. c.ServeSuccessJSON(map[string]interface{}{
  2006. "msg": string(result),
  2007. })
  2008. } else {
  2009. c.ServeSuccessJSON(map[string]interface{}{
  2010. "failed_code": -10,
  2011. "msg": res2.ErrMsg,
  2012. })
  2013. }
  2014. }
  2015. func (c *ZHHisApiController) GetSettleInfo() {
  2016. order_id, _ := c.GetInt64("order_id")
  2017. patient_id, _ := c.GetInt64("patient_id")
  2018. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  2019. admin_user_id, _ := c.GetInt64("admin_user_id")
  2020. pay_way, _ := c.GetInt64("pay_way")
  2021. pay_price, _ := c.GetFloat("pay_price")
  2022. pay_card_no := c.GetString("pay_card_no")
  2023. discount_price, _ := c.GetFloat("discount_price")
  2024. preferential_price, _ := c.GetFloat("preferential_price")
  2025. reality_price, _ := c.GetFloat("reality_price")
  2026. found_price, _ := c.GetFloat("found_price")
  2027. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2028. private_price, _ := c.GetFloat("private_price")
  2029. fapiao_code := c.GetString("fapiao_code")
  2030. fapiao_number := c.GetString("fapiao_number")
  2031. record, _ := service.GetInHospitalRecord(in_hospital_id)
  2032. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2033. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  2034. order, _ := service.GetHisOrderByID(order_id)
  2035. //dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  2036. //tmp_decimal := c.GetString("tmp_decimal")
  2037. //var decimal float64 //本次使用的押金
  2038. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  2039. tmp_decimal := c.GetString("tmp_decimal")
  2040. var decimal float64 //本次使用的押金
  2041. var errmsg error
  2042. if dec_way == "true" && tmp_decimal == "0" || dec_way == "true" && tmp_decimal == "" {
  2043. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  2044. return
  2045. }
  2046. if len(tmp_decimal) > 0 {
  2047. if tmp_decimal[0] == 45 {
  2048. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  2049. return
  2050. }
  2051. }
  2052. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  2053. if errs != nil {
  2054. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  2055. return
  2056. }
  2057. decimal = tt
  2058. var rf []*ResultFive
  2059. json.Unmarshal([]byte(record.Iinfo), &rf)
  2060. chrg_bchno := order.Number
  2061. cert_no := record.Certno
  2062. if record.ID == 0 {
  2063. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2064. return
  2065. }
  2066. if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  2067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  2068. return
  2069. }
  2070. if record.IdCardType == 1 {
  2071. } else {
  2072. cert_no = record.Certno
  2073. }
  2074. var result string
  2075. var src_resquest string
  2076. timeLayout := "2006-01-02"
  2077. loc, _ := time.LoadLocation("Local")
  2078. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record.InHosptialTime, loc)
  2079. if err != nil {
  2080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2081. return
  2082. }
  2083. recordStartDateTime := theTime.Unix()
  2084. theTimeEnd, err := time.ParseInLocation(timeLayout+" 15:04:05", record.OutHosptialTime, loc)
  2085. if err != nil {
  2086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2087. return
  2088. }
  2089. recordEndDateTime := theTimeEnd.Unix()
  2090. prescriptions, _ := service.GetZHSettleMonthHisPrescription(c.GetAdminUserInfo().CurrentOrgId, patient_id, recordStartDateTime, recordEndDateTime)
  2091. var total float64
  2092. for _, item := range prescriptions {
  2093. if item.Type == 1 { //药品
  2094. for _, subItem := range item.HisDoctorAdviceInfo {
  2095. total = total + (subItem.Price * subItem.PrescribingNumber)
  2096. }
  2097. }
  2098. if item.Type == 2 { //项目
  2099. for _, subItem := range item.HisPrescriptionProject {
  2100. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  2101. total = total + (subItem.Price * cnt)
  2102. }
  2103. }
  2104. }
  2105. //allTotal := fmt.Sprintf("%.2f", total)
  2106. var allTotal string
  2107. if record.OutHospitalStatus == 0 && order.ID == 0 {
  2108. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  2109. var total float64
  2110. for _, item := range orders {
  2111. total = total + item.DetItemFeeSumamt
  2112. }
  2113. allTotal = fmt.Sprintf("%.4f", total)
  2114. } else {
  2115. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  2116. }
  2117. if miConfig.MdtrtareaAdmvs == "150499" {
  2118. psn_info, _ := service.GetPsnByPatientId(patient_id)
  2119. mdtrt_cert_no := ""
  2120. if record.IdCardType == 1 {
  2121. bas := strings.Split(psn_info.CardInfo, "|")
  2122. cardNumber := bas[2]
  2123. mdtrt_cert_no = cardNumber
  2124. } else {
  2125. mdtrt_cert_no = record.Certno
  2126. }
  2127. var acct_used_flag string
  2128. if pay_way == 4 {
  2129. acct_used_flag = "1"
  2130. } else {
  2131. acct_used_flag = "0"
  2132. }
  2133. if pay_way == 6 {
  2134. mdtrt_cert_no = psn_info.VerifyNumber
  2135. acct_used_flag = "1"
  2136. record.IdCardType = 4
  2137. } else {
  2138. acct_used_flag = "0"
  2139. }
  2140. fmt.Println(mdtrt_cert_no)
  2141. fmt.Println(acct_used_flag)
  2142. fmt.Println(record.IdCardType)
  2143. //请求内网数据
  2144. api := "http://172.16.13.254:9532/" + "nmyb/2304?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  2145. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  2146. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2147. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(record.IdCardType, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(record.Certificates, 10) + "&name=" + record.Name + "&cert_no=" + mdtrt_cert_no + "&fapiao_number=" + fapiao_number + "&acct_used_flag=" + acct_used_flag
  2148. resp, requestErr := http.Get(api)
  2149. if requestErr != nil {
  2150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2151. return
  2152. }
  2153. body, ioErr := ioutil.ReadAll(resp.Body)
  2154. if ioErr != nil {
  2155. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2157. return
  2158. }
  2159. var respJSON map[string]interface{}
  2160. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2161. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2163. return
  2164. }
  2165. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2166. result_byte, _ := json.Marshal(respJSON)
  2167. result = string(result_byte)
  2168. } else {
  2169. result, src_resquest = service.ZHGdyb2304(record.PsnNo, record.Number, chrg_bchno, cert_no, record.InsutypeType, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "0", record.IdCardType, 0, 0, 0, 0, record.Certificates, "", "1")
  2170. saveLog(result, src_resquest, "2304", "住院结算")
  2171. }
  2172. var dat map[string]interface{}
  2173. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2174. fmt.Println(dat)
  2175. } else {
  2176. fmt.Println(err)
  2177. }
  2178. userJSONBytes, _ := json.Marshal(dat)
  2179. var res ResultSeven
  2180. var resSeven10265 ResultSeven10265
  2181. if miConfig.Code == "H15049901371" {
  2182. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  2183. utils.ErrorLog("解析失败:%v", err)
  2184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2185. return
  2186. }
  2187. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  2188. res.Infcode = Infcode
  2189. res.InfRefmsgid = resSeven10265.InfRefmsgid
  2190. res.RespondTime = resSeven10265.RespondTime
  2191. res.ErrMsg = resSeven10265.ErrMsg
  2192. res.Output = resSeven10265.Output
  2193. res.WarnMsg = resSeven10265.WarnMsg
  2194. res.Cainfo = resSeven10265.Cainfo
  2195. } else {
  2196. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2197. utils.ErrorLog("解析失败:%v", err)
  2198. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2199. return
  2200. }
  2201. }
  2202. if res.Infcode != 0 {
  2203. errlog := &models.HisOrderError{
  2204. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2205. Ctime: time.Now().Unix(),
  2206. Mtime: time.Now().Unix(),
  2207. Number: chrg_bchno,
  2208. ErrMsg: res.ErrMsg,
  2209. Status: 1,
  2210. PatientId: patient_id,
  2211. RecordTime: time.Now().Unix(),
  2212. Stage: 6,
  2213. }
  2214. service.CreateErrMsgLog(errlog)
  2215. c.ServeSuccessJSON(map[string]interface{}{
  2216. "failed_code": -10,
  2217. "msg": res.ErrMsg,
  2218. })
  2219. return
  2220. } else {
  2221. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2222. order.OrderStatus = 2
  2223. order.DiscountPrice = discount_price
  2224. order.MedicalInsurancePrice = medical_insurance_price
  2225. order.FaPiaoNumber = fapiao_number
  2226. order.FaPiaoCode = fapiao_code
  2227. order.PayWay = pay_way
  2228. order.PayPrice = pay_price
  2229. order.PayCardNo = pay_card_no
  2230. order.PreferentialPrice = preferential_price
  2231. order.RealityPrice = reality_price
  2232. order.FoundPrice = found_price
  2233. order.PrivatePrice = private_price
  2234. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2235. order.SetlId = res.Output.Setlinfo.SetlID
  2236. order.PsnNo = res.Output.Setlinfo.PsnNo
  2237. order.PsnName = res.Output.Setlinfo.PsnName
  2238. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2239. order.Certno = res.Output.Setlinfo.Certno
  2240. order.Gend = res.Output.Setlinfo.Gend
  2241. order.Naty = res.Output.Setlinfo.Naty
  2242. order.Age = res.Output.Setlinfo.Age
  2243. order.Insutype = res.Output.Setlinfo.Insutype
  2244. order.PsnType = res.Output.Setlinfo.PsnType
  2245. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2246. order.SetlTime = res.Output.Setlinfo.SetlTime
  2247. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2248. if res.Output.Setlinfo.MedType == "140104" {
  2249. order.MedType = "14"
  2250. } else {
  2251. order.MedType = res.Output.Setlinfo.MedType
  2252. }
  2253. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2254. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2255. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2256. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2257. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2258. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2259. order.HifpPay = res.Output.Setlinfo.HifpPay
  2260. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2261. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2262. order.HifesPay = res.Output.Setlinfo.HifesPay
  2263. order.HifobPay = res.Output.Setlinfo.HifobPay
  2264. order.MafPay = res.Output.Setlinfo.MafPay
  2265. order.OthPay = res.Output.Setlinfo.OthPay
  2266. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2267. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2268. order.AcctPay = res.Output.Setlinfo.AcctPay
  2269. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2270. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2271. order.Balc = res.Output.Setlinfo.Balc
  2272. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2273. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2274. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2275. order.ClrWay = res.Output.Setlinfo.ClrWay
  2276. order.Creator = order.Creator
  2277. order.Modify = roles.AdminUserId
  2278. order.RequestLog = src_resquest
  2279. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2280. detailStr := string(setlDetail)
  2281. order.SetlDetail = detailStr
  2282. err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  2283. err = service.UpDateOrder(order)
  2284. if err == nil {
  2285. //判断是否使用了押金
  2286. if dec_way == "true" {
  2287. tmpstring := strconv.FormatInt(order.ID, 10)
  2288. order.Decimal = decimal
  2289. err = service.UpDateOrder(order)
  2290. //扣押金
  2291. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, patient_id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  2292. if errmsg != nil {
  2293. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  2294. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  2295. return
  2296. }
  2297. }
  2298. c.ServeSuccessJSON(map[string]interface{}{
  2299. "msg": "结算成功",
  2300. })
  2301. } else {
  2302. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2303. return
  2304. }
  2305. }
  2306. }
  2307. func (c *ZHHisApiController) GetPreSettleInfo() {
  2308. order_id, _ := c.GetInt64("order_id")
  2309. patient_id, _ := c.GetInt64("patient_id")
  2310. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  2311. admin_user_id, _ := c.GetInt64("admin_user_id")
  2312. record, _ := service.GetInHospitalRecord(in_hospital_id)
  2313. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  2314. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  2315. order, _ := service.GetHisOrderByID(order_id)
  2316. var allTotal string
  2317. if record.OutHospitalStatus == 0 && order.ID == 0 {
  2318. orders, _ := service.GetHisOrderInfoByNumberFour(record.Number)
  2319. var total float64
  2320. for _, item := range orders {
  2321. total = total + item.DetItemFeeSumamt
  2322. }
  2323. allTotal = fmt.Sprintf("%.4f", total)
  2324. } else {
  2325. allTotal = fmt.Sprintf("%.4f", order.MedfeeSumamt)
  2326. }
  2327. var rf []*ResultFive
  2328. json.Unmarshal([]byte(record.Iinfo), &rf)
  2329. chrg_bchno := order.Number
  2330. cert_no := record.Certno
  2331. if record.ID == 0 {
  2332. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2333. return
  2334. }
  2335. //if record.InHospitalStatus == 1 && record.OutHospitalStatus == 0 {
  2336. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHospitalNoExistDataException)
  2337. // return
  2338. //}
  2339. psn_info, _ := service.GetPsnByPatientId(patient_id)
  2340. if record.IdCardType == 1 {
  2341. bas := strings.Split(psn_info.CardInfo, "|")
  2342. cardNumber := bas[2]
  2343. cert_no = cardNumber
  2344. } else {
  2345. cert_no = record.Certno
  2346. }
  2347. var result string
  2348. var src_resquest string
  2349. if miConfig.MdtrtareaAdmvs == "150499" {
  2350. //请求内网数据
  2351. api := "http://172.16.13.254:9532/" + "nmyb/2303?psn_no=" + record.PsnNo + "&mdtrt_id=" + record.Number + "&chrg_bchno=" + chrg_bchno +
  2352. "&insutype_type=" + record.InsutypeType + "&total=" + allTotal +
  2353. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2354. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(record.IdCardType, 10) + "&card_sn=" + "" + "&certificates=" + strconv.FormatInt(record.Certificates, 10) + "&name=" + record.Name + "&cert_no=" + cert_no
  2355. resp, requestErr := http.Get(api)
  2356. if requestErr != nil {
  2357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2358. return
  2359. }
  2360. body, ioErr := ioutil.ReadAll(resp.Body)
  2361. if ioErr != nil {
  2362. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2364. return
  2365. }
  2366. var respJSON map[string]interface{}
  2367. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2368. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2370. return
  2371. }
  2372. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2373. result_byte, _ := json.Marshal(respJSON)
  2374. result = string(result_byte)
  2375. } else {
  2376. result, src_resquest = service.ZHGdyb2303(record.PsnNo, record.Number, chrg_bchno, cert_no, record.InsutypeType, allTotal, miConfig.OrgName, roles.UserName, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "0", record.IdCardType, 0, 0, 0, 0, record.Certificates)
  2377. saveLog(result, src_resquest, "2303", "住院预结算")
  2378. }
  2379. var dat map[string]interface{}
  2380. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2381. fmt.Println(dat)
  2382. } else {
  2383. fmt.Println(err)
  2384. }
  2385. userJSONBytes, _ := json.Marshal(dat)
  2386. var res ResultSeven
  2387. var resSeven10265 ResultSeven10265
  2388. if miConfig.Code == "H15049901371" {
  2389. if err := json.Unmarshal(userJSONBytes, &resSeven10265); err != nil {
  2390. utils.ErrorLog("解析失败:%v", err)
  2391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2392. return
  2393. }
  2394. Infcode, _ := strconv.ParseInt(resSeven10265.Infcode, 10, 64)
  2395. res.Infcode = Infcode
  2396. res.InfRefmsgid = resSeven10265.InfRefmsgid
  2397. res.RespondTime = resSeven10265.RespondTime
  2398. res.ErrMsg = resSeven10265.ErrMsg
  2399. res.Output = resSeven10265.Output
  2400. res.WarnMsg = resSeven10265.WarnMsg
  2401. res.Cainfo = resSeven10265.Cainfo
  2402. } else {
  2403. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2404. utils.ErrorLog("解析失败:%v", err)
  2405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2406. return
  2407. }
  2408. }
  2409. if res.Infcode != 0 {
  2410. errlog := &models.HisOrderError{
  2411. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2412. Ctime: time.Now().Unix(),
  2413. Mtime: time.Now().Unix(),
  2414. Number: chrg_bchno,
  2415. ErrMsg: res.ErrMsg,
  2416. Status: 1,
  2417. PatientId: patient_id,
  2418. RecordTime: time.Now().Unix(),
  2419. Stage: 6,
  2420. }
  2421. service.CreateErrMsgLog(errlog)
  2422. c.ServeSuccessJSON(map[string]interface{}{
  2423. "failed_code": -10,
  2424. "msg": res.ErrMsg,
  2425. })
  2426. return
  2427. } else {
  2428. //order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  2429. order.OrderStatus = 1
  2430. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  2431. order.SetlId = res.Output.Setlinfo.SetlID
  2432. order.PsnNo = res.Output.Setlinfo.PsnNo
  2433. order.PsnName = res.Output.Setlinfo.PsnName
  2434. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  2435. order.Certno = res.Output.Setlinfo.Certno
  2436. order.Gend = res.Output.Setlinfo.Gend
  2437. order.Naty = res.Output.Setlinfo.Naty
  2438. order.Age = res.Output.Setlinfo.Age
  2439. order.Insutype = res.Output.Setlinfo.Insutype
  2440. order.PsnType = res.Output.Setlinfo.PsnType
  2441. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  2442. order.SetlTime = res.Output.Setlinfo.SetlTime
  2443. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  2444. if res.Output.Setlinfo.MedType == "140104" {
  2445. order.MedType = "14"
  2446. } else {
  2447. order.MedType = res.Output.Setlinfo.MedType
  2448. }
  2449. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  2450. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  2451. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  2452. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  2453. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  2454. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  2455. order.HifmiPay = res.Output.Setlinfo.HifmiPay
  2456. order.HifpPay = res.Output.Setlinfo.HifpPay
  2457. order.HifesPay = res.Output.Setlinfo.HifesPay
  2458. order.HifobPay = res.Output.Setlinfo.HifobPay
  2459. order.MafPay = res.Output.Setlinfo.MafPay
  2460. order.OthPay = res.Output.Setlinfo.OthPay
  2461. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  2462. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  2463. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  2464. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  2465. order.AcctPay = res.Output.Setlinfo.AcctPay
  2466. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  2467. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  2468. order.Balc = res.Output.Setlinfo.Balc
  2469. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  2470. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  2471. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  2472. order.ClrWay = res.Output.Setlinfo.ClrWay
  2473. order.Creator = order.Creator
  2474. order.Modify = roles.AdminUserId
  2475. order.RequestLog = src_resquest
  2476. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  2477. detailStr := string(setlDetail)
  2478. order.SetlDetail = detailStr
  2479. //err := service.UpdataOrderStatusTwo(chrg_bchno, c.GetAdminUserInfo().CurrentOrgId)
  2480. if record.OutHospitalStatus == 1 && order.ID > 0 {
  2481. err := service.UpDateOrder(order)
  2482. if err == nil {
  2483. c.ServeSuccessJSON(map[string]interface{}{
  2484. "msg": "预结算成功",
  2485. "order_way": 1,
  2486. })
  2487. } else {
  2488. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  2489. return
  2490. }
  2491. } else if record.OutHospitalStatus == 0 && order.ID == 0 {
  2492. c.ServeSuccessJSON(map[string]interface{}{
  2493. "msg": "预结算成功",
  2494. "order": order,
  2495. "order_way": 2,
  2496. })
  2497. }
  2498. }
  2499. }
  2500. func (c *ZHHisApiController) GetUploadInfo() {
  2501. id, _ := c.GetInt64("id")
  2502. record_time := c.GetString("record_time")
  2503. in_hospital_id, _ := c.GetInt64("in_hospital_id")
  2504. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2505. admin_user_id, _ := c.GetInt64("admin_user_id")
  2506. timeLayout := "2006-01-02"
  2507. loc, _ := time.LoadLocation("Local")
  2508. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2509. if err != nil {
  2510. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2511. return
  2512. }
  2513. recordDateTime := theTime.Unix()
  2514. adminUser := c.GetAdminUserInfo()
  2515. var prescriptions []*models.HisPrescription
  2516. data := make(map[string]interface{})
  2517. if settle_accounts_type == 1 { //日结
  2518. prescriptions, _ = service.GetZHHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  2519. } else { //月结
  2520. start_time_str := c.GetString("start_time")
  2521. end_time_str := c.GetString("end_time")
  2522. timeLayout := "2006-01-02"
  2523. loc, _ := time.LoadLocation("Local")
  2524. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2525. if err != nil {
  2526. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2527. return
  2528. }
  2529. recordStartTime := theStartTime.Unix()
  2530. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2531. if err != nil {
  2532. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2533. return
  2534. }
  2535. recordEndTime := theEndTime.Unix()
  2536. prescriptions, _ = service.GetZHMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2537. }
  2538. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2539. record, _ := service.GetInHospitalRecord(in_hospital_id)
  2540. if record.ID == 0 {
  2541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2542. return
  2543. }
  2544. timestamp := time.Now().Unix()
  2545. tempTime := time.Unix(timestamp, 0)
  2546. timeFormat := tempTime.Format("20060102150405")
  2547. chrgBchno := rand.Intn(100000) + 10000
  2548. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(record.PatientId, 10)
  2549. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2550. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2551. department, _ := service.GetDepartMentDetail(record.Departments)
  2552. strconv.FormatInt(record.PatientId, 10)
  2553. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, patientPrescription.Creator)
  2554. //client := &http.Client{}
  2555. data["psn_no"] = record.PsnNo
  2556. data["mdtrt_id"] = record.Number
  2557. data["chrg_bchno"] = chrg_bchno
  2558. data["org_name"] = miConfig.OrgName
  2559. data["doctor"] = roles.UserName
  2560. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  2561. data["dept"] = strconv.FormatInt(department.ID, 10)
  2562. data["fixmedins_code"] = miConfig.Code
  2563. if (department.ID == 0 && adminUser.CurrentOrgId == 9919) || (department.ID == 0 && adminUser.CurrentOrgId == 10106) {
  2564. data["dept_code"] = "15"
  2565. } else {
  2566. data["dept_code"] = department.Number
  2567. }
  2568. if miConfig.Code == "H15049901371" {
  2569. if record.MedType == 14 {
  2570. if record.InsutypeType == "390" {
  2571. data["med_type"] = ""
  2572. } else if record.InsutypeType == "310" {
  2573. data["med_type"] = ""
  2574. }
  2575. } else if record.MedType == 11 {
  2576. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  2577. }
  2578. } else {
  2579. if record.MedType == 1112 {
  2580. data["med_type"] = strconv.FormatInt(11, 10)
  2581. } else {
  2582. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  2583. }
  2584. }
  2585. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  2586. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2587. data["secret_key"] = miConfig.SecretKey
  2588. var ids []int64
  2589. fmt.Println(data)
  2590. for _, item := range prescriptions {
  2591. ids = append(ids, item.ID)
  2592. }
  2593. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2594. if config.IsOpen == 1 { //对接了医保,走医保流程
  2595. var pagesize int = 100
  2596. var start int = 1
  2597. var stop int
  2598. var pagecount int
  2599. var curpage int
  2600. var isSuccess bool = true
  2601. var customs []*models.NewCustom
  2602. for _, item := range prescriptions {
  2603. tm := time.Unix(item.PreTime, 0)
  2604. if item.Type == 1 { //药品
  2605. for _, subItem := range item.HisDoctorAdviceInfo {
  2606. if len(subItem.BaseDrugLib.MedicalInsuranceNumber) > 0 && subItem.BaseDrugLib.IsUser != 1 {
  2607. //var randNum int
  2608. //randNum = rand.Intn(10000) + 1000
  2609. cus := &models.NewCustom{
  2610. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  2611. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  2612. FeedetlSn: subItem.FeedetlSn,
  2613. Price: fmt.Sprintf("%.4f", subItem.Price),
  2614. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  2615. HospApprFlag: subItem.BaseDrugLib.HospApprFlag,
  2616. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  2617. DoctorId: item.Creator,
  2618. }
  2619. customs = append(customs, cus)
  2620. }
  2621. }
  2622. }
  2623. if item.Type == 2 { //项目
  2624. for _, subItem := range item.HisPrescriptionProject {
  2625. //var randNum int
  2626. //randNum = rand.Intn(10000) + 1000
  2627. if subItem.Type == 2 {
  2628. if len(subItem.HisProject.MedicalCode) > 0 {
  2629. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  2630. cus := &models.NewCustom{
  2631. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  2632. Cut: fmt.Sprintf("%.4f", cnt),
  2633. FeedetlSn: subItem.FeedetlSn,
  2634. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  2635. MedListCodg: subItem.HisProject.MedicalCode,
  2636. HospApprFlag: -1,
  2637. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  2638. DoctorId: item.Creator,
  2639. }
  2640. customs = append(customs, cus)
  2641. }
  2642. } else if subItem.Type == 3 {
  2643. if len(subItem.GoodInfo.MedicalInsuranceNumber) > 0 && subItem.GoodInfo.IsUser != 1 {
  2644. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  2645. cus := &models.NewCustom{
  2646. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  2647. Cut: fmt.Sprintf("%.4f", cnt),
  2648. FeedetlSn: subItem.FeedetlSn,
  2649. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  2650. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  2651. HospApprFlag: -1,
  2652. FeeOcurTime: tm.Format("2006-01-02 15:04:05"),
  2653. DoctorId: item.Creator,
  2654. }
  2655. customs = append(customs, cus)
  2656. }
  2657. }
  2658. }
  2659. }
  2660. }
  2661. //总页数,向上取整,注意除之前要先转换类型为float64
  2662. pagecount = int(math.Ceil(float64(len(customs)) / float64(pagesize)))
  2663. var ress []*ResultFour
  2664. for curpage = 1; curpage <= pagecount; curpage++ {
  2665. if curpage == 1 {
  2666. start = 1
  2667. } else {
  2668. start = (curpage-1)*pagesize + 1
  2669. }
  2670. stop = curpage * pagesize
  2671. if stop > len(customs) {
  2672. stop = len(customs)
  2673. }
  2674. var result string
  2675. var requestLog string
  2676. if miConfig.MdtrtareaAdmvs == "150499" {
  2677. data := make(map[string]interface{})
  2678. if record.MedType == 14 {
  2679. if record.InsutypeType == "390" {
  2680. data["med_type"] = "9933"
  2681. } else if record.InsutypeType == "310" {
  2682. data["med_type"] = "990502"
  2683. }
  2684. } else if record.MedType == 11 {
  2685. data["med_type"] = strconv.FormatInt(record.MedType, 10)
  2686. }
  2687. data["psn_no"] = record.PsnNo
  2688. data["number"] = record.Number
  2689. data["customs"] = customs[start-1 : stop]
  2690. data["chrg_bchno"] = chrg_bchno
  2691. data["dept"] = strconv.FormatInt(department.ID, 10)
  2692. data["dept_code"] = department.Number
  2693. data["doctor_code"] = doctor_info.DoctorNumber
  2694. data["doctor_name"] = doctor_info.UserName
  2695. data["org_name"] = miConfig.OrgName
  2696. data["opertor"] = roles.UserName
  2697. data["fixmedins_code"] = miConfig.Code
  2698. data["insuplc_admdvs"] = record.InsuplcAdmdvs
  2699. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  2700. data["secret_key"] = miConfig.SecretKey
  2701. var req *http.Request
  2702. bytesData, _ := json.Marshal(data)
  2703. req, _ = http.NewRequest("POST", "http://172.16.13.254:9532/"+"nmyb/2301", bytes.NewReader(bytesData))
  2704. client := &http.Client{}
  2705. resp, _ := client.Do(req)
  2706. defer resp.Body.Close()
  2707. body, ioErr := ioutil.ReadAll(resp.Body)
  2708. if ioErr != nil {
  2709. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2711. return
  2712. }
  2713. var respJSON map[string]interface{}
  2714. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  2715. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2717. return
  2718. }
  2719. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2720. result_byte, _ := json.Marshal(respJSON)
  2721. result = string(result_byte)
  2722. } else {
  2723. result, requestLog = service.ZHGdyb2301(record.PsnNo, record.Number, customs[start-1:stop], chrg_bchno, miConfig.OrgName, roles.UserName, strconv.FormatInt(department.ID, 10), miConfig.Code, department.Number, strconv.FormatInt(roles.AdminUserId, 10), record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, data["med_type"].(string), doctor_info.UserName, doctor_info.DoctorNumber)
  2724. saveLog(result, requestLog, "2301", "上传明细")
  2725. }
  2726. var dat map[string]interface{}
  2727. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2728. fmt.Println(dat)
  2729. } else {
  2730. fmt.Println(err)
  2731. }
  2732. userJSONBytes, _ := json.Marshal(dat)
  2733. var res ResultFour
  2734. var resFour10265 ResultFour10265
  2735. if miConfig.Code == "H15049901371" {
  2736. if err := json.Unmarshal(userJSONBytes, &resFour10265); err != nil {
  2737. utils.ErrorLog("解析失败:%v", err)
  2738. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2739. return
  2740. }
  2741. res.WarnMsg = resFour10265.WarnMsg
  2742. res.Output = resFour10265.Output
  2743. res.ErrMsg = resFour10265.ErrMsg
  2744. res.RespondTime = resFour10265.RespondTime
  2745. res.InfRefmsgid = resFour10265.InfRefmsgid
  2746. Infcode, _ := strconv.ParseInt(resFour10265.Infcode, 10, 64)
  2747. res.Infcode = Infcode
  2748. } else {
  2749. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2750. utils.ErrorLog("解析失败:%v", err)
  2751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2752. return
  2753. }
  2754. }
  2755. if res.Infcode == 0 {
  2756. ress = append(ress, &res)
  2757. } else {
  2758. isSuccess = false
  2759. errlog := &models.HisOrderError{
  2760. UserOrgId: adminUser.CurrentOrgId,
  2761. Ctime: time.Now().Unix(),
  2762. Mtime: time.Now().Unix(),
  2763. Number: chrg_bchno,
  2764. ErrMsg: "",
  2765. Status: 1,
  2766. PatientId: id,
  2767. RecordTime: recordDateTime,
  2768. Stage: 4,
  2769. }
  2770. service.CreateErrMsgLog(errlog)
  2771. c.ServeSuccessJSON(map[string]interface{}{
  2772. "failed_code": -10,
  2773. "msg": "上传明细错误,请联系his厂商",
  2774. })
  2775. return
  2776. }
  2777. }
  2778. if isSuccess == true {
  2779. if settle_accounts_type == 1 {
  2780. for _, subItem := range ress {
  2781. for _, item := range subItem.Output.Result {
  2782. temp := strings.Split(item.FeedetlSn, "-")
  2783. var advice_id int64 = 0
  2784. var project_id int64 = 0
  2785. var types int64 = 0
  2786. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2787. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2788. if temp[1] == "1" {
  2789. advice_id = id
  2790. project_id = 0
  2791. } else if temp[1] == "2" {
  2792. advice_id = 0
  2793. project_id = id
  2794. }
  2795. info := &models.HisOrderInfo{
  2796. OrderNumber: record.Number,
  2797. FeedetlSn: item.FeedetlSn,
  2798. UploadDate: recordDateTime,
  2799. AdviceId: advice_id,
  2800. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2801. Cnt: item.Cnt,
  2802. Pric: float64(item.Pric),
  2803. PatientId: record.PatientId,
  2804. PricUplmtAmt: item.PricUplmtAmt,
  2805. SelfpayProp: item.SelfpayProp,
  2806. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2807. OverlmtAmt: item.OverlmtAmt,
  2808. PreselfpayAmt: item.PreselfpayAmt,
  2809. BasMednFlag: item.BasMednFlag,
  2810. MedChrgitmType: item.MedChrgitmType,
  2811. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2812. Status: 1,
  2813. Memo: item.Memo,
  2814. Mtime: time.Now().Unix(),
  2815. InscpScpAmt: item.InscpScpAmt,
  2816. DrtReimFlag: item.DrtReimFlag,
  2817. Ctime: time.Now().Unix(),
  2818. ListSpItemFlag: item.ListSpItemFlag,
  2819. ChldMedcFlag: item.ChldMedcFlag,
  2820. LmtUsedFlag: item.LmtUsedFlag,
  2821. ChrgitmLv: item.ChrgitmLv,
  2822. UserOrgId: adminUser.CurrentOrgId,
  2823. HisPatientId: record.ID,
  2824. OrderId: 0,
  2825. ProjectId: project_id,
  2826. Type: types,
  2827. SettleType: settle_accounts_type,
  2828. }
  2829. service.CreateOrderInfo(info)
  2830. }
  2831. }
  2832. err := service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  2833. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  2834. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  2835. if err == nil {
  2836. c.ServeSuccessJSON(map[string]interface{}{
  2837. "msg": "上传费用明细成功",
  2838. })
  2839. return
  2840. } else {
  2841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2842. return
  2843. }
  2844. } else {
  2845. for _, subItem := range ress {
  2846. for _, item := range subItem.Output.Result {
  2847. temp := strings.Split(item.FeedetlSn, "-")
  2848. var advice_id int64 = 0
  2849. var project_id int64 = 0
  2850. var types int64 = 0
  2851. id, _ := strconv.ParseInt(temp[2], 10, 64)
  2852. types, _ = strconv.ParseInt(temp[1], 10, 64)
  2853. if temp[1] == "1" {
  2854. advice_id = id
  2855. project_id = 0
  2856. } else if temp[1] == "2" {
  2857. advice_id = 0
  2858. project_id = id
  2859. }
  2860. info := &models.HisOrderInfo{
  2861. OrderNumber: record.Number,
  2862. FeedetlSn: item.FeedetlSn,
  2863. UploadDate: time.Now().Unix(),
  2864. AdviceId: advice_id,
  2865. DetItemFeeSumamt: item.DetItemFeeSumamt,
  2866. Cnt: item.Cnt,
  2867. Pric: float64(item.Pric),
  2868. PatientId: record.PatientId,
  2869. PricUplmtAmt: item.PricUplmtAmt,
  2870. SelfpayProp: item.SelfpayProp,
  2871. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  2872. OverlmtAmt: item.OverlmtAmt,
  2873. PreselfpayAmt: item.PreselfpayAmt,
  2874. BasMednFlag: item.BasMednFlag,
  2875. MedChrgitmType: item.MedChrgitmType,
  2876. HiNegoDrugFlag: item.HiNegoDrugFlag,
  2877. Status: 1,
  2878. Memo: item.Memo,
  2879. Mtime: time.Now().Unix(),
  2880. InscpScpAmt: item.InscpScpAmt,
  2881. DrtReimFlag: item.DrtReimFlag,
  2882. Ctime: time.Now().Unix(),
  2883. ListSpItemFlag: item.ListSpItemFlag,
  2884. ChldMedcFlag: item.ChldMedcFlag,
  2885. LmtUsedFlag: item.LmtUsedFlag,
  2886. ChrgitmLv: item.ChrgitmLv,
  2887. UserOrgId: adminUser.CurrentOrgId,
  2888. HisPatientId: record.ID,
  2889. ProjectId: project_id,
  2890. Type: types,
  2891. SettleType: settle_accounts_type,
  2892. }
  2893. service.CreateOrderInfo(info)
  2894. }
  2895. }
  2896. service.UpDatePrescriptionOrderStatus(adminUser.CurrentOrgId, ids)
  2897. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, record.Number)
  2898. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, record.Number, recordDateTime)
  2899. c.ServeSuccessJSON(map[string]interface{}{
  2900. "msg": "上传费用明细成功",
  2901. })
  2902. }
  2903. }
  2904. }
  2905. }
  2906. func (c *ZHHisApiController) ZHRefund() {
  2907. order_id, _ := c.GetInt64("order_id")
  2908. admin_user_id, _ := c.GetInt64("admin_user_id")
  2909. adminUser := c.GetAdminUserInfo()
  2910. var order models.HisOrder
  2911. order, _ = service.GetHisOrderByID(order_id)
  2912. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  2913. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2914. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2915. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2916. if config.IsOpen == 1 { //对接了医保,走医保流程
  2917. var result string
  2918. var requestLog string
  2919. if miConfig.MdtrtareaAdmvs == "150499" {
  2920. //请求内网数据
  2921. api := "http://172.16.13.254:9532/" + "nmyb/2305?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo + "&setl_id=" + order.SetlId +
  2922. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  2923. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2924. resp, requestErr := http.Get(api)
  2925. if requestErr != nil {
  2926. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2927. return
  2928. }
  2929. body, ioErr := ioutil.ReadAll(resp.Body)
  2930. if ioErr != nil {
  2931. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2932. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2933. return
  2934. }
  2935. var respJSON map[string]interface{}
  2936. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2937. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2939. return
  2940. }
  2941. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2942. result_byte, _ := json.Marshal(respJSON)
  2943. result = string(result_byte)
  2944. //saveLog(result, requestLog, "2404", "入院登记撤销")
  2945. saveLog(result, requestLog, "2305", "退费")
  2946. } else {
  2947. result, requestLog := service.Gdyb2305(order.PsnNo, order.MdtrtId, order.SetlId, miConfig.OrgName, roles.UserName, miConfig.SecretKey, miConfig.Code, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  2948. saveLog(result, requestLog, "2305", "退费")
  2949. }
  2950. var dat map[string]interface{}
  2951. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2952. fmt.Println(dat)
  2953. } else {
  2954. fmt.Println(err)
  2955. }
  2956. userJSONBytes, _ := json.Marshal(dat)
  2957. var res ResultSixteen
  2958. var resSixteen ResultSixteen10265
  2959. if miConfig.Code == "H15049901371" {
  2960. if err := json.Unmarshal(userJSONBytes, &resSixteen); err != nil {
  2961. utils.ErrorLog("解析失败:%v", err)
  2962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2963. return
  2964. }
  2965. res.Cainfo = resSixteen.Cainfo
  2966. res.WarnMsg = resSixteen.WarnMsg
  2967. res.Output = resSixteen.Output
  2968. res.ErrMsg = resSixteen.ErrMsg
  2969. res.RespondTime = resSixteen.RespondTime
  2970. Infcode, _ := strconv.ParseInt(resSixteen.Infcode, 10, 64)
  2971. res.Infcode = Infcode
  2972. } else {
  2973. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2974. utils.ErrorLog("解析失败:%v", err)
  2975. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2976. return
  2977. }
  2978. }
  2979. if res.Infcode == 0 {
  2980. err := service.UpdataOrderStatusThree(order_id, order.Number, adminUser.CurrentOrgId, "", result)
  2981. //不同地区退费流程不一样,肇庆那边退费就包括撤销出院,内蒙古退费不包括撤销明细,所以下面需要根据不同情况进行判断
  2982. if miConfig.UserOrgId == 10215 {
  2983. record.OutHospitalStatus = 0
  2984. service.CreateHospitalRecord(&record)
  2985. }
  2986. service.UpdataOrderStatusByNumber(record.Number)
  2987. if err == nil {
  2988. ////当押金不为零时产生退费记录
  2989. if order.Decimal != 0 {
  2990. tmp := strconv.FormatInt(order.ID, 10)
  2991. err = service.MoneyIncrease(adminUser.CurrentOrgId, order.PatientId, tmp, order.Decimal)
  2992. if err != nil {
  2993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2994. return
  2995. }
  2996. }
  2997. c.ServeSuccessJSON(map[string]interface{}{
  2998. "msg": "退费成功",
  2999. })
  3000. } else {
  3001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3002. return
  3003. }
  3004. } else {
  3005. c.ServeSuccessJSON(map[string]interface{}{
  3006. "code": -10,
  3007. "msg": res.ErrMsg,
  3008. })
  3009. }
  3010. } else {
  3011. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId, "", "")
  3012. if err == nil {
  3013. c.ServeSuccessJSON(map[string]interface{}{
  3014. "msg": "退费成功",
  3015. })
  3016. } else {
  3017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3018. return
  3019. }
  3020. }
  3021. }
  3022. func (c *ZHHisApiController) ZHRefundDetail() {
  3023. patient_id, _ := c.GetInt64("patient_id")
  3024. his_patient_id, _ := c.GetInt64("his_patient_id")
  3025. record_time := c.GetString("record_time")
  3026. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3027. //order_id, _ := c.GetInt64("order_id")
  3028. admin_user_id, _ := c.GetInt64("admin_user_id")
  3029. timeLayout := "2006-01-02"
  3030. loc, _ := time.LoadLocation("Local")
  3031. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3032. if err != nil {
  3033. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3034. return
  3035. }
  3036. recordDateTime := theTime.Unix()
  3037. adminUser := c.GetAdminUserInfo()
  3038. theTimeTwo, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 23:59:59", loc)
  3039. if err != nil {
  3040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3041. return
  3042. }
  3043. recordDateTimeTwo := theTimeTwo.Unix()
  3044. //var prescriptions []*models.HisPrescription
  3045. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  3046. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  3047. if settle_accounts_type == 1 { //日结
  3048. record, _ := service.GetInHospitalRecord(his_patient_id)
  3049. infos, _ := service.GetZHHisUploadOrderInfo(adminUser.CurrentOrgId, patient_id, recordDateTime, recordDateTimeTwo, record.Number)
  3050. var isSuccess bool = true
  3051. for _, item := range infos {
  3052. var result string
  3053. var requestLog string
  3054. if miConfig.MdtrtareaAdmvs == "150499" {
  3055. //请求内网数据
  3056. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&feedetl_sn=" + item.FeedetlSn +
  3057. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  3058. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "1"
  3059. resp, requestErr := http.Get(api)
  3060. if requestErr != nil {
  3061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3062. return
  3063. }
  3064. body, ioErr := ioutil.ReadAll(resp.Body)
  3065. if ioErr != nil {
  3066. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3067. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3068. return
  3069. }
  3070. var respJSON map[string]interface{}
  3071. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3072. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3073. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3074. return
  3075. }
  3076. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3077. result_byte, _ := json.Marshal(respJSON)
  3078. result = string(result_byte)
  3079. saveLog(result, requestLog, "2302", "日结退明细")
  3080. } else {
  3081. result, requestLog := service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, item.FeedetlSn, 1)
  3082. saveLog(result, requestLog, "2302", "日结退明细")
  3083. }
  3084. var dat map[string]interface{}
  3085. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3086. fmt.Println(dat)
  3087. } else {
  3088. fmt.Println(err)
  3089. }
  3090. userJSONBytes, _ := json.Marshal(dat)
  3091. var res2 ResultEmpty
  3092. var resEmpty10265 ResultEmpty10265
  3093. if miConfig.Code == "H15049901371" {
  3094. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3095. utils.ErrorLog("解析失败:%v", err)
  3096. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3097. return
  3098. }
  3099. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3100. res2.Infcode = Infcode
  3101. res2.RespondTime = resEmpty10265.RespondTime
  3102. res2.ErrMsg = resEmpty10265.ErrMsg
  3103. res2.Output = resEmpty10265.Output
  3104. res2.WarnMsg = resEmpty10265.WarnMsg
  3105. } else {
  3106. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3107. utils.ErrorLog("解析失败:%v", err)
  3108. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3109. return
  3110. }
  3111. }
  3112. if res2.Infcode == -1 {
  3113. isSuccess = false
  3114. }
  3115. }
  3116. if isSuccess {
  3117. err := service.UpDateOrderInfoStatus(patient_id, recordDateTime, adminUser.CurrentOrgId, recordDateTimeTwo)
  3118. if err != nil {
  3119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3120. return
  3121. }
  3122. err1 := service.UpDatePrescriptionOrderStatusTwo(patient_id, recordDateTime, adminUser.CurrentOrgId)
  3123. if err1 != nil {
  3124. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3125. return
  3126. }
  3127. c.ServeSuccessJSON(map[string]interface{}{
  3128. "msg": "撤销明细成功",
  3129. })
  3130. }
  3131. } else {
  3132. //prescriptions, _ = service.GetZHMonthHisUploadPrescription(adminUser.CurrentOrgId, patient_id, recordDateTime)
  3133. //var order models.HisOrder
  3134. //order, _ = service.GetHisOrderByID(order_id)
  3135. //record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  3136. var result string
  3137. var requestLog string
  3138. record, _ := service.GetInHospitalRecord(his_patient_id)
  3139. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3140. if config.IsOpen == 1 { //对接了医保,走医保流程
  3141. if miConfig.MdtrtareaAdmvs == "150499" {
  3142. //请求内网数据
  3143. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=0000" +
  3144. "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code +
  3145. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=" + "0"
  3146. resp, requestErr := http.Get(api)
  3147. if requestErr != nil {
  3148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3149. return
  3150. }
  3151. body, ioErr := ioutil.ReadAll(resp.Body)
  3152. if ioErr != nil {
  3153. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3155. return
  3156. }
  3157. var respJSON map[string]interface{}
  3158. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3159. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3161. return
  3162. }
  3163. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3164. result_byte, _ := json.Marshal(respJSON)
  3165. result = string(result_byte)
  3166. //saveLog(result, requestLog, "2302", "日结退明细")
  3167. } else {
  3168. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, roles.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  3169. saveLog(result, requestLog, "2302", "月结退明细")
  3170. }
  3171. var dat map[string]interface{}
  3172. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3173. fmt.Println(dat)
  3174. } else {
  3175. fmt.Println(err)
  3176. }
  3177. userJSONBytes, _ := json.Marshal(dat)
  3178. var res2 ResultEmpty
  3179. var resEmpty10265 ResultEmpty10265
  3180. if miConfig.Code == "H15049901371" {
  3181. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3182. utils.ErrorLog("解析失败:%v", err)
  3183. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3184. return
  3185. }
  3186. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3187. res2.Infcode = Infcode
  3188. res2.RespondTime = resEmpty10265.RespondTime
  3189. res2.ErrMsg = resEmpty10265.ErrMsg
  3190. res2.Output = resEmpty10265.Output
  3191. res2.WarnMsg = resEmpty10265.WarnMsg
  3192. } else {
  3193. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3194. utils.ErrorLog("解析失败:%v", err)
  3195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3196. return
  3197. }
  3198. }
  3199. if res2.Infcode == 0 {
  3200. err := service.UpdataHospitalOrderStatus(record.Number, adminUser.CurrentOrgId)
  3201. if err == nil {
  3202. c.ServeSuccessJSON(map[string]interface{}{
  3203. "msg": "撤销明细成功",
  3204. })
  3205. } else {
  3206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3207. return
  3208. }
  3209. } else {
  3210. c.ServeSuccessJSON(map[string]interface{}{
  3211. "code": -10,
  3212. "msg": res2.ErrMsg,
  3213. })
  3214. }
  3215. }
  3216. }
  3217. }
  3218. func (this *ZHHisApiController) GetZHOutHospitalUnCheck() {
  3219. id, _ := this.GetInt64("id")
  3220. admin_user_id, _ := this.GetInt64("admin_user_id")
  3221. adminInfo := this.GetAdminUserInfo()
  3222. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3223. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  3224. record, _ := service.GetInHospitalRecord(id)
  3225. if record.ID == 0 {
  3226. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  3227. return
  3228. }
  3229. var result string
  3230. var requestLog string
  3231. if miConfig.MdtrtareaAdmvs == "150499" {
  3232. //请求内网数据
  3233. api := "http://172.16.13.254:9532/" + "nmyb/2405?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  3234. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  3235. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3236. fmt.Println(api)
  3237. resp, requestErr := http.Get(api)
  3238. if requestErr != nil {
  3239. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3240. return
  3241. }
  3242. body, ioErr := ioutil.ReadAll(resp.Body)
  3243. if ioErr != nil {
  3244. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3245. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3246. return
  3247. }
  3248. var respJSON map[string]interface{}
  3249. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3250. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3252. return
  3253. }
  3254. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3255. result_byte, _ := json.Marshal(respJSON)
  3256. result = string(result_byte)
  3257. } else {
  3258. result, requestLog = service.ZHGdyb2405(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3259. saveLog(result, requestLog, "2405", "出院登记撤销")
  3260. }
  3261. var dat map[string]interface{}
  3262. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3263. fmt.Println(dat)
  3264. } else {
  3265. fmt.Println(err)
  3266. }
  3267. userJSONBytes, _ := json.Marshal(dat)
  3268. var res ResultEmpty
  3269. var resEmpty10265 ResultEmpty10265
  3270. if miConfig.Code == "H15049901371" {
  3271. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3272. utils.ErrorLog("解析失败:%v", err)
  3273. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3274. return
  3275. }
  3276. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3277. res.Infcode = Infcode
  3278. res.RespondTime = resEmpty10265.RespondTime
  3279. res.ErrMsg = resEmpty10265.ErrMsg
  3280. res.Output = resEmpty10265.Output
  3281. res.WarnMsg = resEmpty10265.WarnMsg
  3282. } else {
  3283. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3284. utils.ErrorLog("解析失败:%v", err)
  3285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3286. return
  3287. }
  3288. }
  3289. if res.Infcode == 0 {
  3290. record.OutHospitalStatus = 0
  3291. service.CreateHospitalRecord(&record)
  3292. service.UpdataOrderStatusByNumber(record.Number)
  3293. this.ServeSuccessJSON(map[string]interface{}{
  3294. "msg": "撤销出院成功",
  3295. })
  3296. } else {
  3297. this.ServeSuccessJSON(map[string]interface{}{
  3298. "failed_code": -10,
  3299. "msg": res.ErrMsg,
  3300. })
  3301. }
  3302. }
  3303. func (this *ZHHisApiController) GetZHInHospitalUnCheck() {
  3304. id, _ := this.GetInt64("id")
  3305. admin_user_id, _ := this.GetInt64("admin_user_id")
  3306. adminInfo := this.GetAdminUserInfo()
  3307. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  3308. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, admin_user_id)
  3309. record, _ := service.GetInHospitalRecord(id)
  3310. if record.ID == 0 {
  3311. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInHospitalNoExistDataException)
  3312. return
  3313. }
  3314. var result string
  3315. var requestLog string
  3316. orders, _ := service.GetHisOrderInfoByNumber(record.Number)
  3317. if len(orders) > 0 { //判断是否上传过明细,有的话需要退明细,后撤销入院
  3318. if miConfig.MdtrtareaAdmvs == "150499" {
  3319. //请求内网数据
  3320. api := "http://172.16.13.254:9532/" + "nmyb/2302?psn_no=" + record.PsnNo + "&mdtrtId=" + record.Number + "&number=" + "0000" +
  3321. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  3322. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&refund_type=0"
  3323. resp, requestErr := http.Get(api)
  3324. if requestErr != nil {
  3325. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3326. return
  3327. }
  3328. body, ioErr := ioutil.ReadAll(resp.Body)
  3329. if ioErr != nil {
  3330. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3331. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3332. return
  3333. }
  3334. var respJSON map[string]interface{}
  3335. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3336. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3337. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3338. return
  3339. }
  3340. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3341. result_byte, _ := json.Marshal(respJSON)
  3342. result = string(result_byte)
  3343. saveLog(result, requestLog, "2302", "月结退明细")
  3344. } else {
  3345. result, requestLog = service.Gdyb2302(record.PsnNo, record.Number, miConfig.OrgName, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, miConfig.Code, "0000", 0)
  3346. saveLog(result, requestLog, "2302", "月结退明细")
  3347. }
  3348. var dat map[string]interface{}
  3349. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3350. fmt.Println(dat)
  3351. } else {
  3352. fmt.Println(err)
  3353. }
  3354. userJSONBytes, _ := json.Marshal(dat)
  3355. var res2 ResultEmpty
  3356. var resEmpty10265 ResultEmpty10265
  3357. if miConfig.Code == "H15049901371" {
  3358. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3359. utils.ErrorLog("解析失败:%v", err)
  3360. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3361. return
  3362. }
  3363. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3364. res2.Infcode = Infcode
  3365. res2.RespondTime = resEmpty10265.RespondTime
  3366. res2.ErrMsg = resEmpty10265.ErrMsg
  3367. res2.Output = resEmpty10265.Output
  3368. res2.WarnMsg = resEmpty10265.WarnMsg
  3369. } else {
  3370. if err := json.Unmarshal(userJSONBytes, &res2); err != nil {
  3371. utils.ErrorLog("解析失败:%v", err)
  3372. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3373. return
  3374. }
  3375. }
  3376. if res2.Infcode == 0 {
  3377. service.UpdataHospitalOrderStatus(record.Number, adminInfo.CurrentOrgId)
  3378. var result string
  3379. var requestLog string
  3380. if miConfig.MdtrtareaAdmvs == "150499" {
  3381. //请求内网数据
  3382. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  3383. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  3384. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3385. resp, requestErr := http.Get(api)
  3386. if requestErr != nil {
  3387. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3388. return
  3389. }
  3390. body, ioErr := ioutil.ReadAll(resp.Body)
  3391. if ioErr != nil {
  3392. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3393. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3394. return
  3395. }
  3396. var respJSON map[string]interface{}
  3397. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3398. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3399. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3400. return
  3401. }
  3402. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3403. result_byte, _ := json.Marshal(respJSON)
  3404. result = string(result_byte)
  3405. } else {
  3406. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3407. saveLog(result, requestLog, "2404", "入院登记撤销")
  3408. }
  3409. var dat map[string]interface{}
  3410. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3411. fmt.Println(dat)
  3412. } else {
  3413. fmt.Println(err)
  3414. }
  3415. userJSONBytes, _ := json.Marshal(dat)
  3416. var res ResultEmpty
  3417. var resEmpty10265 ResultEmpty10265
  3418. if miConfig.Code == "H15049901371" {
  3419. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3420. utils.ErrorLog("解析失败:%v", err)
  3421. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3422. return
  3423. }
  3424. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3425. res.Infcode = Infcode
  3426. res.RespondTime = resEmpty10265.RespondTime
  3427. res.ErrMsg = resEmpty10265.ErrMsg
  3428. res.Output = resEmpty10265.Output
  3429. res.WarnMsg = resEmpty10265.WarnMsg
  3430. } else {
  3431. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3432. utils.ErrorLog("解析失败:%v", err)
  3433. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3434. return
  3435. }
  3436. }
  3437. if res.Infcode == 0 {
  3438. record.Status = 0
  3439. service.CreateHospitalRecord(&record)
  3440. this.ServeSuccessJSON(map[string]interface{}{
  3441. "msg": "撤销入院成功",
  3442. })
  3443. } else {
  3444. this.ServeSuccessJSON(map[string]interface{}{
  3445. "failed_code": -10,
  3446. "msg": res.ErrMsg,
  3447. })
  3448. }
  3449. } else {
  3450. this.ServeSuccessJSON(map[string]interface{}{
  3451. "code": -10,
  3452. "msg": res2.ErrMsg,
  3453. })
  3454. }
  3455. } else { //没有上传过明细的,直接撤销入院
  3456. var result string
  3457. var requestLog string
  3458. if miConfig.MdtrtareaAdmvs == "150499" {
  3459. //请求内网数据
  3460. api := "http://172.16.13.254:9532/" + "nmyb/2404?mdtrt_id=" + record.Number + "&psn_no=" + record.PsnNo +
  3461. "&org_name=" + miConfig.OrgName + "&doctor=" + role.UserName + "&fixmedins_code=" + miConfig.Code +
  3462. "&insuplc_admdvs=" + record.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  3463. resp, requestErr := http.Get(api)
  3464. if requestErr != nil {
  3465. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3466. return
  3467. }
  3468. body, ioErr := ioutil.ReadAll(resp.Body)
  3469. if ioErr != nil {
  3470. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3471. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3472. return
  3473. }
  3474. var respJSON map[string]interface{}
  3475. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3476. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3477. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3478. return
  3479. }
  3480. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  3481. result_byte, _ := json.Marshal(respJSON)
  3482. result = string(result_byte)
  3483. } else {
  3484. result, requestLog = service.ZHGdyb2404(record.Number, record.PsnNo, miConfig.SecretKey, miConfig.OrgName, miConfig.Code, role.UserName, record.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs)
  3485. saveLog(result, requestLog, "2404", "入院登记撤销")
  3486. }
  3487. var dat map[string]interface{}
  3488. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3489. fmt.Println(dat)
  3490. } else {
  3491. fmt.Println(err)
  3492. }
  3493. userJSONBytes, _ := json.Marshal(dat)
  3494. var res ResultEmpty
  3495. var resEmpty10265 ResultEmpty10265
  3496. if miConfig.Code == "H15049901371" {
  3497. if err := json.Unmarshal(userJSONBytes, &resEmpty10265); err != nil {
  3498. utils.ErrorLog("解析失败:%v", err)
  3499. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3500. return
  3501. }
  3502. Infcode, _ := strconv.ParseInt(resEmpty10265.Infcode, 10, 64)
  3503. res.Infcode = Infcode
  3504. res.RespondTime = resEmpty10265.RespondTime
  3505. res.ErrMsg = resEmpty10265.ErrMsg
  3506. res.Output = resEmpty10265.Output
  3507. res.WarnMsg = resEmpty10265.WarnMsg
  3508. } else {
  3509. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3510. utils.ErrorLog("解析失败:%v", err)
  3511. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3512. return
  3513. }
  3514. }
  3515. if res.Infcode == 0 {
  3516. record.Status = 0
  3517. service.CreateHospitalRecord(&record)
  3518. this.ServeSuccessJSON(map[string]interface{}{
  3519. "msg": "撤销入院成功",
  3520. })
  3521. } else {
  3522. this.ServeSuccessJSON(map[string]interface{}{
  3523. "failed_code": -10,
  3524. "msg": res.ErrMsg,
  3525. })
  3526. }
  3527. }
  3528. }
  3529. func saveLog(result string, request string, infno string, desc string) {
  3530. org_id, _ := beego.AppConfig.Int64("org_id")
  3531. miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  3532. dir := miConfig.OrgName + "日志"
  3533. utils.Mkdir(dir)
  3534. month := time.Unix(1557042972, 0).Format("1")
  3535. year := time.Now().Format("2006")
  3536. month = time.Now().Format("01")
  3537. day := time.Now().Format("02")
  3538. hour := time.Now().Format("15")
  3539. min := time.Now().Format("04")
  3540. sec := time.Now().Format("05")
  3541. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  3542. file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  3543. file_name := file + ".txt"
  3544. file_path := miConfig.OrgName + "日志" + "/" + file_name
  3545. exist, _ := utils.PathExists(file_path)
  3546. if exist { //存在
  3547. fmt.Println("存在")
  3548. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  3549. if err != nil {
  3550. fmt.Println("read fail")
  3551. }
  3552. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  3553. n, _ := f.Seek(0, 2)
  3554. _, err = f.WriteAt([]byte(content), n)
  3555. } else { //不存在
  3556. fmt.Println("文件不存在,创建文件")
  3557. f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  3558. defer f.Close()
  3559. if err != nil {
  3560. } else {
  3561. _, err = f.Write([]byte("记录日志"))
  3562. }
  3563. }
  3564. }
  3565. type Charset string
  3566. const (
  3567. UTF8 = Charset("UTF-8")
  3568. GB18030 = Charset("GB18030")
  3569. )
  3570. func ConvertToString(src string, srcCode string, tagCode string) string {
  3571. srcCoder := mahonia.NewDecoder(srcCode)
  3572. srcResult := srcCoder.ConvertString(src)
  3573. tagCoder := mahonia.NewDecoder(tagCode)
  3574. _, cdata, _ := tagCoder.Translate([]byte(srcResult), true)
  3575. result := string(cdata)
  3576. return result
  3577. }
  3578. type ELeData struct {
  3579. Data struct {
  3580. IdNo string `json:"idNo"`
  3581. IdType string `json:"idType"`
  3582. UserName string `json:"userName"`
  3583. EcToken string `json:"ecToken"`
  3584. InsuOrg string `json:"insuOrg"`
  3585. Gender string `json:"gender"`
  3586. Birthday string `json:"birthday"`
  3587. Nationality string `json:"nationality"`
  3588. Email string `json:"email"`
  3589. Extra string `json:"extra"`
  3590. } `json:"data"`
  3591. Code int `json:"code"`
  3592. Message string `json:"message"`
  3593. }
  3594. var initFlagTwo int64 = 0
  3595. func (c *ZHHisApiController) ReadCard() {
  3596. id_card_type, _ := c.GetInt64("id_card_type")
  3597. admin_user_id, _ := c.GetInt64("admin_user_id")
  3598. roles, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, admin_user_id)
  3599. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  3600. switch id_card_type {
  3601. case 1: //社保卡
  3602. if miConfig.MdtrtareaAdmvs == "150499" {
  3603. var api string
  3604. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  3605. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&url=" + miConfig.Url + "&cainfo=" + miConfig.Cainfo + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&operator_id=" + strconv.FormatInt(admin_user_id, 10) + "&operator=" + roles.UserName
  3606. fmt.Println(api)
  3607. resp, requestErr := http.Get(api)
  3608. if requestErr != nil {
  3609. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3610. return
  3611. }
  3612. body, ioErr := ioutil.ReadAll(resp.Body)
  3613. if ioErr != nil {
  3614. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3616. return
  3617. }
  3618. var respJSON map[string]interface{}
  3619. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3620. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3622. return
  3623. }
  3624. var status string
  3625. status = respJSON["data"].(map[string]interface{})["status"].(string)
  3626. card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  3627. //console.log()
  3628. fmt.Println("type===")
  3629. fmt.Println(card_type)
  3630. var token string
  3631. var res ResultTwo //1101结果
  3632. var res10265 ResultTwo10265 //1101结果
  3633. var card_info string //卡信息
  3634. var busi_card_info string
  3635. card_info = respJSON["data"].(map[string]interface{})["card_info"].(string)
  3636. busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  3637. if status == "0" { //读卡成功
  3638. if card_type == "1" {
  3639. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  3640. result, _ := json.Marshal(respJSON)
  3641. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  3642. utils.ErrorLog("解析失败:%v", err)
  3643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3644. return
  3645. }
  3646. res.ErrMsg = res10265.ErrMsg
  3647. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  3648. res.Infcode = infocode
  3649. res.Output = res10265.Output
  3650. res.InfRefmsgid = res10265.InfRefmsgid
  3651. } else {
  3652. //var card_info string //卡信息
  3653. //var busi_card_info string
  3654. token = respJSON["data"].(map[string]interface{})["token"].(string)
  3655. //busi_card_info = respJSON["data"].(map[string]interface{})["busi_card_info"].(string)
  3656. //fmt.Println(card_info)
  3657. //fmt.Println(busi_card_info)
  3658. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  3659. result, _ := json.Marshal(respJSON)
  3660. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  3661. utils.ErrorLog("解析失败:%v", err)
  3662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3663. return
  3664. }
  3665. res.ErrMsg = res10265.ErrMsg
  3666. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  3667. res.Infcode = infocode
  3668. res.Output = res10265.Output
  3669. res.InfRefmsgid = res10265.InfRefmsgid
  3670. }
  3671. if res.Infcode == 0 {
  3672. var insutypes []string
  3673. var insutype string
  3674. var is390 int = 0
  3675. var is310 int = 0
  3676. for _, item := range res.Output.Iinfo {
  3677. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  3678. insutypes = append(insutypes, item.Insutype)
  3679. }
  3680. }
  3681. if len(insutypes) == 1 {
  3682. insutype = insutypes[0]
  3683. } else {
  3684. for _, i := range insutypes {
  3685. if i == "390" {
  3686. is390 = 1
  3687. }
  3688. if i == "310" {
  3689. is310 = 1
  3690. }
  3691. }
  3692. }
  3693. if is390 == 1 {
  3694. insutype = "390"
  3695. }
  3696. if is310 == 1 {
  3697. insutype = "310"
  3698. }
  3699. if len(insutypes) == 0 {
  3700. insutype = "310"
  3701. }
  3702. patient, err := service.GetPatientByIDCard(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  3703. if err == gorm.ErrRecordNotFound {
  3704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3705. return
  3706. } else if err != nil {
  3707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3708. return
  3709. } else {
  3710. if card_type == "1" {
  3711. bas := strings.Split(card_info, "|")
  3712. basNumber := bas[2]
  3713. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3714. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3715. infoStr := string(Iinfos)
  3716. idetinfoStr := string(Idetinfos)
  3717. psn := &models.HisPsn{
  3718. PsnNo: res.Output.Baseinfo.PsnNo,
  3719. Age: res.Output.Baseinfo.Age,
  3720. PatientId: patient.ID,
  3721. Certno: res.Output.Baseinfo.Certno,
  3722. Brdy: res.Output.Baseinfo.Brdy,
  3723. Gend: res.Output.Baseinfo.Gend,
  3724. Naty: res.Output.Baseinfo.Naty,
  3725. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3726. PsnName: res.Output.Baseinfo.PsnName,
  3727. Idetinfo: idetinfoStr,
  3728. Insuinfo: infoStr,
  3729. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3730. CardInfo: card_info,
  3731. VerifyNumber: busi_card_info,
  3732. }
  3733. service.CreateHisPsn(psn)
  3734. c.ServeSuccessJSON(map[string]interface{}{
  3735. "patient": patient,
  3736. "number": basNumber,
  3737. "info": res,
  3738. "insutype": insutype,
  3739. })
  3740. } else {
  3741. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3742. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3743. infoStr := string(Iinfos)
  3744. idetinfoStr := string(Idetinfos)
  3745. psn := &models.HisPsn{
  3746. PsnNo: res.Output.Baseinfo.PsnNo,
  3747. Age: res.Output.Baseinfo.Age,
  3748. PatientId: patient.ID,
  3749. Certno: res.Output.Baseinfo.Certno,
  3750. Brdy: res.Output.Baseinfo.Brdy,
  3751. Gend: res.Output.Baseinfo.Gend,
  3752. Naty: res.Output.Baseinfo.Naty,
  3753. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3754. PsnName: res.Output.Baseinfo.PsnName,
  3755. Idetinfo: idetinfoStr,
  3756. Insuinfo: infoStr,
  3757. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3758. CardInfo: card_info,
  3759. VerifyNumber: token,
  3760. }
  3761. service.CreateHisPsn(psn)
  3762. c.ServeSuccessJSON(map[string]interface{}{
  3763. "patient": patient,
  3764. "number": token,
  3765. "info": res,
  3766. "insutype": insutype,
  3767. })
  3768. }
  3769. }
  3770. } else {
  3771. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  3772. return
  3773. }
  3774. } else { //读卡失败
  3775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  3776. return
  3777. }
  3778. } else {
  3779. if initFlagTwo == 0 {
  3780. c.TestGetBasBaseInitTwo()
  3781. }
  3782. basStr := c.GetBasBaseInfoTwo()
  3783. if len(basStr) == 0 {
  3784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  3785. return
  3786. }
  3787. fmt.Println(basStr)
  3788. bas := strings.Split(basStr, "|")
  3789. id_card_no := bas[1]
  3790. result, _ := service.ZHGdyb1101B(id_card_no, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "", 1, "")
  3791. //result := service.Gdyb1101B(basNumber, miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, id_card_type, card_sn, certificates)
  3792. var dat map[string]interface{}
  3793. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  3794. fmt.Println(dat)
  3795. } else {
  3796. fmt.Println(err)
  3797. }
  3798. userJSONBytes, _ := json.Marshal(dat)
  3799. var res ResultTwo
  3800. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  3801. utils.ErrorLog("解析失败:%v", err)
  3802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3803. return
  3804. }
  3805. if res.Infcode == 0 {
  3806. patient, err := service.GetPatientByNumber(id_card_no, c.GetAdminUserInfo().CurrentOrgId)
  3807. if err == gorm.ErrRecordNotFound {
  3808. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3809. return
  3810. } else if err != nil {
  3811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3812. return
  3813. } else {
  3814. var insutypes []string
  3815. var insutype string
  3816. var is390 int = 0
  3817. var is310 int = 0
  3818. for _, item := range res.Output.Iinfo {
  3819. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  3820. insutypes = append(insutypes, item.Insutype)
  3821. }
  3822. }
  3823. if len(insutypes) == 1 {
  3824. insutype = insutypes[0]
  3825. } else {
  3826. for _, i := range insutypes {
  3827. if i == "390" {
  3828. is390 = 1
  3829. }
  3830. if i == "310" {
  3831. is310 = 1
  3832. }
  3833. }
  3834. }
  3835. if is390 == 1 {
  3836. insutype = "390"
  3837. }
  3838. if is310 == 1 {
  3839. insutype = "310"
  3840. }
  3841. if len(insutypes) == 0 {
  3842. insutype = "310"
  3843. }
  3844. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3845. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3846. infoStr := string(Iinfos)
  3847. idetinfoStr := string(Idetinfos)
  3848. psn := &models.HisPsn{
  3849. PsnNo: res.Output.Baseinfo.PsnNo,
  3850. Age: res.Output.Baseinfo.Age,
  3851. PatientId: patient.ID,
  3852. Certno: res.Output.Baseinfo.Certno,
  3853. Brdy: res.Output.Baseinfo.Brdy,
  3854. Gend: res.Output.Baseinfo.Gend,
  3855. Naty: res.Output.Baseinfo.Naty,
  3856. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3857. PsnName: res.Output.Baseinfo.PsnName,
  3858. Idetinfo: idetinfoStr,
  3859. Insuinfo: infoStr,
  3860. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3861. CardInfo: basStr,
  3862. VerifyNumber: "",
  3863. }
  3864. service.CreateHisPsn(psn)
  3865. c.ServeSuccessJSON(map[string]interface{}{
  3866. "patient": patient,
  3867. "number": id_card_no,
  3868. "info": res,
  3869. "insutype": insutype,
  3870. })
  3871. }
  3872. } else {
  3873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  3874. return
  3875. }
  3876. }
  3877. break
  3878. case 4: //电子凭证
  3879. if miConfig.MdtrtareaAdmvs == "150499" {
  3880. var api string
  3881. api = "http://172.16.13.254:9532/" + "nmyb/readcard?" + "fixmedins_code=" + miConfig.Code + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName +
  3882. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&url=" + miConfig.Url + "&cainfo=" + miConfig.Cainfo + "&id_card_type=" + strconv.FormatInt(id_card_type, 10) + "&operator_id=" + strconv.FormatInt(admin_user_id, 10) + "&operator=" + roles.UserName
  3883. resp, requestErr := http.Get(api)
  3884. if requestErr != nil {
  3885. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3886. return
  3887. }
  3888. body, ioErr := ioutil.ReadAll(resp.Body)
  3889. if ioErr != nil {
  3890. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  3891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3892. return
  3893. }
  3894. var respJSON map[string]interface{}
  3895. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  3896. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  3897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3898. return
  3899. }
  3900. var status string
  3901. status = respJSON["data"].(map[string]interface{})["status"].(string)
  3902. //card_type := respJSON["data"].(map[string]interface{})["type"].(string)
  3903. var token string
  3904. var res ResultTwo //1101结果
  3905. var res10265 ResultTwo10265 //1101结果
  3906. if status == "0" { //读卡成功
  3907. token = respJSON["data"].(map[string]interface{})["token"].(string)
  3908. respJSON = respJSON["data"].(map[string]interface{})["result"].(map[string]interface{})
  3909. result, _ := json.Marshal(respJSON)
  3910. if err := json.Unmarshal([]byte(result), &res10265); err != nil {
  3911. utils.ErrorLog("解析失败:%v", err)
  3912. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3913. return
  3914. }
  3915. res.ErrMsg = res10265.ErrMsg
  3916. infocode, _ := strconv.ParseInt(res10265.Infcode, 10, 64)
  3917. res.Infcode = infocode
  3918. res.Output = res10265.Output
  3919. res.InfRefmsgid = res10265.InfRefmsgid
  3920. if res.Infcode == 0 {
  3921. c.ServeSuccessJSON(map[string]interface{}{
  3922. "number": token,
  3923. })
  3924. }
  3925. }
  3926. } else {
  3927. if initFlagTwo == 0 {
  3928. c.TestGetBasBaseInitTwo()
  3929. }
  3930. token := c.GetEleBaseInfoTwo()
  3931. token = Remove0000(token)
  3932. result2, requestLog2 := service.Gdyb1101ForEleCert(miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, token, "", "")
  3933. saveLog(result2, requestLog2, "1101", "获取人员信息")
  3934. //
  3935. var res ResultTwo
  3936. if err := json.Unmarshal([]byte(result2), &res); err != nil {
  3937. utils.ErrorLog("解析失败:%v", err)
  3938. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3939. return
  3940. }
  3941. if res.Infcode == 0 {
  3942. patient, err := service.GetPatientByNumber(res.Output.Baseinfo.Certno, c.GetAdminUserInfo().CurrentOrgId)
  3943. if err == gorm.ErrRecordNotFound {
  3944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  3945. return
  3946. } else if err != nil {
  3947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3948. return
  3949. } else {
  3950. var insutypes []string
  3951. var insutype string
  3952. var is390 int = 0
  3953. var is310 int = 0
  3954. for _, item := range res.Output.Iinfo {
  3955. if (item.Insutype == "390" && item.PsnInsuStas == "1") || (item.Insutype == "310" && item.PsnInsuStas == "1") {
  3956. insutypes = append(insutypes, item.Insutype)
  3957. }
  3958. }
  3959. if len(insutypes) == 1 {
  3960. insutype = insutypes[0]
  3961. } else {
  3962. for _, i := range insutypes {
  3963. if i == "390" {
  3964. is390 = 1
  3965. }
  3966. if i == "310" {
  3967. is310 = 1
  3968. }
  3969. }
  3970. }
  3971. if is390 == 1 {
  3972. insutype = "390"
  3973. }
  3974. if is310 == 1 {
  3975. insutype = "310"
  3976. }
  3977. if len(insutypes) == 0 {
  3978. insutype = "310"
  3979. }
  3980. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  3981. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  3982. infoStr := string(Iinfos)
  3983. idetinfoStr := string(Idetinfos)
  3984. psn := &models.HisPsn{
  3985. PsnNo: res.Output.Baseinfo.PsnNo,
  3986. Age: res.Output.Baseinfo.Age,
  3987. PatientId: patient.ID,
  3988. Certno: res.Output.Baseinfo.Certno,
  3989. Brdy: res.Output.Baseinfo.Brdy,
  3990. Gend: res.Output.Baseinfo.Gend,
  3991. Naty: res.Output.Baseinfo.Naty,
  3992. PsnCertType: res.Output.Baseinfo.PsnCertType,
  3993. PsnName: res.Output.Baseinfo.PsnName,
  3994. Idetinfo: idetinfoStr,
  3995. Insuinfo: infoStr,
  3996. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3997. CardInfo: "",
  3998. VerifyNumber: token,
  3999. }
  4000. service.CreateHisPsn(psn)
  4001. c.ServeSuccessJSON(map[string]interface{}{
  4002. "patient": patient,
  4003. "number": token,
  4004. "info": res,
  4005. "insutype": insutype,
  4006. })
  4007. }
  4008. } else {
  4009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  4010. return
  4011. }
  4012. }
  4013. break
  4014. }
  4015. }
  4016. func (c *ZHHisApiController) GetEleBaseInfoTwo() string {
  4017. DllDef := syscall.MustLoadDLL("SSCard.dll")
  4018. readCard := DllDef.MustFindProc("GetQRBase")
  4019. fmt.Println(readCard)
  4020. if readCard == nil {
  4021. fmt.Println("readcard is nil")
  4022. readCard = DllDef.MustFindProc("GetQRBase")
  4023. }
  4024. str := make([]byte, 1024)
  4025. str1 := make([]byte, 1024)
  4026. ret2, _, _ := readCard.Call(uintptr(180), (uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
  4027. fmt.Println(ret2)
  4028. fmt.Println(string(str1))
  4029. fmt.Println(string(str))
  4030. fmt.Println(":", ConvertToString(string(str1), "gbk", "utf-8"))
  4031. fmt.Println(":", ConvertToString(string(str), "gbk", "utf-8"))
  4032. if ret2 != 0 {
  4033. return ""
  4034. }
  4035. return string(str)
  4036. }
  4037. func (c *ZHHisApiController) TestGetBasBaseInitTwo() {
  4038. DllDef := syscall.MustLoadDLL("SSCard.dll")
  4039. Iinit := DllDef.MustFindProc("Init")
  4040. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4041. ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_api/prd/api/card/initDll"), StrPtr(miConfig.MdtrtareaAdmvs))
  4042. if ret != 0 {
  4043. fmt.Println("SSCard的报错原因:", err)
  4044. fmt.Println("SSCard的运算结果为:", ret)
  4045. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  4046. return
  4047. }
  4048. result := int(ret)
  4049. fmt.Println("SSCard的运算结果为1:", result)
  4050. initFlagTwo = 1
  4051. return
  4052. }
  4053. func (c *ZHHisApiController) GetBasBaseInfoTwo() string {
  4054. DllDef := syscall.MustLoadDLL("SSCard.dll")
  4055. readCard := DllDef.MustFindProc("ReadCardBas")
  4056. if readCard == nil {
  4057. fmt.Println("readcard is nil")
  4058. readCard = DllDef.MustFindProc("ReadCardBas")
  4059. }
  4060. str := make([]byte, 1024)
  4061. str1 := make([]byte, 1024)
  4062. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), uintptr(1024), (uintptr)(unsafe.Pointer(&str1[0])), uintptr(1024))
  4063. fmt.Println(string(str1))
  4064. fmt.Println(string(str))
  4065. fmt.Println(":", ConvertToString(string(str1), "gbk", "utf-8"))
  4066. fmt.Println(":", ConvertToString(string(str), "gbk", "utf-8"))
  4067. if ret2 != 0 {
  4068. return ""
  4069. }
  4070. return string(str)
  4071. }
  4072. var initFlag int64 = 0
  4073. func (c *ZHHisApiController) TestGetBasBaseInit() {
  4074. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  4075. Iinit := DllDef.MustFindProc("Init")
  4076. //miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  4077. str := make([]byte, 2048)
  4078. inputData := make(map[string]interface{})
  4079. inputData["IP"] = "10.144.211.75"
  4080. inputData["PORT"] = 7021
  4081. inputData["TIMEOUT"] = 180
  4082. inputData["LOG_PATH"] = "C:\\log\\"
  4083. //inputData["SFZ_DRIVER_TYPE"] = 0
  4084. inputData["URL"] = "/call1"
  4085. bytesData, _ := json.Marshal(inputData)
  4086. fmt.Println(inputData)
  4087. fmt.Println(bytesData)
  4088. ret, _, err := Iinit.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&str[0])))
  4089. if ret != 0 {
  4090. fmt.Println("SSCard的报错原因:", err)
  4091. fmt.Println("SSCard的运算结果为:", ret)
  4092. fmt.Println("SSCard的返回结果为:", string(str))
  4093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  4094. return
  4095. }
  4096. fmt.Println("SSCard的返回结果为:", string(str))
  4097. result := int(ret)
  4098. fmt.Println("SSCard的运算结果为1:", result)
  4099. //initFlag = 1
  4100. return
  4101. }
  4102. func (c *ZHHisApiController) GetSFZBaseInfo() string {
  4103. DllDef := syscall.MustLoadDLL("SSCard.dll")
  4104. readCard := DllDef.MustFindProc("ReadSFZ")
  4105. if readCard == nil {
  4106. fmt.Println("readcard is nil")
  4107. readCard = DllDef.MustFindProc("ReadSFZ")
  4108. }
  4109. str := make([]byte, 256)
  4110. str1 := make([]byte, 256)
  4111. r, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  4112. fmt.Println(r)
  4113. return string(str)
  4114. }
  4115. func (c *ZHHisApiController) GetBasBaseInfo(fixmedins_code string, mdtrtarea_admvs string, opter_name string, opter_id string, fixmedins_name string) string {
  4116. DllDef := syscall.MustLoadDLL("HeaSecReadInfo.dll")
  4117. readCard := DllDef.MustFindProc("ReadCardBas")
  4118. fmt.Println(readCard)
  4119. fmt.Println("!!!!!")
  4120. month := time.Unix(1557042972, 0).Format("1")
  4121. year := time.Now().Format("2006")
  4122. month = time.Now().Format("01")
  4123. day := time.Now().Format("02")
  4124. hour := time.Now().Format("15")
  4125. min := time.Now().Format("04")
  4126. sec := time.Now().Format("05")
  4127. msec := time.Now().Format("000")
  4128. timestamp := time.Now().Unix()
  4129. tempTime := time.Unix(timestamp, 0)
  4130. //timeFormat := tempTime.Format("20060102150405")
  4131. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  4132. //randNum := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(10000)
  4133. inputData := make(map[string]interface{})
  4134. inputData["infno"] = "1199"
  4135. //inputData["msgid"] = "7021"
  4136. inputData["msgid"] = fixmedins_code + year + month + day + hour + min + sec + msec + "0" // 发送方报文 ID
  4137. inputData["mdtrtarea_admvs"] = mdtrtarea_admvs // 发送方报文 ID
  4138. inputData["recer_sys_code"] = "01"
  4139. inputData["infver"] = "V1.0"
  4140. inputData["opter_type"] = "1"
  4141. inputData["opter"] = opter_id
  4142. inputData["opter_name"] = opter_name
  4143. inputData["inf_time"] = timeFormatOne
  4144. inputData["fixmedins_code"] = fixmedins_code
  4145. inputData["fixmedins_name"] = fixmedins_name
  4146. inputData["dev_no"] = ""
  4147. inputData["dev_safe_info"] = ""
  4148. inputData["cainfo"] = ""
  4149. inputData["signtype"] = ""
  4150. inputData["sign_no"] = ""
  4151. bytesData, _ := json.Marshal(inputData)
  4152. fmt.Println(string(bytesData))
  4153. pBusiCardInfo := make([]byte, 8192)
  4154. ret2, _, _ := readCard.Call((uintptr)(unsafe.Pointer(&bytesData[0])), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  4155. fmt.Println(ret2)
  4156. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  4157. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  4158. if ret2 != 0 {
  4159. return ""
  4160. }
  4161. return DeleteExtraSpace(string(pBusiCardInfo))
  4162. }
  4163. func DeleteExtraSpace(s string) string {
  4164. //删除字符串中的多余空格,有多个空格时,仅保留一个空格
  4165. s1 := strings.Replace(s, " ", " ", -1) //替换tab为空格
  4166. regstr := "\\s{2,}" //两个及两个以上空格的正则表达式
  4167. reg, _ := regexp.Compile(regstr) //编译正则表达式
  4168. s2 := make([]byte, len(s1)) //定义字符数组切片
  4169. copy(s2, s1) //将字符串复制到切片
  4170. spc_index := reg.FindStringIndex(string(s2)) //在字符串中搜索
  4171. for len(spc_index) > 0 { //找到适配项
  4172. s2 = append(s2[:spc_index[0]+1], s2[spc_index[1]:]...) //删除多余空格
  4173. spc_index = reg.FindStringIndex(string(s2)) //继续在字符串中搜索
  4174. }
  4175. return string(s2)
  4176. }
  4177. func (c *ZHHisApiController) GetELeInfo(code string, operator_id string, operator_name string) (string, string) {
  4178. DllDef := syscall.MustLoadDLL("NationECCode.dll")
  4179. readCard := DllDef.MustFindProc("NationEcTrans")
  4180. fmt.Println(readCard)
  4181. fmt.Println("!!!!!")
  4182. pBusiCardInfo := make([]byte, 8192)
  4183. input := make(map[string]interface{})
  4184. inputData := make(map[string]interface{})
  4185. inputData["orgId"] = code
  4186. inputData["businessType"] = "01101"
  4187. inputData["operatorId"] = operator_id
  4188. inputData["operatorName"] = operator_name
  4189. inputData["officeId"] = "001"
  4190. inputData["officeName"] = "血透室"
  4191. inputData["deviceType"] = ""
  4192. input["data"] = inputData
  4193. input["orgId"] = code
  4194. input["transType"] = "ec.query"
  4195. bytesData, _ := json.Marshal(input)
  4196. gdyb_url := beego.AppConfig.String("gdyb_url")
  4197. url := gdyb_url + "/localcfc/api/hsecfc/localQrCodeQuery"
  4198. ret2, _, _ := readCard.Call(StrPtr(url), StrPtr(string(bytesData)), (uintptr)(unsafe.Pointer(&pBusiCardInfo[0])))
  4199. fmt.Println(ret2)
  4200. fmt.Println(DeleteExtraSpace(string(pBusiCardInfo)))
  4201. fmt.Println(":", ConvertToString(DeleteExtraSpace(string(pBusiCardInfo)), "gbk", "utf-8"))
  4202. if ret2 != 0 {
  4203. return "", ""
  4204. }
  4205. return DeleteExtraSpace(""), DeleteExtraSpace(string(pBusiCardInfo))
  4206. }
  4207. func StrPtr(s string) uintptr {
  4208. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  4209. }
  4210. func Remove0000(s string) string {
  4211. str := make([]rune, 0, len(s))
  4212. for _, v := range []rune(s) {
  4213. if v == 0 {
  4214. continue
  4215. }
  4216. str = append(str, v)
  4217. }
  4218. return string(str)
  4219. }
  4220. func IntPtr(n int) uintptr {
  4221. return uintptr(n)
  4222. }