示例#1
0
    def test_set_update(self):
        trial = set_updated(self.trial)
        assert 'last_updated' in trial, trial
        trial = self._check_trial_post(trial)

        # send again
        trial = set_updated(trial)
        assert 'last_updated' in trial, trial
        assert 'curated_on' in trial and trial['curated_on'] == '', trial
        for field in self.trial_status_fields:
            assert field in trial['_summary'], '%s\n\n %s' % (trial['_summary'], field)
        self._check_trial_post(trial)

        # curate
        trial = set_curated(trial)
        assert 'last_updated' in trial, trial
        assert 'curated_on' in trial and trial['curated_on'], trial
        for field in self.trial_status_fields:
            assert field in trial['_summary'], '%s\n\n%s' % (trial['_summary'], field)
        self._check_trial_post(trial)
示例#2
0
    def test_set_update(self):
        trial = set_updated(self.trial)
        trial = self._prep_trial(trial)
        assert 'last_updated' in trial, trial
        build_trial_elasticsearch_fields([trial])

        # send again
        trial = set_updated(trial)
        build_trial_elasticsearch_fields([trial])
        assert 'last_updated' in trial, trial
        assert 'curated_on' in trial and trial['curated_on'] == '', trial
        for field in self.trial_status_fields:
            assert field in trial['_summary'], '%s\n\n %s' % (
                trial['_summary'], field)

        # curate
        trial = set_curated(trial)
        assert 'last_updated' in trial, trial
        assert 'curated_on' in trial and trial['curated_on'], trial
        for field in self.trial_status_fields:
            assert field in trial['_summary'], '%s\n\n%s' % (trial['_summary'],
                                                             field)
示例#3
0
    def test_set_update(self):
        trial = set_updated(self.trial)
        assert 'last_updated' in trial, trial
        trial = self._check_trial_post(trial)

        # send again
        trial = set_updated(trial)
        assert 'last_updated' in trial, trial
        assert 'curated_on' in trial and trial['curated_on'] == '', trial
        for field in self.trial_status_fields:
            assert field in trial['_summary'], '%s\n\n %s' % (
                trial['_summary'], field)
        self._check_trial_post(trial)

        # curate
        trial = set_curated(trial)
        assert 'last_updated' in trial, trial
        assert 'curated_on' in trial and trial['curated_on'], trial
        for field in self.trial_status_fields:
            assert field in trial['_summary'], '%s\n\n%s' % (trial['_summary'],
                                                             field)
        self._check_trial_post(trial)
示例#4
0
    def test_updatedt_with_curatedt(self):

        # set up
        today = dt.datetime.now().strftime('%B %d, %Y')
        old = 'October 27, 2016'
        on_trial['_genomic'] = {'hugo_symbol': [{'value': 'TEST'}]}
        on_trial['_clinical'] = {'disease_status': [{'value': ['TEST']}]}

        # set both dates to OLD
        on_trial['curated_on'] = old
        on_trial['last_updated'] = old
        assert on_trial['curated_on'] == old, self._debug(
            on_trial, 'curated_on')
        assert on_trial['last_updated'] == old, self._debug(
            on_trial, 'last_updated')

        # set "last_updated" to TODAY
        trial = set_updated(on_trial)
        assert trial['curated_on'] == old, self._debug(trial, 'curated_on')
        assert trial['last_updated'] == today, self._debug(
            trial, 'last_updated')

        # check dates are preserved after trial_insert is called
        trial['protocol_no'] = '01-001'
        trial = trial_insert([trial])
        trial = trial[0]
        assert trial['curated_on'] == old, self._debug(trial, 'curated_on')
        assert trial['last_updated'] == today, self._debug(
            trial, 'last_updated')

        # check the other way around
        on_trial['curated_on'] = old
        trial['last_updated'] = old
        assert trial['curated_on'] == old, self._debug(trial, 'curated_on')
        assert trial['last_updated'] == old, self._debug(trial, 'last_updated')

        trial = set_curated(on_trial)
        assert trial['curated_on'] == today, self._debug(trial, 'curated_on')
        assert trial['last_updated'] == today, self._debug(
            trial, 'last_updated')

        trial = trial_insert([trial])
        trial = trial[0]
        assert trial['curated_on'] == today, self._debug(trial, 'curated_on')
        assert trial['last_updated'] == today, self._debug(
            trial, 'last_updated')
示例#5
0
    def test_updatedt_with_curatedt(self):

        # set up
        today = dt.datetime.now().strftime('%B %d, %Y')
        old = 'October 27, 2016'
        on_trial['_genomic'] = {'hugo_symbol': [{'value': 'TEST'}]}
        on_trial['_clinical'] = {'disease_status': [{'value': ['TEST']}]}

        # set both dates to OLD
        on_trial['curated_on'] = old
        on_trial['last_updated'] = old
        assert on_trial['curated_on'] == old, self._debug(on_trial, 'curated_on')
        assert on_trial['last_updated'] == old, self._debug(on_trial, 'last_updated')

        # set "last_updated" to TODAY
        trial = set_updated(on_trial)
        assert trial['curated_on'] == old, self._debug(trial, 'curated_on')
        assert trial['last_updated'] == today, self._debug(trial, 'last_updated')

        # check dates are preserved after trial_insert is called
        trial = trial_insert([trial])
        trial = trial[0]
        assert trial['curated_on'] == old, self._debug(trial, 'curated_on')
        assert trial['last_updated'] == today, self._debug(trial, 'last_updated')

        # check the other way around
        on_trial['curated_on'] = old
        trial['last_updated'] = old
        assert trial['curated_on'] == old, self._debug(trial, 'curated_on')
        assert trial['last_updated'] == old, self._debug(trial, 'last_updated')

        trial = set_curated(on_trial)
        assert trial['curated_on'] == today, self._debug(trial, 'curated_on')
        assert trial['last_updated'] == today, self._debug(trial, 'last_updated')

        trial = trial_insert([trial])
        trial = trial[0]
        assert trial['curated_on'] == today, self._debug(trial, 'curated_on')
        assert trial['last_updated'] == today, self._debug(trial, 'last_updated')
示例#6
0
def update_from_oncore(protocol_no):
    """
    This processes updates sent directly from oncore. The premise is that a seperate service will
    be polling the OnCore database and passing along the JSON formatted trials to here. This service will
    need to find the equivalent trial (if a new trial is POSTed here it should be ignored) and compute the update
    loging. The logic is divided into two parts:
    1. any non-curated field should be updated in MM seamlessly (such as trial and arm status)
    2. any curated field (such as match) should not be touched, and a change here should notify the curator
    via the email functionality.
    """

    db = get_db()

    # get the trial.
    on_trial = request.get_json(silent=True)

    # assert we have an existing one.
    mm_trial = db['trial'].find_one({"protocol_no": protocol_no})
    if mm_trial is None:
        logging.warning("oncore posted trial that is not in database: %s" %
                        protocol_no)
        return json.dumps({"success": True})

    # USED TO GENERATE TESTING FILES.
    #with open("tests/data/oncore/%s.json" % protocol_no, "w") as fout:
    #    json.dump(oncore_trial, fout)

    # save relavent information for update.
    trial_id = str(mm_trial['_id'])
    etag = mm_trial['_etag']

    # call the comparison.
    cmp = OncoreSync()
    mm_trial, updated, changes = cmp.compare_trials(on_trial, mm_trial)
    for log_entry in cmp.log_entries:
        db.oncore_trial_log.insert(log_entry)
        post_mattermost(msg='Trial Update', hashtag='#OnCore', data=log_entry)
    cmp.send_email()

    # if it is updated then do the update.
    if updated:

        # strip meta
        for key in list(mm_trial.keys()):
            if key[0] == "_":
                del mm_trial[key]
        mm_trial['_id'] = trial_id

        # set headers.
        headers = {
            'Content-Type':
            'application/json',
            'Authorization':
            'Basic ' +
            base64.b64encode(f'{API_TOKEN}:'.encode('utf-8')).decode('utf-8'),
            'If-Match':
            etag
        }

        # set last updated field
        mm_trial = set_updated(mm_trial)

        # post the trial.
        url = '%s/trial/%s' % (API_ADDRESS, trial_id)
        logging.info('PATCH %s' % url)
        r = requests.patch(url, json=mm_trial, headers=headers)
        r_code = r.status_code
        if 199 < r_code < 300:
            return json.dumps({"success": True})
        else:
            logging.error("error updating trial: %s" % protocol_no)

    # return success
    return json.dumps({"success": True})