main.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. package idc
  2. import (
  3. "fmt"
  4. "github.com/guonaihong/gout"
  5. "gogs.uu.mdfitnesscao.com/hys/sdk"
  6. "gogs.uu.mdfitnesscao.com/hys/sdk/response"
  7. "gogs.uu.mdfitnesscao.com/hys/sdk/utils"
  8. )
  9. // 同步回调数据中心的转译结果
  10. func CallbackResult(sn string, dataStr map[string]any) (string, *response.ErrCode) {
  11. var resp string
  12. resp, err := postReqStr[string]("/idcService/callback/medicalData/result/algor", gout.H{
  13. "sn": sn,
  14. "extra": sn,
  15. "data": dataStr,
  16. "type": 2,
  17. })
  18. if err != nil {
  19. return "", &response.ErrCode{
  20. Code: response.PLATFORM_ERROR,
  21. Msg: err.Error(),
  22. }
  23. }
  24. if resp == "" {
  25. return "", response.ErrPlatform
  26. }
  27. return resp, nil
  28. }
  29. // 获取某个档案的所有数据(指标、档案数据【问题答案】)
  30. func GetAllValuesByArchivesId(archivesId string) (*sdk.BaseResponse[*sdk.ArchivesMedicalData], *response.ErrCode) {
  31. var resp *sdk.BaseResponse[*sdk.ArchivesMedicalData]
  32. resp, err := postReq[*sdk.BaseResponse[*sdk.ArchivesMedicalData]]("/idcService/openapi/medicalData/allValuesByArchivesId", gout.H{
  33. "archivesId": archivesId,
  34. })
  35. if err != nil {
  36. return nil, &response.ErrCode{
  37. Code: response.PLATFORM_ERROR,
  38. Msg: err.Error(),
  39. }
  40. }
  41. if resp == nil {
  42. return nil, response.ErrPlatform
  43. }
  44. return resp, nil
  45. }
  46. // 根据档案编号获取已确认的报告数量
  47. func TotalMedicalReportChartsByArchivesIds(archivesIds []string) (*sdk.BaseResponse[*sdk.DetailResponse[map[string]*sdk.MedicalReportCharts]], *response.ErrCode) {
  48. var resp *sdk.BaseResponse[*sdk.DetailResponse[map[string]*sdk.MedicalReportCharts]]
  49. resp, err := postReq[*sdk.BaseResponse[*sdk.DetailResponse[map[string]*sdk.MedicalReportCharts]]]("/idcService/openapi/medicalData/totalChartsByArchivesId", gout.H{
  50. "archivesIds": archivesIds,
  51. })
  52. if err != nil {
  53. return nil, &response.ErrCode{
  54. Code: response.PLATFORM_ERROR,
  55. Msg: err.Error(),
  56. }
  57. }
  58. if resp == nil {
  59. return nil, response.ErrPlatform
  60. }
  61. return resp, nil
  62. }
  63. // 创建报告
  64. func Create(medicalDataForm *sdk.MedicalDataCreateFormByOpenAPI) (*sdk.BaseResponse[map[string]any], *response.ErrCode) {
  65. var resp *sdk.BaseResponse[map[string]any]
  66. resp, err := postReq[*sdk.BaseResponse[map[string]any]]("/idcService/openapi/medicalData/create", utils.StructToGoutH(medicalDataForm))
  67. if err != nil {
  68. return nil, &response.ErrCode{
  69. Code: response.PLATFORM_ERROR,
  70. Msg: err.Error(),
  71. }
  72. }
  73. if resp == nil {
  74. return nil, response.ErrPlatform
  75. }
  76. return resp, nil
  77. }
  78. // 创建报告
  79. func UpdateArchives(medicalDataForm *sdk.MedicalDataBindArchivesFormByOpenAPI) (*sdk.BaseResponse[map[string]any], *response.ErrCode) {
  80. var resp *sdk.BaseResponse[map[string]any]
  81. resp, err := postReq[*sdk.BaseResponse[map[string]any]]("/idcService/openapi/medicalData/update/archives", utils.StructToGoutH(medicalDataForm))
  82. if err != nil {
  83. return nil, &response.ErrCode{
  84. Code: response.PLATFORM_ERROR,
  85. Msg: err.Error(),
  86. }
  87. }
  88. if resp == nil {
  89. return nil, response.ErrPlatform
  90. }
  91. return resp, nil
  92. }
  93. // 获取某个档案最新的一份报告
  94. func GetLatestMedicalReportByArchivesId(archivesId string) (*sdk.BaseResponse[*sdk.DetailResponse[*sdk.MedicalData]], *response.ErrCode) {
  95. var resp *sdk.BaseResponse[*sdk.DetailResponse[*sdk.MedicalData]]
  96. resp, err := getReq[*sdk.BaseResponse[*sdk.DetailResponse[*sdk.MedicalData]]]("/idcService/openapi/medicalData/detailByArchivesId", gout.H{
  97. "archivesId": archivesId,
  98. })
  99. if err != nil {
  100. return nil, &response.ErrCode{
  101. Code: response.PLATFORM_ERROR,
  102. Msg: err.Error(),
  103. }
  104. }
  105. if resp == nil {
  106. return nil, response.ErrPlatform
  107. }
  108. return resp, nil
  109. }
  110. // 获取某个档案的档案报告
  111. func GetArchivesReportByArchivesId(archivesId string, forceGenerate int64) (*sdk.BaseResponse[*sdk.DetailResponse[*sdk.ArchivesReport]], *response.ErrCode) {
  112. var resp *sdk.BaseResponse[*sdk.DetailResponse[*sdk.ArchivesReport]]
  113. resp, err := getReq[*sdk.BaseResponse[*sdk.DetailResponse[*sdk.ArchivesReport]]]("/idcService/openapi/archivesReport/detail", gout.H{
  114. "archivesId": archivesId,
  115. "forceGenerate": forceGenerate,
  116. })
  117. if err != nil {
  118. return nil, &response.ErrCode{
  119. Code: response.PLATFORM_ERROR,
  120. Msg: err.Error(),
  121. }
  122. }
  123. if resp == nil {
  124. return nil, response.ErrPlatform
  125. }
  126. return resp, nil
  127. }
  128. // 获取某个档案的对比报告
  129. func GetCompareReportByArchivesId(archivesId string) (*sdk.BaseResponse[*sdk.DetailResponse[*sdk.MedicalCompareReport]], *response.ErrCode) {
  130. var resp *sdk.BaseResponse[*sdk.DetailResponse[*sdk.MedicalCompareReport]]
  131. resp, err := getReq[*sdk.BaseResponse[*sdk.DetailResponse[*sdk.MedicalCompareReport]]]("/idcService/openapi/medicalData/compareReport/detailByArchivesId", gout.H{
  132. "archivesId": archivesId,
  133. })
  134. if err != nil {
  135. return nil, &response.ErrCode{
  136. Code: response.PLATFORM_ERROR,
  137. Msg: err.Error(),
  138. }
  139. }
  140. if resp == nil {
  141. return nil, response.ErrPlatform
  142. }
  143. return resp, nil
  144. }
  145. // 获取某个档案所有报告的指标数据列表
  146. func QueryIndicatorDataByParams(queryData *sdk.QueryIDCIndicatorDataQuery) (*sdk.BaseResponse[*sdk.ListResponse[*sdk.MedicalDateTransferResultQueryResultItemBody]], *response.ErrCode) {
  147. var resp *sdk.BaseResponse[*sdk.ListResponse[*sdk.MedicalDateTransferResultQueryResultItemBody]]
  148. resp, err := postReq[*sdk.BaseResponse[*sdk.ListResponse[*sdk.MedicalDateTransferResultQueryResultItemBody]]]("/idcService/openapi/medicalData/values/query", utils.StructToGoutH(queryData))
  149. if err != nil {
  150. return nil, &response.ErrCode{
  151. Code: response.PLATFORM_ERROR,
  152. Msg: err.Error(),
  153. }
  154. }
  155. if resp == nil {
  156. return nil, response.ErrPlatform
  157. }
  158. return resp, nil
  159. }
  160. // 获取某个档案所有报告的指标数据列表
  161. func GetArchivesCreatedMapByMemberCardId(memberCardId int64) (*sdk.BaseResponse[map[string]map[string]string], *response.ErrCode) {
  162. var resp *sdk.BaseResponse[map[string]map[string]string]
  163. resp, err := postReq[*sdk.BaseResponse[map[string]map[string]string]]("/idcService/openapi/medicalData/archivesCreatedMapByMemberCardId", gout.H{
  164. "memberCardId": memberCardId,
  165. })
  166. if err != nil {
  167. return nil, &response.ErrCode{
  168. Code: response.PLATFORM_ERROR,
  169. Msg: err.Error(),
  170. }
  171. }
  172. if resp == nil {
  173. return nil, response.ErrPlatform
  174. }
  175. return resp, nil
  176. }
  177. // postReq 发送post请求(响应为string的)
  178. func postReqStr[T any](path string, data gout.H) (T, error) {
  179. var res T
  180. fmt.Println(sdk.GetConfig())
  181. // 检查配置
  182. if sdk.GetConfig().ApiDomain == "" {
  183. return res, fmt.Errorf("请先配置API域名")
  184. }
  185. url := fmt.Sprintf("%s%s", sdk.GetConfig().ApiDomain, path)
  186. fmt.Println("请求地址 ===>", url)
  187. err := gout.POST(url).Debug(sdk.GetConfig().AppDebug).
  188. SetHeader(gout.H{}).
  189. SetJSON(data).
  190. BindBody(&res).
  191. Do()
  192. if err != nil {
  193. fmt.Println("请求失败: ", err)
  194. return res, err
  195. }
  196. return res, nil
  197. }
  198. // postReq 发送post请求
  199. func postReq[T any](path string, data gout.H) (T, error) {
  200. var res T
  201. fmt.Println(sdk.GetConfig())
  202. // 检查配置
  203. if sdk.GetConfig().ApiDomain == "" {
  204. return res, fmt.Errorf("请先配置API域名")
  205. }
  206. url := fmt.Sprintf("%s%s", sdk.GetConfig().ApiDomain, path)
  207. fmt.Println("请求地址 ===>", url)
  208. err := gout.POST(url).Debug(sdk.GetConfig().AppDebug).
  209. SetHeader(gout.H{}).
  210. SetJSON(data).
  211. BindJSON(&res).
  212. Do()
  213. if err != nil {
  214. fmt.Println("请求失败: ", err)
  215. return res, err
  216. }
  217. return res, nil
  218. }
  219. // getReq 发送post请求
  220. func getReq[T any](path string, data gout.H) (T, error) {
  221. var res T
  222. fmt.Println(sdk.GetConfig())
  223. // 检查配置
  224. if sdk.GetConfig().ApiDomain == "" {
  225. return res, fmt.Errorf("请先配置API域名")
  226. }
  227. url := fmt.Sprintf("%s%s", sdk.GetConfig().ApiDomain, path)
  228. fmt.Println("请求地址 ===>", url)
  229. err := gout.GET(url).Debug(sdk.GetConfig().AppDebug).
  230. SetHeader(gout.H{}).
  231. SetQuery(data).
  232. BindJSON(&res).
  233. Do()
  234. if err != nil {
  235. fmt.Println("请求失败: ", err)
  236. return res, err
  237. }
  238. return res, nil
  239. }