123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- package idc
- import (
- "fmt"
- "github.com/guonaihong/gout"
- "gogs.uu.mdfitnesscao.com/hys/sdk"
- "gogs.uu.mdfitnesscao.com/hys/sdk/response"
- "gogs.uu.mdfitnesscao.com/hys/sdk/utils"
- )
- // 同步回调数据中心的转译结果
- func CallbackResult(sn string, dataStr map[string]any) (string, *response.ErrCode) {
- var resp string
- resp, err := postReqStr[string]("/idcService/callback/medicalData/result/algor", gout.H{
- "sn": sn,
- "extra": sn,
- "data": dataStr,
- "type": 2,
- })
- if err != nil {
- return "", &response.ErrCode{
- Code: response.PLATFORM_ERROR,
- Msg: err.Error(),
- }
- }
- if resp == "" {
- return "", response.ErrPlatform
- }
- return resp, nil
- }
- // 获取某个档案的所有数据(指标、档案数据【问题答案】)
- func GetAllValuesByArchivesId(archivesId string) (*sdk.BaseResponse[*sdk.ArchivesMedicalData], *response.ErrCode) {
- var resp *sdk.BaseResponse[*sdk.ArchivesMedicalData]
- resp, err := postReq[*sdk.BaseResponse[*sdk.ArchivesMedicalData]]("/idcService/openapi/medicalData/allValuesByArchivesId", gout.H{
- "archivesId": archivesId,
- })
- if err != nil {
- return nil, &response.ErrCode{
- Code: response.PLATFORM_ERROR,
- Msg: err.Error(),
- }
- }
- if resp == nil {
- return nil, response.ErrPlatform
- }
- return resp, nil
- }
- // 根据档案编号获取已确认的报告数量
- func TotalMedicalReportChartsByArchivesIds(archivesIds []string) (*sdk.BaseResponse[*sdk.DetailResponse[map[string]*sdk.MedicalReportCharts]], *response.ErrCode) {
- var resp *sdk.BaseResponse[*sdk.DetailResponse[map[string]*sdk.MedicalReportCharts]]
- resp, err := postReq[*sdk.BaseResponse[*sdk.DetailResponse[map[string]*sdk.MedicalReportCharts]]]("/idcService/openapi/medicalData/totalChartsByArchivesId", gout.H{
- "archivesIds": archivesIds,
- })
- if err != nil {
- return nil, &response.ErrCode{
- Code: response.PLATFORM_ERROR,
- Msg: err.Error(),
- }
- }
- if resp == nil {
- return nil, response.ErrPlatform
- }
- return resp, nil
- }
- // 创建报告
- func Create(medicalDataForm *sdk.MedicalDataCreateFormByOpenAPI) (*sdk.BaseResponse[map[string]any], *response.ErrCode) {
- var resp *sdk.BaseResponse[map[string]any]
- resp, err := postReq[*sdk.BaseResponse[map[string]any]]("/idcService/openapi/medicalData/create", utils.StructToGoutH(medicalDataForm))
- if err != nil {
- return nil, &response.ErrCode{
- Code: response.PLATFORM_ERROR,
- Msg: err.Error(),
- }
- }
- if resp == nil {
- return nil, response.ErrPlatform
- }
- return resp, nil
- }
- // 创建报告
- func UpdateArchives(medicalDataForm *sdk.MedicalDataBindArchivesFormByOpenAPI) (*sdk.BaseResponse[map[string]any], *response.ErrCode) {
- var resp *sdk.BaseResponse[map[string]any]
- resp, err := postReq[*sdk.BaseResponse[map[string]any]]("/idcService/openapi/medicalData/update/archives", utils.StructToGoutH(medicalDataForm))
- if err != nil {
- return nil, &response.ErrCode{
- Code: response.PLATFORM_ERROR,
- Msg: err.Error(),
- }
- }
- if resp == nil {
- return nil, response.ErrPlatform
- }
- return resp, nil
- }
- // 获取某个档案最新的一份报告
- func GetLatestMedicalReportByArchivesId(archivesId string) (*sdk.BaseResponse[*sdk.DetailResponse[*sdk.MedicalData]], *response.ErrCode) {
- var resp *sdk.BaseResponse[*sdk.DetailResponse[*sdk.MedicalData]]
- resp, err := getReq[*sdk.BaseResponse[*sdk.DetailResponse[*sdk.MedicalData]]]("/idcService/openapi/medicalData/detailByArchivesId", gout.H{
- "archivesId": archivesId,
- })
- if err != nil {
- return nil, &response.ErrCode{
- Code: response.PLATFORM_ERROR,
- Msg: err.Error(),
- }
- }
- if resp == nil {
- return nil, response.ErrPlatform
- }
- return resp, nil
- }
- // 获取某个档案的档案报告
- func GetArchivesReportByArchivesId(archivesId string, forceGenerate int64) (*sdk.BaseResponse[*sdk.DetailResponse[*sdk.ArchivesReport]], *response.ErrCode) {
- var resp *sdk.BaseResponse[*sdk.DetailResponse[*sdk.ArchivesReport]]
- resp, err := getReq[*sdk.BaseResponse[*sdk.DetailResponse[*sdk.ArchivesReport]]]("/idcService/openapi/archivesReport/detail", gout.H{
- "archivesId": archivesId,
- "forceGenerate": forceGenerate,
- })
- if err != nil {
- return nil, &response.ErrCode{
- Code: response.PLATFORM_ERROR,
- Msg: err.Error(),
- }
- }
- if resp == nil {
- return nil, response.ErrPlatform
- }
- return resp, nil
- }
- // 获取某个档案的对比报告
- func GetCompareReportByArchivesId(archivesId string) (*sdk.BaseResponse[*sdk.DetailResponse[*sdk.MedicalCompareReport]], *response.ErrCode) {
- var resp *sdk.BaseResponse[*sdk.DetailResponse[*sdk.MedicalCompareReport]]
- resp, err := getReq[*sdk.BaseResponse[*sdk.DetailResponse[*sdk.MedicalCompareReport]]]("/idcService/openapi/medicalData/compareReport/detailByArchivesId", gout.H{
- "archivesId": archivesId,
- })
- if err != nil {
- return nil, &response.ErrCode{
- Code: response.PLATFORM_ERROR,
- Msg: err.Error(),
- }
- }
- if resp == nil {
- return nil, response.ErrPlatform
- }
- return resp, nil
- }
- // 获取某个档案所有报告的指标数据列表
- func QueryIndicatorDataByParams(queryData *sdk.QueryIDCIndicatorDataQuery) (*sdk.BaseResponse[*sdk.ListResponse[*sdk.MedicalDateTransferResultQueryResultItemBody]], *response.ErrCode) {
- var resp *sdk.BaseResponse[*sdk.ListResponse[*sdk.MedicalDateTransferResultQueryResultItemBody]]
- resp, err := postReq[*sdk.BaseResponse[*sdk.ListResponse[*sdk.MedicalDateTransferResultQueryResultItemBody]]]("/idcService/openapi/medicalData/values/query", utils.StructToGoutH(queryData))
- if err != nil {
- return nil, &response.ErrCode{
- Code: response.PLATFORM_ERROR,
- Msg: err.Error(),
- }
- }
- if resp == nil {
- return nil, response.ErrPlatform
- }
- return resp, nil
- }
- // 获取某个档案所有报告的指标数据列表
- func GetArchivesCreatedMapByMemberCardId(memberCardId int64) (*sdk.BaseResponse[map[string]map[string]string], *response.ErrCode) {
- var resp *sdk.BaseResponse[map[string]map[string]string]
- resp, err := postReq[*sdk.BaseResponse[map[string]map[string]string]]("/idcService/openapi/medicalData/archivesCreatedMapByMemberCardId", gout.H{
- "memberCardId": memberCardId,
- })
- if err != nil {
- return nil, &response.ErrCode{
- Code: response.PLATFORM_ERROR,
- Msg: err.Error(),
- }
- }
- if resp == nil {
- return nil, response.ErrPlatform
- }
- return resp, nil
- }
- // postReq 发送post请求(响应为string的)
- func postReqStr[T any](path string, data gout.H) (T, error) {
- var res T
- fmt.Println(sdk.GetConfig())
- // 检查配置
- if sdk.GetConfig().ApiDomain == "" {
- return res, fmt.Errorf("请先配置API域名")
- }
- url := fmt.Sprintf("%s%s", sdk.GetConfig().ApiDomain, path)
- fmt.Println("请求地址 ===>", url)
- err := gout.POST(url).Debug(sdk.GetConfig().AppDebug).
- SetHeader(gout.H{}).
- SetJSON(data).
- BindBody(&res).
- Do()
- if err != nil {
- fmt.Println("请求失败: ", err)
- return res, err
- }
- return res, nil
- }
- // postReq 发送post请求
- func postReq[T any](path string, data gout.H) (T, error) {
- var res T
- fmt.Println(sdk.GetConfig())
- // 检查配置
- if sdk.GetConfig().ApiDomain == "" {
- return res, fmt.Errorf("请先配置API域名")
- }
- url := fmt.Sprintf("%s%s", sdk.GetConfig().ApiDomain, path)
- fmt.Println("请求地址 ===>", url)
- err := gout.POST(url).Debug(sdk.GetConfig().AppDebug).
- SetHeader(gout.H{}).
- SetJSON(data).
- BindJSON(&res).
- Do()
- if err != nil {
- fmt.Println("请求失败: ", err)
- return res, err
- }
- return res, nil
- }
- // getReq 发送post请求
- func getReq[T any](path string, data gout.H) (T, error) {
- var res T
- fmt.Println(sdk.GetConfig())
- // 检查配置
- if sdk.GetConfig().ApiDomain == "" {
- return res, fmt.Errorf("请先配置API域名")
- }
- url := fmt.Sprintf("%s%s", sdk.GetConfig().ApiDomain, path)
- fmt.Println("请求地址 ===>", url)
- err := gout.GET(url).Debug(sdk.GetConfig().AppDebug).
- SetHeader(gout.H{}).
- SetQuery(data).
- BindJSON(&res).
- Do()
- if err != nil {
- fmt.Println("请求失败: ", err)
- return res, err
- }
- return res, nil
- }
|