main.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. package idc
  2. import (
  3. "fmt"
  4. "github.com/guonaihong/gout"
  5. "gogs.uu.mdfitnesscao.com/Algor/sdk"
  6. "gogs.uu.mdfitnesscao.com/Algor/sdk/response"
  7. "gogs.uu.mdfitnesscao.com/Algor/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 GetCompareReportByArchivesId(archivesId string) (*sdk.BaseResponse[*sdk.DetailResponse[*sdk.MedicalCompareReport]], *response.ErrCode) {
  112. var resp *sdk.BaseResponse[*sdk.DetailResponse[*sdk.MedicalCompareReport]]
  113. resp, err := getReq[*sdk.BaseResponse[*sdk.DetailResponse[*sdk.MedicalCompareReport]]]("/idcService/openapi/medicalData/compareReport/detailByArchivesId", gout.H{
  114. "archivesId": archivesId,
  115. })
  116. if err != nil {
  117. return nil, &response.ErrCode{
  118. Code: response.PLATFORM_ERROR,
  119. Msg: err.Error(),
  120. }
  121. }
  122. if resp == nil {
  123. return nil, response.ErrPlatform
  124. }
  125. return resp, nil
  126. }
  127. // 获取某个档案所有报告的指标数据列表
  128. func QueryIndicatorDataByParams(queryData *sdk.QueryIDCIndicatorDataQuery) (*sdk.BaseResponse[*sdk.ListResponse[*sdk.MedicalDateTransferResultQueryResultItemBody]], *response.ErrCode) {
  129. var resp *sdk.BaseResponse[*sdk.ListResponse[*sdk.MedicalDateTransferResultQueryResultItemBody]]
  130. resp, err := postReq[*sdk.BaseResponse[*sdk.ListResponse[*sdk.MedicalDateTransferResultQueryResultItemBody]]]("/idcService/openapi/medicalData/values/query", utils.StructToGoutH(queryData))
  131. if err != nil {
  132. return nil, &response.ErrCode{
  133. Code: response.PLATFORM_ERROR,
  134. Msg: err.Error(),
  135. }
  136. }
  137. if resp == nil {
  138. return nil, response.ErrPlatform
  139. }
  140. return resp, nil
  141. }
  142. // 获取某个档案所有报告的指标数据列表
  143. func GetArchivesCreatedMapByMemberCardId(memberCardId int64) (*sdk.BaseResponse[map[string]map[string]string], *response.ErrCode) {
  144. var resp *sdk.BaseResponse[map[string]map[string]string]
  145. resp, err := postReq[*sdk.BaseResponse[map[string]map[string]string]]("/idcService/openapi/medicalData/archivesCreatedMapByMemberCardId", gout.H{
  146. "memberCardId": memberCardId,
  147. })
  148. if err != nil {
  149. return nil, &response.ErrCode{
  150. Code: response.PLATFORM_ERROR,
  151. Msg: err.Error(),
  152. }
  153. }
  154. if resp == nil {
  155. return nil, response.ErrPlatform
  156. }
  157. return resp, nil
  158. }
  159. // postReq 发送post请求(响应为string的)
  160. func postReqStr[T any](path string, data gout.H) (T, error) {
  161. var res T
  162. fmt.Println(sdk.GetConfig())
  163. // 检查配置
  164. if sdk.GetConfig().ApiDomain == "" {
  165. return res, fmt.Errorf("请先配置API域名")
  166. }
  167. url := fmt.Sprintf("%s%s", sdk.GetConfig().ApiDomain, path)
  168. fmt.Println("请求地址 ===>", url)
  169. err := gout.POST(url).Debug(sdk.GetConfig().AppDebug).
  170. SetHeader(gout.H{}).
  171. SetJSON(data).
  172. BindBody(&res).
  173. Do()
  174. if err != nil {
  175. fmt.Println("请求失败: ", err)
  176. return res, err
  177. }
  178. return res, nil
  179. }
  180. // postReq 发送post请求
  181. func postReq[T any](path string, data gout.H) (T, error) {
  182. var res T
  183. fmt.Println(sdk.GetConfig())
  184. // 检查配置
  185. if sdk.GetConfig().ApiDomain == "" {
  186. return res, fmt.Errorf("请先配置API域名")
  187. }
  188. url := fmt.Sprintf("%s%s", sdk.GetConfig().ApiDomain, path)
  189. fmt.Println("请求地址 ===>", url)
  190. err := gout.POST(url).Debug(sdk.GetConfig().AppDebug).
  191. SetHeader(gout.H{}).
  192. SetJSON(data).
  193. BindJSON(&res).
  194. Do()
  195. if err != nil {
  196. fmt.Println("请求失败: ", err)
  197. return res, err
  198. }
  199. return res, nil
  200. }
  201. // getReq 发送post请求
  202. func getReq[T any](path string, data gout.H) (T, error) {
  203. var res T
  204. fmt.Println(sdk.GetConfig())
  205. // 检查配置
  206. if sdk.GetConfig().ApiDomain == "" {
  207. return res, fmt.Errorf("请先配置API域名")
  208. }
  209. url := fmt.Sprintf("%s%s", sdk.GetConfig().ApiDomain, path)
  210. fmt.Println("请求地址 ===>", url)
  211. err := gout.GET(url).Debug(sdk.GetConfig().AppDebug).
  212. SetHeader(gout.H{}).
  213. SetQuery(data).
  214. BindJSON(&res).
  215. Do()
  216. if err != nil {
  217. fmt.Println("请求失败: ", err)
  218. return res, err
  219. }
  220. return res, nil
  221. }