@classmethod
    def create_from_reminder(cls, reminder_definition, reminder, recipient=None):
        if reminder_definition.messaging_event_id:
            return cls.objects.get(pk=reminder_definition.messaging_event_id)

        source, source_id = cls.get_source_from_reminder(reminder_definition)
        content_type, form_unique_id, form_name = cls.get_content_info_from_reminder(
            reminder_definition, reminder)

        if recipient and reminder_definition.recipient_is_list_of_locations(recipient):
            if len(recipient) == 1:
                recipient_type = (cls.RECIPIENT_LOCATION_PLUS_DESCENDANTS
                                  if reminder_definition.include_child_locations
                                  else cls.RECIPIENT_LOCATION)
                recipient_id = recipient[0].location_id
            elif 1 > len(recipient):
                recipient_type = (cls.RECIPIENT_VARIOUS_LOCATIONS_PLUS_DESCENDANTS
                                  if reminder_definition.include_child_locations
                                  else cls.RECIPIENT_VARIOUS_LOCATIONS)
                recipient_id = None
            else:
                # len(recipient) should never be 0 when we invoke this method,
                # but catching this situation here just in case
                recipient_type = cls.RECIPIENT_UNKNOWN
                recipient_id = None
        elif isinstance(recipient, list):
            recipient_type = cls.RECIPIENT_VARIOUS
            recipient_id = None
        elif recipient is None:
            recipient_type = cls.RECIPIENT_UNKNOWN
            recipient_id = None
        else:
            recipient_type = cls.get_recipient_type(recipient)
            recipient_id = recipient.get_id if recipient_type else None

        return cls.objects.create(
            domain=reminder_definition.domain,
            date=datetime.utcnow(),
            source=source,
            source_id=source_id,
            content_type=content_type,
            form_unique_id=form_unique_id,
            form_name=form_name,
            status=cls.STATUS_IN_PROGRESS,
            recipient_type=recipient_type,
            recipient_id=recipient_id
        )
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/sms/models.py/MessagingEvent.create_from_reminder/swapped operands of `>`