audit

package
v0.85.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 14 Imported by: 0

README

Using the audit client

package main

import (
	"fmt"
	"net/http"
	"time"

	dstu2ct "github.com/google/fhir/go/proto/google/fhir/proto/dstu2/codes_go_proto"
	dstu2dt "github.com/google/fhir/go/proto/google/fhir/proto/dstu2/datatypes_go_proto"
	dstu2pb "github.com/google/fhir/go/proto/google/fhir/proto/dstu2/resources_go_proto"

	"github.com/philips-software/go-hsdp-api/audit/helper/fhir/dstu2"

	"github.com/philips-software/go-hsdp-api/audit"
)

func main() {
	productKey := "xxx-your-key-here-xxx"
	now := time.Now()

	client, err := audit.NewClient(http.DefaultClient, &audit.Config{
		SharedSecret: "secrethere",
		SharedKey:    "keyhere",
		AuditBaseURL: "https://your-create-url-here.eu-west.philips-healthsuite.com",
	})
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	event, err := dstu2.NewAuditEvent(productKey, "andy",
		dstu2.AddSourceExtensionUriValue("applicationName", "patientapp"),
		dstu2.AddParticipant(&dstu2pb.AuditEvent_Participant{
			UserId: &dstu2dt.Identifier{
				Value: &dstu2dt.String{Value: "smokeuser@philips.com"},
			},
			Requestor: &dstu2dt.Boolean{Value: true},
		}),
		dstu2.WithEvent(&dstu2pb.AuditEvent_Event{
			Action: &dstu2ct.AuditEventActionCode{
				Value: dstu2ct.AuditEventActionCode_E,
			},
			DateTime: dstu2.DateTime(now),
			Type: &dstu2dt.Coding{
				System:  &dstu2dt.Uri{Value: "http://hl7.org/fhir/ValueSet/audit-event-type"},
				Version: &dstu2dt.String{Value: "1"},
				Code:    &dstu2dt.Code{Value: "11011"},
				Display: &dstu2dt.String{Value: fmt.Sprintf("Timestamp %v", now.String())},
			},
			Outcome: &dstu2ct.AuditEventOutcomeCode{
				Value: dstu2ct.AuditEventOutcomeCode_INVALID_UNINITIALIZED,
			},
			OutcomeDesc: &dstu2dt.String{Value: "Success"},
		}),
		dstu2.WithSourceIdentifier(&dstu2dt.Identifier{
			Value: &dstu2dt.String{Value: "smokeuser@philips.com"},
			Type: &dstu2dt.CodeableConcept{
				Coding: []*dstu2dt.Coding{
					{
						System:  &dstu2dt.Uri{Value: "http://hl7.org/fhir/ValueSet/identifier-type"},
						Code:    &dstu2dt.Code{Value: "4"},
						Display: &dstu2dt.String{Value: "application server"},
					},
				},
			},
		}))

	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	outcome, resp, err := client.CreateAuditEvent(event)
	if err != nil {
		fmt.Printf("Error: %v\n", err)
	}
	if resp == nil {
		fmt.Printf("response is nil\n")
		return
	}
	fmt.Printf("Audit result: %d\n", resp.StatusCode)
	if outcome != nil {
		fmt.Printf("Outcome: %v\n", outcome)
	}
}

Documentation

Overview

Package audit provides support for interacting with the HSDP Audit service

Index

Constants

View Source
const (
	APIVersion = "2"
)

Variables

View Source
var (
	ErrBaseURLCannotBeEmpty = errors.New("base URL cannot be empty")
	ErrEmptyResult          = errors.New("empty result")
	ErrBadRequest           = errors.New("bad request")
)

Errors

Functions

This section is empty.

Types

type Client

type Client struct {

	// User agent used when communicating with the HSDP IAM API.
	UserAgent string
	// contains filtered or unexported fields
}

Client holds state of a HSDP Audit client

func NewClient

func NewClient(httpClient *http.Client, config *Config) (*Client, error)

NewClient returns a new HSDP Audit API client. Configured console and IAM clients must be provided as the underlying API requires tokens from respective services

func (*Client) Close

func (c *Client) Close()

Close releases allocated resources of clients

func (*Client) CreateAuditEvent

func (c *Client) CreateAuditEvent(event *dstu2pb.AuditEvent) (*stu3pb.ContainedResource, *Response, error)

type Config

type Config struct {
	Region      string
	Environment string
	// AuditBaseURL is provided as part of Auditing onboarding
	AuditBaseURL string
	// SharedKey is the IAM API signing key
	SharedKey string
	// SharedSecret is the IAM API signing secret
	SharedSecret string
	TimeZone     string
	DebugLog     io.Writer
}

Config contains the configuration of a client

type OptionFunc

type OptionFunc func(*http.Request) error

OptionFunc is the function signature function for options

type Response

type Response struct {
	*http.Response
}

Response is a HSDP Audit API response. This wraps the standard http.Response returned from HSDP Audit and provides convenient access to things like errors

func (*Response) StatusCode added in v0.73.0

func (r *Response) StatusCode() int

Directories

Path Synopsis
helper
fhir/dstu2
Package dstu2 contains helper methods to construct AuditEvent resources
Package dstu2 contains helper methods to construct AuditEvent resources

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL