forked from intervention-engine/fhir
/
config.go
146 lines (114 loc) · 4.87 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package server
import (
"fmt"
"net/http"
"net/url"
"strings"
"time"
"github.com/eug48/fhir/auth"
)
// Config is used to hold information about the configuration of the FHIR server.
type Config struct {
// ServerURL is the full URL for the root of the server. This may be used
// by other middleware to compute redirect URLs
ServerURL string
// Auth determines what, if any authentication and authorization will be used
// by the FHIR server
Auth auth.Config
// Whether to create indexes on startup
CreateIndexes bool
// IndexConfigPath is the path to an indexes.conf configuration file, specifying
// what mongo indexes the server should create (or verify) on startup
IndexConfigPath string
// DatabaseURI is the url of the mongo replica set to use for the FHIR database.
// A replica set is required for transactions support
// e.g. mongodb://db1:27017,db2:27017/?replicaSet=rs1
DatabaseURI string
// DatabaseName is the name of the mongo database used for the fhir database by default.
// Typically this will be the "fhir".
DefaultDatabaseName string
// EnableMultiDB allows requests to specify a specific Mongo database instead of the default
// e.g. to use test4_fhir http://fhir-server/db/test4_fhir/Patient?name=alex
EnableMultiDB bool
// All custom database names should end with this suffix (default is "_fhir")
DatabaseSuffix string
// DatabaseSocketTimeout is the amount of time the mgo driver will wait for a response
// from mongo before timing out.
DatabaseSocketTimeout time.Duration
// DatabaseOpTimeout is the amount of time GoFHIR will wait before killing a long-running
// database process. This defaults to a reasonable upper bound for slow, pipelined queries: 30s.
DatabaseOpTimeout time.Duration
// DatabaseKillOpPeriod is the length of time between scans of the database to kill long-running ops.
DatabaseKillOpPeriod time.Duration
// CountTotalResults toggles whether the searcher should also get a total
// count of the total results of a search. In practice this is a performance hit
// for large datasets.
CountTotalResults bool
// EnableCISearches toggles whether the mongo searches uses regexes to maintain
// case-insesitivity when performing searches on string fields, codes, etc.
EnableCISearches bool
// Whether to use case-sensitive search for token-type search parameters
// Slower but default off for backwards compatibility and strict STU3 support
// R4 leans towards case-sensitive, whereas STU3 text suggests case-insensitive (https://github.com/HL7/fhir/commit/13fb1c1f102caf7de7266d6e78ab261efac06a1f)
TokenParametersCaseSensitive bool
// Whether to support storing previous versions of each resource
EnableHistory bool
// Number of concurrent operations to do during batch bundle processing
BatchConcurrency int
// Whether to allow retrieving resources with no meta component,
// meaning Last-Modified & ETag headers can't be generated (breaking spec compliance)
// May be needed to support previous databases
AllowResourcesWithoutMeta bool
// ValidatorURL is an endpoint to which validation requests will be sent
ValidatorURL string
// ReadOnly toggles whether the server is in read-only mode. In read-only
// mode any HTTP verb other than GET, HEAD or OPTIONS is rejected.
ReadOnly bool
// Enables requests and responses using FHIR XML MIME-types
EnableXML bool
// Debug toggles debug-level logging.
Debug bool
// Where to dump failed requests for debugging
FailedRequestsDir string
}
// DefaultConfig is the default server configuration
var DefaultConfig = Config{
ServerURL: "",
IndexConfigPath: "config/indexes.conf",
DatabaseURI: "mongodb://localhost:27017/?replicaSet=rs0",
DatabaseSuffix: "_fhir",
DatabaseSocketTimeout: 2 * time.Minute,
DatabaseOpTimeout: 90 * time.Second,
DatabaseKillOpPeriod: 10 * time.Second,
Auth: auth.None(),
EnableCISearches: true,
TokenParametersCaseSensitive: false,
EnableHistory: true,
BatchConcurrency: 1,
EnableXML: true,
CountTotalResults: true,
ReadOnly: false,
Debug: false,
}
func (config *Config) responseURL(r *http.Request, paths ...string) *url.URL {
dbPrefix := r.Header.Get("db")
if dbPrefix != "" {
dbPrefix = "/db/" + dbPrefix
}
if config.ServerURL != "" {
theURL := fmt.Sprintf("%s%s/%s", strings.TrimSuffix(config.ServerURL, "/"), dbPrefix, strings.Join(paths, "/"))
responseURL, err := url.Parse(theURL)
if err == nil {
return responseURL
}
}
responseURL := url.URL{}
if r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" {
responseURL.Scheme = "https"
} else {
responseURL.Scheme = "http"
}
responseURL.Host = r.Host
responseURL.Path = fmt.Sprintf("%s/%s", dbPrefix, strings.Join(paths, "/"))
return &responseURL
}