diff --git a/bcda/client/bluebutton.go b/bcda/client/bluebutton.go index 0837fbb2b..a1e77c1cf 100644 --- a/bcda/client/bluebutton.go +++ b/bcda/client/bluebutton.go @@ -20,7 +20,7 @@ var logger *logrus.Logger const blueButtonBasePath = "/v1/fhir" type APIClient interface { - GetExplanationOfBenefitData(patientID string) (string, error) + GetExplanationOfBenefitData(patientID string, jobID string) (string, error) } type BlueButtonClient struct { @@ -31,10 +31,10 @@ func init() { logger = logrus.New() logger.Formatter = &logrus.JSONFormatter{} filePath := os.Getenv("BCDA_BB_LOG") - + /* #nosec -- 0640 permissions required for Splunk ingestion */ file, err := os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY, 0640) - + if err == nil { logger.SetOutput(file) } else { @@ -82,30 +82,30 @@ func (bbc *BlueButtonClient) GetPatientData(patientID string) (string, error) { params := url.Values{} params.Set("_id", patientID) params.Set("_format", "application/fhir+json") - return bbc.getData(blueButtonBasePath+"/Patient/", params) + return bbc.getData(blueButtonBasePath+"/Patient/", params, "") } func (bbc *BlueButtonClient) GetCoverageData(beneficiaryID string) (string, error) { params := url.Values{} params.Set("beneficiary", beneficiaryID) params.Set("_format", "application/fhir+json") - return bbc.getData(blueButtonBasePath+"/Coverage/", params) + return bbc.getData(blueButtonBasePath+"/Coverage/", params, "") } -func (bbc *BlueButtonClient) GetExplanationOfBenefitData(patientID string) (string, error) { +func (bbc *BlueButtonClient) GetExplanationOfBenefitData(patientID string, jobID string) (string, error) { params := url.Values{} params.Set("patient", patientID) params.Set("_format", "application/fhir+json") - return bbc.getData(blueButtonBasePath+"/ExplanationOfBenefit/", params) + return bbc.getData(blueButtonBasePath+"/ExplanationOfBenefit/", params, jobID) } func (bbc *BlueButtonClient) GetMetadata() (string, error) { params := url.Values{} params.Set("_format", "application/fhir+json") - return bbc.getData(blueButtonBasePath+"/metadata/", params) + return bbc.getData(blueButtonBasePath+"/metadata/", params, "") } -func (bbc *BlueButtonClient) getData(path string, params url.Values) (string, error) { +func (bbc *BlueButtonClient) getData(path string, params url.Values, jobID string) (string, error) { reqID := uuid.NewRandom() bbServer := os.Getenv("BB_SERVER_LOCATION") @@ -120,7 +120,7 @@ func (bbc *BlueButtonClient) getData(path string, params url.Values) (string, er addRequestHeaders(req, reqID) resp, err := bbc.httpClient.Do(req) - logRequest(req, resp) + logRequest(req, resp, jobID) if err != nil { return "", err } @@ -153,11 +153,12 @@ func addRequestHeaders(req *http.Request, reqID uuid.UUID) { req.Header.Add("BlueButton-BackendCall", "") } -func logRequest(req *http.Request, resp *http.Response) { +func logRequest(req *http.Request, resp *http.Response, jobID string) { logger.WithFields(logrus.Fields{ "bb_query_id": req.Header.Get("BlueButton-OriginalQueryId"), "bb_query_ts": req.Header.Get("BlueButton-OriginalQueryTimestamp"), "bb_uri": req.Header.Get("BlueButton-OriginalUrl"), + "job_id": jobID, }).Infoln("Blue Button request") if resp != nil { @@ -166,6 +167,7 @@ func logRequest(req *http.Request, resp *http.Response) { "bb_query_id": resp.Header.Get("BlueButton-OriginalQueryId"), "bb_query_ts": resp.Header.Get("BlueButton-OriginalQueryTimestamp"), "bb_uri": resp.Header.Get("BlueButton-OriginalUrl"), + "job_id": jobID, "content_length": resp.ContentLength, }).Infoln("Blue Button response") } diff --git a/bcda/client/bluebutton_test.go b/bcda/client/bluebutton_test.go index 5fcfdb7ad..50070acba 100644 --- a/bcda/client/bluebutton_test.go +++ b/bcda/client/bluebutton_test.go @@ -49,7 +49,7 @@ func (s *BBTestSuite) TestGetBlueButtonCoverageData() { } func (s *BBTestSuite) TestGetBlueButtonExplanationOfBenefitData() { - e, err := s.bbClient.GetExplanationOfBenefitData("012345") + e, err := s.bbClient.GetExplanationOfBenefitData("012345", "543210") assert.Nil(s.T(), err) assert.Equal(s.T(), `{ "test": "ok" }`, e) } diff --git a/bcdaworker/main.go b/bcdaworker/main.go index 50dd1ab76..fceec8862 100644 --- a/bcdaworker/main.go +++ b/bcdaworker/main.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "github.com/CMSgov/bcda-app/bcda/encryption" "io/ioutil" "os" "os/signal" @@ -13,6 +12,8 @@ import ( "strconv" "syscall" + "github.com/CMSgov/bcda-app/bcda/encryption" + "github.com/jackc/pgx" log "github.com/sirupsen/logrus" @@ -172,7 +173,7 @@ func writeEOBDataToFile(bb client.APIClient, acoID string, beneficiaryIDs []stri w := bufio.NewWriter(f) for _, beneficiaryID := range beneficiaryIDs { - pData, err := bb.GetExplanationOfBenefitData(beneficiaryID) + pData, err := bb.GetExplanationOfBenefitData(beneficiaryID, jobID) if err != nil { log.Error(err) appendErrorToFile(acoID, responseutils.Exception, responseutils.BbErr, fmt.Sprintf("Error retrieving ExplanationOfBenefit for beneficiary %s in ACO %s", beneficiaryID, acoID), jobID) diff --git a/bcdaworker/main_test.go b/bcdaworker/main_test.go index 542969a3a..51b58915a 100644 --- a/bcdaworker/main_test.go +++ b/bcdaworker/main_test.go @@ -147,7 +147,7 @@ func TestAppendErrorToFile(t *testing.T) { os.Remove(filePath) } -func (bbc *MockBlueButtonClient) GetExplanationOfBenefitData(patientID string) (string, error) { +func (bbc *MockBlueButtonClient) GetExplanationOfBenefitData(patientID string, jobID string) (string, error) { args := bbc.Called(patientID) return args.String(0), args.Error(1) }