Exemplo n.º 1
0
def create_study_doc(dal: DalClinicalTrials, **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `study_docs` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "doc_id": "doc_id",
        "doc_type": "doc_type",
        "doc_url": "doc_url",
        "doc_comment": "doc_comment",
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.insert_study_doc(**refr)

    return obj_id, refr
Exemplo n.º 2
0
def create_expanded_access_info(dal: DalClinicalTrials,
                                **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `expanded_access_infos` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "expanded_access_type_individual": True,
        "expanded_access_type_intermediate": True,
        "expanded_access_type_treatment": True,
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.insert_expanded_access_info(**refr)

    return obj_id, refr
Exemplo n.º 3
0
def create_person(dal: DalClinicalTrials, **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `persons` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "name_first": "John",
        "name_middle": "Malcolm",
        "name_last": "Doe",
        "degrees": "PhD",
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.iodi_person(**refr)

    return obj_id, refr
Exemplo n.º 4
0
def create_study_dates(dal: DalClinicalTrials, **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `study_dates` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "study_first_submitted": datetime.date(2019, 1, 1),
        "study_first_submitted_qc": datetime.date(2019, 1, 2),
        "study_first_posted": datetime.date(2019, 1, 3),
        "results_first_submitted": datetime.date(2019, 1, 4),
        "results_first_submitted_qc": datetime.date(2019, 1, 5),
        "results_first_posted": datetime.date(2019, 1, 6),
        "disposition_first_submitted": datetime.date(2019, 1, 7),
        "disposition_first_submitted_qc": datetime.date(2019, 1, 8),
        "disposition_first_posted": datetime.date(2019, 1, 9),
        "last_update_submitted": datetime.date(2019, 1, 10),
        "last_update_submitted_qc": datetime.date(2019, 1, 11),
        "last_update_posted": datetime.date(2019, 1, 12),
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.insert_study_dates(**refr)

    return obj_id, refr
Exemplo n.º 5
0
def create_responsible_party(dal: DalClinicalTrials,
                             **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `responsible_parties` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "name_title": "name_title",
        "organization": "organization",
        "responsible_party_type": ResponsiblePartyType.PRINCIPAL,
        "investigator_affiliation": "investigator_affiliation",
        "investigator_full_name": "investigator_full_name",
        "investigator_title": "investigator_title",
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.insert_responsible_party(**refr)

    return obj_id, refr
Exemplo n.º 6
0
def create_study_design_info(dal: DalClinicalTrials,
                             **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `study_design_infos` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "allocation": "allocation",
        "intervention_model": "intervention_model",
        "intervention_model_description": "intervention_model_description",
        "primary_purpose": "primary_purpose",
        "observational_model": "observational_model",
        "time_perspective": "time_perspective",
        "masking": "masking",
        "masking_description": "masking_description",
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.insert_study_design_info(**refr)

    return obj_id, refr
Exemplo n.º 7
0
def create_eligibility(dal: DalClinicalTrials, **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `eligibilities` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "study_pop": "study_pop",
        "sampling_method": SamplingMethodType.PROBABILITY,
        "criteria": "criteria",
        "gender": GenderType.ALL,
        "gender_based": False,
        "gender_description": "gender_description",
        "minimum_age": "1 year",
        "maximum_age": "10 years",
        "healthy_volunteers": "healthy_volunteers",
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.insert_eligibility(**refr)

    return obj_id, refr
Exemplo n.º 8
0
def create_patient_data(dal: DalClinicalTrials, **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `patient_data` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "sharing_ipd": "sharing_ipd",
        "ipd_description": "ipd_description",
        "ipd_time_frame": "ipd_time_frame",
        "ipd_access_criteria": "ipd_access_criteria",
        "ipd_url": "ipd_url",
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.insert_patient_data(**refr)

    return obj_id, refr
Exemplo n.º 9
0
def main(args):
    cfg = load_config(args=args)

    # Initialize the Sentry agent.
    initialize_sentry(cfg=cfg)

    dal = DalClinicalTrials(
        sql_username=cfg.sql_username,
        sql_password=cfg.sql_password,
        sql_host=cfg.sql_host,
        sql_port=cfg.sql_port,
        sql_db=cfg.sql_db,
    )
    ingester = IngesterDocumentClinicalTrial(dal=dal)
    parser = ParserXmlClinicaStudy()

    if arguments.mode == "file":
        for filename in args.filenames:
            clinical_study = parser.parse(filename_xml=filename)
            ingester.ingest(doc=clinical_study)
    elif arguments.mode == "rss":
        retriever = RetrieverCtRss()
        for xml_string in retriever.get_new_studies():
            clinical_study = parser.parse_string(xml_string=xml_string)
            ingester.ingest(doc=clinical_study)
Exemplo n.º 10
0
def create_facility(dal: DalClinicalTrials, **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `facilities` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "name": "The Alfred",
        "city": "Melbourne",
        "state": "Victoria",
        "zip_code": "3000",
        "country": "Australia",
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.iodi_facility(**refr)

    return obj_id, refr
Exemplo n.º 11
0
def create_arm_group(dal: DalClinicalTrials, **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `arm_groups` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "label": "label",
        "arm_group_type": "arm_group_type",
        "description": "description",
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.insert_arm_group(**refr)

    return obj_id, refr
Exemplo n.º 12
0
def create_intervention(dal: DalClinicalTrials, **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `interventions` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "intervention_type": InterventionType.BEHAVIORAL,
        "name": "name",
        "description": "description",
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.iodi_intervention(**refr)

    return obj_id, refr
Exemplo n.º 13
0
def create_investigator(dal: DalClinicalTrials,
                        person_id: Optional[int] = None,
                        **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `investigators` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.
        person_id (int): The PK ID of the `persons` record.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    if not person_id:
        person_id, _ = create_person(dal=dal)

    refr = {
        "person_id": person_id,
        "role": RoleType.DIRECTOR,
        "affiliation": "affiliation",
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.iodi_investigator(**refr)

    return obj_id, refr
Exemplo n.º 14
0
def create_contact(dal: DalClinicalTrials, person_id: int,
                   **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `contacts` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.
        person_id (int): The PK ID of the `persons` record.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    if not person_id:
        person_id, _ = create_person(dal=dal)

    refr = {
        "person_id": person_id,
        "phone": "phone",
        "phone_ext": "phone_ext",
        "email": "email",
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.iodi_contact(**refr)

    return obj_id, refr
Exemplo n.º 15
0
def create_protocol_outcome(dal: DalClinicalTrials,
                            **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `protocol_outcomes` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "measure": "measure",
        "time_frame": "time_frame",
        "description": "description",
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.insert_protocol_outcome(**refr)

    return obj_id, refr
Exemplo n.º 16
0
def create_oversight_info(dal: DalClinicalTrials,
                          **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `oversight_infos` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "has_dmc": True,
        "is_fda_regulated_drug": True,
        "is_fda_regulated_device": True,
        "is_unapproved_device": True,
        "is_ppsd": True,
        "is_us_export": True,
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.insert_oversight_info(**refr)

    return obj_id, refr
Exemplo n.º 17
0
def populate(
    dal: DalClinicalTrials,
    num_days: Optional[int] = None,
    chunk_size: Optional[int] = 1000,
    skip_populated: Optional[bool] = False,
    dry_run: Optional[bool] = False,
):

    with dal.session_scope() as session:  # type: sqlalchemy.orm.Session

        studies_chunks = find_recent_studies(
            session=session,
            num_days=num_days,
            chunk_size=chunk_size,
            skip_populated=skip_populated,
        )
        for studies_chunk in studies_chunks:
            studies = list(studies_chunk)  # type: List[Study]
            logger.warning(len(studies))
            for study in studies:
                logger.info(f"Processing study with ID {study.study_id}")

                for location in study.locations:
                    logger.info(
                        f"Processing location with ID {location.location_id}")

                    facility_id = location.facility_id
                    facility_canonical_id = (
                        location.facility.facility_canonical_id)

                    _prefix = "[DRY RUN] " if dry_run else ""

                    logger.info(
                        f"{_prefix}IODUing `StudyFacility` with a `study_id`"
                        f" of '{study.study_id}', `facility_id` of "
                        f"{facility_id}, and `facility_canonical_id` of "
                        f"'{facility_canonical_id}'.")

                    if not dry_run:
                        dal.iodu_study_facility(
                            study_id=study.study_id,
                            facility_id=facility_id,
                            facility_canonical_id=facility_canonical_id,
                        )
Exemplo n.º 18
0
    def setup_dal(self) -> DalClinicalTrials:
        # Instantiate a DAL.
        dal = DalClinicalTrials(
            sql_username=self.cfg.sql_username,
            sql_password=self.cfg.sql_password,
            sql_host=self.cfg.sql_host,
            sql_port=self.cfg.sql_port,
            sql_db=self.cfg.sql_db
        )

        return dal
Exemplo n.º 19
0
def create_location(dal: DalClinicalTrials,
                    facility_id: Optional[int] = None,
                    contact_primary_id: Optional[int] = None,
                    contact_backup_id: Optional[int] = None,
                    **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `locations` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.
        facility_id (int): The PK ID of the `facilities` record.
        contact_primary_id (int): The PK ID of the primary `contacts` record.
        contact_backup_id (int): The PK ID of the backup `contacts` record.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    if not facility_id:
        facility_id, _ = create_facility(dal=dal)

    if not contact_primary_id:
        person_01_id, _ = create_person(dal=dal, name_first="A")
        contact_primary_id, _ = create_contact(dal=dal, person_id=person_01_id)

    if not contact_backup_id:
        person_02_id, _ = create_person(dal=dal, name_first="B")
        contact_backup_id, _ = create_contact(dal=dal, person_id=person_02_id)

    refr = {
        "facility_id": facility_id,
        "status": RecruitmentStatusType.ACTIVE_NOT,
        "contact_primary_id": contact_primary_id,
        "contact_backup_id": contact_backup_id,
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.iodu_location(**refr)

    return obj_id, refr
Exemplo n.º 20
0
def find_recent_unmatched_facilities(dal: DalClinicalTrials):

    with dal.session_scope() as session:  # type: sqlalchemy.orm.Session
        query = session.query(Facility)
        query = query.join(Facility.studies)
        query = query.join(Study.study_dates)

        # Filter down to facilities not matched with a canonical facility.
        query = query.filter(Facility.facility_canonical_id.is_(None))

        # Filter down to studies updated in the last 2 days.
        query = query.filter(
            StudyDates.last_update_posted > (datetime.date.today() -
                                             datetime.timedelta(days=2)))

        query = query.group_by(Facility.facility_id)

        facilities_unmatched = query.all()

    return facilities_unmatched
Exemplo n.º 21
0
    def setUp(self):
        """Instantiates the DAL and creates the schema."""

        # Load the configuration.
        self.cfg = import_config(
            fname_config_file="/etc/ct-ingester/ct-ingester-test.json", )

        self.dal = DalClinicalTrials(sql_username=self.cfg.sql_username,
                                     sql_password=self.cfg.sql_password,
                                     sql_host=self.cfg.sql_host,
                                     sql_port=self.cfg.sql_port,
                                     sql_db=self.cfg.sql_db)

        self.ingester = IngesterDocumentClinicalTrial(dal=self.dal)

        self.parser = ParserXmlClinicaStudy()

        # Drop any schema remnants and recreate it.
        Base.metadata.drop_all(self.dal.engine)
        Base.metadata.create_all(self.dal.engine)
Exemplo n.º 22
0
def create_keyword(dal: DalClinicalTrials, **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `keywords` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "keyword": "keyword",
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.iodi_keyword(**refr)

    return obj_id, refr
Exemplo n.º 23
0
def create_enrollment(dal: DalClinicalTrials, **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `enrollments` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "value": 1,
        "enrollment_type": ActualType.ACTUAL,
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.insert_enrollment(**refr)

    return obj_id, refr
Exemplo n.º 24
0
def create_sponsor(dal: DalClinicalTrials, **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `sponsors` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    refr = {
        "agency": "agency",
        "agency_class": AgencyClassType.INDUSTRY,
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.iodi_sponsor(**refr)

    return obj_id, refr
Exemplo n.º 25
0
        "--config-file",
        dest="config_file",
        help="configuration file",
        required=True,
    )
    arguments = argument_parser.parse_args()

    if arguments.dry_run:
        logger.info("Performing a dry-run.")

    cfg = import_config(arguments.config_file)

    # Initialize the Sentry agent.
    initialize_sentry(cfg=cfg)

    # Create a new DAL.
    _dal = DalClinicalTrials(
        sql_username=cfg.sql_username,
        sql_password=cfg.sql_password,
        sql_host=cfg.sql_host,
        sql_port=cfg.sql_port,
        sql_db=cfg.sql_db,
    )

    populate(
        dal=_dal,
        num_days=int(arguments.num_days) if arguments.num_days else None,
        skip_populated=arguments.skip_populated,
        dry_run=arguments.dry_run,
    )
Exemplo n.º 26
0
def match(dal: DalClinicalTrials, retriever: RetrieverGoogleMaps):

    logger.info(
        "Retrieving unmatched facilities linked to studies updated in the "
        "past 2 days.")

    facilities_unmatched = find_recent_unmatched_facilities(dal=dal)

    logger.info(
        f"Retrieved {len(facilities_unmatched)} unmatched facilities linked "
        f"to studies updated in the past 2 days.")

    for facility in facilities_unmatched:

        logger.info(f"Processing facility {facility}.")

        logger.info(f"Matching facility {facility} against a Google Place.")

        place_response = find_facility_google_place(retriever=retriever,
                                                    facility=facility)

        # Skip empty responses.
        if not place_response or not place_response.get("candidates"):
            logger.warning(
                f"No Google Place match found for facility {facility}."
                f" Skipping.")
            continue

        # Retrieving Google Place ID from the first candidate.
        google_place_id = place_response["candidates"][0]["place_id"]

        logger.info(f"Google Place with ID '{google_place_id}' found matching "
                    f" facility {facility}.")

        with dal.session_scope() as session:  # type: sqlalchemy.orm.Session
            # noinspection PyTypeChecker
            facility_canonical = dal.get_by_attr(
                orm_class=FacilityCanonical,
                attr_name="google_place_id",
                attr_value=google_place_id,
                session=session,
            )  # type: FacilityCanonical

            if facility_canonical:
                facility_canonical_id = facility_canonical.facility_canonical_id

                logger.info(
                    f"Google Place with ID '{google_place_id}' previously "
                    f"stored as canonical facility {facility_canonical}.")
            else:
                logger.info(
                    f"Google Place with ID '{google_place_id}' not previously "
                    f"stored as a canonical facility.")

                logger.info(
                    f"Retrieving Google Place details for Google Place with "
                    f"ID '{google_place_id}'.")

                details_response = get_place_details(
                    google_place_id=google_place_id, retriever=retriever)

                if not details_response:
                    logger.warning(
                        f"No Google Place details retrieved for Google Place "
                        f"with ID '{google_place_id}'. Skipping.")
                    continue

                facility_canonical_id = iodu_canonical_facility_from_google(
                    dal=dal,
                    google_place_id=google_place_id,
                    google_response=details_response,
                )

            logger.info(f"Linking facility {facility} with canonical facility "
                        f"{facility_canonical}.")

            dal.update_attr_value(
                orm_class=Facility,
                pk=facility.facility_id,
                attr_name="facility_canonical_id",
                attr_value=facility_canonical_id,
                session=session,
            )
Exemplo n.º 27
0
def iodu_canonical_facility_from_google(dal: DalClinicalTrials,
                                        google_place_id: str,
                                        google_response: Dict):
    result = google_response["result"]

    components = result.get("address_components")

    if not components:
        return None

    # Fallback to the country defined in the facility if Google
    # returns no country.
    country = get_address_component_name(components, ("country", ))

    facility_canonical_id = dal.iodu_facility_canonical(
        google_place_id=google_place_id,
        name=result["name"],
        google_url=result["url"],
        url=result.get("website"),
        address=result["formatted_address"],
        phone_number=result.get("international_phone_number"),
        coordinate_longitude=result["geometry"]["location"]["lng"],
        coordinate_latitude=result["geometry"]["location"]["lat"],
        country=country,
        administrative_area_level_1=get_address_component_name(
            components, ("administrative_area_level_1", )),
        administrative_area_level_2=get_address_component_name(
            components, ("administrative_area_level_2", )),
        administrative_area_level_3=get_address_component_name(
            components, ("administrative_area_level_3", )),
        administrative_area_level_4=get_address_component_name(
            components, ("administrative_area_level_4", )),
        administrative_area_level_5=get_address_component_name(
            components, ("administrative_area_level_5", )),
        locality=get_address_component_name(components, ("locality", )),
        sublocality=get_address_component_name(
            components,
            ("sublocality", ),
            (
                "sublocality_level_1",
                "sublocality_level_2",
                "sublocality_level_3",
                "sublocality_level_4",
                "sublocality_level_5",
            ),
        ),
        sublocality_level_1=get_address_component_name(
            components, ("sublocality_level_1", )),
        sublocality_level_2=get_address_component_name(
            components, ("sublocality_level_2", )),
        sublocality_level_3=get_address_component_name(
            components, ("sublocality_level_3", )),
        sublocality_level_4=get_address_component_name(
            components, ("sublocality_level_4", )),
        sublocality_level_5=get_address_component_name(
            components, ("sublocality_level_5", )),
        colloquial_area=get_address_component_name(components,
                                                   ("colloquial_area", )),
        floor=get_address_component_name(components, ("floor", )),
        room=get_address_component_name(components, ("room", )),
        intersection=get_address_component_name(components,
                                                ("intersection", )),
        neighborhood=get_address_component_name(components,
                                                ("neighborhood", )),
        post_box=get_address_component_name(components, ("post_box", )),
        postal_code=get_address_component_name(components, ("postal_code", )),
        postal_code_prefix=get_address_component_name(
            components, ("postal_code_prefix", )),
        postal_code_suffix=get_address_component_name(
            components, ("postal_code_suffix", )),
        postal_town=get_address_component_name(components, ("postal_town", )),
        premise=get_address_component_name(components, ("premise", )),
        subpremise=get_address_component_name(components, ("subpremise", )),
        route=get_address_component_name(components, ("route", )),
        street_address=get_address_component_name(components,
                                                  ("street_address", )),
        street_number=get_address_component_name(components,
                                                 ("street_number", )),
    )

    return facility_canonical_id
Exemplo n.º 28
0
                premise=fac.premise,
                subpremise=fac.subpremise,
                route=fac.route,
                street_address=fac.street_address,
                street_number=fac.street_number,
            )


if __name__ == '__main__':

    cfg = import_config("/etc/ct-ingester/ct-ingester-dev.json")

    # Create a new clinical-trials DAL.
    dal_ct = DalClinicalTrials(
        sql_username="******",
        sql_password="******",
        sql_host="192.168.0.12",
        sql_port=cfg.sql_port,
        sql_db=cfg.sql_db,
    )

    dal_pm = DalPubmed(
        sql_username="******",
        sql_password="******",
        sql_host="192.168.0.12",
        sql_port=cfg.sql_port,
        sql_db=cfg.sql_db,
    )

    populate()
Exemplo n.º 29
0
def create_study(dal: DalClinicalTrials,
                 oversight_info_id: Optional[int] = None,
                 expanded_access_info_id: Optional[int] = None,
                 study_design_info_id: Optional[int] = None,
                 enrollment_id: Optional[int] = None,
                 eligibility_id: Optional[int] = None,
                 contact_primary_id: Optional[int] = None,
                 contact_backup_id: Optional[int] = None,
                 study_dates_id: Optional[int] = None,
                 responsible_party_id: Optional[int] = None,
                 patient_data_id: Optional[int] = None,
                 **kwargs) -> Tuple[int, Dict]:
    """ Inserts a new `oversight_infos` record.

    Args:
        dal (DalClinicalTrials): The DAL used to interact with the DB.
        oversight_info_id (int): The PK ID of the `oversight_infos` record.
        expanded_access_info_id (int): The PK ID of the `expanded_access_infos`
            record.
        study_design_info_id (int): The PK ID of the `study_design_infos`
            record.
        enrollment_id (int): The PK ID of the `enrollments` record.
        eligibility_id (int): The PK ID of the `eligibilities` record.
        contact_primary_id (int): The PK ID of the `contacts` record pertaining
            to the primary contact.
        contact_backup_id (int): The PK ID of the `contacts` record pertaining
            to the backup contact
        study_dates_id (int): The PK ID of the `study_dates` record.
        responsible_party_id (int): The PK ID of the `responsible_parties`
            record.
        patient_data_id (int): The PK ID of the `patient_datas` record.

    Returns:
        Tuple(int, Dict):
            - The PK ID of the new record.
            - The inserted record reference.
    """

    if not oversight_info_id:
        oversight_info_id, _ = create_oversight_info(dal=dal)

    if not expanded_access_info_id:
        expanded_access_info_id, _ = create_expanded_access_info(dal=dal)

    if not study_design_info_id:
        study_design_info_id, _ = create_study_design_info(dal=dal)

    if not enrollment_id:
        enrollment_id, _ = create_enrollment(dal=dal)

    if not eligibility_id:
        eligibility_id, _ = create_eligibility(dal=dal)

    if not contact_primary_id:
        person_01_id, _ = create_person(dal=dal, name_first="A")
        contact_primary_id, _ = create_contact(dal=dal, person_id=person_01_id)

    if not contact_backup_id:
        person_02_id, _ = create_person(dal=dal, name_first="B")
        contact_backup_id, _ = create_contact(dal=dal, person_id=person_02_id)

    if not study_dates_id:
        study_dates_id, _ = create_study_dates(dal=dal)

    if not responsible_party_id:
        responsible_party_id, _ = create_responsible_party(dal=dal)

    if not patient_data_id:
        patient_data_id, _ = create_patient_data(dal=dal)

    refr = {
        "org_study_id": "org_study_id",
        "nct_id": "nct_id",
        "brief_title": "brief_title",
        "acronym": "acronym",
        "official_title": "official_title",
        "source": "source",
        "oversight_info_id": oversight_info_id,
        "brief_summary": "brief_summary",
        "detailed_description": "detailed_description",
        "overall_status": OverallStatusType.ACTIVE_NOT,
        "last_known_status": OverallStatusType.APPROVED,
        "why_stopped": "why_stopped",
        "start_date": datetime.date(2019, 1, 1),
        "completion_date": datetime.date(2019, 1, 1),
        "primary_completion_date": datetime.date(2019, 1, 1),
        "verification_date": datetime.date(2019, 1, 1),
        "phase": PhaseType.PHASE_1,
        "study_type": StudyType.EXPANDED,
        "expanded_access_info_id": expanded_access_info_id,
        "study_design_info_id": study_design_info_id,
        "target_duration": "target_duration",
        "enrollment_id": enrollment_id,
        "biospec_retention": BiospecRetentionType.SAMPLES_W_DNA,
        "biospec_description": "biospec_description",
        "eligibility_id": eligibility_id,
        "contact_primary_id": contact_primary_id,
        "contact_backup_id": contact_backup_id,
        "study_dates_id": study_dates_id,
        "responsible_party_id": responsible_party_id,
        "patient_data_id": patient_data_id,
    }

    # Override any reference pairs with values under `kwargs`.
    for k, v in kwargs.items():
        refr[k] = v

    obj_id = dal.iodu_study(**refr)

    return obj_id, refr