diff --git a/packtools/sps/formats/pubmed.py b/packtools/sps/formats/pubmed.py index f99b2651d..60b876799 100644 --- a/packtools/sps/formats/pubmed.py +++ b/packtools/sps/formats/pubmed.py @@ -14,6 +14,7 @@ journal_meta, kwd_group, ) +from packtools.sps.utils.xml_utils import node_plain_text def xml_pubmed_article_pipe(): @@ -508,18 +509,38 @@ def xml_pubmed_history(xml_pubmed, xml_tree): xml_pubmed.append(history) +def get_copyright_information(xml_tree): + copyright_statement = xml_tree.find(".//permissions/copyright-statement") + return node_plain_text(copyright_statement) or None + + def xml_pubmed_copyright_information(xml_pubmed, xml_tree): - ... - # TODO - # The Copyright information associated with this article. - # There is no example of using this value in the files. + """ + Copyright © 2023 The Authors + """ + copyright_information = get_copyright_information(xml_tree) + if copyright_information: + el = ET.Element("CopyrightInformation") + el.text = copyright_information + xml_pubmed.append(el) + + +def get_coi_statement(xml_tree): + fn_node = xml_tree.find('.//fn[@fn-type="coi-statement"]') + if fn_node is None: + return None + return node_plain_text(fn_node.find("p")) or node_plain_text(fn_node) or None def xml_pubmed_coi_statement(xml_pubmed, xml_tree): - ... - # TODO - # The Conflict of Interest statement associated with this article. - # There is no example of using this value in the files. + """ + Não há conflito de interesse entre os autores do artigo. + """ + coi_statement = get_coi_statement(xml_tree) + if coi_statement: + el = ET.Element("CoiStatement") + el.text = coi_statement + xml_pubmed.append(el) def get_keywords(xml_tree): diff --git a/tests/sps/formats/test_pubmed.py b/tests/sps/formats/test_pubmed.py index a8afad598..fba999b66 100644 --- a/tests/sps/formats/test_pubmed.py +++ b/tests/sps/formats/test_pubmed.py @@ -19,6 +19,8 @@ xml_pubmed_publication_type, xml_pubmed_article_id, xml_pubmed_history, + xml_pubmed_copyright_information, + xml_pubmed_coi_statement, xml_pubmed_vernacular_title_pipe, xml_pubmed_object_list, xml_pubmed_title_reference_list, @@ -1243,6 +1245,119 @@ def test_xml_pubmed_history(self): self.assertEqual(obtained, expected) + def test_xml_pubmed_copyright_information(self): + expected = ( + '
' + 'Copyright © 2023 The Authors' + '
' + ) + xml_pubmed = ET.fromstring( + '
' + ) + xml_tree = ET.fromstring( + '
' + '' + '' + '' + 'Copyright © 2023 The Authors' + '' + '' + '' + '
' + ) + + xml_pubmed_copyright_information(xml_pubmed, xml_tree) + + obtained = ET.tostring(xml_pubmed, encoding="utf-8").decode("utf-8") + + self.assertEqual(obtained, expected) + + def test_xml_pubmed_copyright_information_without_statement(self): + expected = ( + '
' + ) + xml_pubmed = ET.fromstring( + '
' + ) + xml_tree = ET.fromstring( + '
' + '' + '' + '' + '' + '' + '' + '
' + ) + + xml_pubmed_copyright_information(xml_pubmed, xml_tree) + + obtained = ET.tostring(xml_pubmed, encoding="utf-8").decode("utf-8") + + self.assertEqual(obtained, expected) + + def test_xml_pubmed_coi_statement(self): + expected = ( + '
' + 'Não há conflito de interesse entre os autores do artigo.' + '
' + ) + xml_pubmed = ET.fromstring( + '
' + ) + xml_tree = ET.fromstring( + '
' + '' + '' + '' + '' + '' + '

Não há conflito de interesse entre os autores do artigo.

' + '
' + '
' + '
' + '
' + '
' + ) + + xml_pubmed_coi_statement(xml_pubmed, xml_tree) + + obtained = ET.tostring(xml_pubmed, encoding="utf-8").decode("utf-8") + + self.assertEqual(obtained, expected) + + def test_xml_pubmed_coi_statement_without_fn(self): + expected = ( + '
' + ) + xml_pubmed = ET.fromstring( + '
' + ) + xml_tree = ET.fromstring( + '
' + '' + '' + '' + '' + '' + '' + '
' + ) + + xml_pubmed_coi_statement(xml_pubmed, xml_tree) + + obtained = ET.tostring(xml_pubmed, encoding="utf-8").decode("utf-8") + + self.assertEqual(obtained, expected) + def test_xml_pubmed_object_list_keyword(self): expected = ( '
'