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

Bringing in changes from thehanriver/pl-tpdf but making them so that … #2

Open
wants to merge 1 commit 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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ htmlcov
.idea/
.vscode/

in/
out/
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,12 @@ Examples
-v $PWD/covidnet-out:/incoming:ro -v $PWD/pdfgeneration-out:/outgoing:rw \
fnndsc/pl-covidnet-pdfgeneration:0.2.0 pdfgeneration \
--imagefile chest-scan.jpg --patientId 12345678 /incoming /outgoing

docker run --rm -v $(pwd)/in:/incoming -v $(pwd)/out:/outgoing \
jonocameron/pl-pdfgeneration pdfgeneration --imagefile "ex-covid.jpeg" --patientId "77812345" \
/incoming /outgoing

docker run --rm -u $(id -u) \
-v $(pwd)/in:/incoming -v $(pwd)/out:/outgoing \
jonocameron/pl-tpdf tpdf --dir "41" \
--imagefile "ex-covid.jpeg" --patientId 12345678 /incoming /outgoing
Binary file added in/41/ex-covid.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions in/41/prediction-default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"**DISCLAIMER**": "Do not use this prediction for self-diagnosis. You should check with your local authorities for the latest advice on seeking medical assistance.",
"prediction": "COVID-19",
"Normal": "0.00052875147",
"Pneumonia": "0.010959083",
"COVID-19": "0.98851216"
}
8 changes: 8 additions & 0 deletions in/41/severity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Geographic severity": "52",
"Geographic extent score": "4.2",
"GeoInfo": "For each lung: 0 = no involvement; 1 = <25%; 2 = 25-50%; 3 = 50-75%; 4 = >75% involvement.",
"Opacity severity": "52",
"Opacity extent score": "3.1",
"OpcInfo": "For each lung: 0 = no opacity; 1 = ground glass opacity; 2 =consolidation; 3 = white-out."
}
Binary file added in/ex-covid.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions in/prediction-default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"**DISCLAIMER**": "Do not use this prediction for self-diagnosis. You should check with your local authorities for the latest advice on seeking medical assistance.",
"prediction": "COVID-19",
"Normal": "0.00052875147",
"Pneumonia": "0.010959083",
"COVID-19": "0.98851216"
}
8 changes: 8 additions & 0 deletions in/severity.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Geographic severity": "52",
"Geographic extent score": "4.2",
"GeoInfo": "For each lung: 0 = no involvement; 1 = <25%; 2 = 25-50%; 3 = 50-75%; 4 = >75% involvement.",
"Opacity severity": "52",
"Opacity extent score": "3.1",
"OpcInfo": "For each lung: 0 = no opacity; 1 = ground glass opacity; 2 =consolidation; 3 = white-out."
}
24 changes: 19 additions & 5 deletions pdfgeneration/pdfgeneration.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def define_parameters(self):
Define the CLI arguments accepted by this plugin app.
Use self.add_argument to specify a new app argument.
"""
self.add_argument('--dir',
dest = 'dir',
type = str,
optional = True,
default = '',
help = 'directory')
self.add_argument('--imagefile',
dest = 'imagefile',
type = str,
Expand All @@ -84,11 +90,17 @@ def run(self, options):
"""
print(Gstr_title)
print('Version: %s' % self.get_version())


directory = options.dir
parent_dir = options.inputdir
nPath = os.path.join(parent_dir , directory)

# fetch input data
with open('{}/prediction-default.json'.format(options.inputdir)) as f:
with open('{}/prediction-default.json'.format(nPath)) as f:
classification_data = json.load(f)
try:
with open('{}/severity.json'.format(options.inputdir)) as f:
with open('{}/severity.json'.format(nPath)) as f:
severityScores = json.load(f)
except:
severityScores = None
Expand Down Expand Up @@ -120,9 +132,11 @@ def run(self, options):
# when input is a string
for asset_file in files('pdfgeneration').joinpath('template/assets').iterdir():
os.symlink(asset_file, path.join('/tmp', asset_file.name))
os.symlink(path.join(options.inputdir, options.imagefile), path.join('/tmp', options.imagefile))
os.symlink(path.join(nPath, options.imagefile), path.join('/tmp', options.imagefile))

pdfkit.from_string(txt, path.join(options.outputdir, 'patient_analysis.pdf'))

def show_man_page(self):
self.print_help()
"""
Print the app's man page.
"""
print(Gstr_synopsis)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name = 'pdfgeneration',
version = '0.2.0',
version = '0.3.0',
description = 'An app that takes in COVID-Net prediction results and generates PDF',
long_description = readme,
author = 'DarwinAI',
Expand Down