Skip to content

Commit

Permalink
bcda-521: log jobID for BlueButton ExplanationOfBenefit requests and …
Browse files Browse the repository at this point in the history
…responses (#83)

* bcda-521: log jobID for bluebutton eob requests

* add job_id to bluebutton response logs
  • Loading branch information
alexhova authored Nov 29, 2018
1 parent 8ee76df commit f5d12eb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
24 changes: 13 additions & 11 deletions bcda/client/bluebutton.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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")
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion bcda/client/bluebutton_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions bcdaworker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/CMSgov/bcda-app/bcda/encryption"
"io/ioutil"
"os"
"os/signal"
"regexp"
"strconv"
"syscall"

"github.com/CMSgov/bcda-app/bcda/encryption"

"github.com/jackc/pgx"
log "github.com/sirupsen/logrus"

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion bcdaworker/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit f5d12eb

Please sign in to comment.