-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1407 from CMS-Enterprise/task/MINT-3157_data_exch…
…ange_data_loader [MINT-3157] Plan Data Exchange Data Loader
- Loading branch information
Showing
9 changed files
with
212 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
pkg/sqlqueries/SQL/plan_data_exchange_approach/get_by_model_plan_id_LOADER.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
WITH QUERIED_IDS AS ( | ||
/*Translate the input to a table */ | ||
SELECT UNNEST(CAST(:model_plan_ids AS UUID[])) AS model_plan_id | ||
) | ||
|
||
SELECT | ||
approach.id, | ||
approach.model_plan_id, | ||
approach.data_to_collect_from_participants, | ||
approach.data_to_collect_from_participants_reports_details, | ||
approach.data_to_collect_from_participants_other, | ||
approach.data_will_not_be_collected_from_participants, | ||
approach.data_to_collect_from_participants_note, | ||
approach.data_to_send_to_participants, | ||
approach.data_to_send_to_participants_note, | ||
approach.does_need_to_make_multi_payer_data_available, | ||
approach.anticipated_multi_payer_data_availability_use_case, | ||
approach.does_need_to_make_multi_payer_data_available_note, | ||
approach.does_need_to_collect_and_aggregate_multi_source_data, | ||
approach.multi_source_data_to_collect, | ||
approach.multi_source_data_to_collect_other, | ||
approach.does_need_to_collect_and_aggregate_multi_source_data_note, | ||
approach.will_implement_new_data_exchange_methods, | ||
approach.new_data_exchange_methods_description, | ||
approach.new_data_exchange_methods_note, | ||
approach.additional_data_exchange_considerations_description, | ||
approach.created_by, | ||
approach.created_dts, | ||
approach.modified_by, | ||
approach.modified_dts, | ||
approach.marked_complete_by, | ||
approach.marked_complete_dts, | ||
approach.status | ||
FROM plan_data_exchange_approach AS approach | ||
INNER JOIN QUERIED_IDS ON approach.model_plan_id = QUERIED_IDS.model_plan_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package loaders | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/stretchr/testify/suite" | ||
"golang.org/x/sync/errgroup" | ||
) | ||
|
||
type KeyAndExpected[K comparable, Expected any] struct { | ||
Key K | ||
Expected Expected | ||
} | ||
|
||
// verifyLoader is meant to be called by VerifyLoaders to validate a result set of data, and the returned results | ||
func verifyLoader[K comparable, V any, Expected any](ctx context.Context, suite *suite.Suite, loaderWrapper LoaderWrapper[K, V], key K, expected Expected, validateResult func(V, Expected) bool) bool { | ||
res, err := loaderWrapper.Load(ctx, key) | ||
suite.NoError(err) | ||
return validateResult(res, expected) | ||
} | ||
|
||
// VerifyLoaders validates a data loader. It takes a loaderWrapper and a list of expected results and loads the data loader asynchronously. This ensures that the dataloader is returning the results as expected | ||
/* | ||
example | ||
expectedResults := []loaders.KeyAndExpected[uuid.UUID, uuid.UUID]{ | ||
{Key: model_plan1.ID, Expected: approach1.ID}, | ||
{Key: model_plan2.ID, Expected: approach2.ID}, | ||
{Key: model_plan3.ID, Expected: approach3.ID}, | ||
} | ||
verifyFunc := func(data *models.PlanDataExchangeApproach, expected uuid.UUID) bool { | ||
if suite.NotNil(data) { | ||
return suite.EqualValues(expected, data.ID) | ||
} | ||
return false | ||
} | ||
loaders.VerifyLoaders[uuid.UUID, *models.PlanDataExchangeApproach, uuid.UUID](suite.testConfigs.Context, &suite.Suite, loaders.PlanDataExchangeApproach.ByModelPlanID, | ||
expectedResults, verifyFunc) | ||
This example takes the model_plan_id keys, and specifies the expected values. | ||
*/ | ||
func VerifyLoaders[K comparable, V any, Expected any](ctx context.Context, suite *suite.Suite, loaderWrapper LoaderWrapper[K, V], expectedResults []KeyAndExpected[K, Expected], validateResult func(V, Expected) bool) { | ||
g, ctx := errgroup.WithContext(ctx) | ||
for _, expected := range expectedResults { | ||
g.Go(func() error { | ||
passed := verifyLoader[K, V, Expected](ctx, suite, loaderWrapper, expected.Key, expected.Expected, validateResult) | ||
if !passed { | ||
return fmt.Errorf("dataloader verification function failed") | ||
} | ||
return nil | ||
}) | ||
} | ||
err := g.Wait() | ||
suite.NoError(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package loaders | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/google/uuid" | ||
|
||
"github.com/cms-enterprise/mint-app/pkg/appcontext" | ||
"github.com/cms-enterprise/mint-app/pkg/models" | ||
"github.com/cms-enterprise/mint-app/pkg/storage" | ||
|
||
"github.com/graph-gophers/dataloader/v7" | ||
) | ||
|
||
// planDataExchangeApproachLoaders is a struct that holds LoaderWrappers related to Plan Data Exchange Approach | ||
type planDataExchangeApproachLoaders struct { | ||
// ByModelPlanID Gets a plan data exchange approach record associated with a model plan by the supplied model plan id | ||
ByModelPlanID LoaderWrapper[uuid.UUID, *models.PlanDataExchangeApproach] | ||
} | ||
|
||
var PlanDataExchangeApproach = &planDataExchangeApproachLoaders{ | ||
ByModelPlanID: NewLoaderWrapper(batchPlanDataExchangeApproachByModelPlanID), | ||
} | ||
|
||
func batchPlanDataExchangeApproachByModelPlanID(ctx context.Context, modelPlanIDs []uuid.UUID) []*dataloader.Result[*models.PlanDataExchangeApproach] { | ||
logger := appcontext.ZLogger(ctx) | ||
loaders, err := Loaders(ctx) | ||
if err != nil { | ||
return errorPerEachKey[uuid.UUID, *models.PlanDataExchangeApproach](modelPlanIDs, err) | ||
} | ||
|
||
data, err := storage.PlanDataExchangeApproachGetByModelPlanIDLoader(loaders.DataReader.Store, logger, modelPlanIDs) | ||
if err != nil { | ||
return errorPerEachKey[uuid.UUID, *models.PlanDataExchangeApproach](modelPlanIDs, err) | ||
} | ||
getKeyFunc := func(data *models.PlanDataExchangeApproach) uuid.UUID { | ||
return data.ModelPlanID | ||
} | ||
return oneToOneDataLoaderFunc(modelPlanIDs, data, getKeyFunc) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters