<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def validate_doc(self, document: BioCDocument):
 """Validate a single document."""

        annotations = []
        annotations.extend(document.annotations)
        annotations.extend(document.relations)
        for passage in document.passages:
            annotations.extend(passage.annotations)
            annotations.extend(passage.relations)
            for sentence in passage.sentences:
                annotations.extend(sentence.annotations)
                annotations.extend(sentence.relations)

        self.current_docid = document.id
        self.traceback.append(document)

        text = self.__get_doc_text(document)
        self.__validate_ann(document.annotations, text, 0)
        self.__validate_rel(annotations, document.relations, f'document {document.id}')

        for passage in document.passages:
            self.traceback.append(passage)

            text = self.__get_passage_text(passage)
            self.__validate_ann(passage.annotations, text, passage.offset)
            self.__validate_rel(annotations, passage.relations,
                                f'document {document.id} --> passage {passage.offset}')

            for sentence in passage.sentences:
                self.traceback.append(sentence)
                self.__validate_ann(sentence.annotations, sentence.text, sentence.offset)
                self.__validate_rel(annotations, sentence.relations,
                                    f'document {document.id} --> sentence {sentence.offset}')
                self.traceback.pop()
            self.traceback.pop()
        self.traceback.pop()