Exemplo n.º 1
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())
Exemplo n.º 2
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())
Exemplo n.º 3
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())
Exemplo n.º 4
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())
Exemplo n.º 5
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')
Exemplo n.º 6
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())
Exemplo n.º 7
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')
Exemplo n.º 8
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')
Exemplo n.º 9
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')
Exemplo n.º 10
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')
Exemplo n.º 11
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')
Exemplo n.º 12
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)
Exemplo n.º 13
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")))
Exemplo n.º 14
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())