Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta version #1

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/*
__pycache__/*
*.pyc
Binary file added Documentation for MMCI convector.pdf
Binary file not shown.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# data-quality
This repository contains all materials tied to the Data Quality Framework Project.
# Development version

Run the app by executing the script "gui.py."
Empty file added mmci_convertor/__init__.py
Empty file.
159 changes: 159 additions & 0 deletions mmci_convertor/export_graphs_fhir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
import quality_checks_fhir as qc


# disclaimer: parts of this function were generated by ChatGPT.
def create_report_fhir(server):
"""
Create dataframes, run quality checks and create report.

:param server: FHIR server.
:return:
None
"""
pdf = qc.create_patient_data_frame(server)
sdf = qc.create_specimen_data_frame(server)
cdf = qc.create_condition_data_frame(server)

# Create canvas
can = canvas.Canvas("plots_fhir.pdf", pagesize=letter)
# create pages
create_dq_checks(can, pdf, cdf, sdf, server)
create_warnings(can, pdf, cdf, sdf)
create_reports(can, pdf, cdf, sdf)
# Save PDF
can.save()


# disclaimer: parts of this function were generated by ChatGPT.
def create_page(can, header, fig, graph_image_name, graph_size):
"""
Helper function of create_report_fhir. Draw page.

:param can: Canvas.
:param header: Header in page.
:param fig: Figure in page.
:param graph_image_name: Path to save figure.
:param graph_size: Size of figure.
:return:
None
"""
# Add text to canvas for page 1
text_page = "FHIR data quality checks"
can.setFont("Helvetica-Bold", 14)
can.drawString(50, 750, text_page)

# header
can.drawString(50, 700, header)

# Save Plotly graph as PNG
fig.write_image("graphs/fhir/" + graph_image_name + ".png")

# Add Plotly graph to the PDF
can.drawImage("graphs/fhir/" + graph_image_name + ".png", 50, 50, width=graph_size[0], height=graph_size[1])

can.showPage()

def create_dq_checks(can, pdf, cdf, sdf, server):
"""
Helper function of create_report_fhir. Run basic data quality checks.

:param can: Canvas.
:param pdf: Patient data frame.
:param cdf: Condition data frame.
:param sdf: Specimen data frame.
:param server: FHIR server.
:return:
None
"""
completeness = "completeness"

person = qc.completeness(pdf)
person.update_layout(width=400, height=400)
create_page(can, completeness + " person", person,
completeness + "_person", (500,500))

condition = qc.completeness(cdf)
condition.update_layout(width=400, height=400)
create_page(can, completeness + " condition", condition, completeness + "_condition", (500, 500))

specimens = qc.completeness(sdf)
specimens.update_layout(width=400, height=400)
create_page(can, completeness + " specimen", specimens, completeness + "_specimens", (500, 500))

uniqueness = "uniqueness"

person = qc.uniqueness(pdf, "person")
person.update_layout(width=400, height=400)
create_page(can, uniqueness + " person", person, uniqueness + "_person", (500, 500))

condition = qc.uniqueness(cdf, "condition")
condition.update_layout(width=400, height=400)
create_page(can, uniqueness + " condition", condition, uniqueness + "_condition", (500, 500))

specimens = qc.uniqueness(sdf, "specimen")
specimens.update_layout(width=400, height=400)
create_page(can, uniqueness + " specimen", specimens, uniqueness + "_specimens", (500, 500))

qc.conformance_patient(pdf)
qc.conformance_condition(cdf)
qc.conformance_specimen(sdf)

qc.conformance_relational(sdf, server)
qc.conformance_relational(cdf, server)
qc.conformance_computational(pdf, sdf, cdf)
# TODO proč tady není vykreslení?

def create_warnings(can, pdf, cdf, sdf):
"""
Helper function of create_report_fhir. Run warnings.

:param can: Canvas.
:param pdf: Patient data frame.
:param cdf: Condition data frame.
:param sdf: Specimen data frame.
:return:
None
"""
young = qc.age_at_primary_diagnosis(pdf, cdf)
young.update_layout(width=400, height=400)
create_page(can, "age_at_primary_diagnosis",
young, "age_at_primary_diagnosis",
(500, 500))

diagnosis_in_future = qc.diagnosis_in_future(cdf)
diagnosis_in_future.update_layout(width=400, height=400)
create_page(can, "diagnosis_in_future",
diagnosis_in_future, "diagnosis_in_future",
(500, 500))


def create_reports(can, pdf, cdf, sdf):
"""
Helper function of create_report_fhir. Run reports.

:param can: Canvas.
:param pdf: Patient data frame.
:param cdf: Condition data frame.
:param sdf: Specimen data frame.
:return:
None
"""
missing_collection_collectedDateTime = qc.missing_collection_collectedDateTime(pdf, sdf)
missing_collection_collectedDateTime.update_layout(width=400, height=400)
create_page(can, "missing_collection_collectedDateTime",
missing_collection_collectedDateTime, "missing_collection_collectedDateTime",
(500, 500))

patients_without_specimen_type_text = qc.patients_without_specimen_type_text(pdf, sdf)
patients_without_specimen_type_text.update_layout(width=400, height=400)
create_page(can, "patients_without_specimen_type_text",
patients_without_specimen_type_text, "patients_without_specimen_type_text",
(500, 500))

patients_without_specimen_type_text = qc.patients_without_condition_values(pdf, cdf)
patients_without_specimen_type_text.update_layout(width=400, height=400)
create_page(can, "patients_without_condition_values",
patients_without_specimen_type_text, "patients_without_condition_values",
(500, 500))
Loading