-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MINT-3157] Plan Data Exchange Data Loader #1407
Merged
StevenWadeOddball
merged 6 commits into
feature/MINT-2720_data_exchange
from
task/MINT-3157_data_exchange_data_loader
Oct 11, 2024
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dabb0f3
feat: plan data exchange approach loader implementation
StevenWadeOddball bfa913c
feat: plan data exchange approach loader test first pass, as well as …
StevenWadeOddball dc19ab1
Merge feature/MINT-2720_data_exchange in
ClayBenson94 89999a5
Merge branch 'feature/MINT-2720_data_exchange' into task/MINT-3157_da…
StevenWadeOddball 2d4b8dd
Merge branch 'feature/MINT-2720_data_exchange' into task/MINT-3157_da…
StevenWadeOddball cb9cf1d
feat: use sorting utility methods in data exchange, add a comment to …
StevenWadeOddball File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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,67 @@ | ||
package loaders | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/google/uuid" | ||
"github.com/samber/lo" | ||
|
||
"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) | ||
output := make([]*dataloader.Result[*models.PlanDataExchangeApproach], len(modelPlanIDs)) | ||
loaders, err := Loaders(ctx) | ||
if err != nil { | ||
for index := range modelPlanIDs { | ||
output[index] = &dataloader.Result[*models.PlanDataExchangeApproach]{Data: nil, Error: err} | ||
} | ||
return output | ||
} | ||
|
||
// TODO, when sorting and erroring utilities are merged to main, replace these functions with them | ||
data, err := storage.PlanDataExchangeApproachGetByModelPlanIDLoader(loaders.DataReader.Store, logger, modelPlanIDs) | ||
if err != nil { | ||
|
||
for index := range modelPlanIDs { | ||
output[index] = &dataloader.Result[*models.PlanDataExchangeApproach]{Data: nil, Error: err} | ||
} | ||
return output | ||
} | ||
|
||
approachByModelPlanID := lo.Associate(data, func(data *models.PlanDataExchangeApproach) (uuid.UUID, *models.PlanDataExchangeApproach) { | ||
return data.ModelPlanID, data | ||
}) | ||
|
||
// TODO (loaders) implement the generic sorting functionality once it is merged to main | ||
|
||
// RETURN IN THE SAME ORDER REQUESTED | ||
for index, id := range modelPlanIDs { | ||
|
||
data, ok := approachByModelPlanID[id] | ||
if ok { | ||
output[index] = &dataloader.Result[*models.PlanDataExchangeApproach]{Data: data, Error: nil} | ||
} else { | ||
err2 := fmt.Errorf("plan data exchange approach not found for modelPlanID id %s", id) | ||
output[index] = &dataloader.Result[*models.PlanDataExchangeApproach]{Data: nil, Error: err2} | ||
} | ||
} | ||
return output | ||
|
||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the introduction of this function, do we still need
PlanDataExchangeApproachGetByID
?storage
method by the same name, since it's used inresolvers.PlanDataExchangeApproachUpdate