Skip to content

Commit

Permalink
MVHub: some updates for consent parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-sturm committed Jan 16, 2025
1 parent b7cea4a commit efb375e
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 34 deletions.
116 changes: 85 additions & 31 deletions src/MVHub/MVHub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,47 @@ MVHub::MVHub(QWidget *parent)
ui_.setupUi(this);
setWindowTitle(QCoreApplication::applicationName());

connect(ui_.api_consent, SIGNAL(clicked()), this, SLOT(test_apiConsent()));
connect(ui_.update_consent, SIGNAL(clicked()), this, SLOT(updateConsentData()));
connect(ui_.api_pseudo, SIGNAL(clicked()), this, SLOT(test_apiPseudo()));
connect(ui_.api_redcap_case, SIGNAL(clicked()), this, SLOT(test_apiReCapCaseManagement()));
connect(ui_.table, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(tableContextMenu(QPoint)));
}

void MVHub::delayedInitialization()
{
loadSamplesFromNGSD();
}

void MVHub::tableContextMenu(QPoint pos)
{
//execute menu
QMenu menu;
QAction* a_copy = menu.addAction("Copy all");
QAction* action = menu.exec(ui_.table->viewport()->mapToGlobal(pos));
if (action==nullptr) return;

if (action==a_copy)
{
GUIHelper::copyToClipboard(ui_.table);
}
}

void MVHub::updateConsentData()
{
clearOutput(sender());

int c_consent = GUIHelper::columnIndex(ui_.table, "Consent");

for (int r=0; r<ui_.table->rowCount(); ++r)
{
QString ps = ui_.table->item(r,0)->text();
QString consent = getConsent(ps, false);

QTableWidgetItem* item = GUIHelper::createTableItem(consent);
ui_.table->setItem(r, c_consent, item);
}
}

void MVHub::loadSamplesFromNGSD()
{
NGSD db;
Expand Down Expand Up @@ -97,6 +128,21 @@ void MVHub::loadSamplesFromNGSD()

}

QString MVHub::getSAP(QString ps)
{
int c_sap = GUIHelper::columnIndex(ui_.table, "SAP ID");

for (int r=0; r<ui_.table->rowCount(); ++r)
{
if (ui_.table->item(r,0)->text()==ps)
{
return ui_.table->item(r,c_sap)->text();
}
}

return "";
}

QByteArray MVHub::jsonDataPseudo(QByteArray str)
{
return QByteArray( "{ \"resourceType\": \"Bundle\", ")+
Expand Down Expand Up @@ -160,57 +206,65 @@ void MVHub::clearOutput(QObject* sender)
}
}

void MVHub::test_apiConsent()
QString MVHub::getConsent(QString ps, bool debug)
{
try
{
clearOutput(sender());

//test or production
bool test_server = true;
bool test_server = false;
if (test_server)
{
ui_.output->appendPlainText("ATTENTION: using test server!");
ui_.output->appendPlainText("ATTENTION: using test servers for getConsent");
ui_.output->appendPlainText("");
}

//get token
ui_.output->appendPlainText("Getting token...");
HttpHeaders headers;
headers.insert("Content-Type", "application/x-www-form-urlencoded");
headers.insert("Prefer", "handling=strict");
QByteArray data = "grant_type=client_credentials&client_id="+Settings::string("consent_client_id"+QString(test_server ? "_test" : "")).toLatin1()+"&client_secret="+Settings::string("consent_client_secret"+QString(test_server ? "_test" : "")).toLatin1();
QString url = test_server ? "https://tc-t.med.uni-tuebingen.de/auth/realms/consent-test/protocol/openid-connect/token" : "https://tc-p.med.uni-tuebingen.de/auth/realms/consent/protocol/openid-connect/token";
ui_.output->appendPlainText("URL: "+url);
ui_.output->appendPlainText("data: " + data);
HttpHandler handler(true);
QByteArray reply = handler.post(url, data, headers);
QByteArrayList parts = reply.split('"');
if (parts.count()<4) THROW(Exception, "Reply could not be split by '\"' into 4 parts:\n" + reply);
//get token if missing
static QByteArray token = "";
if (token.isEmpty())
{
ui_.output->appendPlainText("");
ui_.output->appendPlainText("Getting consent token...");
HttpHeaders headers;
headers.insert("Content-Type", "application/x-www-form-urlencoded");
headers.insert("Prefer", "handling=strict");
QByteArray data = "grant_type=client_credentials&client_id="+Settings::string("consent_client_id"+QString(test_server ? "_test" : "")).toLatin1()+"&client_secret="+Settings::string("consent_client_secret"+QString(test_server ? "_test" : "")).toLatin1();
QString url = test_server ? "https://tc-t.med.uni-tuebingen.de/auth/realms/consent-test/protocol/openid-connect/token" : "https://tc-p.med.uni-tuebingen.de/auth/realms/consent/protocol/openid-connect/token";
if (debug) ui_.output->appendPlainText("URL: "+url);
if (debug) ui_.output->appendPlainText("data: " + data);
HttpHandler handler(true);
QByteArray reply = handler.post(url, data, headers);
QByteArrayList parts = reply.split('"');
if (parts.count()<4) THROW(Exception, "Reply could not be split by '\"' into 4 parts:\n" + reply);

QByteArray token = parts[3];
ui_.output->appendPlainText("Token: "+ token);
token = parts[3];
ui_.output->appendPlainText("Token: "+ token);
}

//get consent
ui_.output->appendPlainText("Getting consent...");
QString ps = "DNA2411657A1_01";
GenLabDB genlab;
QString sap_id = genlab.sapID(ps);
ui_.output->appendPlainText("Getting consent for "+ps+"...");
QString sap_id = getSAP(ps);
HttpHeaders headers2;
headers2.insert("Authorization", "Bearer "+token);
QString url2 = test_server ? "https://tc-t.med.uni-tuebingen.de:8443/fhir/Consent" : "https://tc-p.med.uni-tuebingen.de:8443/fhir/Consent";
reply = handler.get(url2+"?patient.identifier="+sap_id, headers2);
QString url = test_server ? "https://tc-t.med.uni-tuebingen.de:8443/fhir/Consent" : "https://tc-p.med.uni-tuebingen.de:8443/fhir/Consent";
HttpHandler handler(true);
QByteArray reply = handler.get(url+"?patient.identifier="+sap_id, headers2);
if (debug)
{
ui_.output->appendPlainText("SAP ID:" + sap_id);
ui_.output->appendPlainText("Consent:" + reply);
}

//TODO parse for research use: MDAT_wissenschaftlich_nutzen_EU_DSGVO_NIVEAU

ui_.output->appendPlainText("IMGAG ID: " + ps);
ui_.output->appendPlainText("SAP ID:" + sap_id);
ui_.output->appendPlainText("Consent:");
ui_.output->appendPlainText(reply);
return reply;
}
catch (Exception& e)
{
ui_.output->appendPlainText("ERROR:");
ui_.output->appendPlainText(e.message());
}

return "";
}

void MVHub::test_apiPseudo()
Expand Down
13 changes: 12 additions & 1 deletion src/MVHub/MVHub.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,28 @@ class MVHub

public slots:
void delayedInitialization();
void tableContextMenu(QPoint pos);

void test_apiConsent();
void updateConsentData();
void test_apiPseudo();
void test_apiReCapCaseManagement();

private:
Ui::MVHub ui_;
DelayedInitializationTimer delayed_init_;

//clear output panel on bottom
void clearOutput(QObject* sender);
//load samples in Modellvorhaben from NGSD
void loadSamplesFromNGSD();
//annotate consent data of sample

//get SAP patient ID for processed sample. Empty string if not available.
QString getSAP(QString ps);

//get consent status of patient. Empty string if not available.
QString getConsent(QString ps, bool debug);


//creates JSON input for pseudonymization
static QByteArray jsonDataPseudo(QByteArray str);
Expand Down
12 changes: 10 additions & 2 deletions src/MVHub/MVHub.ui
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QPushButton" name="api_consent">
<widget class="QPushButton" name="update_consent">
<property name="text">
<string>API Consent</string>
<string>update consent data</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -91,6 +91,9 @@
<enum>Qt::Vertical</enum>
</property>
<widget class="QTableWidget" name="table">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
Expand Down Expand Up @@ -127,6 +130,11 @@
<string>Netzwerk</string>
</property>
</column>
<column>
<property name="text">
<string>Consent</string>
</property>
</column>
</widget>
<widget class="QPlainTextEdit" name="output"/>
</widget>
Expand Down

0 comments on commit efb375e

Please sign in to comment.