You can use the DicomwebQueryCreateInput and DicomwebQueryEndpoint methods in the Rhino SDK to extract metrics directly from a Dicomweb server without extracting any image data or importing it into the Rhino client.
Below is some example code for how this workflow works:
Import relevant libraries
from rhino_health import RhinoSession
from rhino_health.lib.endpoints.dicomweb_query.dicomweb_query_endpoints import DicomwebQueryEndpoint
from rhino_health.lib.endpoints.dicomweb_query.dicomweb_query_dataclass import DicomwebQueryCreateInput
Define Dicomweb connection parameters
dicomweb_server_url="http://orthanc-external:4321/dicom-web/"
dicomweb_auth_credentials=dict(
auth_type="basic_http",
username="orthanc-user-external",
password=getpass("DICOMweb Server Password:"),
)
Define which studies to include in your query with DicomwebQueryCreateInput, then run your query with DicomwebQueryEndpoint
create_query_input = DicomwebQueryCreateInput(
project=project_uid,
workgroup=workgroup_uid,
dicomweb_server_url=dicomweb_server_url,
dicomweb_auth_credentials=dicomweb_auth_credentials,
dicomweb_query={"Study Instance UID": "1.2.156.14702.1.1000.16.0.19480514*"},
dicom_object_level="Series",
metric_definitions=[dict(
metric_name="count",
metric_params={},
request_arguments=dict(
variable="Modality",
),
)],
)
query = DicomwebQueryEndpoint(session).run_query(create_query_input, timeout_seconds=30)
if query.results:
for metric in query.results:
print("Calculated Metric:", metric.calculated_metric)
if metric.errors:
print("Metric Calculation Errors:", metric.errors)
else:
print("Errors:", query.errors)
Example output:
DICOMweb query status: Started
DICOMweb query status: Completed
Calculated Metric: {
'': {'count': 250}
}
create_query_input = DicomwebQueryCreateInput(
project=project_uid,
workgroup=workgroup_uid,
dicomweb_server_url=dicomweb_server_url,
dicomweb_auth_credentials=dicomweb_auth_credentials,
dicomweb_query={},
dicom_object_level="Instance",
metric_definitions=[dict(
metric_name="count",
metric_params={},
request_arguments=dict(
variable="Modality",
group_by={"groupings": ["Modality", "PatientSex"]}
),
)],
)
query = DicomwebQueryEndpoint(session).run_query(create_query_input, timeout_seconds=30)
if query.results:
for metric in query.results:
print("Calculated Metric:", metric.calculated_metric)
if metric.errors:
print("Metric Calculation Errors:", metric.errors)
else:
print("Errors:", query.errors)
Example output:
DICOMweb query status: Started
DICOMweb query status: Completed
Calculated Metric: {
"('Ultrasound', 'Male')": { 'count': 59 },
"('Ultrasound', 'Female')": { 'count': 58 },
"('Magnetic Resonance', 'Male')": { 'count': 57 },
"('Computed Tomography', 'Male')": { 'count': 70 },
"('Magnetic Resonance', 'Female')": { 'count': 61 },
"('Computed Tomography', 'Female')": { 'count': 78 }
}
create_query_input = DicomwebQueryCreateInput(
project=project_uid,
workgroup=workgroup_uid,
dicomweb_server_url=dicomweb_server_url,
dicomweb_auth_credentials=dicomweb_auth_credentials,
dicomweb_query={},
dicom_object_level="Series",
metric_definitions=[
dict(
metric_name="mean",
metric_params={},
request_arguments=dict(
variable="PatientAge",
group_by={"groupings": ["PatientSex"]}
),
),
dict(
metric_name="std",
metric_params={},
request_arguments=dict(
variable="PatientAge",
group_by={"groupings": ["PatientSex"]}
),
),
],
)
query = DicomwebQueryEndpoint(session).run_query(create_query_input, timeout_seconds=30)
if query.results:
for metric in query.results:
print("Calculated Metric:", metric.calculated_metric)
if metric.errors:
print("Metric Calculation Errors:", metric.errors)
else:
print("Errors:", query.errors)
Example output:
DICOMweb query status: Started
DICOMweb query status: Completed
Calculated Metric: {
'Male': {
'mean': 46.65,
'variable_count': 120
},
'Female': {
'mean': 47.03076923076923,
'variable_count': 130
}
}
Calculated Metric: {
'Male': {
'std': 25.11130223624414,
'variable_count': 120
},
'Female': {
'std': 25.49447555890626,
'variable_count': 130
}
}