Skip to content
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

BCDA-8443|8444: Update attribution to support csv files #1012

Merged

Conversation

laurenkrugen-navapbc
Copy link
Contributor

@laurenkrugen-navapbc laurenkrugen-navapbc commented Nov 15, 2024

🎫 Ticket

https://jira.cms.gov/browse/BCDA-4443
https://jira.cms.gov/browse/BCDA-4444

🛠 Changes

  • CSV file import logic has been created that works with local file handler and s3 file handler
  • tests added/updated
  • removed most logging statements so that errors are pushed to handlecsvimport, where there is logging already. this reduces log noise
  • added custom errors to improve readability and error handling

ℹ️ Context

Changes were made to support attribution files in a csv file format. Follows the flow and structure of the CCLF file importer and was adapted to fit expected csv file format.

🧪 Validation

Added new tests and current tests passing.

bcda/cclf/csv.go Outdated Show resolved Hide resolved
bcda/cclf/csv.go Outdated Show resolved Hide resolved
bcda/cclf/csv.go Outdated Show resolved Hide resolved
bcda/cclf/csv.go Outdated Show resolved Hide resolved
bcda/cclf/csv.go Outdated Show resolved Hide resolved
bcda/cclf/parser.go Outdated Show resolved Hide resolved
bcda/cclf/parser.go Outdated Show resolved Hide resolved
bcda/cclf/parser.go Outdated Show resolved Hide resolved
bcda/cclf/parser.go Outdated Show resolved Hide resolved
bcda/cclf/csv.go Outdated Show resolved Hide resolved
bcda/cclf/csv.go Outdated Show resolved Hide resolved
bcda/cclf/csv.go Outdated

tx, err := conn.BeginEx(ctx, nil)
if err != nil {
err = fmt.Errorf("failed to start transaction: %w", err)
Copy link
Contributor

@bhagatparwinder bhagatparwinder Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here (and a couple of places below)

bcda/cclf/csv.go Outdated Show resolved Hide resolved

rtx := postgres.NewRepositoryPgxTx(tx)

defer func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could change this to handle panic, error, and commit.

defer func() {
  if p := recover(); p != nil {
	  tx.Rollback()
	  panic(p)
  } else if err != nil {
	  tx.Rollback()
  } else {
	  err = tx.Commit()
  }
}()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's two other places that are currently using the existing method of handling rollbacks/transaction errors. I am going to ticket this one as a separate item so we can update those outside of the PR.

bcda/cclf/csv.go Outdated Show resolved Hide resolved
bcda/cclf/csv.go Outdated
err = nil
break
}
// should there be additional validation here so that we know the mbi is a valid mbi?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it wouldn't hurt to add validation for MBI. We can create a utility function. At a minimum, we can check if it is 11 characters long. If we want to spend a day with regex (or if BFD has it) we can do the full logic of numbers and characters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think this would be good to add some validation here and within our CCLF import as well. Maybe we can discuss the implications of adding that validation step - should we always ingest no matter what so that we don't suppress an MBI that is correct but isn't valid?

I'm going to create a ticket for this and hold off on this change for now.

}

filenameDate := subMatches[6]
t, err := time.Parse("D060102.T150405", filenameDate)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we declare these and reference dates as constants? #nomagicstrings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we definitely should -- I pulled this from some other places that could use updating as well. I will put this one in a separate ticket and put out a smaller PR.

@laurenkrugen-navapbc laurenkrugen-navapbc merged commit c347ca3 into epic/attribution-lambda-generalization Dec 5, 2024
8 checks passed
@laurenkrugen-navapbc laurenkrugen-navapbc deleted the lauren/BCDA-8443 branch December 5, 2024 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants