Skip to content

Commit

Permalink
Merge branch 'deploy/omop' of github.com:samply/focus into feature/cql
Browse files Browse the repository at this point in the history
  • Loading branch information
enola-dkfz committed Dec 6, 2023
2 parents 5860bdd + 197e010 commit f683ec9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ EPSILON = "0.1" # Privacy budget parameter for obfuscating the counts in the str
ROUNDING_STEP = "10" # The granularity of the rounding of the obfuscated values, has no effect if OBFUSCATE = "no", default value: 10
PROJECTS_NO_OBFUSCATION = "exliquid;dktk_supervisors" # Projects for which the results are not to be obfuscated, separated by ;, default value: "exliquid; dktk_supervisors"
QUERIES_TO_CACHE_FILE_PATH = "resources/bbmri" # The path to the file containing BASE64 encoded queries whose results are to be cached, if not set, no results are cached
PROVIDER = "" #OMOP provider name
PROVIDER_ICON = "" #Base64 encoded OMOP provider icon
PROVIDER = "name" #OMOP provider name
PROVIDER_ICON = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII=" #Base64 encoded OMOP provider icon
AUTH_HEADER = "ApiKey XXXX" #Authorization header
```

Obfuscating zero counts is by default switched off. To enable obfuscating zero counts, set the env. variable `OBFUSCATE_ZERO`.
Expand Down
10 changes: 8 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,17 @@ struct CliArgs {
tls_ca_certificates_dir: Option<PathBuf>,

/// OMOP provider name
#[clap(long, env, value_parser, default_value = "")]
#[clap(long, env, value_parser)]
provider: Option<String>,

/// Base64 encoded OMOP provider icon
#[clap(long, env, value_parser, default_value = "")]
#[clap(long, env, value_parser)]
provider_icon: Option<String>,

/// Authorization header
#[clap(long, env, value_parser)]
auth_header: Option<String>,

}

pub(crate) struct Config {
Expand All @@ -162,6 +166,7 @@ pub(crate) struct Config {
pub client: Client,
pub provider: Option<String>,
pub provider_icon: Option<String>,
pub auth_header: Option<String>,
}

impl Config {
Expand Down Expand Up @@ -199,6 +204,7 @@ impl Config {
tls_ca_certificates,
provider: cli_args.provider,
provider_icon: cli_args.provider_icon,
auth_header: cli_args.auth_header,
client,
};
Ok(config)
Expand Down
3 changes: 3 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ pub enum FocusError {
AstOperatorValueMismatch(),
#[error("Invalid date format: {0}")]
AstInvalidDateFormat(String),
#[error("Invalid Header Value: {0}")]
InvalidHeaderValue(http::header::InvalidHeaderValue),

}
21 changes: 20 additions & 1 deletion src/omop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use http::HeaderMap;
use http::HeaderValue;
use http::StatusCode;
use http::header;
use serde::Deserialize;
use serde::Serialize;
use tracing::{debug, warn};
Expand All @@ -24,10 +27,26 @@ pub async fn post_ast(ast: ast::Ast) -> Result<String, FocusError> {

debug!("{}", ast_string.clone());

let mut headers = HeaderMap::new();

headers.insert(header::CONTENT_TYPE,
HeaderValue::from_str("application/json")
.map_err(|e| FocusError::InvalidHeaderValue(e))?);

match CONFIG.auth_header.clone() {
Some(auth_header_value) => {
headers.insert(header::AUTHORIZATION,
HeaderValue::from_str(auth_header_value.as_str())
.map_err(|e| FocusError::InvalidHeaderValue(e))?);
},

None => {}
}

let resp = CONFIG
.client
.post(format!("{}", CONFIG.endpoint_url))
.header("Content-Type", "application/json")
.headers(headers)
.body(ast_string.clone())
.send()
.await
Expand Down

0 comments on commit f683ec9

Please sign in to comment.