Ejemplo n.º 1
0
    def test_dhiv_not_tested(self):
        """
    It should report the results are not available if nat is P and dhiv is NT
    """
        from aeh.earlytest.results import process
        from datetime import date
        from aeh.earlytest import Session, models

        site_code = '99X'
        reference_number = '12345'
        expected = site_code + reference_number

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number,
                          test_date=date.today(),
                          draw_date=date.today(),
                          nat='P',
                          dhiv='NT',
                          file='results.txt'))

        request = DummyRequest({
            'userInput1':
            ' '.join(list(site_code + reference_number)),
            'userInput2':
            site_code + ' ' + reference_number
        })

        ret = process(request)
        self.assertEquals(ret['queryStatus'], 'RESULTS_NOT_AVAILABLE')
Ejemplo n.º 2
0
    def test_unavailable(self):
        """
    It should not report the patient's status after 90 days
    """
        from aeh.earlytest.results import process
        from datetime import date, timedelta
        from aeh.earlytest import Session, models

        site_code = '99X'
        reference_number = '12345'
        expected = site_code + reference_number

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number,
                          test_date=date.today() - timedelta(90),
                          draw_date=date.today() - timedelta(90),
                          nat='N',
                          file='results.txt'))

        request = DummyRequest({
            'userInput1': expected,
            'userInput2': expected,
        })

        ret = process(request)
        self.assertEquals(ret['queryStatus'], 'RESULTS_OUT_OF_DATE')
Ejemplo n.º 3
0
    def test_negative_available(self):
        """
    It should report the patient's status after 14 days of draw date
    """
        from aeh.earlytest.results import process
        from datetime import date, timedelta
        from aeh.earlytest import Session, models

        site_code = '99X'
        reference_number = '12345'
        expected = site_code + reference_number

        result = models.Result(site_code=site_code,
                               reference_number=reference_number,
                               test_date=date.today() - timedelta(14),
                               draw_date=date.today() - timedelta(14),
                               nat='N',
                               file='results.txt')
        Session.add(result)

        request = DummyRequest({
            'userInput1': expected,
            'userInput2': expected,
        })

        ret = process(request)
        self.assertEquals(ret['queryStatus'], 'RESULTS_NEGATIVE')
Ejemplo n.º 4
0
    def test_positive(self):
        """
    It should not let the user know if they are HIV positive
    (This will be done in person)
    """
        from aeh.earlytest.results import process
        from datetime import date
        from aeh.earlytest import Session, models

        site_code = '99X'
        reference_number = '12345'
        expected = site_code + reference_number

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number,
                          test_date=date.today(),
                          draw_date=date.today(),
                          nat='P',
                          dhiv='P',
                          file='results.txt'))

        request = DummyRequest({
            'userInput1': expected,
            'userInput2': expected,
        })

        ret = process(request)
        self.assertEquals(ret['queryStatus'], 'RESULTS_NOT_AVAILABLE')
Ejemplo n.º 5
0
    def test_duplicate_entry_error_status(self):
        """
    Should fail and set error_status = duplicateEntry
    """
        from aeh.earlytest.draw_input import process
        from datetime import date
        from aeh.earlytest import Session, models

        site_code = '76C'
        reference_number = '33333'
        expected = site_code + reference_number
        draw_date = '2015-01-01'

        Session.add(
            models.Draw(
                site_code=site_code,
                reference_number=reference_number,
                draw_date=date.today(),
            ))

        request = DummyRequest({
            'redcrossid-entry': expected,
            'drawdate-input': draw_date,
            'rcidform.submitted': True,
        })

        ret = process(request)
        self.assertEquals(ret['errorStatus'], 'duplicateEntry')
Ejemplo n.º 6
0
    def test_positive(self):
        """
        It should not let the user know if they are HIV positive
        (This will be done in person)
        """
        from datetime import date
        import transaction
        from aeh.earlytest import Session, models

        site_code = '99X'
        reference_number = '12345'
        expected = site_code + reference_number

        with transaction.manager:
            Session.add(
                models.Result(site_code=site_code,
                              reference_number=reference_number,
                              test_date=date.today(),
                              draw_date=date.today(),
                              nat='P',
                              dhiv='P',
                              file='results.txt'))

        response = self.app.post('/results', {
            'userInput1': expected,
            'userInput2': expected,
        })

        html = BeautifulSoup(response.text)
        e = html.find(class_='alert-info')
        self.assertIn('we are not able to give you your results', e.get_text())
Ejemplo n.º 7
0
def process_date_update(request, site_codes):
    # This method receives the GET request for draw date update
    # and updates the new date in the DB
    # FIX: Date validations should not be greater than

    #redcap = RCProject(site_codes, rcs)
    max_date = datetime.date.today()
    min_date = max_date - datetime.timedelta(days=365)

    new_date_raw = request.GET['new_date_raw']
    print new_date_raw
    new_date = datetime.datetime.strptime(new_date_raw, "%Y-%m-%d").date()
    print new_date
    ref_num = request.GET['ref_num']
    site_code = request.GET['site']
    # retrieve the record from the db

    if min_date <= new_date and new_date <= max_date:
        session = Session()
        record = session.query(models.Result).\
          filter(models.Result.site_code == site_code).\
          filter(models.Result.reference_number == ref_num).first()

        if record:
            record.draw_date = new_date
            transaction.commit()
    return response
Ejemplo n.º 8
0
    def test_valid(self):
        """
    It should be able to parse a number with whitespace in it
    """
        from aeh.earlytest.results import process
        from datetime import date
        from aeh.earlytest import Session, models

        site_code = '99X'
        reference_number = '12345'
        expected = site_code + reference_number

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number,
                          test_date=date.today(),
                          draw_date=date.today(),
                          nat='N',
                          file='results.txt'))

        request = DummyRequest({
            'userInput1':
            ' '.join(list(site_code + reference_number)),
            'userInput2':
            site_code + ' ' + reference_number
        })

        ret = process(request)
        self.assertEquals(ret['defaultNumber'], expected)
        self.assertEquals(ret['cleanNumber1'], expected)
        self.assertEquals(ret['cleanNumber2'], expected)
Ejemplo n.º 9
0
 def setUpClass(cls):
     from pyramid.paster import get_appsettings
     from sqlalchemy import engine_from_config
     from aeh.earlytest import Session, models
     cls.settings = settings = get_appsettings(TEST_INI)
     Session.configure(bind=engine_from_config(settings, 'sqlalchemy.'))
     models.Base.metadata.create_all(Session.bind)
Ejemplo n.º 10
0
    def test_unavailable(self):
        """
        It should not report the patient's status after 90 days
        """
        from datetime import date, timedelta
        import transaction
        from aeh.earlytest import Session, models

        site_code = '99X'
        reference_number = '12345'
        expected = site_code + reference_number

        with transaction.manager:
            Session.add(
                models.Result(site_code=site_code,
                              reference_number=reference_number,
                              test_date=date.today() - timedelta(90),
                              draw_date=date.today() - timedelta(90),
                              nat='N',
                              file='results.txt'))

        response = self.app.post('/results', {
            'userInput1': expected,
            'userInput2': expected,
        })

        html = BeautifulSoup(response.text)
        e = html.find(class_='alert-info')
        self.assertIn('has been more than 90 days', e.get_text())
Ejemplo n.º 11
0
    def test_dhiv_not_tested(self):
        """
        It should report the results are not available if nat is P and dhiv is NT
        """
        from aeh.earlytest.results import process
        from datetime import date
        import transaction
        from aeh.earlytest import Session, models

        site_code = '99X'
        reference_number = '12345'
        expected = site_code + reference_number

        with transaction.manager:
            Session.add(
                models.Result(site_code=site_code,
                              reference_number=reference_number,
                              test_date=date.today(),
                              draw_date=date.today(),
                              nat='P',
                              dhiv='NT',
                              file='results.txt'))

        response = self.app.post('/results', {
            'userInput1': expected,
            'userInput2': expected,
        })

        html = BeautifulSoup(response.text)
        e = html.find(class_='alert-info')
        self.assertIn('we are not able to give you your results', e.get_text())
Ejemplo n.º 12
0
    def test_negative_not_available(self):
        """
        It should not report the patient's status before 14 days of draw date
        """
        from datetime import date
        import transaction
        from aeh.earlytest import Session, models

        site_code = '99X'
        reference_number = '12345'
        expected = site_code + reference_number

        with transaction.manager:
            Session.add(
                models.Result(site_code=site_code,
                              reference_number=reference_number,
                              test_date=date.today(),
                              draw_date=date.today(),
                              nat='N',
                              file='results.txt'))

        response = self.app.post('/results', {
            'userInput1': expected,
            'userInput2': expected,
        })

        html = BeautifulSoup(response.text)
        e = html.find(class_='alert-info')
        self.assertIn('we are not able to give you your results', e.get_text())
Ejemplo n.º 13
0
    def test_invalid(self):
        """
    It should fail if inputs are not equal
    """
        from aeh.earlytest.results import process
        from datetime import date
        from aeh.earlytest import Session, models

        site_code = '99X'
        reference_number = '12345'

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number,
                          test_date=date.today(),
                          draw_date=date.today(),
                          nat='N',
                          file='results.txt'))

        request = DummyRequest({
            'userInput1': site_code + reference_number,
            'userInput2': 'LOL' + ' ' + reference_number
        })

        ret = process(request)
        self.assertEquals(ret['queryStatus'], 'QUERY_INVALID')
Ejemplo n.º 14
0
    def test_invalid(self):
        """
        It should fail if inputs are not equal
        """
        from datetime import date
        import transaction
        from aeh.earlytest import Session, models

        site_code = '99X'
        reference_number = '12345'
        expected = site_code + reference_number

        with transaction.manager:
            Session.add(
                models.Result(site_code=site_code,
                              reference_number=reference_number,
                              test_date=date.today(),
                              draw_date=date.today(),
                              nat='N',
                              file='results.txt'))

        response = self.app.post('/results', {
            'userInput1': expected,
            'userInput2': 'LOL' + reference_number
        })

        html = BeautifulSoup(response.text)
        e = html.find(class_='alert-danger')
        self.assertIn('test numbers entered do not match', e.get_text())
Ejemplo n.º 15
0
def generate_reports(conditions, reports_start=0, reports_end=0):
    session = Session()
    reports_max = int(session.query(models.Result).filter(conditions).count())
    if reports_end == 0:
        reports_end = reports_max

    return session.query(models.Result).filter(conditions).order_by(
        desc(models.Result.test_date)).slice(reports_start, reports_end)
Ejemplo n.º 16
0
    def test_valid_entry_update_result_draw_date(self):
        """
    Should pass, save entry in draw table, and update draw date in corresponding result
    entry in result table
    """
        from aeh.earlytest.draw_input import process
        from datetime import date
        from datetime import datetime
        from aeh.earlytest import Session, models

        site_code = '76C'
        reference_number = '55555'
        expected = site_code + reference_number
        draw_date = '2015-01-01'

        Session.add(
            models.Result(site_code=site_code,
                          reference_number=reference_number,
                          test_date=date.today(),
                          nat='N',
                          file='results.txt'))

        request = DummyRequest({
            'redcrossid-entry': expected,
            'drawdate-input': draw_date,
            'rcidform.submitted': True,
        })

        ret = process(request)
        self.assertEquals(ret['errorStatus'], 'rcidAccepted')

        draw = Session.query(models.Draw)\
           .filter(models.Draw.site_code == site_code)\
           .filter(models.Draw.reference_number == reference_number).first()

        self.assertEquals(draw.site_code, site_code)
        self.assertEquals(draw.reference_number, reference_number)
        self.assertEquals(
            draw.draw_date,
            datetime.date(datetime.strptime(draw_date, "%Y-%m-%d")))

        result = Session.query(models.Result)\
           .filter(models.Result.site_code == site_code)\
           .filter(models.Result.reference_number == reference_number).first()

        self.assertEquals(
            result.draw_date,
            datetime.date(datetime.strptime(draw_date, "%Y-%m-%d")))
Ejemplo n.º 17
0
    def test_valid_entry_update_database(self):
        """
    Should pass and the entry gets saved in draw table
    """
        from aeh.earlytest.draw_input import process
        from datetime import date
        from datetime import datetime
        from aeh.earlytest import Session, models

        site_code = '76C'
        reference_number = '44444'
        expected = site_code + reference_number
        draw_date = '2015-01-01'

        request = DummyRequest({
            'redcrossid-entry': expected,
            'drawdate-input': draw_date,
            'rcidform.submitted': True,
        })

        ret = process(request)
        self.assertEquals(ret['errorStatus'], 'rcidAccepted')

        draw = Session.query(models.Draw)\
           .filter(models.Draw.site_code == site_code)\
           .filter(models.Draw.reference_number == reference_number).first()

        self.assertTrue(draw)
        self.assertEquals(draw.site_code, site_code)
        self.assertEquals(draw.reference_number, reference_number)
        self.assertEquals(
            draw.draw_date,
            datetime.date(datetime.strptime(draw_date, "%Y-%m-%d")))
Ejemplo n.º 18
0
def get_reports_max(conditions):
    session = Session()
    return int(session.query(models.Result).filter(conditions).count())
Ejemplo n.º 19
0
def process(request, default_view={}):
    error_status = ''
    site_code = ''
    ref_num = ''
    draw_date = ''
    draw_date_raw = ''

    # Calculate min and max attributes for draw-input.pt page
    max_date = datetime.date.today()
    min_date = max_date - datetime.timedelta(days=365)

    max_date = max_date.strftime("%Y-%m-%d")
    min_date = min_date.strftime("%Y-%m-%d")
    if 'rcidform.submitted' in request.params:
        redcrossid = parse_input(request.params['redcrossid-entry'])
        site_code = redcrossid['site_code']
        ref_num = redcrossid['ref_num']
        draw_date_raw = request.params['drawdate-input']
        draw_date = datetime.datetime.strptime(draw_date_raw,
                                               "%Y-%m-%d").date()

        # Check if red cross id is in correct format
        if not check_format(site_code, ref_num):
            #Error. Incorrect red cross id format
            error_status = "incorrectFormat"
        else:
            session = Session()
            draw = session.query(models.Draw)\
                     .filter(models.Draw.site_code == site_code)\
                     .filter(models.Draw.reference_number == ref_num).first()
            #check if it exists in the database
            if not draw:
                #Sucess! Save the entry in the draw database
                new_draw_entry = models.Draw(site_code=site_code,
                                             reference_number=ref_num,
                                             draw_date=draw_date,
                                             has_result=int(0))
                session.add(new_draw_entry)
                transaction.commit()

                error_status = "rcidAccepted"

                #Check if this draw's rcid is currently in our results table. If so, update
                #the result's draw date.
                result = session.query(models.Result)\
                            .filter(models.Result.site_code == site_code)\
                            .filter(models.Result.reference_number == ref_num).first()
                if result:
                    result.draw_date = draw_date

                    # Update has_result status of the draw date entry to True
                    draw_entry = session.query(models.Draw)\
                            .filter(models.Draw.site_code == site_code)\
                            .filter(models.Draw.reference_number == ref_num).first()
                    draw_entry.has_result = int(1)

                    transaction.commit()

            else:
                #Error. Duplicate entry
                error_status = "duplicateEntry"

    ret = {
        'defaultNumber': site_code + ref_num,
        'errorStatus': error_status,
        'drawDate': draw_date,
        'drawDateRaw': draw_date_raw,
        'maxDate': max_date,
        'minDate': min_date,
    }

    return dict(default_view.items() + ret.items())
Ejemplo n.º 20
0
def disconnect_db():
    from aeh.earlytest import Session
    Session.remove()
Ejemplo n.º 21
0
def get_results(input_rcid):
    print 'im in there '
  
    # parse inputs for site_code and reference_number
    clean_rcid = parse_input(input_rcid)

    site_code = clean_rcid['site_code']
    ref_num   = clean_rcid['ref_num']
    current_time  = datetime.date.today()
    # Var used to determine expiration of test results
    results_expiration = current_time - datetime.timedelta(days=int(Config.get('aeh:results', 'results_expiration')))
    # Var used to calculate buffer time for test result retrieval
    results_buffer = current_time - datetime.timedelta(days=int(Config.get('aeh:results', 'results_buffer')))

    site_code_list = Config.get('aeh:results', 'site.codes').split()
    if not site_code in site_code_list:
      query_status = 'RESULTS_NOT_FOUND'
    else:
            session  = Session()
            result   = session.query(models.Result)\
                         .filter(models.Result.site_code == site_code)\
                         .filter(models.Result.reference_number == ref_num).first()

            show_results = Config.getboolean('aeh:results', 'site.{0}.show_results'.format(site_code.upper()))

            # Check if result exists
            if result:
                print 'results exist'
                query_draw_date = result.draw_date
                # Check if the site allows access to results
                if not show_results:
                    print 'results not allowed'
                    query_status = 'RESULTS_NOT_AVAILABLE'

                # Check if there is a draw date
                elif not query_draw_date:
                    print 'no draw date'
                    query_status = 'RESULTS_NOT_AVAILABLE'

                # Check if dhiv result is P
                elif result.check('dhiv'):
                    print 'dhiv p'
                    query_status = 'RESULTS_NOT_AVAILABLE'

                # Check if dhiv result in N
                elif result.check('dhiv') is False:
                    # Check if draw date is 14 or more days
                    print 'dhiv n'
                    if query_draw_date <= results_buffer:
                        # Check if draw date is less than 90 days old
                        if query_draw_date > results_expiration:
                            query_status = 'RESULTS_NEGATIVE'
                            print 'draw date less than 90'
                        else:
                            query_status = 'RESULTS_OUT_OF_DATE'
                    else:
                        query_status = 'RESULTS_NOT_AVAILABLE'
                        print 'draw date less than 14'

                # Else return results not available, such if dhiv is NT or something weird
                else:
                    query_status = 'RESULTS_NOT_AVAILABLE'
                    print 'something weird'
            else:
                query_status = 'RESULTS_NOT_FOUND'
                print 'result dont exist'


    return query_status