<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def raise_on_changed_subject_identifier(self):
 """Raises an exception if there is an attempt to change the subject identifier for an existing instance if the subject identifier is already set. """

        if self.id and self.subject_identifier_is_set():
            with transaction.atomic():
                obj = self.__class__.objects.get(pk=self.id)
                if obj.subject_identifier != self.subject_identifier_as_pk.hex:
                    if self.subject_identifier != obj.subject_identifier:
                        raise RegisteredSubjectError(
                            'Subject identifier cannot be changed for '
                            'existing registered subject. Got {} <> {}.'.format(
                                self.subject_identifier, obj.subject_identifier))