his_api_controller.go 94KB

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