his_api_controller.go 101KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830
  1. package controllers
  2. import (
  3. "archive/zip"
  4. "bytes"
  5. "encoding/json"
  6. "fmt"
  7. "gdyb/enums"
  8. "gdyb/models"
  9. "gdyb/service"
  10. "gdyb/utils"
  11. "github.com/astaxie/beego"
  12. "github.com/jinzhu/gorm"
  13. "github.com/shopspring/decimal"
  14. "io"
  15. "io/ioutil"
  16. "math/rand"
  17. "net/http"
  18. "os"
  19. "path/filepath"
  20. "strconv"
  21. "strings"
  22. "syscall"
  23. "time"
  24. "unsafe"
  25. )
  26. type HisApiController struct {
  27. BaseAuthAPIController
  28. }
  29. func HisManagerApiRegistRouters() {
  30. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  31. beego.Router("/api/diag/upload", &HisApiController{}, "get:GetUploadDiag")
  32. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  33. beego.Router("/api/settle/get", &HisApiController{}, "get:GetSettleInfo")
  34. //beego.Router("/api/upload/get", &HisApiController{}, "get:Sel")
  35. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  36. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  37. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  38. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  39. beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  40. beego.Router("/api/refundnumber/post", &HisApiController{}, "get:RefundNumber")
  41. beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail")
  42. beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
  43. beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
  44. beego.Router("/api/patient/info", &HisApiController{}, "get:GetHisPatientInfo")
  45. beego.Router("/api/org/info", &HisApiController{}, "get:GetOrgInfo")
  46. }
  47. func (c *HisApiController) GetOrgInfo() {
  48. miConfig, _ := service.FindMedicalInsuranceInfo(9919)
  49. service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
  50. }
  51. func (c *HisApiController) GetHisPatientInfo() {
  52. medical_insurance_card := c.GetString("medical_insurance_card")
  53. id_card_type, _ := c.GetInt64("id_card_type")
  54. id_card := c.GetString("id_card")
  55. adminInfo := c.GetAdminUserInfo()
  56. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  57. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  58. appRole, _ := service.GetAppRole(adminInfo.CurrentOrgId)
  59. IdCardNo := ""
  60. if id_card_type == 1 {
  61. IdCardNo = medical_insurance_card
  62. } else if id_card_type == 2 {
  63. IdCardNo = id_card
  64. }
  65. if config.IsOpen == 1 {
  66. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  67. resp, requestErr := http.Get(api)
  68. if requestErr != nil {
  69. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  70. return
  71. }
  72. defer resp.Body.Close()
  73. body, ioErr := ioutil.ReadAll(resp.Body)
  74. if ioErr != nil {
  75. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  76. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  77. return
  78. }
  79. var respJSON map[string]interface{}
  80. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  81. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  82. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  83. return
  84. }
  85. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  86. userJSONBytes, _ := json.Marshal(userJSON)
  87. var res ResultTwo
  88. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  89. utils.ErrorLog("解析失败:%v", err)
  90. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  91. return
  92. }
  93. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  94. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  95. infoStr := string(Iinfos)
  96. idetinfoStr := string(Idetinfos)
  97. if res.Infcode == 0 {
  98. his := models.VMHisPatient{
  99. Status: 1,
  100. Ctime: time.Now().Unix(),
  101. Mtime: time.Now().Unix(),
  102. PsnNo: res.Output.Baseinfo.PsnNo,
  103. PsnCertType: res.Output.Baseinfo.PsnCertType,
  104. Certno: res.Output.Baseinfo.Certno,
  105. PsnName: res.Output.Baseinfo.PsnName,
  106. Gend: res.Output.Baseinfo.Gend,
  107. Naty: res.Output.Baseinfo.Naty,
  108. Brdy: res.Output.Baseinfo.Brdy,
  109. Age: res.Output.Baseinfo.Age,
  110. Iinfo: infoStr,
  111. Idetinfo: idetinfoStr,
  112. UserOrgId: adminInfo.CurrentOrgId,
  113. IsReturn: 1,
  114. IdCardType: id_card_type,
  115. }
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "info": his,
  118. })
  119. } else {
  120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  121. return
  122. }
  123. }
  124. }
  125. func (c *HisApiController) Sscard() {
  126. id_card_type, _ := c.GetInt64("id_card_type")
  127. adminUser := c.GetAdminUserInfo()
  128. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  129. r := CardInit()
  130. fmt.Println(r)
  131. //if r == 0 {
  132. switch id_card_type {
  133. case 1:
  134. basStr, err := GetBasBaseInfo()
  135. if err != nil {
  136. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  137. return
  138. } else {
  139. fmt.Println(basStr)
  140. bas := strings.Split(basStr, "|")
  141. basNumber := bas[1]
  142. //basNumber := bas[2]
  143. card_sn := bas[3]
  144. appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  145. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + basNumber + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10) + "&card_sn=" + card_sn
  146. resp, requestErr := http.Get(api)
  147. if requestErr != nil {
  148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  149. return
  150. }
  151. defer resp.Body.Close()
  152. body, ioErr := ioutil.ReadAll(resp.Body)
  153. if ioErr != nil {
  154. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  156. return
  157. }
  158. var respJSON map[string]interface{}
  159. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  160. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  162. return
  163. }
  164. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  165. userJSONBytes, _ := json.Marshal(userJSON)
  166. var res ResultTwo
  167. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  168. utils.ErrorLog("解析失败:%v", err)
  169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  170. return
  171. }
  172. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  173. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  174. infoStr := string(Iinfos)
  175. idetinfoStr := string(Idetinfos)
  176. if res.Infcode == 0 {
  177. his := models.VMHisPatient{
  178. Status: 1,
  179. Ctime: time.Now().Unix(),
  180. Mtime: time.Now().Unix(),
  181. PsnNo: res.Output.Baseinfo.PsnNo,
  182. PsnCertType: res.Output.Baseinfo.PsnCertType,
  183. Certno: res.Output.Baseinfo.Certno,
  184. PsnName: res.Output.Baseinfo.PsnName,
  185. Gend: res.Output.Baseinfo.Gend,
  186. Naty: res.Output.Baseinfo.Naty,
  187. Brdy: res.Output.Baseinfo.Brdy,
  188. Age: res.Output.Baseinfo.Age,
  189. Iinfo: infoStr,
  190. Idetinfo: idetinfoStr,
  191. UserOrgId: adminUser.CurrentOrgId,
  192. IsReturn: 1,
  193. IdCardType: id_card_type,
  194. }
  195. patient, err := service.GetPatientByNumber(basNumber, adminUser.CurrentOrgId)
  196. if err == gorm.ErrRecordNotFound {
  197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  198. return
  199. } else if err != nil {
  200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  201. return
  202. } else {
  203. c.ServeSuccessJSON(map[string]interface{}{
  204. "patient": patient,
  205. "his": his,
  206. "number": basNumber,
  207. })
  208. }
  209. } else {
  210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  211. return
  212. }
  213. }
  214. break
  215. case 2:
  216. ////SFZStr, err := GetSFZBaseInfo()
  217. //if err != nil {
  218. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  219. // return
  220. //
  221. //} else {
  222. //
  223. // id_card_str := strings.Split(SFZStr, "^")
  224. // id_card_number := id_card_str[0]
  225. //appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  226. //
  227. //api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + id_card_number + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
  228. //resp, requestErr := http.Get(api)
  229. //if requestErr != nil {
  230. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  231. // return
  232. //}
  233. //defer resp.Body.Close()
  234. //body, ioErr := ioutil.ReadAll(resp.Body)
  235. //if ioErr != nil {
  236. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  237. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  238. // return
  239. //}
  240. //var respJSON map[string]interface{}
  241. //
  242. //if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  243. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  244. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  245. // return
  246. //}
  247. //
  248. //userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  249. //userJSONBytes, _ := json.Marshal(userJSON)
  250. //var res ResultTwo
  251. //if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  252. // utils.ErrorLog("解析失败:%v", err)
  253. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  254. // return
  255. //}
  256. //Iinfos, _ := json.Marshal(res.Output.Iinfo)
  257. //Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  258. //infoStr := string(Iinfos)
  259. //idetinfoStr := string(Idetinfos)
  260. //
  261. //if res.Infcode == 0 {
  262. // his := models.VMHisPatient{
  263. // Status: 1,
  264. // Ctime: time.Now().Unix(),
  265. // Mtime: time.Now().Unix(),
  266. // PsnNo: res.Output.Baseinfo.PsnNo,
  267. // PsnCertType: res.Output.Baseinfo.PsnCertType,
  268. // Certno: res.Output.Baseinfo.Certno,
  269. // PsnName: res.Output.Baseinfo.PsnName,
  270. // Gend: res.Output.Baseinfo.Gend,
  271. // Naty: res.Output.Baseinfo.Naty,
  272. // Brdy: res.Output.Baseinfo.Brdy,
  273. // Age: res.Output.Baseinfo.Age,
  274. // Iinfo: infoStr,
  275. // Idetinfo: idetinfoStr,
  276. // UserOrgId: adminUser.CurrentOrgId,
  277. // IsReturn: 1,
  278. // IdCardType: id_card_type,
  279. // }
  280. // patient, err := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  281. // if err == gorm.ErrRecordNotFound {
  282. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  283. // return
  284. //
  285. // } else if err != nil {
  286. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  287. // return
  288. //
  289. // } else {
  290. // c.ServeSuccessJSON(map[string]interface{}{
  291. // "patient": patient,
  292. // "number": id_card_number,
  293. // })
  294. // }
  295. //}
  296. break
  297. case 3:
  298. break
  299. }
  300. }
  301. func GetBasBaseInfo() (jsonStr string, err error) {
  302. handle := syscall.MustLoadDLL("SSCard.dll")
  303. ReadCardBas := handle.MustFindProc("ReadCardBas")
  304. str := make([]byte, 256)
  305. str1 := make([]byte, 256)
  306. r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  307. fmt.Println(r)
  308. fmt.Println(string(str))
  309. return string(str), nil
  310. }
  311. //func GetSFZBaseInfo() (jsonStr string, err error) {
  312. // //handle := syscall.MustLoadDLL("SSCard.dll")
  313. //
  314. // str := make([]byte, 256)
  315. // str1 := make([]byte, 256)
  316. // r, _, _ := ReadIDCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  317. //
  318. // fmt.Println(r)
  319. // return string(str), nil
  320. //}
  321. //func GetQRBaseInfo() (jsonStr string, err error) {
  322. // handle := syscall.LoadDLL("SSCard.dll")
  323. // ReadCardBas := handle.FindProc("GetQRBase")
  324. //
  325. // str := make([]byte, 256)
  326. // str1 := make([]byte, 256)
  327. // r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  328. //
  329. // fmt.Println(string(str))
  330. // fmt.Println(r)
  331. // return string(str), nil
  332. //}
  333. func CardInit() int {
  334. DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  335. add := DllTestDef.MustFindProc("Init")
  336. ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  337. if err != nil {
  338. fmt.Println("SSCard的运算结果为:", ret)
  339. }
  340. result := int(ret)
  341. return result
  342. }
  343. //func CardInit() int {
  344. // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  345. // if err != nil {
  346. // fmt.Println("SSCard的运算结果为:", ret)
  347. // }
  348. // fmt.Println(err)
  349. // result := int(ret)
  350. // return result
  351. //}
  352. func IntPtr(n int) uintptr {
  353. return uintptr(n)
  354. }
  355. func StrPtr(s string) uintptr {
  356. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  357. }
  358. type ResultTwo struct {
  359. ErrMsg string `json:"err_msg"`
  360. InfRefmsgid string `json:"inf_refmsgid"`
  361. Infcode int64 `json:"infcode"`
  362. Output struct {
  363. Baseinfo struct {
  364. Age float64 `json:"age"`
  365. Brdy string `json:"brdy"`
  366. Certno string `json:"certno"`
  367. Gend string `json:"gend"`
  368. Naty string `json:"naty"`
  369. PsnCertType string `json:"psn_cert_type"`
  370. PsnName string `json:"psn_name"`
  371. PsnNo string `json:"psn_no"`
  372. } `json:"baseinfo"`
  373. Idetinfo []interface{} `json:"idetinfo"`
  374. Iinfo []struct {
  375. Balc int64 `json:"balc"`
  376. CvlservFlag string `json:"cvlserv_flag"`
  377. EmpName string `json:"emp_name"`
  378. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  379. Insutype string `json:"insutype"`
  380. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  381. PausInsuDate interface{} `json:"paus_insu_date"`
  382. PsnInsuDate string `json:"psn_insu_date"`
  383. PsnInsuStas string `json:"psn_insu_stas"`
  384. PsnType string `json:"psn_type"`
  385. } `json:"insuinfo"`
  386. } `json:"output"`
  387. RefmsgTime string `json:"refmsg_time"`
  388. RespondTime string `json:"respond_time"`
  389. Signtype interface{} `json:"signtype"`
  390. WarnInfo interface{} `json:"warn_info"`
  391. }
  392. type ResultThree struct {
  393. Cainfo interface{} `json:"cainfo"`
  394. ErrMsg string `json:"err_msg"`
  395. InfRefmsgid string `json:"inf_refmsgid"`
  396. Infcode int64 `json:"infcode"`
  397. Output struct {
  398. Data struct {
  399. IptOtpNo string `json:"ipt_otp_no"`
  400. MdtrtID string `json:"mdtrt_id"`
  401. PsnNo string `json:"psn_no"`
  402. } `json:"data"`
  403. } `json:"output"`
  404. RefmsgTime string `json:"refmsg_time"`
  405. RespondTime string `json:"respond_time"`
  406. Signtype interface{} `json:"signtype"`
  407. WarnMsg interface{} `json:"warn_msg"`
  408. }
  409. type ResultFour struct {
  410. Cainfo string `json:"cainfo"`
  411. ErrMsg string `json:"err_msg"`
  412. InfRefmsgid string `json:"inf_refmsgid"`
  413. Infcode int64 `json:"infcode"`
  414. Output struct {
  415. Result []struct {
  416. BasMednFlag string `json:"bas_medn_flag"`
  417. ChldMedcFlag string `json:"chld_medc_flag"`
  418. ChrgitmLv string `json:"chrgitm_lv"`
  419. Cnt float64 `json:"cnt"`
  420. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  421. DrtReimFlag string `json:"drt_reim_flag"`
  422. FeedetlSn string `json:"feedetl_sn"`
  423. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  424. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  425. InscpScpAmt float64 `json:"inscp_scp_amt"`
  426. ListSpItemFlag string `json:"list_sp_item_flag"`
  427. LmtUsedFlag string `json:"lmt_used_flag"`
  428. MedChrgitmType string `json:"med_chrgitm_type"`
  429. Memo string `json:"memo"`
  430. OverlmtAmt float64 `json:"overlmt_amt"`
  431. PreselfpayAmt float64 `json:"preselfpay_amt"`
  432. Pric float64 `json:"pric"`
  433. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  434. SelfpayProp float64 `json:"selfpay_prop"`
  435. } `json:"result"`
  436. } `json:"output"`
  437. RefmsgTime string `json:"refmsg_time"`
  438. RespondTime string `json:"respond_time"`
  439. Signtype string `json:"signtype"`
  440. WarnMsg string `json:"warn_msg"`
  441. }
  442. type ResultFive struct {
  443. Insutype string `json:"insutype"`
  444. }
  445. type ResultSix struct {
  446. Cainfo interface{} `json:"cainfo"`
  447. ErrMsg string `json:"err_msg"`
  448. InfRefmsgid string `json:"inf_refmsgid"`
  449. Infcode int64 `json:"infcode"`
  450. Output struct {
  451. } `json:"output"`
  452. RefmsgTime string `json:"refmsg_time"`
  453. RespondTime string `json:"respond_time"`
  454. Signtype interface{} `json:"signtype"`
  455. WarnMsg interface{} `json:"warn_msg"`
  456. }
  457. type ResultSeven struct {
  458. Cainfo string `json:"cainfo"`
  459. ErrMsg string `json:"err_msg"`
  460. InfRefmsgid string `json:"inf_refmsgid"`
  461. Infcode int64 `json:"infcode"`
  462. Output struct {
  463. Setldetail []interface{} `json:"setldetail"`
  464. Setlinfo struct {
  465. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  466. AcctPay float64 `json:"acct_pay"`
  467. ActPayDedc float64 `json:"act_pay_dedc"`
  468. Age float64 `json:"age"`
  469. Balc float64 `json:"balc"`
  470. Brdy string `json:"brdy"`
  471. Certno string `json:"certno"`
  472. ClrOptins string `json:"clr_optins"`
  473. ClrType string `json:"clr_type"`
  474. ClrWay string `json:"clr_way"`
  475. CvlservFlag string `json:"cvlserv_flag"`
  476. CvlservPay float64 `json:"cvlserv_pay"`
  477. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  478. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  479. Gend string `json:"gend"`
  480. HifesPay float64 `json:"hifes_pay"`
  481. HifmiPay float64 `json:"hifmi_pay"`
  482. HifpPay float64 `json:"hifp_pay"`
  483. HospPartAmt float64 `json:"hosp_part_amt"`
  484. InscpScpAmt float64 `json:"inscp_scp_amt"`
  485. Insutype string `json:"insutype"`
  486. MafPay float64 `json:"maf_pay"`
  487. MdtrtCertType string `json:"mdtrt_cert_type"`
  488. HifobPay float64 `json:"hifob_pay"`
  489. MdtrtID string `json:"mdtrt_id"`
  490. MedType string `json:"med_type"`
  491. MedfeeSumamt float64 `json:"medfee_sumamt"`
  492. MedinsSetlID string `json:"medins_setl_id"`
  493. Naty string `json:"naty"`
  494. OthPay float64 `json:"oth_pay"`
  495. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  496. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  497. PreselfpayAmt float64 `json:"preselfpay_amt"`
  498. PsnCashPay float64 `json:"psn_cash_pay"`
  499. PsnCertType string `json:"psn_cert_type"`
  500. PsnName string `json:"psn_name"`
  501. PsnNo string `json:"psn_no"`
  502. PsnPartAmt float64 `json:"psn_part_amt"`
  503. PsnType string `json:"psn_type"`
  504. SetlID string `json:"setl_id"`
  505. SetlTime string `json:"setl_time"`
  506. } `json:"setlinfo"`
  507. } `json:"output"`
  508. RefmsgTime string `json:"refmsg_time"`
  509. RespondTime string `json:"respond_time"`
  510. Signtype interface{} `json:"signtype"`
  511. WarnMsg interface{} `json:"warn_msg"`
  512. }
  513. type ResultEight struct {
  514. Cainfo string `json:"cainfo"`
  515. ErrMsg string `json:"err_msg"`
  516. InfRefmsgid string `json:"inf_refmsgid"`
  517. Infcode int64 `json:"infcode"`
  518. Output struct {
  519. Stmtinfo struct {
  520. SetlOptins string `json:"setl_optins"`
  521. StmtRslt string `json:"stmt_rslt"`
  522. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  523. } `json:"stmtinfo"`
  524. } `json:"output"`
  525. RefmsgTime string `json:"refmsg_time"`
  526. RespondTime string `json:"respond_time"`
  527. Signtype interface{} `json:"signtype"`
  528. WarnMsg interface{} `json:"warn_msg"`
  529. }
  530. type ResultNine struct {
  531. Cainfo string `json:"cainfo"`
  532. ErrMsg string `json:"err_msg"`
  533. InfRefmsgid string `json:"inf_refmsgid"`
  534. Infcode int64 `json:"infcode"`
  535. Output struct {
  536. FileQuryNo string `json:"file_qury_no"`
  537. } `json:"output"`
  538. RefmsgTime string `json:"refmsg_time"`
  539. RespondTime string `json:"respond_time"`
  540. Signtype interface{} `json:"signtype"`
  541. WarnMsg interface{} `json:"warn_msg"`
  542. }
  543. type ResultTen struct {
  544. Cainfo string `json:"cainfo"`
  545. ErrMsg string `json:"err_msg"`
  546. InfRefmsgid string `json:"inf_refmsgid"`
  547. Infcode int64 `json:"infcode"`
  548. Output struct {
  549. DldEndtime string `json:"dld_endtime"`
  550. FileQuryNo string `json:"file_qury_no"`
  551. Filename string `json:"filename"`
  552. } `json:"output"`
  553. RefmsgTime string `json:"refmsg_time"`
  554. RespondTime string `json:"respond_time"`
  555. Signtype interface{} `json:"signtype"`
  556. WarnMsg interface{} `json:"warn_msg"`
  557. }
  558. type ResultEleven struct {
  559. Cainfo string `json:"cainfo"`
  560. ErrMsg string `json:"err_msg"`
  561. InfRefmsgid string `json:"inf_refmsgid"`
  562. Infcode int64 `json:"infcode"`
  563. Output struct {
  564. Setlinfo struct {
  565. FixmedinsName string `json:"fixmedins_name"`
  566. FixmedinsCode string `json:"fixmedins_code"`
  567. PsnNo string `json:"psn_no"`
  568. PsnName string `json:"psn_name"`
  569. HifobPay float64 `json:"hifob_pay"`
  570. Gend string `json:"gend"`
  571. Brdy string `json:"brdy"`
  572. PsnCertType string `json:"psn_cert_type"`
  573. PsnType string `json:"psn_type"`
  574. EmpName string `json:"emp_name"`
  575. Certno string `json:"certno"`
  576. Insutype string `json:"insutype"`
  577. MedfeeSumamt float64 `json:"medfee_sumamt"`
  578. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  579. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  580. PreselfpayAmt float64 `json:"preselfpay_amt"`
  581. InscpScpAmt float64 `json:"inscp_scp_amt"`
  582. ActPayDedc float64 `json:"act_pay_dedc"`
  583. HifpPay float64 `json:"hifp_pay"`
  584. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  585. CvlservPay float64 `json:"cvlserv_pay"`
  586. HifesPay float64 `json:"hifes_pay"`
  587. HifmiPay float64 `json:"hifmi_pay"`
  588. MafPay float64 `json:"maf_pay"`
  589. OthPay float64 `json:"oth_pay"`
  590. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  591. PsnPay float64 `json:"psn_pay"`
  592. AcctPay float64 `json:"acct_pay"`
  593. CashPayamt float64 `json:"cash_payamt"`
  594. Balc float64 `json:"balc"`
  595. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  596. MedinsSetlId string `json:"medins_setl_id"`
  597. RefdSetlFlag string `json:"refd_setl_flag"`
  598. SetlTime string `json:"setl_time"`
  599. MedType string `json:"med_type"`
  600. HospLv string `json:"hosp_lv"`
  601. } `json:"setlinfo"`
  602. } `json:"output"`
  603. RefmsgTime string `json:"refmsg_time"`
  604. RespondTime string `json:"respond_time"`
  605. Signtype interface{} `json:"signtype"`
  606. WarnMsg interface{} `json:"warn_msg"`
  607. }
  608. type ResultTwelve struct {
  609. Cainfo string `json:"cainfo"`
  610. ErrMsg string `json:"err_msg"`
  611. InfRefmsgid string `json:"inf_refmsgid"`
  612. Infcode int64 `json:"infcode"`
  613. Output struct {
  614. MdtrtId string `json:"mdtrt_id"`
  615. ChrgBchno string `json:"chrg_bchno"`
  616. PsnNo string `json:"psn_no"`
  617. } `json:"output"`
  618. RefmsgTime string `json:"refmsg_time"`
  619. RespondTime string `json:"respond_time"`
  620. Signtype interface{} `json:"signtype"`
  621. WarnMsg interface{} `json:"warn_msg"`
  622. }
  623. type Custom struct {
  624. DetItemFeeSumamt string
  625. Cut string
  626. FeedetlSn string
  627. Price string
  628. MedListCodg string
  629. Type int64
  630. AdviceId int64
  631. ProjectId int64
  632. ItemId int64
  633. }
  634. //获取个人信息----挂号-----上传就诊信息
  635. func (c *HisApiController) GetRegisterInfo() {
  636. id, _ := c.GetInt64("id")
  637. record_time := c.GetString("record_time")
  638. settlementValue, _ := c.GetInt64("settlement_value")
  639. medical_insurance_card := c.GetString("medical_insurance_card")
  640. name := c.GetString("name")
  641. id_card_type, _ := c.GetInt64("id_card_type")
  642. certificates, _ := c.GetInt64("certificates")
  643. medical_care, _ := c.GetInt64("medical_care")
  644. birthday := c.GetString("birthday")
  645. age, _ := c.GetInt64("age")
  646. id_card := c.GetString("id_card")
  647. register_type, _ := c.GetInt64("register")
  648. doctor, _ := c.GetInt64("doctor")
  649. department, _ := c.GetInt64("department")
  650. gender, _ := c.GetInt64("sex")
  651. phone := c.GetString("phone")
  652. registration_fee, _ := c.GetFloat("registration_fee")
  653. medical_expenses, _ := c.GetFloat("medical_expenses")
  654. social_type, _ := c.GetInt64("social_type")
  655. admin_user_id, _ := c.GetInt64("admin_user_id")
  656. diagnosis_id, _ := c.GetInt64("diagnosis")
  657. sick_type, _ := c.GetInt64("sick_type")
  658. reg_type := c.GetString("p_type")
  659. timeLayout := "2006-01-02"
  660. loc, _ := time.LoadLocation("Local")
  661. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  662. birthUnix := birthdays.Unix()
  663. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  664. if err != nil {
  665. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  666. return
  667. }
  668. recordDateTime := theTime.Unix()
  669. adminInfo := c.GetAdminUserInfo()
  670. var patient service.Patients
  671. if id == 0 {
  672. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  673. } else {
  674. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  675. }
  676. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  677. if patientPrescription.ID == 0 {
  678. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  679. }
  680. //adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  681. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  682. sickConfig, _ := service.FindSickById(sick_type)
  683. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  684. if patient.ID == 0 {
  685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  686. return
  687. }
  688. if len(patient.IdCardNo) == 0 {
  689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  690. return
  691. }
  692. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  693. if config.IsOpen == 1 {
  694. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  695. resp, requestErr := http.Get(api)
  696. if requestErr != nil {
  697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  698. return
  699. }
  700. defer resp.Body.Close()
  701. body, ioErr := ioutil.ReadAll(resp.Body)
  702. if ioErr != nil {
  703. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  704. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  705. return
  706. }
  707. var respJSON map[string]interface{}
  708. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  709. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  711. return
  712. }
  713. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  714. userJSONBytes, _ := json.Marshal(userJSON)
  715. var res ResultTwo
  716. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  717. utils.ErrorLog("解析失败:%v", err)
  718. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  719. return
  720. }
  721. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  722. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  723. infoStr := string(Iinfos)
  724. idetinfoStr := string(Idetinfos)
  725. if res.Infcode == 0 {
  726. his := models.VMHisPatient{
  727. Name: name,
  728. Gender: gender,
  729. Birthday: birthUnix,
  730. MedicalTreatmentType: medical_care,
  731. IdType: certificates,
  732. IdCardNo: id_card,
  733. BalanceAccountsType: settlementValue,
  734. SocialType: social_type,
  735. MedicalInsuranceNumber: medical_insurance_card,
  736. RegisterType: register_type,
  737. RegisterCost: registration_fee,
  738. TreatmentCost: medical_expenses,
  739. Status: 1,
  740. Ctime: time.Now().Unix(),
  741. Mtime: time.Now().Unix(),
  742. PsnNo: res.Output.Baseinfo.PsnNo,
  743. PsnCertType: res.Output.Baseinfo.PsnCertType,
  744. Certno: res.Output.Baseinfo.Certno,
  745. PsnName: res.Output.Baseinfo.PsnName,
  746. Gend: res.Output.Baseinfo.Gend,
  747. Naty: res.Output.Baseinfo.Naty,
  748. Brdy: res.Output.Baseinfo.Brdy,
  749. Age: res.Output.Baseinfo.Age,
  750. Iinfo: infoStr,
  751. Idetinfo: idetinfoStr,
  752. PatientId: patient.ID,
  753. RecordDate: theTime.Unix(),
  754. UserOrgId: adminInfo.CurrentOrgId,
  755. AdminUserId: admin_user_id,
  756. IsReturn: 1,
  757. IdCardType: id_card_type,
  758. Doctor: doctor,
  759. Departments: department,
  760. }
  761. timestamp := time.Now().Unix()
  762. tempTime := time.Unix(timestamp, 0)
  763. timeFormat := tempTime.Format("20060102150405")
  764. chrgBchno := rand.Intn(100000) + 10000
  765. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  766. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  767. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  768. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  769. IdCardNo := ""
  770. if id_card_type == 1 {
  771. IdCardNo = medical_insurance_card
  772. } else {
  773. IdCardNo = patient.IdCardNo
  774. }
  775. if count <= 0 {
  776. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + IdCardNo + "&insutype=" +
  777. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  778. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  779. "&dept=" + department.Name + "&fixmedins_code=" + miConfig.Code + "&dept_code=" + department.Number + "&doctor_id=" + doctor_id + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10)
  780. resp, requestErr := http.Get(api)
  781. if requestErr != nil {
  782. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  783. return
  784. }
  785. defer resp.Body.Close()
  786. body, ioErr := ioutil.ReadAll(resp.Body)
  787. if ioErr != nil {
  788. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  790. return
  791. }
  792. var respJSON map[string]interface{}
  793. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  794. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  795. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  796. return
  797. }
  798. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  799. userJSONBytes, _ := json.Marshal(respJSON)
  800. var res ResultThree
  801. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  802. utils.ErrorLog("解析失败:%v", err)
  803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  804. return
  805. }
  806. if res.Infcode == -1 {
  807. adminUser := c.GetAdminUserInfo()
  808. errlog := &models.HisOrderError{
  809. UserOrgId: adminUser.CurrentOrgId,
  810. Ctime: time.Now().Unix(),
  811. Mtime: time.Now().Unix(),
  812. ErrMsg: res.ErrMsg,
  813. Status: 1,
  814. PatientId: id,
  815. RecordTime: recordDateTime,
  816. Stage: 2,
  817. }
  818. service.CreateErrMsgLog(errlog)
  819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  820. return
  821. }
  822. his.Number = res.Output.Data.MdtrtID
  823. his.PsnNo = res.Output.Data.PsnNo
  824. his.IptOtpNo = res.Output.Data.IptOtpNo
  825. his.IdCardNo = patient.IdCardNo
  826. his.PhoneNumber = patient.Phone
  827. his.UserOrgId = adminInfo.CurrentOrgId
  828. his.Ctime = time.Now().Unix()
  829. his.Mtime = time.Now().Unix()
  830. his.Status = 1
  831. err := service.CreateHisPatientTwo(&his)
  832. if err == nil {
  833. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  834. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  835. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + reg_type + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  836. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  837. resp2, requestErr2 := http.Get(api2)
  838. if requestErr2 != nil {
  839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  840. return
  841. }
  842. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  843. if ioErr2 != nil {
  844. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  845. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  846. return
  847. }
  848. var respJSON2 map[string]interface{}
  849. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  850. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  852. return
  853. }
  854. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  855. userJSONBytes2, _ := json.Marshal(respJSON2)
  856. var res2 ResultSix
  857. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  858. utils.ErrorLog("解析失败:%v", err)
  859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  860. return
  861. }
  862. if res2.Infcode == -1 {
  863. adminUser := c.GetAdminUserInfo()
  864. errlog := &models.HisOrderError{
  865. UserOrgId: adminUser.CurrentOrgId,
  866. Ctime: time.Now().Unix(),
  867. Mtime: time.Now().Unix(),
  868. ErrMsg: res2.ErrMsg,
  869. Status: 1,
  870. PatientId: id,
  871. RecordTime: recordDateTime,
  872. Stage: 3,
  873. }
  874. service.CreateErrMsgLog(errlog)
  875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  876. return
  877. }
  878. c.ServeSuccessJSON(map[string]interface{}{
  879. "his_info": his,
  880. })
  881. } else {
  882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  883. return
  884. }
  885. } else {
  886. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  887. return
  888. }
  889. } else {
  890. adminUser := c.GetAdminUserInfo()
  891. errlog := &models.HisOrderError{
  892. UserOrgId: adminUser.CurrentOrgId,
  893. Ctime: time.Now().Unix(),
  894. Mtime: time.Now().Unix(),
  895. ErrMsg: res.ErrMsg,
  896. Status: 1,
  897. PatientId: id,
  898. RecordTime: recordDateTime,
  899. Stage: 1,
  900. }
  901. service.CreateErrMsgLog(errlog)
  902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  903. return
  904. }
  905. } else {
  906. timeStr := time.Now().Format("2006-01-02")
  907. timeArr := strings.Split(timeStr, "-")
  908. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  909. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  910. var hisPatient models.XtHisPatient
  911. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  912. hisPatient = models.XtHisPatient{
  913. Name: name,
  914. Age: age,
  915. Gender: gender,
  916. Birthday: birthUnix,
  917. Phone: phone,
  918. MedicalTreatmentType: medical_care,
  919. IdType: certificates,
  920. IdCardNo: id_card,
  921. BalanceAccountsType: settlementValue,
  922. SocialType: social_type,
  923. MedicalInsuranceNumber: medical_insurance_card,
  924. RegisterType: register_type,
  925. RegisterCost: registration_fee,
  926. TreatmentCost: medical_expenses,
  927. AdminUserId: admin_user_id,
  928. UserOrgId: adminInfo.CurrentOrgId,
  929. Status: 1,
  930. RecordDate: recordDateTime,
  931. IsReturn: 1,
  932. PatientId: patient.ID,
  933. Ctime: time.Now().Unix(),
  934. Mtime: time.Now().Unix(),
  935. Number: str,
  936. }
  937. service.CreateHisPatient(&hisPatient)
  938. }
  939. c.ServeSuccessJSON(map[string]interface{}{
  940. "his_info": hisPatient,
  941. })
  942. }
  943. }
  944. //上传明细----结算
  945. func (c *HisApiController) GetUploadInfo() {
  946. id, _ := c.GetInt64("id")
  947. record_time := c.GetString("record_time")
  948. pay_way, _ := c.GetInt64("pay_way")
  949. pay_price, _ := c.GetFloat("pay_price")
  950. pay_card_no := c.GetString("pay_card_no")
  951. discount_price, _ := c.GetFloat("discount_price")
  952. preferential_price, _ := c.GetFloat("preferential_price")
  953. reality_price, _ := c.GetFloat("reality_price")
  954. found_price, _ := c.GetFloat("found_price")
  955. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  956. private_price, _ := c.GetFloat("private_price")
  957. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  958. admin_user_id, _ := c.GetInt64("admin_user_id")
  959. timeLayout := "2006-01-02"
  960. loc, _ := time.LoadLocation("Local")
  961. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  962. if err != nil {
  963. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  964. return
  965. }
  966. recordDateTime := theTime.Unix()
  967. adminUser := c.GetAdminUserInfo()
  968. var prescriptions []*models.HisPrescription
  969. var start_time int64
  970. var end_time int64
  971. data := make(map[string]interface{})
  972. if settle_accounts_type == 1 { //日结
  973. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  974. data["pre"] = prescriptions
  975. } else { //月结
  976. start_time_str := c.GetString("start_time")
  977. end_time_str := c.GetString("end_time")
  978. timeLayout := "2006-01-02"
  979. loc, _ := time.LoadLocation("Local")
  980. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  981. if err != nil {
  982. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  983. return
  984. }
  985. recordStartTime := theStartTime.Unix()
  986. start_time = recordStartTime
  987. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  988. if err != nil {
  989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  990. return
  991. }
  992. recordEndTime := theEndTime.Unix()
  993. end_time = recordEndTime
  994. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  995. data["pre"] = prescriptions
  996. }
  997. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  998. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  999. timestamp := time.Now().Unix()
  1000. tempTime := time.Unix(timestamp, 0)
  1001. timeFormat := tempTime.Format("20060102150405")
  1002. chrgBchno := rand.Intn(100000) + 10000
  1003. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1004. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1005. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1006. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1007. strconv.FormatInt(his.PatientId, 10)
  1008. client := &http.Client{}
  1009. data["psn_no"] = his.PsnNo
  1010. data["mdtrt_id"] = his.Number
  1011. data["chrg_bchno"] = chrg_bchno
  1012. data["org_name"] = miConfig.OrgName
  1013. data["doctor"] = roles.UserName
  1014. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1015. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1016. data["fixmedins_code"] = miConfig.Code
  1017. data["dept_code"] = department.Number
  1018. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1019. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1020. data["secret_key"] = miConfig.SecretKey
  1021. var ids []int64
  1022. for _, item := range prescriptions {
  1023. ids = append(ids, item.ID)
  1024. }
  1025. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1026. if config.IsOpen == 1 { //对接了医保,走医保流程
  1027. bytesData, _ := json.Marshal(data)
  1028. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1029. resp, _ := client.Do(req)
  1030. defer resp.Body.Close()
  1031. body, ioErr := ioutil.ReadAll(resp.Body)
  1032. if ioErr != nil {
  1033. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1034. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1035. return
  1036. }
  1037. var respJSON map[string]interface{}
  1038. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1039. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1040. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1041. return
  1042. }
  1043. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1044. userJSONBytes, _ := json.Marshal(respJSON)
  1045. var res ResultFour
  1046. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1047. utils.ErrorLog("解析失败:%v", err)
  1048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1049. return
  1050. }
  1051. if res.Infcode == 0 {
  1052. order := &models.HisOrder{
  1053. UserOrgId: adminUser.CurrentOrgId,
  1054. HisPatientId: his.ID,
  1055. PatientId: his.PatientId,
  1056. SettleAccountsDate: recordDateTime,
  1057. Ctime: time.Now().Unix(),
  1058. Mtime: time.Now().Unix(),
  1059. Status: 1,
  1060. Number: chrg_bchno,
  1061. Infcode: res.Infcode,
  1062. WarnMsg: res.WarnMsg,
  1063. Cainfo: res.Cainfo,
  1064. ErrMsg: res.ErrMsg,
  1065. RespondTime: res.RefmsgTime,
  1066. InfRefmsgid: res.InfRefmsgid,
  1067. OrderStatus: 1,
  1068. PayWay: pay_way,
  1069. PayPrice: pay_price,
  1070. PayCardNo: pay_card_no,
  1071. DiscountPrice: discount_price,
  1072. PreferentialPrice: preferential_price,
  1073. RealityPrice: reality_price,
  1074. FoundPrice: found_price,
  1075. MedicalInsurancePrice: medical_insurance_price,
  1076. PrivatePrice: private_price,
  1077. IsMedicineInsurance: 1,
  1078. SettleType: settle_accounts_type,
  1079. SettleStartTime: start_time,
  1080. SettleEndTime: end_time,
  1081. Creator: roles.ID,
  1082. Modify: roles.ID,
  1083. }
  1084. err = service.CreateOrder(order)
  1085. if err != nil {
  1086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1087. return
  1088. }
  1089. for _, item := range res.Output.Result {
  1090. temp := strings.Split(item.FeedetlSn, "-")
  1091. var advice_id int64 = 0
  1092. var project_id int64 = 0
  1093. var types int64 = 0
  1094. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1095. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1096. if temp[1] == "1" {
  1097. advice_id = id
  1098. project_id = 0
  1099. } else if temp[1] == "2" {
  1100. advice_id = 0
  1101. project_id = id
  1102. }
  1103. info := &models.HisOrderInfo{
  1104. OrderNumber: order.Number,
  1105. FeedetlSn: item.FeedetlSn,
  1106. UploadDate: time.Now().Unix(),
  1107. AdviceId: advice_id,
  1108. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1109. Cnt: item.Cnt,
  1110. Pric: float64(item.Pric),
  1111. PatientId: his.PatientId,
  1112. PricUplmtAmt: item.PricUplmtAmt,
  1113. SelfpayProp: item.SelfpayProp,
  1114. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1115. OverlmtAmt: item.OverlmtAmt,
  1116. PreselfpayAmt: item.PreselfpayAmt,
  1117. BasMednFlag: item.BasMednFlag,
  1118. MedChrgitmType: item.MedChrgitmType,
  1119. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1120. Status: 1,
  1121. Memo: item.Memo,
  1122. Mtime: time.Now().Unix(),
  1123. InscpScpAmt: item.InscpScpAmt,
  1124. DrtReimFlag: item.DrtReimFlag,
  1125. Ctime: time.Now().Unix(),
  1126. ListSpItemFlag: item.ListSpItemFlag,
  1127. ChldMedcFlag: item.ChldMedcFlag,
  1128. LmtUsedFlag: item.LmtUsedFlag,
  1129. ChrgitmLv: item.ChrgitmLv,
  1130. UserOrgId: adminUser.CurrentOrgId,
  1131. HisPatientId: his.ID,
  1132. OrderId: order.ID,
  1133. ProjectId: project_id,
  1134. Type: types,
  1135. }
  1136. service.CreateOrderInfo(info)
  1137. }
  1138. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1139. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1140. var total float64
  1141. for _, item := range prescriptions {
  1142. if item.Type == 1 { //药品
  1143. for _, subItem := range item.HisDoctorAdviceInfo {
  1144. total = total + (subItem.Price * subItem.PrescribingNumber)
  1145. }
  1146. }
  1147. if item.Type == 2 { //项目
  1148. for _, subItem := range item.HisPrescriptionProject {
  1149. total = total + (subItem.Price * float64(subItem.Count))
  1150. }
  1151. }
  1152. }
  1153. for _, item := range prescriptions {
  1154. for _, subItem := range item.HisAdditionalCharge {
  1155. total = total + (subItem.Price * float64(subItem.Count))
  1156. }
  1157. }
  1158. allTotal := fmt.Sprintf("%.2f", total)
  1159. if res.Infcode == 0 {
  1160. var rf []*ResultFive
  1161. json.Unmarshal([]byte(his.Iinfo), &rf)
  1162. psn_no := his.PsnNo
  1163. mdtrt_id := his.Number
  1164. chrg_bchno := chrg_bchno
  1165. cert_no := his.Certno
  1166. insutype := rf[0].Insutype
  1167. if his.IdCardType == 1 {
  1168. cert_no = his.MedicalInsuranceNumber
  1169. } else {
  1170. cert_no = his.Certno
  1171. }
  1172. api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" +
  1173. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1174. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  1175. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  1176. resp, requestErr := http.Get(api)
  1177. if requestErr != nil {
  1178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1179. return
  1180. }
  1181. defer resp.Body.Close()
  1182. body, ioErr := ioutil.ReadAll(resp.Body)
  1183. if ioErr != nil {
  1184. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1186. return
  1187. }
  1188. var respJSON map[string]interface{}
  1189. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1190. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1191. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1192. return
  1193. }
  1194. fmt.Println(respJSON)
  1195. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1196. userJSONBytes, _ := json.Marshal(respJSON)
  1197. var res ResultSeven
  1198. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1199. utils.ErrorLog("解析失败:%v", err)
  1200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1201. return
  1202. }
  1203. if res.Infcode == -1 {
  1204. errlog := &models.HisOrderError{
  1205. UserOrgId: adminUser.CurrentOrgId,
  1206. Ctime: time.Now().Unix(),
  1207. Mtime: time.Now().Unix(),
  1208. Number: chrg_bchno,
  1209. ErrMsg: res.ErrMsg,
  1210. Status: 1,
  1211. PatientId: id,
  1212. RecordTime: recordDateTime,
  1213. Stage: 6,
  1214. }
  1215. service.CreateErrMsgLog(errlog)
  1216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1217. return
  1218. } else {
  1219. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1220. order.OrderStatus = 1
  1221. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1222. order.SetlId = res.Output.Setlinfo.SetlID
  1223. order.PsnNo = res.Output.Setlinfo.PsnNo
  1224. order.PsnName = res.Output.Setlinfo.PsnName
  1225. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1226. order.Certno = res.Output.Setlinfo.Certno
  1227. order.Gend = res.Output.Setlinfo.Gend
  1228. order.Naty = res.Output.Setlinfo.Naty
  1229. order.Age = res.Output.Setlinfo.Age
  1230. order.Insutype = res.Output.Setlinfo.Insutype
  1231. order.PsnType = res.Output.Setlinfo.PsnType
  1232. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1233. order.SetlTime = res.Output.Setlinfo.SetlTime
  1234. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1235. order.MedType = res.Output.Setlinfo.MedType
  1236. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1237. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1238. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1239. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1240. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1241. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1242. order.HifpPay = res.Output.Setlinfo.HifpPay
  1243. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1244. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1245. order.HifesPay = res.Output.Setlinfo.HifesPay
  1246. order.HifobPay = res.Output.Setlinfo.HifobPay
  1247. order.MafPay = res.Output.Setlinfo.MafPay
  1248. order.OthPay = res.Output.Setlinfo.OthPay
  1249. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1250. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1251. order.AcctPay = res.Output.Setlinfo.AcctPay
  1252. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1253. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1254. order.Balc = res.Output.Setlinfo.Balc
  1255. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1256. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1257. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1258. order.ClrWay = res.Output.Setlinfo.ClrWay
  1259. order.Creator = order.Creator
  1260. order.Modify = roles.ID
  1261. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1262. detailStr := string(setlDetail)
  1263. order.SetlDetail = detailStr
  1264. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1265. err = service.UpDateOrder(order)
  1266. //订单确认
  1267. result := service.Gdyb6201(miConfig.OrgName, roles.UserName, miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, order)
  1268. var dat map[string]interface{}
  1269. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1270. userJSONBytes, _ := json.Marshal(dat)
  1271. var res ResultTwelve
  1272. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1273. utils.ErrorLog("解析失败:%v", err)
  1274. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1275. return
  1276. }
  1277. if res.Infcode == 0 {
  1278. if err == nil {
  1279. c.ServeSuccessJSON(map[string]interface{}{
  1280. "msg": "预结算成功",
  1281. })
  1282. } else {
  1283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePreSettleFaildParamWrong)
  1284. return
  1285. }
  1286. } else {
  1287. adminUser := c.GetAdminUserInfo()
  1288. errlog := &models.HisOrderError{
  1289. UserOrgId: adminUser.CurrentOrgId,
  1290. Ctime: time.Now().Unix(),
  1291. Mtime: time.Now().Unix(),
  1292. ErrMsg: res.ErrMsg,
  1293. Status: 1,
  1294. PatientId: id,
  1295. RecordTime: recordDateTime,
  1296. Stage: 7,
  1297. }
  1298. service.CreateErrMsgLog(errlog)
  1299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1300. }
  1301. } else {
  1302. fmt.Println(err)
  1303. }
  1304. }
  1305. } else {
  1306. adminUser := c.GetAdminUserInfo()
  1307. errlog := &models.HisOrderError{
  1308. UserOrgId: adminUser.CurrentOrgId,
  1309. Ctime: time.Now().Unix(),
  1310. Mtime: time.Now().Unix(),
  1311. ErrMsg: res.ErrMsg,
  1312. Status: 1,
  1313. PatientId: id,
  1314. RecordTime: recordDateTime,
  1315. Stage: 4,
  1316. }
  1317. service.CreateErrMsgLog(errlog)
  1318. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1319. return
  1320. }
  1321. } else {
  1322. adminUser := c.GetAdminUserInfo()
  1323. errlog := &models.HisOrderError{
  1324. UserOrgId: adminUser.CurrentOrgId,
  1325. Ctime: time.Now().Unix(),
  1326. Mtime: time.Now().Unix(),
  1327. ErrMsg: res.ErrMsg,
  1328. Status: 1,
  1329. PatientId: id,
  1330. RecordTime: recordDateTime,
  1331. Stage: 4,
  1332. }
  1333. service.CreateErrMsgLog(errlog)
  1334. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  1335. return
  1336. }
  1337. }
  1338. }
  1339. func (c *HisApiController) GetSettleInfo() {
  1340. id, _ := c.GetInt64("id")
  1341. record_time := c.GetString("record_time")
  1342. //pay_way, _ := c.GetInt64("pay_way")
  1343. //pay_price, _ := c.GetFloat("pay_price")
  1344. //pay_card_no := c.GetString("pay_card_no")
  1345. //discount_price, _ := c.GetFloat("discount_price")
  1346. //preferential_price, _ := c.GetFloat("preferential_price")
  1347. //reality_price, _ := c.GetFloat("reality_price")
  1348. //found_price, _ := c.GetFloat("found_price")
  1349. //medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1350. //private_price, _ := c.GetFloat("private_price")
  1351. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1352. admin_user_id, _ := c.GetInt64("admin_user_id")
  1353. timeLayout := "2006-01-02"
  1354. loc, _ := time.LoadLocation("Local")
  1355. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1356. if err != nil {
  1357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1358. return
  1359. }
  1360. recordDateTime := theTime.Unix()
  1361. adminUser := c.GetAdminUserInfo()
  1362. var prescriptions []*models.HisPrescription
  1363. //var start_time int64
  1364. //var end_time int64
  1365. data := make(map[string]interface{})
  1366. if settle_accounts_type == 1 { //日结
  1367. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1368. data["pre"] = prescriptions
  1369. } else { //月结
  1370. start_time_str := c.GetString("start_time")
  1371. end_time_str := c.GetString("end_time")
  1372. timeLayout := "2006-01-02"
  1373. loc, _ := time.LoadLocation("Local")
  1374. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1375. if err != nil {
  1376. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1377. return
  1378. }
  1379. recordStartTime := theStartTime.Unix()
  1380. //start_time = recordStartTime
  1381. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1382. if err != nil {
  1383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1384. return
  1385. }
  1386. recordEndTime := theEndTime.Unix()
  1387. //end_time = recordEndTime
  1388. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1389. data["pre"] = prescriptions
  1390. }
  1391. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1392. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1393. timestamp := time.Now().Unix()
  1394. tempTime := time.Unix(timestamp, 0)
  1395. timeFormat := tempTime.Format("20060102150405")
  1396. chrgBchno := rand.Intn(100000) + 10000
  1397. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1398. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1399. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1400. strconv.FormatInt(his.PatientId, 10)
  1401. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1402. if config.IsOpen == 1 { //对接了医保,走医保流程
  1403. var total float64
  1404. for _, item := range prescriptions {
  1405. if item.Type == 1 { //药品
  1406. for _, subItem := range item.HisDoctorAdviceInfo {
  1407. total = total + (subItem.Price * subItem.PrescribingNumber)
  1408. }
  1409. }
  1410. if item.Type == 2 { //项目
  1411. for _, subItem := range item.HisPrescriptionProject {
  1412. total = total + (subItem.Price * float64(subItem.Count))
  1413. }
  1414. }
  1415. }
  1416. for _, item := range prescriptions {
  1417. for _, subItem := range item.HisAdditionalCharge {
  1418. total = total + (subItem.Price * float64(subItem.Count))
  1419. }
  1420. }
  1421. allTotal := fmt.Sprintf("%.2f", total)
  1422. var rf []*ResultFive
  1423. json.Unmarshal([]byte(his.Iinfo), &rf)
  1424. psn_no := his.PsnNo
  1425. mdtrt_id := his.Number
  1426. chrg_bchno := chrg_bchno
  1427. cert_no := his.Certno
  1428. insutype := rf[0].Insutype
  1429. if his.IdCardType == 1 {
  1430. cert_no = his.MedicalInsuranceNumber
  1431. } else {
  1432. cert_no = his.Certno
  1433. }
  1434. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1435. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1436. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  1437. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  1438. resp, requestErr := http.Get(api)
  1439. if requestErr != nil {
  1440. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1441. return
  1442. }
  1443. defer resp.Body.Close()
  1444. body, ioErr := ioutil.ReadAll(resp.Body)
  1445. if ioErr != nil {
  1446. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1447. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1448. return
  1449. }
  1450. var respJSON map[string]interface{}
  1451. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1452. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1454. return
  1455. }
  1456. fmt.Println(respJSON)
  1457. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1458. userJSONBytes, _ := json.Marshal(respJSON)
  1459. var res ResultSeven
  1460. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1461. utils.ErrorLog("解析失败:%v", err)
  1462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1463. return
  1464. }
  1465. if res.Infcode == -1 {
  1466. errlog := &models.HisOrderError{
  1467. UserOrgId: adminUser.CurrentOrgId,
  1468. Ctime: time.Now().Unix(),
  1469. Mtime: time.Now().Unix(),
  1470. Number: chrg_bchno,
  1471. ErrMsg: res.ErrMsg,
  1472. Status: 1,
  1473. PatientId: id,
  1474. RecordTime: recordDateTime,
  1475. Stage: 6,
  1476. }
  1477. service.CreateErrMsgLog(errlog)
  1478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1479. return
  1480. } else {
  1481. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1482. order.OrderStatus = 2
  1483. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1484. order.SetlId = res.Output.Setlinfo.SetlID
  1485. order.PsnNo = res.Output.Setlinfo.PsnNo
  1486. order.PsnName = res.Output.Setlinfo.PsnName
  1487. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1488. order.Certno = res.Output.Setlinfo.Certno
  1489. order.Gend = res.Output.Setlinfo.Gend
  1490. order.Naty = res.Output.Setlinfo.Naty
  1491. order.Age = res.Output.Setlinfo.Age
  1492. order.Insutype = res.Output.Setlinfo.Insutype
  1493. order.PsnType = res.Output.Setlinfo.PsnType
  1494. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1495. order.SetlTime = res.Output.Setlinfo.SetlTime
  1496. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1497. order.MedType = res.Output.Setlinfo.MedType
  1498. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1499. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1500. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1501. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1502. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1503. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1504. order.HifpPay = res.Output.Setlinfo.HifpPay
  1505. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1506. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1507. order.HifesPay = res.Output.Setlinfo.HifesPay
  1508. order.HifobPay = res.Output.Setlinfo.HifobPay
  1509. order.MafPay = res.Output.Setlinfo.MafPay
  1510. order.OthPay = res.Output.Setlinfo.OthPay
  1511. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1512. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1513. order.AcctPay = res.Output.Setlinfo.AcctPay
  1514. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1515. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1516. order.Balc = res.Output.Setlinfo.Balc
  1517. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1518. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1519. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1520. order.ClrWay = res.Output.Setlinfo.ClrWay
  1521. order.Creator = order.Creator
  1522. order.Modify = roles.ID
  1523. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1524. detailStr := string(setlDetail)
  1525. order.SetlDetail = detailStr
  1526. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1527. err = service.UpDateOrder(order)
  1528. if err == nil {
  1529. c.ServeSuccessJSON(map[string]interface{}{
  1530. "msg": "结算成功",
  1531. })
  1532. } else {
  1533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1534. return
  1535. }
  1536. }
  1537. }
  1538. }
  1539. //退款
  1540. func (c *HisApiController) Refund() {
  1541. order_id, _ := c.GetInt64("order_id")
  1542. number := c.GetString("number")
  1543. record_time := c.GetString("record_time")
  1544. patient_id, _ := c.GetInt64("patient_id")
  1545. timeLayout := "2006-01-02"
  1546. loc, _ := time.LoadLocation("Local")
  1547. adminUser := c.GetAdminUserInfo()
  1548. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1549. fmt.Println(err)
  1550. if err != nil {
  1551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1552. return
  1553. }
  1554. recordDateTime := theTime.Unix()
  1555. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1556. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1557. var order models.HisOrder
  1558. order, _ = service.GetHisOrderByID(order_id)
  1559. if order.ID == 0 {
  1560. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  1561. }
  1562. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1563. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1564. if config.IsOpen == 1 { //对接了医保,走医保流程
  1565. api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo +
  1566. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1567. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1568. resp, requestErr := http.Get(api)
  1569. if requestErr != nil {
  1570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1571. return
  1572. }
  1573. body, ioErr := ioutil.ReadAll(resp.Body)
  1574. if ioErr != nil {
  1575. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1577. return
  1578. }
  1579. var respJSON map[string]interface{}
  1580. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1581. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1582. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1583. return
  1584. }
  1585. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1586. userJSONBytes, _ := json.Marshal(respJSON)
  1587. fmt.Println(respJSON)
  1588. fmt.Println(userJSONBytes)
  1589. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1590. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1591. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1592. resp2, requestErr2 := http.Get(api2)
  1593. if requestErr2 != nil {
  1594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1595. return
  1596. }
  1597. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1598. if ioErr2 != nil {
  1599. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1601. return
  1602. }
  1603. var respJSON2 map[string]interface{}
  1604. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1605. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1607. return
  1608. }
  1609. //api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1610. // "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1611. // "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1612. //resp3, requestErr3 := http.Get(api3)
  1613. //if requestErr3 != nil {
  1614. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1615. // return
  1616. //}
  1617. //
  1618. //body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1619. //if ioErr3 != nil {
  1620. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1621. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1622. // return
  1623. //}
  1624. //var respJSON3 map[string]interface{}
  1625. //if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1626. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1627. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1628. // return
  1629. //}
  1630. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1631. //service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1632. if err == nil {
  1633. c.ServeSuccessJSON(map[string]interface{}{
  1634. "msg": "退费成功",
  1635. })
  1636. } else {
  1637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1638. return
  1639. }
  1640. } else {
  1641. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1642. if err == nil {
  1643. c.ServeSuccessJSON(map[string]interface{}{
  1644. "msg": "退费成功",
  1645. })
  1646. } else {
  1647. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1648. return
  1649. }
  1650. }
  1651. }
  1652. func (c *HisApiController) RefundNumber() {
  1653. record_time := c.GetString("record_time")
  1654. patient_id, _ := c.GetInt64("patient_id")
  1655. timeLayout := "2006-01-02"
  1656. loc, _ := time.LoadLocation("Local")
  1657. adminUser := c.GetAdminUserInfo()
  1658. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1659. fmt.Println(err)
  1660. if err != nil {
  1661. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1662. return
  1663. }
  1664. recordDateTime := theTime.Unix()
  1665. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1666. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1667. //order, _ := service.GetHisOrderByID(order_id)
  1668. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1669. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1670. if config.IsOpen == 1 { //对接了医保,走医保流程
  1671. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1672. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1673. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1674. resp3, requestErr3 := http.Get(api3)
  1675. if requestErr3 != nil {
  1676. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1677. return
  1678. }
  1679. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1680. if ioErr3 != nil {
  1681. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1683. return
  1684. }
  1685. var respJSON3 map[string]interface{}
  1686. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1687. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1688. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1689. return
  1690. }
  1691. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1692. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1693. if err == nil {
  1694. c.ServeSuccessJSON(map[string]interface{}{
  1695. "msg": "退费成功",
  1696. })
  1697. } else {
  1698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1699. return
  1700. }
  1701. } else {
  1702. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1703. //if err == nil {
  1704. // c.ServeSuccessJSON(map[string]interface{}{
  1705. // "msg": "退费成功",
  1706. // })
  1707. //} else {
  1708. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1709. // return
  1710. //}
  1711. }
  1712. }
  1713. func (c *HisApiController) RefundDetail() {
  1714. order_id, _ := c.GetInt64("order_id")
  1715. number := c.GetString("number")
  1716. record_time := c.GetString("record_time")
  1717. patient_id, _ := c.GetInt64("patient_id")
  1718. timeLayout := "2006-01-02"
  1719. loc, _ := time.LoadLocation("Local")
  1720. adminUser := c.GetAdminUserInfo()
  1721. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1722. fmt.Println(err)
  1723. if err != nil {
  1724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1725. return
  1726. }
  1727. recordDateTime := theTime.Unix()
  1728. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1729. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1730. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1731. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1732. var order models.HisOrder
  1733. order, _ = service.GetHisOrderByID(order_id)
  1734. if order.ID == 0 {
  1735. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  1736. }
  1737. if config.IsOpen == 1 { //对接了医保,走医保流程
  1738. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1739. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1740. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1741. resp2, requestErr2 := http.Get(api2)
  1742. if requestErr2 != nil {
  1743. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1744. return
  1745. }
  1746. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1747. if ioErr2 != nil {
  1748. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1749. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1750. return
  1751. }
  1752. var respJSON2 map[string]interface{}
  1753. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1754. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1756. return
  1757. }
  1758. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1759. if err == nil {
  1760. c.ServeSuccessJSON(map[string]interface{}{
  1761. "msg": "退费成功",
  1762. })
  1763. } else {
  1764. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1765. return
  1766. }
  1767. } else {
  1768. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1769. if err == nil {
  1770. c.ServeSuccessJSON(map[string]interface{}{
  1771. "msg": "退费成功",
  1772. })
  1773. } else {
  1774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1775. return
  1776. }
  1777. }
  1778. }
  1779. //对账
  1780. func (c *HisApiController) GetCheckAccount() {
  1781. start_time := c.GetString("start_time")
  1782. end_time := c.GetString("end_time")
  1783. insutype := c.GetString("insutype")
  1784. clr_type := c.GetString("clr_type")
  1785. admin_user_id, _ := c.GetInt64("admin_user_id")
  1786. adminUser := c.GetAdminUserInfo()
  1787. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1788. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1789. timeLayout := "2006-01-02"
  1790. loc, _ := time.LoadLocation("Local")
  1791. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1792. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1793. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  1794. decimal.DivisionPrecision = 2
  1795. var medfee_sumamt float64
  1796. var acct_pay float64
  1797. var fund_pay_sumamt float64
  1798. fixmedins_setl_cnt := int64(len(orders))
  1799. for _, item := range orders {
  1800. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1801. acct_pay, _ = decimal.NewFromFloat(acct_pay).Add(decimal.NewFromFloat(item.AcctPay)).Float64()
  1802. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1803. }
  1804. var user_name string
  1805. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1806. if role.ID == 0 {
  1807. user_name = "xxx"
  1808. } else {
  1809. user_name = role.UserName
  1810. }
  1811. if config.IsOpen == 1 {
  1812. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  1813. "insutype=" + insutype +
  1814. "&clr_type=" + clr_type +
  1815. "&setl_optins=" + miConfig.OrgName +
  1816. "&stmt_begndate=" + start_time +
  1817. "&stm_enddate=" + end_time +
  1818. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1819. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1820. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  1821. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1822. "&fixmedins_code=" + miConfig.Code +
  1823. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  1824. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  1825. "&secret_key=" + miConfig.SecretKey +
  1826. "&org_name=" + miConfig.OrgName +
  1827. "&doctor=" + user_name
  1828. fmt.Println(api)
  1829. resp, requestErr := http.Get(api)
  1830. if requestErr != nil {
  1831. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1832. return
  1833. }
  1834. body, ioErr := ioutil.ReadAll(resp.Body)
  1835. fmt.Println(body)
  1836. if ioErr != nil {
  1837. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1839. return
  1840. }
  1841. var respJSON map[string]interface{}
  1842. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1843. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1844. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1845. return
  1846. }
  1847. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1848. userJSONBytes, _ := json.Marshal(respJSON)
  1849. var res ResultEight
  1850. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1851. utils.ErrorLog("解析失败:%v", err)
  1852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1853. return
  1854. }
  1855. if res.Infcode == 0 {
  1856. c.ServeSuccessJSON(map[string]interface{}{
  1857. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  1858. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  1859. })
  1860. } else {
  1861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1862. }
  1863. }
  1864. }
  1865. //对账明细
  1866. func (c *HisApiController) GetCheckDetailAccount() {
  1867. start_time := c.GetString("start_time")
  1868. end_time := c.GetString("end_time")
  1869. admin_user_id, _ := c.GetInt64("admin_user_id")
  1870. adminUser := c.GetAdminUserInfo()
  1871. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1872. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1873. timeLayout := "2006-01-02"
  1874. loc, _ := time.LoadLocation("Local")
  1875. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1876. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1877. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  1878. Mkdir(miConfig.OrgName)
  1879. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  1880. file_name := file + ".txt"
  1881. zip_name := file + ".zip"
  1882. zip_path := miConfig.OrgName + "/" + zip_name
  1883. file_path := miConfig.OrgName + "/" + file_name
  1884. decimal.DivisionPrecision = 2
  1885. var medfee_sumamt float64
  1886. var psn_cash_pay float64
  1887. var fund_pay_sumamt float64
  1888. fixmedins_setl_cnt := int64(len(orders))
  1889. for _, item := range orders {
  1890. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1891. psn_cash_pay, _ = decimal.NewFromFloat(psn_cash_pay).Add(decimal.NewFromFloat(item.PsnCashPay)).Float64()
  1892. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1893. }
  1894. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  1895. defer f.Close()
  1896. if err != nil {
  1897. fmt.Println(err.Error())
  1898. } else {
  1899. for _, item := range orders {
  1900. var refd_setl_flag string
  1901. if item.OrderStatus == 2 {
  1902. refd_setl_flag = "0"
  1903. }
  1904. if item.OrderStatus == 3 {
  1905. refd_setl_flag = "1"
  1906. }
  1907. var str string
  1908. str = item.SetlId + " " +
  1909. item.MdtrtId + " " +
  1910. item.PsnNo + " " +
  1911. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  1912. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  1913. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  1914. _, err = f.Write([]byte(str))
  1915. }
  1916. }
  1917. Zip(file_path, zip_path)
  1918. fmt.Println(ReadFile(zip_path))
  1919. fmt.Println(string(ReadFile(zip_path)))
  1920. if config.IsOpen == 1 {
  1921. var user_name string
  1922. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1923. if role.ID == 0 {
  1924. user_name = "管理员"
  1925. } else {
  1926. user_name = role.UserName
  1927. }
  1928. baseParams := models.BaseParams{
  1929. SecretKey: miConfig.SecretKey,
  1930. FixmedinsCode: miConfig.Code,
  1931. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1932. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1933. OrgName: miConfig.OrgName,
  1934. Doctor: user_name,
  1935. }
  1936. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  1937. var dat map[string]interface{}
  1938. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1939. fmt.Println(dat)
  1940. } else {
  1941. fmt.Println(err)
  1942. }
  1943. userJSONBytes, _ := json.Marshal(dat)
  1944. var res ResultNine
  1945. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1946. utils.ErrorLog("解析失败:%v", err)
  1947. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1948. return
  1949. }
  1950. if res.Infcode == 0 {
  1951. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  1952. "file_qury_no=" + res.Output.FileQuryNo +
  1953. "&setl_optins=" + miConfig.OrgName +
  1954. "&stmt_begndate=" + start_time +
  1955. "&stm_enddate=" + end_time +
  1956. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1957. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1958. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  1959. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1960. "&fixmedins_code=" + miConfig.Code +
  1961. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  1962. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  1963. "&secret_key=" + miConfig.SecretKey +
  1964. "&org_name=" + miConfig.OrgName +
  1965. "&doctor=" + user_name
  1966. resp, requestErr := http.Get(api)
  1967. if requestErr != nil {
  1968. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1969. return
  1970. }
  1971. body, ioErr := ioutil.ReadAll(resp.Body)
  1972. if ioErr != nil {
  1973. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1974. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1975. return
  1976. }
  1977. var respJSON map[string]interface{}
  1978. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1979. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1981. return
  1982. }
  1983. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1984. userJSONBytes, _ := json.Marshal(respJSON)
  1985. var res ResultTen
  1986. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1987. utils.ErrorLog("解析失败:%v", err)
  1988. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1989. return
  1990. }
  1991. if res.Infcode == 0 {
  1992. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  1993. c.ServeSuccessJSON(map[string]interface{}{
  1994. "msg": "明细对账成功",
  1995. })
  1996. }
  1997. } else {
  1998. }
  1999. }
  2000. }
  2001. func (c *HisApiController) GetSettleAccounts() {
  2002. //id, _ := c.GetInt64("id")
  2003. //record_time := c.GetString("record_time")
  2004. order_id, _ := c.GetInt64("order_id")
  2005. admin_user_id, _ := c.GetInt64("admin_user_id")
  2006. //timeLayout := "2006-01-02"
  2007. //loc, _ := time.LoadLocation("Local")
  2008. //
  2009. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2010. //if err != nil {
  2011. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2012. // return
  2013. //}
  2014. //recordDateTime := theTime.Unix()
  2015. adminUser := c.GetAdminUserInfo()
  2016. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2017. order, _ := service.GetHisOrderByID(order_id)
  2018. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  2019. var bedCostTotal float64 = 0 //床位总费
  2020. var bedCostSelfTotal float64 = 0 //床位自费
  2021. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  2022. var operationCostTotal float64 = 0 //手术费
  2023. var operationCostSelfTotal float64 = 0 //手术费
  2024. var operationCostPartSelfTotal float64 = 0 //手术费
  2025. var otherCostTotal float64 = 0 //其他费用
  2026. var otherCostSelfTotal float64 = 0 //其他费用
  2027. var otherCostPartSelfTotal float64 = 0 //其他费用
  2028. var materialCostTotal float64 = 0 //材料费
  2029. var materialCostSelfTotal float64 = 0 //材料费
  2030. var materialCostPartSelfTotal float64 = 0 //材料费
  2031. var westernMedicineCostTotal float64 = 0 //西药费
  2032. var westernMedicineCostSelfTotal float64 = 0 //西药费
  2033. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  2034. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  2035. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  2036. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  2037. var checkCostTotal float64 = 0 //检查费
  2038. var checkCostSelfTotal float64 = 0 //检查费
  2039. var checkCostPartSelfTotal float64 = 0 //检查费
  2040. var laboratoryCostTotal float64 = 0 //化验费
  2041. var laboratoryCostSelfTotal float64 = 0 //化验费
  2042. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  2043. var treatCostTotal float64 = 0 //治疗费用
  2044. var treatCostSelfTotal float64 = 0 //治疗费用
  2045. var treatCostPartSelfTotal float64 = 0 //治疗费用
  2046. decimal.DivisionPrecision = 2
  2047. for _, item := range orderInfos {
  2048. if item.MedChrgitmType == "01" { //床位费
  2049. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2050. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2051. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2052. }
  2053. if item.MedChrgitmType == "03" { //检查费
  2054. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2055. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2056. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2057. }
  2058. if item.MedChrgitmType == "04" { //化验费
  2059. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2060. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2061. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2062. }
  2063. if item.MedChrgitmType == "05" { //治疗费
  2064. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2065. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2066. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2067. }
  2068. if item.MedChrgitmType == "06" { //手术费
  2069. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2070. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2071. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2072. }
  2073. if item.MedChrgitmType == "08" { //材料费
  2074. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2075. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2076. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2077. }
  2078. if item.MedChrgitmType == "09" { //西药费
  2079. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2080. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2081. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2082. }
  2083. if item.MedChrgitmType == "11" { //中成费
  2084. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2085. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2086. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2087. }
  2088. if item.MedChrgitmType == "14" { //其他费
  2089. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2090. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2091. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2092. }
  2093. }
  2094. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2095. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2096. var user_name string
  2097. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2098. if role.ID == 0 {
  2099. user_name = "管理员"
  2100. } else {
  2101. user_name = role.UserName
  2102. }
  2103. baseParams := models.BaseParams{
  2104. SecretKey: miConfig.SecretKey,
  2105. FixmedinsCode: miConfig.Code,
  2106. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2107. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2108. OrgName: miConfig.OrgName,
  2109. Doctor: user_name,
  2110. }
  2111. businessParams := models.BusinessParams{
  2112. PsnNo: order.PsnNo,
  2113. MdtrtId: order.MdtrtId,
  2114. SetlId: order.SetlId,
  2115. }
  2116. if config.IsOpen == 1 {
  2117. result := service.Gdyb5203(baseParams, businessParams)
  2118. var dat map[string]interface{}
  2119. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2120. fmt.Println(dat)
  2121. } else {
  2122. fmt.Println(err)
  2123. }
  2124. userJSONBytes, _ := json.Marshal(dat)
  2125. var res ResultEleven
  2126. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2127. utils.ErrorLog("解析失败:%v", err)
  2128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2129. return
  2130. }
  2131. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2132. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  2133. if res.Infcode == 0 {
  2134. c.ServeSuccessJSON(map[string]interface{}{
  2135. "charge_admin": charge_admin,
  2136. "printor_admin": printor_admin,
  2137. "info": res.Output.Setlinfo,
  2138. "bedCostTotal": bedCostTotal,
  2139. "bedCostSelfTotal": bedCostSelfTotal,
  2140. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  2141. "operationCostTotal": operationCostTotal,
  2142. "operationCostSelfTotal": operationCostSelfTotal,
  2143. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  2144. "otherCostTotal": otherCostTotal,
  2145. "otherCostSelfTotal": otherCostSelfTotal,
  2146. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  2147. "materialCostTotal": materialCostTotal,
  2148. "materialCostSelfTotal": materialCostSelfTotal,
  2149. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  2150. "westernMedicineCostTotal": westernMedicineCostTotal,
  2151. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  2152. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  2153. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  2154. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  2155. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  2156. "checkCostTotal": checkCostTotal,
  2157. "checkCostSelfTotal": checkCostSelfTotal,
  2158. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  2159. "laboratoryCostTotal": laboratoryCostTotal,
  2160. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  2161. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  2162. "treatCostTotal": treatCostTotal,
  2163. "treatCostSelfTotal": treatCostSelfTotal,
  2164. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  2165. })
  2166. }
  2167. }
  2168. }
  2169. func (c *HisApiController) GetCode() {
  2170. name := c.GetString("name")
  2171. codg := c.GetString("codg")
  2172. adminUser := c.GetAdminUserInfo()
  2173. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2174. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2175. var user_name string
  2176. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2177. if role.ID == 0 {
  2178. user_name = "xxx"
  2179. } else {
  2180. user_name = role.UserName
  2181. }
  2182. baseParams := &models.BaseParams{
  2183. SecretKey: miConfig.SecretKey,
  2184. FixmedinsCode: miConfig.Code,
  2185. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2186. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2187. OrgName: miConfig.OrgName,
  2188. Doctor: user_name,
  2189. }
  2190. if config.IsOpen == 1 {
  2191. result := service.Gdyb3301(baseParams, name, codg)
  2192. var dat map[string]interface{}
  2193. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2194. fmt.Println(dat)
  2195. } else {
  2196. fmt.Println(err)
  2197. }
  2198. }
  2199. }
  2200. func (c *HisApiController) CheckTreatment() {
  2201. patient_id, _ := c.GetInt64("patient_id", 0)
  2202. record_time := c.GetString("record_time")
  2203. insutype := c.GetString("insutype")
  2204. timeLayout := "2006-01-02"
  2205. loc, _ := time.LoadLocation("Local")
  2206. adminUser := c.GetAdminUserInfo()
  2207. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2208. fmt.Println(err)
  2209. if err != nil {
  2210. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2211. return
  2212. }
  2213. recordDateTime := theTime.Unix()
  2214. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2215. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2216. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2217. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2218. var user_name string
  2219. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2220. if role.ID == 0 {
  2221. user_name = "xxx"
  2222. } else {
  2223. user_name = role.UserName
  2224. }
  2225. baseParams := models.BaseParams{
  2226. SecretKey: miConfig.SecretKey,
  2227. FixmedinsCode: miConfig.Code,
  2228. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2229. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2230. OrgName: miConfig.OrgName,
  2231. Doctor: user_name,
  2232. }
  2233. if config.IsOpen == 1 {
  2234. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  2235. var dat map[string]interface{}
  2236. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2237. fmt.Println(dat)
  2238. } else {
  2239. fmt.Println(err)
  2240. }
  2241. }
  2242. }
  2243. func (c *HisApiController) PutRecord() {
  2244. id, _ := c.GetInt64("id")
  2245. record_time := c.GetString("record_time")
  2246. timeLayout := "2006-01-02"
  2247. loc, _ := time.LoadLocation("Local")
  2248. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2249. if err != nil {
  2250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2251. return
  2252. }
  2253. recordDateTime := theTime.Unix()
  2254. adminInfo := c.GetAdminUserInfo()
  2255. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  2256. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2257. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2258. fmt.Println(miConfig.SecretKey)
  2259. if patient == nil {
  2260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2261. return
  2262. }
  2263. if len(patient.IdCardNo) == 0 {
  2264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  2265. return
  2266. }
  2267. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  2268. if config.IsOpen == 1 {
  2269. api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  2270. resp, requestErr := http.Get(api)
  2271. if requestErr != nil {
  2272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2273. return
  2274. }
  2275. defer resp.Body.Close()
  2276. body, ioErr := ioutil.ReadAll(resp.Body)
  2277. if ioErr != nil {
  2278. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2280. return
  2281. }
  2282. var respJSON map[string]interface{}
  2283. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2284. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2286. return
  2287. }
  2288. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2289. userJSONBytes, _ := json.Marshal(userJSON)
  2290. var res ResultTwo
  2291. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2292. utils.ErrorLog("解析失败:%v", err)
  2293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2294. return
  2295. }
  2296. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  2297. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  2298. infoStr := string(Iinfos)
  2299. idetinfoStr := string(Idetinfos)
  2300. if res.Infcode == 0 {
  2301. his := models.VMHisPatient{
  2302. Status: 1,
  2303. Ctime: time.Now().Unix(),
  2304. Mtime: time.Now().Unix(),
  2305. PsnNo: res.Output.Baseinfo.PsnNo,
  2306. PsnCertType: res.Output.Baseinfo.PsnCertType,
  2307. Certno: res.Output.Baseinfo.Certno,
  2308. PsnName: res.Output.Baseinfo.PsnName,
  2309. Gend: res.Output.Baseinfo.Gend,
  2310. Naty: res.Output.Baseinfo.Naty,
  2311. Brdy: res.Output.Baseinfo.Brdy,
  2312. Age: res.Output.Baseinfo.Age,
  2313. Iinfo: infoStr,
  2314. Idetinfo: idetinfoStr,
  2315. PatientId: patient.ID,
  2316. RecordDate: theTime.Unix(),
  2317. UserOrgId: adminInfo.CurrentOrgId,
  2318. AdminUserId: adminInfo.AdminUser.Id,
  2319. IsReturn: 1,
  2320. }
  2321. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  2322. result := service.Gdyb2503(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  2323. result2 := service.Gdyb5301(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801")
  2324. var dat map[string]interface{}
  2325. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2326. fmt.Println(dat)
  2327. } else {
  2328. fmt.Println(err)
  2329. }
  2330. var dat2 map[string]interface{}
  2331. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  2332. fmt.Println(dat2)
  2333. } else {
  2334. fmt.Println(err)
  2335. }
  2336. } else {
  2337. adminUser := c.GetAdminUserInfo()
  2338. errlog := &models.HisOrderError{
  2339. UserOrgId: adminUser.CurrentOrgId,
  2340. Ctime: time.Now().Unix(),
  2341. Mtime: time.Now().Unix(),
  2342. ErrMsg: res.ErrMsg,
  2343. Status: 1,
  2344. PatientId: id,
  2345. RecordTime: recordDateTime,
  2346. Stage: 1,
  2347. }
  2348. service.CreateErrMsgLog(errlog)
  2349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  2350. return
  2351. }
  2352. }
  2353. }
  2354. func (c *HisApiController) GetUploadDiag() {
  2355. id, _ := c.GetInt64("id")
  2356. record_time := c.GetString("record_time")
  2357. diagnosis_id, _ := c.GetInt64("diagnosis")
  2358. sick_type, _ := c.GetInt64("sick_type")
  2359. reg_type, _ := c.GetInt64("reg_type")
  2360. timeLayout := "2006-01-02"
  2361. loc, _ := time.LoadLocation("Local")
  2362. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2363. if err != nil {
  2364. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2365. return
  2366. }
  2367. var patientPrescription models.HisPrescriptionInfo
  2368. recordDateTime := theTime.Unix()
  2369. adminInfo := c.GetAdminUserInfo()
  2370. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2371. if patientPrescription.ID == 0 {
  2372. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2373. }
  2374. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2375. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  2376. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2377. sickConfig, _ := service.FindSickById(sick_type)
  2378. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2379. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  2380. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  2381. "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(reg_type, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode +
  2382. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  2383. resp2, requestErr2 := http.Get(api2)
  2384. if requestErr2 != nil {
  2385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2386. return
  2387. }
  2388. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2389. if ioErr2 != nil {
  2390. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2392. return
  2393. }
  2394. var respJSON2 map[string]interface{}
  2395. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2396. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2398. return
  2399. }
  2400. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2401. userJSONBytes2, _ := json.Marshal(respJSON2)
  2402. var res2 ResultSix
  2403. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  2404. utils.ErrorLog("解析失败:%v", err)
  2405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2406. return
  2407. }
  2408. if res2.Infcode == -1 {
  2409. adminUser := c.GetAdminUserInfo()
  2410. errlog := &models.HisOrderError{
  2411. UserOrgId: adminUser.CurrentOrgId,
  2412. Ctime: time.Now().Unix(),
  2413. Mtime: time.Now().Unix(),
  2414. ErrMsg: res2.ErrMsg,
  2415. Status: 1,
  2416. PatientId: id,
  2417. RecordTime: recordDateTime,
  2418. Stage: 3,
  2419. }
  2420. service.CreateErrMsgLog(errlog)
  2421. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  2422. return
  2423. }
  2424. c.ServeSuccessJSON(map[string]interface{}{
  2425. "msg": "上传成功",
  2426. })
  2427. }
  2428. func PathExists(path string) (bool, error) {
  2429. _, err := os.Stat(path)
  2430. if err == nil {
  2431. return true, nil
  2432. }
  2433. if os.IsNotExist(err) {
  2434. return false, nil
  2435. }
  2436. return false, err
  2437. }
  2438. //创建文件夹
  2439. func Mkdir(dir string) {
  2440. // 创建文件夹
  2441. exist, err := PathExists(dir)
  2442. if err != nil {
  2443. fmt.Println(err.Error())
  2444. } else {
  2445. if exist {
  2446. fmt.Println(dir + "文件夹已存在!")
  2447. } else {
  2448. // 文件夹名称,权限
  2449. err := os.Mkdir(dir, os.ModePerm)
  2450. if err != nil {
  2451. fmt.Println(dir+"文件夹创建失败:", err.Error())
  2452. } else {
  2453. fmt.Println(dir + "文件夹创建成功!")
  2454. }
  2455. }
  2456. }
  2457. }
  2458. //压缩文件
  2459. func Zip(srcFile string, destZip string) error {
  2460. zipfile, err := os.Create(destZip)
  2461. if err != nil {
  2462. return err
  2463. }
  2464. defer zipfile.Close()
  2465. archive := zip.NewWriter(zipfile)
  2466. defer archive.Close()
  2467. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  2468. if err != nil {
  2469. return err
  2470. }
  2471. header, err := zip.FileInfoHeader(info)
  2472. if err != nil {
  2473. return err
  2474. }
  2475. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  2476. // header.Name = path
  2477. if info.IsDir() {
  2478. header.Name += "/"
  2479. } else {
  2480. header.Method = zip.Deflate
  2481. }
  2482. writer, err := archive.CreateHeader(header)
  2483. if err != nil {
  2484. return err
  2485. }
  2486. if !info.IsDir() {
  2487. file, err := os.Open(path)
  2488. if err != nil {
  2489. return err
  2490. }
  2491. defer file.Close()
  2492. _, err = io.Copy(writer, file)
  2493. }
  2494. return err
  2495. })
  2496. return err
  2497. }
  2498. func ReadFile(filePath string) []byte {
  2499. f, err := os.Open(filePath)
  2500. if err != nil {
  2501. fmt.Println("read file fail", err)
  2502. return nil
  2503. }
  2504. defer f.Close()
  2505. fd, err := ioutil.ReadAll(f)
  2506. if err != nil {
  2507. fmt.Println("read to fd fail", err)
  2508. return nil
  2509. }
  2510. return fd
  2511. }
  2512. func RemoveRepeatedCode(arr []string) (newArr []string) {
  2513. newArr = make([]string, 0)
  2514. for i := 0; i < len(arr); i++ {
  2515. repeat := false
  2516. for j := i + 1; j < len(arr); j++ {
  2517. if arr[i] == arr[j] {
  2518. repeat = true
  2519. break
  2520. }
  2521. }
  2522. if !repeat {
  2523. newArr = append(newArr, arr[i])
  2524. }
  2525. }
  2526. return
  2527. }
  2528. //func ShowMessage1(caption, text string, style uintptr) (result int) {
  2529. // user32, _ := syscall.LoadLibrary("SSCard.dll")
  2530. // messageBox, _ := syscall.GetProcAddress(user32, "MessageBoxW")
  2531. // defer syscall.FreeLibrary(user32)
  2532. //
  2533. // ret, _, _ := syscall.Syscall9(messageBox,
  2534. // 4,
  2535. // 0,
  2536. // StrPtr(text),
  2537. // StrPtr(caption),
  2538. // style,
  2539. // 0, 0, 0, 0, 0)
  2540. // result = int(ret)
  2541. // return
  2542. //}