def _create_sample_from_row(row, biobank_id_prefix):
    """Creates a new BiobankStoredSample object from a CSV row.

  Raises:
    DataError if the row is invalid.
  Returns:
    A new BiobankStoredSample, or None if the row should be skipped.
  """
    biobank_id_str = row[_Columns.EXTERNAL_PARTICIPANT_ID]
    if not biobank_id_str.startswith(biobank_id_prefix):
        # This is a biobank sample for another environment. Ignore it.
        return None
    if _Columns.BIOBANK_ORDER_IDENTIFIER not in row:
        return None
    biobank_id = from_client_biobank_id(biobank_id_str)
    sample = BiobankStoredSample(
        biobankStoredSampleId=row[_Columns.SAMPLE_ID],
        biobankId=biobank_id,
        biobankOrderIdentifier=row[_Columns.BIOBANK_ORDER_IDENTIFIER],
        test=row[_Columns.TEST_CODE])
    if row[_Columns.PARENT_ID]:
        # Skip child samples.
        return None
    sample.confirmed = _parse_timestamp(row, _Columns.CONFIRMED_DATE, sample)
    sample.created = _parse_timestamp(row, _Columns.CREATE_DATE, sample)
    return sample
Esempio n. 2
0
    def make_query_filter(self, field_name, value):
        """Handle HPO and code values when parsing filter values."""
        if field_name == 'biobankId':
            value = from_client_biobank_id(value, log_exception=True)
        if field_name == 'hpoId' or field_name == 'awardee':
            hpo = self.hpo_dao.get_by_name(value)
            if not hpo:
                raise BadRequest('No HPO found with name %s' % value)
            if field_name == 'awardee':
                field_name = 'hpoId'
            return super(ParticipantSummaryDao,
                         self).make_query_filter(field_name, hpo.hpoId)
        if field_name == 'organization':
            organization = self.organization_dao.get_by_external_id(value)
            if not organization:
                raise BadRequest('No organization found with name %s' % value)
            return super(ParticipantSummaryDao,
                         self).make_query_filter(field_name + 'Id',
                                                 organization.organizationId)
        if field_name in _SITE_FIELDS:
            if value == UNSET:
                return super(ParticipantSummaryDao,
                             self).make_query_filter(field_name + 'Id', None)
            site = self.site_dao.get_by_google_group(value)
            if not site:
                raise BadRequest('No site found with google group %s' % value)
            return super(ParticipantSummaryDao,
                         self).make_query_filter(field_name + 'Id',
                                                 site.siteId)
        if field_name in _CODE_FILTER_FIELDS:
            if value == UNSET:
                return super(ParticipantSummaryDao,
                             self).make_query_filter(field_name + 'Id', None)
            # Note: we do not at present support querying for UNMAPPED code values.
            code = self.code_dao.get_code(PPI_SYSTEM, value)
            if not code:
                raise BadRequest('No code found: %s' % value)
            return super(ParticipantSummaryDao,
                         self).make_query_filter(field_name + 'Id',
                                                 code.codeId)

        if field_name == 'patientStatus':
            return self._make_patient_status_field_filter(field_name, value)

        return super(ParticipantSummaryDao,
                     self).make_query_filter(field_name, value)