-
Notifications
You must be signed in to change notification settings - Fork 11
/
software_products.go
88 lines (75 loc) · 3.83 KB
/
software_products.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
package cedarcore
import (
"context"
"fmt"
"github.com/guregu/null/zero"
"github.com/cmsgov/easi-app/pkg/appcontext"
software_products "github.com/cmsgov/easi-app/pkg/cedar/core/gen/client/software_products"
"github.com/cmsgov/easi-app/pkg/local/cedarcoremock"
"github.com/cmsgov/easi-app/pkg/models"
)
// GetSoftwareProductsBySystem queries CEDAR for software product/tooling information associated with a particular system, taking the version-independent ID of a system
func (c *Client) GetSoftwareProductsBySystem(ctx context.Context, cedarSystemID string) (*models.CedarSoftwareProducts, error) {
if c.mockEnabled {
appcontext.ZLogger(ctx).Info("CEDAR Core is disabled")
if cedarcoremock.IsMockSystem(cedarSystemID) {
return cedarcoremock.GetSoftwareProducts(), nil
}
return nil, cedarcoremock.NoSystemFoundError()
}
cedarSystem, err := c.GetSystem(ctx, cedarSystemID)
if err != nil {
return nil, err
}
// Construct the parameters
params := software_products.NewSoftwareProductsFindListParams()
params.SetID(cedarSystem.VersionID.String)
params.HTTPClient = c.hc
// Make the API call
resp, err := c.sdk.SoftwareProducts.SoftwareProductsFindList(params, c.auth)
if err != nil {
return nil, err
}
if resp.Payload == nil {
return nil, fmt.Errorf("no body received")
}
// Convert the auto-generated struct to our own pkg/models struct
// Start by converting child SoftwareProduct object array
softwareProductItems := make([]*models.SoftwareProductItem, 0, len(resp.Payload.SoftwareProducts))
for _, softwareProduct := range resp.Payload.SoftwareProducts {
softwareProductItems = append(softwareProductItems, &models.SoftwareProductItem{
APIGatewayUse: softwareProduct.APIGatewayUse,
ElaPurchase: zero.StringFrom(softwareProduct.ElaPurchase),
ElaVendorID: zero.StringFrom(softwareProduct.ElaVendorID),
ProvidesAiCapability: softwareProduct.ProvidesAiCapability,
Refstr: zero.StringFrom(softwareProduct.Refstr),
SoftwareCatagoryConnectionGUID: zero.StringFrom(softwareProduct.SoftwareCatagoryConnectionGUID),
SoftwareVendorConnectionGUID: zero.StringFrom(softwareProduct.SoftwareVendorConnectionGUID),
SoftwareCost: zero.StringFrom(softwareProduct.SoftwareCost),
SoftwareElaOrganization: zero.StringFrom(softwareProduct.SoftwareElaOrganization),
SoftwareName: zero.StringFrom(softwareProduct.SoftwareName),
SystemSoftwareConnectionGUID: zero.StringFrom(softwareProduct.SystemSoftwareConnectionGUID),
TechnopediaCategory: zero.StringFrom(softwareProduct.TechnopediaCategory),
TechnopediaID: zero.StringFrom(softwareProduct.TechnopediaID),
VendorName: zero.StringFrom(softwareProduct.VendorName),
})
}
// Convert the rest of the parent SoftwareProducts object
retVal := &models.CedarSoftwareProducts{
AiSolnCatg: models.ZeroStringsFrom(resp.Payload.AiSolnCatg),
ApiDataArea: models.ZeroStringsFrom(resp.Payload.APIDataArea),
SoftwareProducts: softwareProductItems,
AISolnCatgOther: zero.StringFrom(resp.Payload.AiSolnCatgOther),
APIDescPubLocation: zero.StringFrom(resp.Payload.APIDescPubLocation),
APIDescPublished: zero.StringFrom(resp.Payload.APIDescPublished),
APIFHIRUse: zero.StringFrom(resp.Payload.APIFHIRUse),
APIFHIRUseOther: zero.StringFrom(resp.Payload.APIFHIRUseOther),
APIHasPortal: resp.Payload.APIHasPortal,
ApisAccessibility: zero.StringFrom(resp.Payload.ApisAccessibility),
ApisDeveloped: zero.StringFrom(resp.Payload.ApisDeveloped),
DevelopmentStage: zero.StringFrom(resp.Payload.DevelopmentStage),
SystemHasAPIGateway: resp.Payload.SystemHasAPIGateway,
UsesAiTech: zero.StringFrom(resp.Payload.UsesAiTech),
}
return retVal, nil
}