<commit_before>Feature: XML API for CMRs

  Because other systems need to interact w/ TriSano
  As a developer
  I want to be able to programmatically access cmrs as XML

  Scenario: Accessing a CMR XML representation
    Given a basic morbidity event exists
     When I retrieve the event's XML representation
     Then I should have an xml document
     When I use xpath to find the patient's last name
     Then I should have 1 node

  Scenario: Putting a CMR back using the XML representation
    Given a basic morbidity event exists
     When I retrieve the event's XML representation
      And I PUT the XML back
     Then I should get a 200 response

  Scenario: Putting an invalid CMR should returns errors
    Given a basic morbidity event exists
    When I retrieve the event's XML representation
    And I make the XML invalid
    And I PUT the XML back
    Then I should get a 422 response

  Scenario: Creating a CMR from an XML representation
     When I retrieve a new CMR xml representation
      And I replace the patient's last name with "Davis"
      And I replace the first reported to public health date with yesterday's date
      And I POST the XML to the "index" link
     Then I should get a 201 response
      And the Location header should have a link to the new event

  Scenario: Adding a note to a CMR
    Given a basic morbidity event exists
    When I retrieve the event's XML representation
    And I add "Updated from the API" as an administrative note
    And I PUT the XML back
    And I go to the CMR show page
    Then I should see "Updated from the API"

  Scenario: Retrieve an edit_jurisdiction template
    Given a basic morbidity event exists
    When I retrieve the edit_jurisdiction CMR XML representation
    Then I should have an xml document
    And these xpaths should exist:
      | /routing/atom:link[@rel='route'][contains(@href, 'cmrs')]                                              |
      | /routing/atom:link[@rel='https://wiki.csinitiative.com/display/tri/Relationship+-+Jurisdiction']       |
      | /routing/jurisdiction-id[@rel='https://wiki.csinitiative.com/display/tri/Relationship+-+Jurisdiction'] |
      | /routing/note                                                                                          |

  Scenario: Route a CMR to a jurisdiction
    Given a basic morbidity event exists
    When I retrieve the edit_jurisdiction CMR XML representation
    And I replace jurisdiction-id with jurisdiction "Bear River"
    And I add the assignment note "Hello, Bear River"
    And I POST the XML to the "route" link
    And I retrieve the event's XML representation
    Then these xpaths should exist:
      | //jurisdiction-attributes                     |
      | //jurisdiction-attributes/secondary-entity-id |
    And I should see the new jurisdiction
    And I should see "Hello, Bear River"

  Scenario: Route a CMR to an invalid jurisdiction
    Given a basic morbidity event exists
    When I retrieve the edit_jurisdiction CMR XML representation
    And I invalidate the jurisdiction
    And I POST the XML to the "route" link
    Then I should get a 400 response<commit_msg>No idea if this will work, but I replaced theh step that seems to inexplicably fail from time to time.<commit_after>Feature: XML API for CMRs

  Because other systems need to interact w/ TriSano
  As a developer
  I want to be able to programmatically access cmrs as XML

  Scenario: Accessing a CMR XML representation
    Given a basic morbidity event exists
     When I retrieve the event's XML representation
     Then I should have an xml document
     When I use xpath to find the patient's last name
     Then I should have 1 node

  Scenario: Putting a CMR back using the XML representation
    Given a basic morbidity event exists
     When I retrieve the event's XML representation
      And I PUT the XML back
     Then I should get a 200 response

  Scenario: Putting an invalid CMR should returns errors
    Given a basic morbidity event exists
    When I retrieve the event's XML representation
    And I make the XML invalid
    And I PUT the XML back
    Then I should get a 422 response

  Scenario: Creating a CMR from an XML representation
     When I retrieve a new CMR xml representation
      And I replace the patient's last name with "Davis"
      And I replace the first reported to public health date with yesterday's date
      And I POST the XML to the "index" link
     Then I should get a 201 response
      And the Location header should have a link to the new event

  Scenario: Adding a note to a CMR
    Given a basic morbidity event exists
    When I retrieve the event's XML representation
    And I add "Updated from the API" as an administrative note
    And I PUT the XML back
    And I go to the CMR show page
    Then I should see "Updated from the API"

  Scenario: Retrieve an edit_jurisdiction template
    Given a basic morbidity event exists
    When I retrieve the edit_jurisdiction CMR XML representation
    Then I should have an xml document
    And these xpaths should exist:
      | /routing/atom:link[@rel='route'][contains(@href, 'cmrs')]                                              |
      | /routing/atom:link[@rel='https://wiki.csinitiative.com/display/tri/Relationship+-+Jurisdiction']       |
      | /routing/jurisdiction-id[@rel='https://wiki.csinitiative.com/display/tri/Relationship+-+Jurisdiction'] |
      | /routing/note                                                                                          |

  Scenario: Route a CMR to a jurisdiction
    Given a basic morbidity event exists
    When I retrieve the edit_jurisdiction CMR XML representation
    And I replace jurisdiction-id with jurisdiction "Bear River"
    And I add the assignment note "Hello, <NAME>"
    And I POST the XML to the "route" link
    And I retrieve the event's XML representation
    Then these xpaths should exist:
      | //jurisdiction-attributes                     |
      | //jurisdiction-attributes/secondary-entity-id |
    And I should see the new jurisdiction
    And these xpaths should exist:
      | //note[text()='Hello, <NAME>'] |

  Scenario: Route a CMR to an invalid jurisdiction
    Given a basic morbidity event exists
    When I retrieve the edit_jurisdiction CMR XML representation
    And I invalidate the jurisdiction
    And I POST the XML to the "route" link
    Then I should get a 400 response
{'fraction_non_alphanumeric': 0.041044776119402986, 'fraction_numerical': 0.00404228855721393, 'mean_word_length': 2.573888888888889, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6637264', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1540, 'n_words': 851}