import shutil
import tempfile
import subprocess

from posda.queries import Query
from posda.main import args
from posda.util import md5sum

# from collections import namedtuple, defaultdict

help = """
Consume a posda filelist (plist) file and import all listed files into Posda.
"""

parser = args.Parser(arguments=[
    args.CustomArgument("plist", "The Posda Filelist (plist) file to read"),
],
                     purpose="Import plist into posda",
                     help=help)
pargs = parser.parse()

# Preload queries that will be used in functions, so they aren't loaded repeatedly
get_posda_file_id_by_digest = Query("GetPosdaFileIdByDigest")
insert_file_posda = Query("InsertFilePosda")
get_current_posda_file_id = Query("GetCurrentPosdaFileId")
insert_file_import_long = Query("InsertFileImportLong")
make_posda_file_ready_to_process = Query("MakePosdaFileReadyToProcess")
insert_file_location = Query("InsertFileLocation")
get_matching_root = Query("GetMatchingRootID")
create_new_root = Query("InsertNewRootPath")
Esempio n. 2
0
from posda.main import args

import os
import sys
import csv
from multiprocessing import Pool, Queue

help = """
Build a spreadsheet report from a directory.

This script does not read from stdin.
"""

parser = args.Parser(arguments=[
    args.Presets.background_id,
    args.CustomArgument("scan_dir", "The directory to build the report from"),
    args.Presets.notify
],
                     purpose="Build a report from a directory",
                     help=help)
pargs = parser.parse()

print(f"Building report for dir: {pargs.scan_dir}")
print(f"This script does not read lines from stdin, so no lines read")

background = BackgroundProcess(pargs.background_id, pargs.notify)

background.daemonize()

background.log_input_count(0)
Esempio n. 3
0
A report is generated which compares each image, matching on SOP Instance UID.

Input is read from STDIN. Lines should be in the form:
    <filename>,<collection>,<site>,<patient>,<series>,<sop>,<md5sum>,<size>
(basically CSV)

An output report will be generated and emailed to NOTIFY, and will contain
details of the following discrepencies:
* SOPs missing from the file, or in Intake
* Duplicate SOP entires in file, or in Intake
* Data mismatch in Patient ID/Series Instance UID
"""

parser = args.Parser(
    arguments=[args.Presets.background_id, 
               args.CustomArgument("collection", 
                                   "The collection to compare against"),
               args.CustomArgument("site", 
                                   "The site to compare against"),
               args.Presets.notify],

    purpose="Compare a spreadsheet report to Intake",
    help=help)
pargs = parser.parse()

background = BackgroundProcess(pargs.background_id, pargs.notify)

reader = csv.reader(sys.stdin)
lines = {}

header = 'filename,collection,site,patient,series,sop,md5sum,size'.split(',')
InputLine = namedtuple("InputLine", header)
Esempio n. 4
0
help = """
Runs a scan for PHI.

 file_query_name can be one of:
    "IntakeFilesInSeries" - get list of series in intake database
    "PublicFilesInSeries" - get list of series in public database
    "FilesInSeries" - get list of series in posda database

Expects a list of series on STDIN
"""

parser = args.Parser(
    arguments=[args.Presets.background_id, 
               args.Presets.description, 
               args.CustomArgument("file_query_name", 
                                   "Name of query to use for getting list of "
                                   "files in given series"), 
               args.Presets.notify],

    purpose="Background Process to scan for PHI",
    help=help)
args = parser.parse()

# TODO: this (and some other stuff) could be moved into
# an util lib, posda.background.shortcuts or something?

subprocess_id = Query("CreateBackgroundSubprocess").get_single_value(
    subprocess_invocation_id=args.background_id,
    command_executed='???',
    foreground_pid=os.getpid(),
    user_to_notify=args.notify