Skip to content

Commit

Permalink
Merge pull request #181 from Emory-HITI/dev
Browse files Browse the repository at this point in the history
Fix CFIND-ONLY mode
  • Loading branch information
pradeeban authored Jul 20, 2021
2 parents d4c5970 + 6b7c8df commit 3d942e6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
34 changes: 27 additions & 7 deletions modules/cold-extraction/ColdDataRetriever.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import os
import os, glob
import signal
import csv
import time
Expand All @@ -13,6 +13,7 @@
import threading
import argparse
import random
import pandas as pd

from collections import defaultdict

Expand Down Expand Up @@ -141,7 +142,7 @@ def initialize():
logging.info("{0}: StoreScp process for the current Niffler extraction is starting now".format(
datetime.datetime.now()))

if not storage_folder == "CFIND-ONLY":
if not file_path == "CFIND-ONLY":
subprocess.call("{0}/storescp --accept-unknown --directory {1} --filepath {2} -b {3} > storescp.out &".format(
DCM4CHE_BIN, storage_folder, file_path, QUERY_AET), shell=True)

Expand Down Expand Up @@ -211,22 +212,41 @@ def retrieve():
if number_of_query_attributes > 3 or number_of_query_attributes <= 1:
# For the cases that extract entirely based on the PatientID - Patient-level extraction.
if first_attr == "PatientID":
temp_folder = "csv/cfind-temp"
if not os.path.exists(temp_folder):
os.makedirs(temp_folder)

for pid in range(0, length):
sleep_for_nightly_mode()
patient = firsts[pid]
if (not resume) or (resume and (patient not in extracted_ones)):
if storage_folder == "CFIND-ONLY":
inc = random.randint(0,1000000)
subprocess.call("{0}/findscu -c {1} -b {2} -M PatientRoot -m PatientID={3} "
if file_path == "CFIND-ONLY":
if not os.path.exists(temp_folder):
os.makedirs(temp_folder)

inc = random.randint(0, 1000000)
subprocess.call("{0}/findscu -c {1} -b {2} -M PatientRoot -m PatientID={3} -r AccessionNumber "
"-r StudyInstanceUID -r StudyDescription -x description.csv.xsl "
"--out-cat --out-file {4}_{5}.csv --out-dir .".format(
DCM4CHE_BIN, SRC_AET, QUERY_AET, patient, csv_file, inc), shell=True)
"--out-cat --out-file {4}/{5}.csv --out-dir .".format(
DCM4CHE_BIN, SRC_AET, QUERY_AET, patient, temp_folder, inc), shell=True)

else:
subprocess.call("{0}/movescu -c {1} -b {2} -M PatientRoot -m PatientID={3} --dest {4}".format(
DCM4CHE_BIN, SRC_AET, QUERY_AET, patient, DEST_AET), shell=True)
extracted_ones.append(patient)

if file_path == "CFIND-ONLY":
cwd = os.getcwd()
os.chdir(temp_folder)
all_filenames = [i for i in glob.glob('*.*')]
with open(storage_folder + "/cfind-output.csv", 'w') as outfile:
for fname in all_filenames:
with open(fname) as infile:
for line in infile:
outfile.write(line)
os.chdir(cwd)
shutil.rmtree(temp_folder)

# For the cases that extract based on a single property other than EMPI/PatientID. Goes to study level.
# "Any" mode. Example: Extractions based on just AccessionNumber of AcquisitionDate.
else:
Expand Down
7 changes: 3 additions & 4 deletions modules/cold-extraction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,16 @@ Niffler experimentally supports a CFIND-ONLY mode.

To activate, use the below value,
```
"StorageFolder": "CFIND-ONLY",
"FilePath": "CFIND-ONLY",
```
As of now, this is only supported for the below mode, C-FIND based entirely on PatientID.
```
"NumberOfQueryAttributes": 1,
"FirstAttr": "PatientID",
"FirstIndex": 0,
```
The output will be a list of CSV files consisting of PatientID, StudyInstanceUI, and StudyDescription.

The CSV outputs will be in the folder of the original CSV file, with the name of CsvFile appended by random numbers.
The output will be in cfind-output.csv consisting of PatientID, StudyInstanceUID, AccessionNumber, and StudyDescription
in the StorageFolder.

## Troubleshooting

Expand Down
8 changes: 6 additions & 2 deletions modules/cold-extraction/description.csv.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@
<xsl:output method="text"/>

<xsl:template match="/NativeDicomModel">
<xsl:text>"</xsl:text>
<xsl:apply-templates select="DicomAttribute[@tag='00100020']"/>
<xsl:text>"</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>"</xsl:text>
<xsl:apply-templates select="DicomAttribute[@tag='0020000D']"/>
<xsl:text>"</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>"</xsl:text>
<xsl:apply-templates select="DicomAttribute[@tag='00100020']"/>
<xsl:text>"</xsl:text>
<xsl:apply-templates select="DicomAttribute[@tag='00080050']"/>
<xsl:text>"</xsl:text>
<xsl:text>,</xsl:text>
<xsl:text>"</xsl:text>
Expand Down

0 comments on commit 3d942e6

Please sign in to comment.