/
exchange.go
98 lines (86 loc) · 3.88 KB
/
exchange.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package cedarcore
import (
"context"
"time"
"github.com/guregu/null/zero"
"github.com/cmsgov/easi-app/pkg/appcontext"
"github.com/cmsgov/easi-app/pkg/cedar/core/gen/client/exchange"
"github.com/cmsgov/easi-app/pkg/local/cedarcoremock"
"github.com/cmsgov/easi-app/pkg/models"
)
// GetExchangesBySystem fetches a list of CEDAR exchange records for a given system
func (c *Client) GetExchangesBySystem(ctx context.Context, cedarSystemID string) ([]*models.CedarExchange, error) {
if c.mockEnabled {
appcontext.ZLogger(ctx).Info("CEDAR Core is disabled")
if cedarcoremock.IsMockSystem(cedarSystemID) {
return cedarcoremock.GetExchange(cedarSystemID), nil
}
return nil, cedarcoremock.NoSystemFoundError()
}
cedarSystem, err := c.GetSystem(ctx, cedarSystemID)
if err != nil {
return nil, err
}
// Construct the parameters
params := exchange.NewExchangeFindListParams()
params.SetSystemID(cedarSystem.VersionID.String)
params.SetDirection("both")
params.HTTPClient = c.hc
// Make the API call
resp, err := c.sdk.Exchange.ExchangeFindList(params, c.auth)
if err != nil {
return nil, err
}
// Convert the auto-generated struct to our own pkg/models struct
retVal := make([]*models.CedarExchange, 0, len(resp.Payload.Exchanges))
for _, exch := range resp.Payload.Exchanges {
typeOfData := make([]*models.CedarExchangeTypeOfDataItem, 0, len(exch.TypeOfData))
for _, item := range exch.TypeOfData {
typeOfData = append(typeOfData, &models.CedarExchangeTypeOfDataItem{
ID: zero.StringFrom(item.ID),
Name: zero.StringFrom(item.Name),
})
}
var direction models.ExchangeDirection
if exch.FromOwnerID == cedarSystem.VersionID.String {
direction = models.ExchangeDirection(models.ExchangeDirectionSender)
} else if exch.ToOwnerID == cedarSystem.VersionID.String {
direction = models.ExchangeDirection(models.ExchangeDirectionReceiver)
}
connectionFrequency := []zero.String{}
for _, v := range exch.ConnectionFrequency {
connectionFrequency = append(connectionFrequency, zero.StringFrom(v))
}
retVal = append(retVal, &models.CedarExchange{
ConnectionFrequency: connectionFrequency,
ContainsBankingData: exch.ContainsBankingData,
ContainsBeneficiaryAddress: exch.ContainsBeneficiaryAddress,
ContainsPhi: exch.ContainsPhi,
ContainsPii: exch.ContainsPii,
ContainsHealthDisparityData: exch.ContainsHealthDisparityData,
DataExchangeAgreement: zero.StringFrom(exch.DataExchangeAgreement),
DataFormat: zero.StringFrom(exch.DataFormat),
DataFormatOther: zero.StringFrom(exch.DataFormatOther),
ExchangeDescription: zero.StringFrom(exch.ExchangeDescription),
ExchangeEndDate: zero.TimeFrom(time.Time(exch.ExchangeEndDate)),
ExchangeID: zero.StringFrom(exch.ExchangeID),
ExchangeName: zero.StringFrom(exch.ExchangeName),
ExchangeRetiredDate: zero.TimeFrom(time.Time(exch.ExchangeRetiredDate)),
ExchangeStartDate: zero.TimeFrom(time.Time(exch.ExchangeStartDate)),
ExchangeState: zero.StringFrom(exch.ExchangeState),
ExchangeVersion: zero.StringFrom(exch.ExchangeVersion),
ExchangeDirection: direction,
FromOwnerID: zero.StringFrom(exch.FromOwnerID),
FromOwnerName: zero.StringFrom(exch.FromOwnerName),
FromOwnerType: zero.StringFrom(exch.FromOwnerType),
IsBeneficiaryMailingFile: exch.IsBeneficiaryMailingFile,
NumOfRecords: zero.StringFrom(exch.NumOfRecords),
SharedViaAPI: exch.SharedViaAPI,
ToOwnerID: zero.StringFrom(exch.ToOwnerID),
ToOwnerName: zero.StringFrom(exch.ToOwnerName),
ToOwnerType: zero.StringFrom(exch.ToOwnerType),
TypeOfData: typeOfData,
})
}
return retVal, nil
}