Skip to content

Commit

Permalink
fixed url generation
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickskowronekdkfz committed Jul 4, 2024
1 parent 04c8a9f commit 9dcc286
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn main() -> anyhow::Result<()> {

//Use normal client in prod
let mainzel_client = reqwest::ClientBuilder::new()
// .danger_accept_invalid_certs(true) // TODO: Remove
.danger_accept_invalid_certs(true) // TODO: Remove
.default_headers(HeaderMap::from_iter([(
HeaderName::from_static("mainzellisteapikey"),
CONFIG.mainzelliste_apikey.clone(),
Expand All @@ -61,10 +61,10 @@ async fn main() -> anyhow::Result<()> {
),
];

let url = ma_session(&mainzel_client).await?;
let session_id = ma_session(&mainzel_client).await?;

for project in projects {
let token = match ma_token_request(&mainzel_client, &url, &project).await {
let token = match ma_token_request(&mainzel_client, &session_id, &project).await {
Ok(url) => url,
Err(_e) => {
eprintln!("Project {} not configured ", project.name);
Expand All @@ -77,7 +77,7 @@ async fn main() -> anyhow::Result<()> {
};

let fhir_client = reqwest::ClientBuilder::new()
// .danger_accept_invalid_certs(true) // TODO: Remove
.danger_accept_invalid_certs(true) // TODO: Remove
.build()?;

for patient in &patients {
Expand All @@ -101,26 +101,37 @@ async fn main() -> anyhow::Result<()> {
}
println!("Updated Patients of Project {}", project.name);
}
tokio::time::sleep(Duration::MAX).await;
Ok(())
}

// 1. Get Mainzelliste Session
async fn ma_session(client: &Client) -> anyhow::Result<String> {
let res = client
.post(CONFIG.mainzelliste_url.join("/sessions")?)
.post(CONFIG.mainzelliste_url.join("/patientlist/sessions")?)
.send()
.await?
.error_for_status()?;
dbg!(&res);

Ok(res
.headers()
.get("location")
.ok_or(anyhow::anyhow!("No location header"))?
.to_str()?
.trim_end_matches("/")
.rsplit_once("/")
.ok_or(anyhow::anyhow!("No Session ID"))?
.1
.to_string())
}

async fn ma_token_request(client: &Client, url: &str, project: &Project) -> anyhow::Result<String> {
async fn ma_token_request(
client: &Client,
session_id: &str,
project: &Project,
) -> anyhow::Result<String> {
dbg!(session_id);
let mrdataids = mainzelliste::SearchId {
id_string: "*".to_owned(),
id_type: format!("{}_{}_L-ID", project.id, CONFIG.site_name),
Expand All @@ -144,7 +155,11 @@ async fn ma_token_request(client: &Client, url: &str, project: &Project) -> anyh
};

let res = client
.post(format!("{url}tokens"))
.post(
CONFIG
.mainzelliste_url
.join(&format!("/patientlist/sessions/{}/tokens", session_id))?,
)
.json(&body)
.send()
.await?
Expand All @@ -163,7 +178,7 @@ async fn get_patient(client: &Client, token: String) -> anyhow::Result<Vec<Strin
.get(
CONFIG
.mainzelliste_url
.join(&format!("/patients/tokenId/{token}"))?,
.join(&format!("/patientlist/patients/tokenId/{token}"))?,
)
.send()
.await?
Expand Down

0 comments on commit 9dcc286

Please sign in to comment.