Skip to content

Commit

Permalink
Added CI/Build and fhir calls
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickskowronekdkfz committed Jul 4, 2024
1 parent 4e80e71 commit d23302f
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 50 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "cargo" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
target-branch: "main"
28 changes: 28 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Rust

on:
push:
branches: [main]
workflow_dispatch:
pull_request:

env:
CARGO_TERM_COLOR: always
PROFILE: release

jobs:
rust:
# This workflow defines how a maven package is built, tested and published.
# Visit: https://github.com/samply/github-workflows/blob/develop/.github/workflows/docker-ci.yml, for more information
uses: samply/github-workflows/.github/workflows/rust.yml@main
with:
image-prefix: "samply/"
components: '[ "beam-file" ]'
#architectures: '[ "amd64", "arm64" ]'
#profile: debug
test-via-script: false
features: '[ "", "server" ]'
push-to: ${{ (github.ref_protected == true || github.event_name == 'workflow_dispatch') && 'dockerhub' || 'none' }}
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
13 changes: 13 additions & 0 deletions .github/workflows/rust_security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
on:
schedule:
- cron: '0 3 * * 1'
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/audit-check@v1
with:

token: ${{ secrets.GITHUB_TOKEN }}

11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM alpine AS chmodder
ARG TARGETARCH
ARG COMPONENT
ARG FEATURE
COPY /artifacts/binaries-$TARGETARCH$FEATURE/$COMPONENT /app/$COMPONENT
RUN chmod +x /app/*

FROM gcr.io/distroless/cc-debian12
ARG COMPONENT
COPY --from=chmodder /app/$COMPONENT /usr/local/bin/samply
ENTRYPOINT [ "/usr/local/bin/samply" ]
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "3.8"
services:
pi:
build: .
environment:
MAINZELLISTE_URL: ${MAINZELLISTE_URL:-http://id-manager}
MAINZELLISTE_APIKEY: ${MAINZELLISTE_APIKEY:-mainzelliste}
SITE_NAME: ${SITE_NAME:-Teststandort}
BLAZE_URL: ${BLAZE_URL:-http://bridgehead-ccp-blaze:8080}
109 changes: 59 additions & 50 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use std::time::Duration;

use clap::Parser;
use config::Config;
use fhir::Extension;
use fhir::Resource;
use fhir::Root;
use once_cell::sync::Lazy;
use reqwest::header::HeaderMap;
use reqwest::header::HeaderName;
use reqwest::Client;
use serde_json::Value;
use tokio::time::sleep;

mod fhir;
mod mainzelliste;
Expand All @@ -28,68 +32,82 @@ impl Project {

#[tokio::main]
async fn main() -> anyhow::Result<()> {
sleep(Duration::from_secs(120)).await;
println!("Starting Patient-Project-Indentificator...");

//Use normal client in prod
let mainzel_client = reqwest::ClientBuilder::new()
.danger_accept_invalid_certs(true) // TODO: Remove
.default_headers(HeaderMap::from_iter([(HeaderName::from_static("mainzellisteapikey"), CONFIG.mainzelliste_apikey.clone())]))
// .danger_accept_invalid_certs(true) // TODO: Remove
.default_headers(HeaderMap::from_iter([(
HeaderName::from_static("mainzellisteapikey"),
CONFIG.mainzelliste_apikey.clone(),
)]))
.build()?;

let projects = [
Project::new("DKTK000000791".to_string(), "ReKo".to_string()),
Project::new("DKTK000002089".to_string(), "EXLIQUID".to_string()),
// Project::new("DKTK000005001".to_string(), "CRC-Advanced".to_string()),
// Project::new("DKTK000004877".to_string(), "Meth4CRC".to_string()),
// Project::new("DKTK000002016".to_string(), "NeoLung".to_string()),
Project::new("DKTK000005001".to_string(), "CRC-Advanced".to_string()),
Project::new("DKTK000004877".to_string(), "Meth4CRC".to_string()),
Project::new("DKTK000002016".to_string(), "NeoLung".to_string()),
Project::new("DKTK000001986".to_string(), "MASTER-Programm".to_string()),
Project::new("DKTK000001985".to_string(), "RiskY-AML".to_string()),
Project::new("DKTK000001951".to_string(), "ARMANI".to_string()),
Project::new("DKTK000001950".to_string(), "IRCC".to_string()),
// Project::new("DKTK000001087".to_string(), "TamoBreastCa".to_string()),
// Project::new("DKTK000000899".to_string(), "Cov2Cancer-Register".to_string()),
Project::new("DKTK000001087".to_string(), "TamoBreastCa".to_string()),
Project::new(
"DKTK000000899".to_string(),
"Cov2Cancer-Register".to_string(),
),
];

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

println!("{}", url);
println!("-----------------------------");

for project in projects {
let token = match ma_token_request(&mainzel_client, &url, &project).await {
Ok(url) => url,
Err(e) => {
eprintln!("Failed to get token url for {}: {e}", project.name);
Err(_e) => {
eprintln!("Project {} not configured ", project.name);
continue;
},
}
};
let Ok(patients) = get_patient(&mainzel_client, token).await else { continue; };
dbg!(patients);

// for patient in &patients {
// let mut fhirPatient = get_patient_from_blaze(&client, patient.to_string()).await;

// if let Some(ref mut extension) = fhirPatient.extension {
// if(!extension.contains(&Extension{url: "http://dktk.dkfz.de/fhir/Projects/".to_string() + &project.0.as_str()})) {
// extension.push(Extension{url: "http://dktk.dkfz.de/fhir/Projects/".to_string() + &project.0.as_str()})
// }
// } else {
// fhirPatient.extension = Some(vec![Extension{url: "http://dktk.dkfz.de/fhir/Projects/".to_string() + &project.0.as_str()}]);
// }
// post_patient_to_blaze(&client, fhirPatient).await;
// }
let Ok(patients) = get_patient(&mainzel_client, token).await else {
println!("Did not found any Patients in {}", project.name);
continue;
};

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

for patient in &patients {
let mut fhir_patient = get_patient_from_blaze(&fhir_client, patient.to_string()).await;

if let Some(ref mut extension) = fhir_patient.extension {
if !extension.contains(&Extension {
url: "http://dktk.dkfz.de/fhir/Projects/".to_string() + &project.id.as_str(),
}) {
extension.push(Extension {
url: "http://dktk.dkfz.de/fhir/Projects/".to_string()
+ &project.id.as_str(),
})
}
} else {
fhir_patient.extension = Some(vec![Extension {
url: "http://dktk.dkfz.de/fhir/Projects/".to_string() + &project.id.as_str(),
}]);
}
post_patient_to_blaze(&fhir_client, fhir_patient).await;
}
println!("Updated Patients of Project {}", project.name);
}
Ok(())
}

// 1. Get Mainzelliste Session
async fn ma_session(client: &Client) -> anyhow::Result<String> {
let res = client
.post(
CONFIG
.mainzelliste_url
.join("/patientlist/sessions")?,
)
.post(CONFIG.mainzelliste_url.join("/patientlist/sessions")?)
.send()
.await?
.error_for_status()?;
Expand All @@ -102,11 +120,7 @@ async fn ma_session(client: &Client) -> anyhow::Result<String> {
.to_string())
}

async fn ma_token_request(
client: &Client,
url: &str,
project: &Project,
) -> anyhow::Result<String> {
async fn ma_token_request(client: &Client, url: &str, project: &Project) -> anyhow::Result<String> {
let mrdataids = mainzelliste::SearchId {
id_string: "*".to_owned(),
id_type: format!("{}_{}_L-ID", project.id, CONFIG.site_name),
Expand All @@ -129,8 +143,6 @@ async fn ma_token_request(
data: mrdata,
};

// println!("{}", serde_json::to_string(&body).unwrap());

let res = client
.post(format!("{url}tokens"))
.json(&body)
Expand All @@ -148,21 +160,22 @@ async fn ma_token_request(

async fn get_patient(client: &Client, token: String) -> anyhow::Result<Vec<String>> {
Ok(client
.get(CONFIG.mainzelliste_url.join(&format!("/patientlist/patients/tokenId/{token}"))?)
.get(
CONFIG
.mainzelliste_url
.join(&format!("/patientlist/patients/tokenId/{token}"))?,
)
.send()
.await?
.error_for_status()?
.json::<Vec<Value>>()
.await?
.into_iter()
.filter_map(|v| v["ids"][0]["idString"].as_str().map(ToOwned::to_owned))
.collect()
)
.collect())
}

async fn get_patient_from_blaze(client: &Client, patient_id: String) -> Resource {
print!("Getting Patient");

let res = client
.get(
CONFIG
Expand All @@ -178,9 +191,7 @@ async fn get_patient_from_blaze(client: &Client, patient_id: String) -> Resource
}

async fn post_patient_to_blaze(client: &Client, patient: Resource) {
println!("Posting Patient");

let res = client
client
.put(
CONFIG
.blaze_url
Expand All @@ -191,6 +202,4 @@ async fn post_patient_to_blaze(client: &Client, patient: Resource) {
.send()
.await
.unwrap();

dbg!(res);
}

0 comments on commit d23302f

Please sign in to comment.