|
4 | 4 | package main |
5 | 5 |
|
6 | 6 | import ( |
7 | | - "net/http" |
8 | | - "fmt" |
9 | | - "time" |
10 | | - "github.com/philips-software/go-hsdp-api/audit" |
| 7 | + "fmt" |
| 8 | + "net/http" |
| 9 | + "time" |
11 | 10 |
|
12 | | - dstu2cp "github.com/google/fhir/go/proto/google/fhir/proto/dstu2/codes_go_proto" |
| 11 | + dstu2ct "github.com/google/fhir/go/proto/google/fhir/proto/dstu2/codes_go_proto" |
13 | 12 | dstu2dt "github.com/google/fhir/go/proto/google/fhir/proto/dstu2/datatypes_go_proto" |
14 | 13 | dstu2pb "github.com/google/fhir/go/proto/google/fhir/proto/dstu2/resources_go_proto" |
| 14 | + |
| 15 | + "github.com/philips-software/go-hsdp-api/audit/helper/fhir/dstu2" |
| 16 | + |
| 17 | + "github.com/philips-software/go-hsdp-api/audit" |
15 | 18 | ) |
16 | 19 |
|
17 | 20 | func main() { |
18 | | - client, err := audit.NewClient(http.DefaultClient, logging.Config{ |
19 | | - SharedKey: "YourSharedKeyHere=", |
20 | | - SharedSecret: "YourSharedSecretHere==", |
21 | | - BaseURL: "https://audit-service.host.com", |
22 | | - }) |
23 | | - if err != nil { |
24 | | - fmt.Printf("Error: %v\n", err) |
25 | | - return |
26 | | - } |
27 | | - timestamp := time.Date(2020, 12, 31, 23, 59, 59, 0, time.UTC) |
28 | | - event := &dstu2pb.AuditEvent{ |
29 | | - Id: &dstu2dt.Id{Value: "someID"}, |
30 | | - Event: &dstu2pb.AuditEvent_Event{ |
| 21 | + productKey := "xxx-your-key-here-xxx" |
| 22 | + now := time.Now() |
| 23 | + |
| 24 | + client, err := audit.NewClient(http.DefaultClient, &audit.Config{ |
| 25 | + SharedSecret: "secrethere", |
| 26 | + SharedKey: "keyhere", |
| 27 | + AuditBaseURL: "https://your-create-url-here.eu-west.philips-healthsuite.com", |
| 28 | + }) |
| 29 | + if err != nil { |
| 30 | + fmt.Printf("Error: %v\n", err) |
| 31 | + return |
| 32 | + } |
| 33 | + event, err := dstu2.NewAuditEvent(productKey, "andy", |
| 34 | + dstu2.AddSourceExtensionUriValue("applicationName", "patientapp"), |
| 35 | + dstu2.AddParticipant(&dstu2pb.AuditEvent_Participant{ |
| 36 | + UserId: &dstu2dt.Identifier{ |
| 37 | + Value: &dstu2dt.String{Value: "smokeuser@philips.com"}, |
| 38 | + }, |
| 39 | + Requestor: &dstu2dt.Boolean{Value: true}, |
| 40 | + }), |
| 41 | + dstu2.WithEvent(&dstu2pb.AuditEvent_Event{ |
| 42 | + Action: &dstu2ct.AuditEventActionCode{ |
| 43 | + Value: dstu2ct.AuditEventActionCode_E, |
| 44 | + }, |
| 45 | + DateTime: dstu2.DateTime(now), |
31 | 46 | Type: &dstu2dt.Coding{ |
32 | 47 | System: &dstu2dt.Uri{Value: "http://hl7.org/fhir/ValueSet/audit-event-type"}, |
33 | 48 | Version: &dstu2dt.String{Value: "1"}, |
34 | | - Code: &dstu2dt.Code{Value: "110112"}, |
35 | | - Display: &dstu2dt.String{Value: "Query"}, |
| 49 | + Code: &dstu2dt.Code{Value: "11011"}, |
| 50 | + Display: &dstu2dt.String{Value: fmt.Sprintf("Timestamp %v", now.String())}, |
36 | 51 | }, |
37 | | - Action: &dstu2cp.AuditEventActionCode{Value: dstu2cp.AuditEventActionCode_E}, |
38 | | - DateTime: &dstu2dt.Instant{ |
39 | | - Precision: dstu2dt.Instant_MICROSECOND, |
40 | | - ValueUs: timestamp.UnixNano() / 1000, |
| 52 | + Outcome: &dstu2ct.AuditEventOutcomeCode{ |
| 53 | + Value: dstu2ct.AuditEventOutcomeCode_INVALID_UNINITIALIZED, |
41 | 54 | }, |
42 | | - Outcome: &dstu2cp.AuditEventOutcomeCode{Value: dstu2cp.AuditEventOutcomeCode_SUCCESS}, |
43 | 55 | OutcomeDesc: &dstu2dt.String{Value: "Success"}, |
44 | | - }, |
45 | | - Participant: []*dstu2pb.AuditEvent_Participant{ |
46 | | - { |
47 | | - UserId: &dstu2dt.Identifier{Value: &dstu2dt.String{Value: "smokeuser@philips.com"}}, |
48 | | - Requestor: &dstu2dt.Boolean{Value: true}, |
49 | | - }, |
50 | | - }, |
51 | | - Extension: []*dstu2dt.Extension{ |
52 | | - { |
53 | | - Url: &dstu2dt.Uri{Value: "http://foo.bar/com"}, |
54 | | - Value: &dstu2dt.Extension_ValueX{ |
55 | | - Choice: &dstu2dt.Extension_ValueX_Uri{ |
56 | | - Uri: &dstu2dt.Uri{Value: "http://lala.local"}, |
| 56 | + }), |
| 57 | + dstu2.WithSourceIdentifier(&dstu2dt.Identifier{ |
| 58 | + Value: &dstu2dt.String{Value: "smokeuser@philips.com"}, |
| 59 | + Type: &dstu2dt.CodeableConcept{ |
| 60 | + Coding: []*dstu2dt.Coding{ |
| 61 | + { |
| 62 | + System: &dstu2dt.Uri{Value: "http://hl7.org/fhir/ValueSet/identifier-type"}, |
| 63 | + Code: &dstu2dt.Code{Value: "4"}, |
| 64 | + Display: &dstu2dt.String{Value: "application server"}, |
57 | 65 | }, |
58 | 66 | }, |
59 | 67 | }, |
60 | | - }, |
| 68 | + })) |
| 69 | + |
| 70 | + if err != nil { |
| 71 | + fmt.Printf("Error: %v\n", err) |
| 72 | + return |
| 73 | + } |
| 74 | + outcome, resp, err := client.CreateAuditEvent(event) |
| 75 | + if err != nil { |
| 76 | + fmt.Printf("Error: %v\n", err) |
| 77 | + } |
| 78 | + if resp == nil { |
| 79 | + fmt.Printf("response is nil\n") |
| 80 | + return |
| 81 | + } |
| 82 | + fmt.Printf("Audit result: %d\n", resp.StatusCode) |
| 83 | + if outcome != nil { |
| 84 | + fmt.Printf("Outcome: %v\n", outcome) |
61 | 85 | } |
62 | | - _, _, err = client.CreateAuditEvent(event) |
63 | | - if err != nil { |
64 | | - fmt.Printf("Create audit event failed: %v\n", err) |
65 | | - } |
66 | 86 | } |
67 | 87 | ``` |
0 commit comments