scout/adapter/mongo/case.py
def update_caseid(self, case_obj, family_id):
        """Update case id for a case across the database.

        This function is used when a case is a rerun or updated for another reason.

        Args:
            case_obj(dict)
            family_id(str): The new family id

        Returns:
            new_case(dict): The updated case object

        """
        new_case = deepcopy(case_obj)
        new_case['_id'] = family_id

        # update suspects and causatives
        for case_variants in ['suspects', 'causatives']:
            new_variantids = []
            for variant_id in case_obj.get(case_variants, []):
                case_variant = self.variant(variant_id)
                if not case_variant:
                    continue
                new_variantid = get_variantid(case_variant, family_id)
                new_variantids.append(new_variantid)
            new_case[case_variants] = new_variantids

        # update ACMG
        for acmg_obj in self.acmg_collection.find({'case_id': case_obj['_id']}):
            LOG.info("update ACMG classification: %s", acmg_obj['classification'])
            acmg_variant = self.variant(acmg_obj['variant_specific'])
            new_specific_id = get_variantid(acmg_variant, family_id)
            self.acmg_collection.find_one_and_update(
                {'_id': acmg_obj['_id']},
                {'$set': {'case_id': family_id, 'variant_specific': new_specific_id}},
            )

        # update events
        institute_obj = self.institute(case_obj['owner'])
        for event_obj in self.events(institute_obj, case=case_obj):
            LOG.info("update event: %s", event_obj['verb'])
            self.event_collection.find_one_and_update(
                {'_id': event_obj['_id']},
                {'$set': {'case': family_id}},
            )

        # insert the updated case
        self.case_collection.insert_one(new_case)
        # delete the old case
        self.case_collection.find_one_and_delete({'_id': case_obj['_id']})
        return new_case
def update_caseid(self, case_obj, family_id):
        """Update case id for a case across the database.

        This function is used when a case is a rerun or updated for another reason.

        Args:
            case_obj(dict)
            family_id(str): The new family id

        Returns:
            new_case(dict): The updated case object

        """
        new_case = deepcopy(case_obj)
        new_case['_id'] = family_id

        # update suspects and causatives
        for case_variants in ['suspects', 'causatives']:
            new_variantids = []
            for variant_id in case_obj.get(case_variants, []):
                case_variant = self.variant(variant_id)
                if not case_variant:
                    continue
                new_variantid = get_variantid(case_variant, family_id)
                new_variantids.append(new_variantid)
            new_case[case_variants] = new_variantids

        # update ACMG
        for acmg_obj in self.acmg_collection.find({'case_id': case_obj['_id']}):
            LOG.info("update ACMG classification: %s", acmg_obj['classification'])
            acmg_variant = self.variant(acmg_obj['variant_specific'])
            new_specific_id = get_variantid(acmg_variant, family_id)
            self.acmg_collection.find_one_and_update(
                {'_id': acmg_obj['_id']},
                {'$set': {'case_id': family_id, 'variant_specific': new_specific_id}},
            )

        # update events
        institute_obj = self.institute(case_obj['owner'])
        for event_obj in self.events(institute_obj, case=case_obj):
            LOG.info("update event: %s", event_obj['verb'])
            self.event_collection.find_one_and_update(
                {'_id': event_obj['_id']},
                {'$set': {'case': family_id}},
            )

        # insert the updated case
        self.case_collection.insert_one(new_case)
        # delete the old case
        self.case_collection.find_one_and_delete({'_id': case_obj['_id']})
        return new_case
Update case id for a case across the database.

        This function is used when a case is a rerun or updated for another reason.

        Args:
            case_obj(dict)
            family_id(str): The new family id

        Returns:
            new_case(dict): The updated case object