Skip to content

Commit

Permalink
DRY up some code for sonarqube flagged code (#999)
Browse files Browse the repository at this point in the history
## 🎫 Ticket

An extension of https://jira.cms.gov/browse/BCDA-8230

## 🛠 Changes

Removed some duplicate code as was flagged by sonarqube

## ℹ️ Context

<!-- Why were these changes made? Add background context suitable for a
non-technical audience. -->

<!-- If any of the following security implications apply, this PR must
not be merged without Stephen Walter's approval. Explain in this section
and add @SJWalter11 as a reviewer.
  - Adds a new software dependency or dependencies.
  - Modifies or invalidates one or more of our security controls.
  - Stores or transmits data that was not stored or transmitted before.
- Requires additional review of security implications for other reasons.
-->

## 🧪 Validation

Full linting and testing performed
  • Loading branch information
carlpartridge authored Oct 9, 2024
1 parent bd692a5 commit 9999a37
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions bcda/client/bluebutton.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (bbc *BlueButtonClient) GetPatient(jobData models.JobEnqueueArgs, patientID
return nil, err
}

return bbc.getBundleData(u, jobData, header)
return bbc.makeBundleDataRequest("GET", u, jobData, header, nil)
}

func (bbc *BlueButtonClient) GetPatientByMbi(jobData models.JobEnqueueArgs, mbi string) (string, error) {
Expand All @@ -183,7 +183,7 @@ func (bbc *BlueButtonClient) GetCoverage(jobData models.JobEnqueueArgs, benefici
return nil, err
}

return bbc.getBundleData(u, jobData, nil)
return bbc.makeBundleDataRequest("GET", u, jobData, nil, nil)
}

func (bbc *BlueButtonClient) GetClaim(jobData models.JobEnqueueArgs, mbi string, claimsWindow ClaimsWindow) (*fhirModels.Bundle, error) {
Expand All @@ -202,7 +202,7 @@ func (bbc *BlueButtonClient) GetClaim(jobData models.JobEnqueueArgs, mbi string,
}

body := fmt.Sprintf(`{"identifier":"http://hl7.org/fhir/sid/us-mbi|%s"}`, mbi)
return bbc.postBundleData(u, jobData, header, strings.NewReader(body))
return bbc.makeBundleDataRequest("POST", u, jobData, header, strings.NewReader(body))
}

func (bbc *BlueButtonClient) GetClaimResponse(jobData models.JobEnqueueArgs, mbi string, claimsWindow ClaimsWindow) (*fhirModels.Bundle, error) {
Expand All @@ -221,7 +221,7 @@ func (bbc *BlueButtonClient) GetClaimResponse(jobData models.JobEnqueueArgs, mbi
}

body := fmt.Sprintf(`{"identifier":"http://hl7.org/fhir/sid/us-mbi|%s"}`, mbi)
return bbc.postBundleData(u, jobData, header, strings.NewReader(body))
return bbc.makeBundleDataRequest("POST", u, jobData, header, strings.NewReader(body))
}

func (bbc *BlueButtonClient) GetExplanationOfBenefit(jobData models.JobEnqueueArgs, patientID string, claimsWindow ClaimsWindow) (*fhirModels.Bundle, error) {
Expand All @@ -239,7 +239,7 @@ func (bbc *BlueButtonClient) GetExplanationOfBenefit(jobData models.JobEnqueueAr
return nil, err
}

return bbc.getBundleData(u, jobData, header)
return bbc.makeBundleDataRequest("GET", u, jobData, header, nil)
}

func (bbc *BlueButtonClient) GetMetadata() (string, error) {
Expand All @@ -252,14 +252,6 @@ func (bbc *BlueButtonClient) GetMetadata() (string, error) {
return bbc.getRawData(jobData, "GET", u, nil)
}

func (bbc *BlueButtonClient) getBundleData(u *url.URL, jobData models.JobEnqueueArgs, headers http.Header) (*fhirModels.Bundle, error) {
return bbc.makeBundleDataRequest("GET", u, jobData, headers, nil)
}

func (bbc *BlueButtonClient) postBundleData(u *url.URL, jobData models.JobEnqueueArgs, headers http.Header, body io.Reader) (*fhirModels.Bundle, error) {
return bbc.makeBundleDataRequest("POST", u, jobData, headers, body)
}

func (bbc *BlueButtonClient) makeBundleDataRequest(method string, u *url.URL, jobData models.JobEnqueueArgs, headers http.Header, body io.Reader) (*fhirModels.Bundle, error) {
var b *fhirModels.Bundle
for ok := true; ok; {
Expand Down

0 comments on commit 9999a37

Please sign in to comment.