예제 #1
0
 def testBackwards(self):
     df = Datefile(datetime.strptime('2009-01-01', '%Y-%m-%d'),
                   persistence_file=self.persistence_file,
                   direction='backwards')
     self.assertEquals(df.get_date().strftime('%Y-%m-%d'), '2009-01-01')
     df.bump_date()
     self.assertEquals(df.get_date().strftime('%Y-%m-%d'), '2008-12-31')
예제 #2
0
 def testRangeSansStep(self):
     "range w/o step"
     df = Datefile(datetime.strptime('2009-10-31', '%Y-%m-%d'),
                   persistence_file=self.persistence_file,
                   direction='forwards')
     start, end = df.get_date_range()
     self.assertEquals(start.strftime('%Y-%m-%d'), '2009-10-31')
     self.assertEquals(end.strftime('%Y-%m-%d'), '2009-10-31')
예제 #3
0
 def testRangeStepSansDirection(self):
     "give step and no directon"
     df = Datefile(datetime.strptime('2009-10-31', '%Y-%m-%d'),
                   persistence_file=self.persistence_file,
                   step=30)
     start, end = df.get_date_range()
     self.assertEquals(start.strftime('%Y-%m-%d'), '2009-10-02')
     self.assertEquals(end.strftime('%Y-%m-%d'), '2009-10-31')
예제 #4
0
 def testNoDirection(self):
     df = Datefile(datetime.now())
     self.assert_(df.get_date(), "Even w/o direction, should get "
                  "initial date back")
     datebefore = df.get_date()
     df.bump_date()
     dateafter = df.get_date()
     self.assertEquals(datebefore, dateafter)
예제 #5
0
 def testStepDatesBack(self):
     "steping backward, end date should be step-1 days before start"
     df = Datefile(datetime.strptime('2009-01-31', '%Y-%m-%d'),
                   persistence_file=self.persistence_file,
                   direction='backwards',
                   step=10)
     start, end = df.get_date_range()
     self.assertEquals(start.strftime('%Y-%m-%d'), '2009-01-22')
     self.assertEquals(end.strftime('%Y-%m-%d'), '2009-01-31')
예제 #6
0
 def testStepDatesFwd(self):
     "steping forward, end date should be step-1 days after start"
     df = Datefile(datetime.strptime('2009-02-01', '%Y-%m-%d'),
                   persistence_file=self.persistence_file,
                   direction='forwards',
                   step=10)
     start, end = df.get_date_range()
     self.assertEquals(start.strftime('%Y-%m-%d'), '2009-02-01')
     self.assertEquals(end.strftime('%Y-%m-%d'), '2009-02-10')
예제 #7
0
    def testInitialDate(self):
        # write a date to the file, then call with a different initial
        # date.  should get the date from the file.
        with open(self.persistence_file, 'w') as p_file:
            p_file.write('2009-06-06')

        df = Datefile(datetime.strptime('2009-01-01', '%Y-%m-%d'),
                      persistence_file=self.persistence_file,
                      direction='backwards')
        self.assertEquals(df.get_date().strftime('%Y-%m-%d'), '2009-06-06')
        df.bump_date()
        self.assertEquals(df.get_date().strftime('%Y-%m-%d'), '2009-06-05')
예제 #8
0
 def testStepDatesBackThrice(self):
     "steping backward three times, duplication avoided?"
     df = Datefile(datetime.strptime('2011-04-30', '%Y-%m-%d'),
                   persistence_file=self.persistence_file,
                   direction='backwards',
                   step=10)
     start, end = df.get_date_range()
     self.assertEquals(start.strftime('%Y-%m-%d'), '2011-04-21')
     self.assertEquals(end.strftime('%Y-%m-%d'), '2011-04-30')
     df.bump_date()
     start, end = df.get_date_range()
     self.assertEquals(start.strftime('%Y-%m-%d'), '2011-04-11')
     self.assertEquals(end.strftime('%Y-%m-%d'), '2011-04-20')
     df.bump_date()
     start, end = df.get_date_range()
     self.assertEquals(start.strftime('%Y-%m-%d'), '2011-04-01')
     self.assertEquals(end.strftime('%Y-%m-%d'), '2011-04-10')
예제 #9
0
 def __init__(self, data_warehouse=None, data_mart=None,
              reportDate=None, database_user=None,
              database_password=None, verbosity=0):
     self.data_warehouse = data_warehouse
     self.warehouse_port = 5432  # postgres default
     self.data_mart = data_mart
     self.mart_port = 5432  # postgres default
     self.reportDate = reportDate and parseDate(reportDate) or None
     self.database_user = database_user
     self.database_password = database_password
     self.dir, thisFile = os.path.split(__file__)
     self.verbosity = verbosity
     self.queue = JoinableQueue()
     self.datefile = "/tmp/longitudinal_datefile"
     self.datePersistence = Datefile(initial_date=self.reportDate)
     self.lock = FileLock(LOCKFILE)
     self.skip_prep = False
예제 #10
0
    def processArgs(self):
        """ Process any optional arguments and possitional parameters
        """
        parser = OptionParser(usage=usage)
        parser.add_option("-c", "--countdown", dest="countdown",
                          default=None,
                          help="count {down,up} date using date string in "\
                              "%s - set to 'forwards' or 'backwards' "\
                              "if desired" % self.datefile)
        parser.add_option("-d", "--date", dest="date", default=None,
                          help="single admission date to dedup "\
                          "(by default, checks the entire database)")
        parser.add_option("-s", "--skip-prep", dest="skip_prep",
                          default=False, action="store_true",
                          help="skip the expense of looking for new "\
                          "messages")
        parser.add_option("-v", "--verbose", dest="verbosity",
                          action="count", default=self.verbosity,
                          help="increase output verbosity")
        parser.add_option("-m", "--mart-port", dest="mart_port",
                          default=self.mart_port, type="int",
                          help="alternate port number for data mart")
        parser.add_option("-w", "--warehouse-port", dest="warehouse_port",
                          default=self.warehouse_port, type="int",
                          help="alternate port number for data warehouse")

        (options, args) = parser.parse_args()
        if len(args) != 2:
            parser.error("incorrect number of arguments")

        self.data_warehouse = args[0]
        self.data_mart = args[1]
        self.warehouse_port = parser.values.warehouse_port
        self.mart_port = parser.values.mart_port
        self.verbosity = parser.values.verbosity
        self.skip_prep = parser.values.skip_prep
        initial_date = parser.values.date and \
            parseDate(parser.values.date) or None
        self.datePersistence = Datefile(initial_date=initial_date,
                                        persistence_file=self.datefile,
                                        direction=parser.values.countdown)

        self.reportDate = self.datePersistence.get_date()
예제 #11
0
    def process_args(self):
        """Process any optional arguments and possitional parameters

        Using the values provided, assemble ReportCriteria and
        Datefile instances to control report generation.

        """
        parser = OptionParser(usage=usage)
        # Provide the ReportCriteria instance an error callback so any
        # command line errors provoke the standard graceful exit with
        # warning text.
        self.criteria.error_callback = parser.error

        parser.add_option("-u",
                          "--user",
                          dest="user",
                          default=self.user,
                          help="database user")
        parser.add_option("-p", "--password", dest="password",
                          default=self.password,
                          help="database password, or file containing "\
                              "just the password")
        parser.add_option("-c", "--countdown", dest="countdown",
                          default=None,
                          help="count {down,up} the start and end dates "\
                              "set to 'forwards' or 'backwards' "\
                              "if desired")
        parser.add_option("-i", "--include-updates",
                          action='store_true', dest="includeUpdates",
                          default=False, help="include "\
                              "visits updated since last similar report")
        parser.add_option("--include-vitals",
                          action='store_true', dest="includeVitals",
                          default=False, help="include "\
                              "vitals (measured temperature, O2 "\
                              "saturation, influenza and H1N1 vaccine "\
                              "data) as additional columns in the "\
                              "report")
        parser.add_option("-k", "--patient-class",
                          dest="patient_class",
                          default=None, help="use "\
                          "to filter report on a specific patient "\
                          "class [E,I,O]")
        parser.add_option("-r", "--region", dest="region",
                          default=None,
                          help="reportable region defining limited set "\
                              "of facilities to include, by default "\
                              "all  facilities are included")
        parser.add_option("-s", "--save-and-upload",
                          action='store_true', dest="save_upload",
                          default=False, help="save file and upload to "\
                              "DOH")
        parser.add_option("-x",
                          "--save-without-upload",
                          action='store_true',
                          dest="save_only",
                          default=False,
                          help="save file but don't upload")
        parser.add_option("-d", "--upload-diff",
                          action='store_true', dest="upload_diff",
                          default=False, help="upload differences only "\
                              "(from yesterdays like report) to DOH")
        parser.add_option("-t", "--thirty-days",
                          action='store_true', dest="thirty_days",
                          default=False, help="include 30 days up to "\
                              "requested date ")
        parser.add_option("-v",
                          "--verbose",
                          dest="verbosity",
                          action="count",
                          default=self.verbosity,
                          help="increase output verbosity")

        (options, args) = parser.parse_args()
        if len(args) != 2:
            parser.error("incorrect number of arguments")

        # Database to query
        self.criteria.database = args[0]
        self.user = options.user
        self.password = options.password
        self.criteria.credentials(user=self.user, password=self.password)

        # Potential region restriction
        self.criteria.reportable_region = options.region

        # Potential patient class restriction
        self.criteria.patient_class = options.patient_class

        # Potential to include vitals (not tied to gipse format)
        self.criteria.include_vitals = options.includeVitals

        # Potential inclusion of updates
        self.criteria.include_updates = options.includeUpdates

        # Report date(s) and potential step direction.
        # NB - several options affect report_method and must be set
        # first!

        initial_date = parseDate(args[1])
        config = Config()
        ps_file = os.path.join(
            config.get('general', 'tmp_dir', default='/tmp'),
            self.criteria.report_method)
        step = options.thirty_days and 30 or None
        direction = options.countdown
        self.datefile = Datefile(initial_date=initial_date,
                                 persistence_file=ps_file,
                                 direction=direction,
                                 step=step)
        self.criteria.start_date, self.criteria.end_date =\
            self.datefile.get_date_range()

        # What to do once report is completed.  Complicated, protect
        # user from themselves!
        self.save_report = options.save_upload or \
            options.save_only or options.upload_diff
        self.transmit_report = options.save_upload
        self.transmit_differences = options.upload_diff

        if options.save_only and options.save_upload:
            parser.error("save-without-upload and save-and-upload "\
                         "are mutually exclusive")
        if options.save_only and options.upload_diff:
            parser.error("save-without-upload and upload-diff "\
                         "are mutually exclusive")
        if options.upload_diff and options.save_upload:
            parser.error("upload-diff and save-and-upload"\
                         "are mutually exclusive")

        # Can't transmit w/o saving
        if options.save_upload or options.upload_diff:
            assert (self.save_report)
        # Sanity check
        if options.save_only:
            assert (self.save_report and not self.transmit_report
                    and not self.transmit_differences)

        # How verbosely to log
        self.verbosity = options.verbosity
예제 #12
0
 def testDefaultAccess(self):
     df = Datefile(initial_date=datetime.strptime('2009-01-01', '%Y-%m-%d'))
     self.assertEquals(df.get_date().strftime('%Y-%m-%d'), '2009-01-01')
예제 #13
0
 def testRangeSansFile(self):
     "range w/o step"
     df = Datefile(datetime.strptime('2009-10-31', '%Y-%m-%d'))
     start, end = df.get_date_range()
     self.assertEquals(start.strftime('%Y-%m-%d'), '2009-10-31')
     self.assertEquals(end.strftime('%Y-%m-%d'), '2009-10-31')