Skip to content

Commit

Permalink
Add a flag for logging ACK responses
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 660963400
  • Loading branch information
Cloud Healthcare Team authored and copybara-github committed Aug 8, 2024
1 parent 903a912 commit dbc450d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mllp_adapter/mllp_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
hl7V2LocationID = flag.String("hl7_v2_location_id", "", "ID of Cloud Location where the healthcare dataset is stored")
hl7V2DatasetID = flag.String("hl7_v2_dataset_id", "", "ID of the healthcare dataset")
hl7V2StoreID = flag.String("hl7_v2_store_id", "", "ID of the HL7v2 store inside the healthcare dataset")
logACK = flag.Bool("log_ack", false, "[Optional] Whether to log the ACK received from the API. These info logs will contain sensitive data.")
logNACKedMsg = flag.Bool("log_nacked_msg", false, "[Optional] Whether to log the contents of messages that receive NACK from the API. These error logs will contain sensitive data.")
logErrorMsg = flag.Bool("log_error_msg", false, "[Optional] Whether to log the error message when NACK is received from the API. These error logs will contain sensitive data.")
exportStats = flag.Bool("export_stats", true, "[Optional] Whether to export stackdriver stats")
Expand Down Expand Up @@ -79,7 +80,7 @@ func run() error {
log.Warningf("Flag --api_addr_prefix deprecated, API calls will be made to healthcare.googleapis.com/v1.")
}
si := healthapiclient.StoreInfo{*hl7V2ProjectID, *hl7V2LocationID, *hl7V2DatasetID, *hl7V2StoreID}
opt := healthapiclient.Option{*logNACKedMsg, *logErrorMsg}
opt := healthapiclient.Option{*logNACKedMsg, *logErrorMsg, *logACK}
apiClient, err := healthapiclient.NewHL7V2Client(ctx, *credentials, mon, si, opt)
if err != nil {
return fmt.Errorf("failed to connect to HL7v2 API: %v", err)
Expand Down
6 changes: 6 additions & 0 deletions shared/healthapiclient/healthapiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type HL7V2Client struct {
hl7V2StoreID string
logNACKedMsg bool
logErrMsg bool
logACK bool
}

type sendMessageErrorResp struct {
Expand All @@ -77,6 +78,7 @@ type StoreInfo struct {
type Option struct {
LogNACKedMessage bool
LogErrorMessage bool
LogACK bool
}

// NewHL7V2Client creates a properly authenticated client that talks to an HL7v2 backend.
Expand All @@ -99,6 +101,7 @@ func NewHL7V2Client(ctx context.Context, cred string, metrics monitoring.Client,
hl7V2StoreID: si.HL7V2StoreID,
logNACKedMsg: opt.LogNACKedMessage,
logErrMsg: opt.LogErrorMessage,
logACK: opt.LogACK,
}
c.initMetrics()
return c, nil
Expand Down Expand Up @@ -188,6 +191,9 @@ func (c *HL7V2Client) Send(data []byte) ([]byte, error) {
c.metrics.IncCounter(sendErrorMetric)
return nil, fmt.Errorf("unable to parse ACK response: %v", err)
}
if c.logACK {
log.Infof("Received ACK from HL7V2 Store: %s", sanitizeMessageForPrintout(ack))
}
log.Infof("Message was successfully sent to the Cloud Healthcare API HL7V2 Store.")
return ack, nil
}
Expand Down

0 comments on commit dbc450d

Please sign in to comment.