Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(test) O3-2943: Edit E2E test for the immunization recording workflow #1768

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Vijaykv5
Copy link
Contributor

@Vijaykv5 Vijaykv5 commented Mar 31, 2024

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work conforms to the OpenMRS 3.0 Styleguide and design documentation.
  • My work includes tests or is validated by existing tests.

Summary

This PR introduces changes that edits E2E test for recording an immunization

Related Issue

O3-2943

Other

@Vijaykv5 Vijaykv5 changed the title (test) O3-2943: Edit e2e test for the immunization recording workflow (test) O3-2943: Edit E2E test for the immunization recording workflow Mar 31, 2024
@Vijaykv5
Copy link
Contributor Author

Vijaykv5 commented Mar 31, 2024

@kdaud This was passing in local instance,but in github cli, the test is failing
Kindly can you review it
Thanks

@kdaud
Copy link
Member

kdaud commented Apr 1, 2024

@Vijaykv5 did you take a look at the logs?

@denniskigen
Copy link
Member

Here's the playwright report:

playwright-report (2).zip

Looks like the test is failing because there are no immunizations to edit. Maybe you need to combine the two specs.

@Vijaykv5
Copy link
Contributor Author

Vijaykv5 commented Apr 5, 2024

@Vijaykv5 did you take a look at the logs?

Yes @kdaud
I'm not able to figure out, the test is failing here:
await page.click('[aria-label="Expand current row"]');

@Vijaykv5
Copy link
Contributor Author

Vijaykv5 commented Apr 5, 2024

but @denniskigen we are separating each functions right?
add, edit and cancel immunization. #comment

@denniskigen
Copy link
Member

I defer to @jayasanka-sack for the ideal approach.

@jayasanka-sack
Copy link
Member

@Vijaykv5

Check line 10. When the edit test runs, it fails because it's using a brand-new patient with no existing data. We could switch to using beforeAll to avoid this, but then the edit test would depend on the create test, and we want to keep them separate.

A good fix would be to create an immunization record at the start of the edit test using the REST API. That should provide the necessary data for the test to work properly.

Lemme know if you have any questions! :)

@Vijaykv5
Copy link
Contributor Author

@Vijaykv5

Check line 10. When the edit test runs, it fails because it's using a brand-new patient with no existing data. We could switch to using beforeAll to avoid this, but then the edit test would depend on the create test, and we want to keep them separate.

A good fix would be to create an immunization record at the start of the edit test using the REST API. That should provide the necessary data for the test to work properly.

Lemme know if you have any questions! :)

@jayasanka-sack So do I need to call this API inside commands or I may need to create a separate file for creating immunization record using the REST API?

@jayasanka-sack
Copy link
Member

jayasanka-sack commented Apr 24, 2024

@jayasanka-sack So do I need to call this API inside commands or I may need to create a separate file for creating immunization record using the REST API?

@Vijaykv5 Write a command and call it within the edit test. Yes, you may need to create a new file under the commands directory.

@denniskigen
Copy link
Member

@jayasanka-sack could you please help Vijay get this over the line?

Copy link
Member

@jayasanka-sack jayasanka-sack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vijaykv5 Follow these steps:

  1. In e2e/fixtures/api.ts, update the base url of the API fixture to ${process.env.E2E_BASE_URL}/ws. So that we can invoke fhir endpoints

  2. Update existing API calls to use /rest/ prefix. ex: const patientRes = await api.post('/rest/patient', {

  3. Create a new function under patient-operations.ts file to create an immunization.
    You should send a post request to the following endpoint with the given payload (feel free to edit).
    /fhir2/R4/Immunization?_summary=data

       {
        "resourceType": "Immunization",
        "status": "completed",
        "vaccineCode": {
          "coding": [
            {
              "code": "783AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
              "display": "Polio vaccination, oral"
            }
          ]
        },
        "patient": {
          "type": "Patient",
          "reference": "Patient/703840a5-7339-4dc2-8993-f7cc7b96fc94"
        },
        "encounter": {
          "type": "Encounter",
          "reference": "Encounter/fca94b00-8b1f-4468-b006-68e77f438978"
        },
        "occurrenceDateTime": "2024-06-10T13:50:00.000Z",
        "expirationDate": "2052-06-29T18:30:00.000Z",
        "location": {
          "type": "Location",
          "reference": "Location/44c3efb0-2583-4c80-a79e-1f756a03c0a1"
        },
        "performer": [
          {
            "actor": {
              "type": "Practitioner",
              "reference": "Practitioner/f39e57d8-1185-4199-8567-6f1eeb160f05"
            }
          }
        ],
        "manufacturer": {
          "display": " Sanofi Pasteur SA"
        },
        "lotNumber": "POLIO-001",
        "protocolApplied": [
          {
            "doseNumberPositiveInt": 1,
            "series": null
          }
        ]
      }
    
  4. Create a new spec file for the edit immunization

  5. Call the created function from the beforeEach hook of the test.

@Vijaykv5 Vijaykv5 marked this pull request as draft June 15, 2024 11:14
@Vijaykv5
Copy link
Contributor Author

Vijaykv5 commented Jun 24, 2024

@jayasanka-sack The PR now works fine locally with the help of Immunization data but It fails in E2E Tests .
Any possible reason for this?

@brandones
Copy link
Contributor

Hi @Vijaykv5 , are you still available to work on this? You need to be able to debug test failures on your own. Especially if they are as straightforward as the one here.

@Vijaykv5
Copy link
Contributor Author

Sorry @brandones I was pinned with some other tickets.

Will soon fix this up!

@jayasanka-sack
Copy link
Member

I tested this locally with Docker and dev3 and it works fine. It only fails when running on GitHub Actions. I'm not sure why. This is the request and the response. @ibacher @mogoodrich @mseaton @mherman22 any idea what this error message means?

Request:

{
  "resourceType": "Immunization",
  "status": "completed",
  "vaccineCode": {
    "coding": [
      {
        "code": "783AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
        "display": "Hepatitis B vaccination"
      }
    ]
  },
  "patient": {
    "type": "Patient",
    "reference": "Patient/abd466a2-b4cc-4290-901c-5444c96662f0"
  },
  "encounter": {
    "type": "Encounter",
    "reference": "Encounter/a394aaa2-d9ef-42bd-9abc-813d91a68423"
  },
  "occurrenceDateTime": "2024-06-10T13:50:00.000Z",
  "expirationDate": "2052-06-29T18:30:00.000Z",
  "location": {
    "type": "Location",
    "reference": "Location/44c3efb0-2583-4c80-a79e-1f756a03c0a1"
  },
  "performer": [
    {
      "actor": {
        "type": "Practitioner",
        "reference": "Practitioner/f39e57d8-1185-4199-8567-6f1eeb160f05"
      }
    }
  ],
  "manufacturer": {
    "display": "Sanofi Pasteur SA"
  },
  "lotNumber": "POLIO-001",
  "protocolApplied": [
    {
      "doseNumberPositiveInt": 1,
      "series": null
    }
  ]
}

Response:

{
  "resourceType": "OperationOutcome",
  "text": {
    "status": "generated",
    "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><h1>Operation Outcome</h1><table border=\"0\"><tr><td style=\"font-weight: bold;\">ERROR</td><td>[]</td><td><pre>The Immunization resource is required to be attached to an OpenMRS encounter involving a single encounter provider with the role 'Clinician'. This is not the case for immunization '5f109c97-9f6f-4330-bb9f-a29d1d18fad9' attached to encounter 'f647ef65-07e6-42ff-9e1c-cb6e45f8ed3d'.</pre></td>\n\t\t\t</tr>\n\t\t</table>\n\t</div>"
  },
  "issue": [
    {
      "severity": "error",
      "code": "business-rule",
      "diagnostics": "The Immunization resource is required to be attached to an OpenMRS encounter involving a single encounter provider with the role 'Clinician'. This is not the case for immunization '5f109c97-9f6f-4330-bb9f-a29d1d18fad9' attached to encounter 'f647ef65-07e6-42ff-9e1c-cb6e45f8ed3d'."
    }
  ]
}

@mherman22
Copy link
Member

I tested this locally with Docker and dev3 and it works fine. It only fails when running on GitHub Actions. I'm not sure why. This is the request and the response. @ibacher @mogoodrich @mseaton @mherman22 any idea what this error message means?

Request:

{
  "resourceType": "Immunization",
  "status": "completed",
  "vaccineCode": {
    "coding": [
      {
        "code": "783AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
        "display": "Hepatitis B vaccination"
      }
    ]
  },
  "patient": {
    "type": "Patient",
    "reference": "Patient/abd466a2-b4cc-4290-901c-5444c96662f0"
  },
  "encounter": {
    "type": "Encounter",
    "reference": "Encounter/a394aaa2-d9ef-42bd-9abc-813d91a68423"
  },
  "occurrenceDateTime": "2024-06-10T13:50:00.000Z",
  "expirationDate": "2052-06-29T18:30:00.000Z",
  "location": {
    "type": "Location",
    "reference": "Location/44c3efb0-2583-4c80-a79e-1f756a03c0a1"
  },
  "performer": [
    {
      "actor": {
        "type": "Practitioner",
        "reference": "Practitioner/f39e57d8-1185-4199-8567-6f1eeb160f05"
      }
    }
  ],
  "manufacturer": {
    "display": "Sanofi Pasteur SA"
  },
  "lotNumber": "POLIO-001",
  "protocolApplied": [
    {
      "doseNumberPositiveInt": 1,
      "series": null
    }
  ]
}

Response:

{
  "resourceType": "OperationOutcome",
  "text": {
    "status": "generated",
    "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\"><h1>Operation Outcome</h1><table border=\"0\"><tr><td style=\"font-weight: bold;\">ERROR</td><td>[]</td><td><pre>The Immunization resource is required to be attached to an OpenMRS encounter involving a single encounter provider with the role 'Clinician'. This is not the case for immunization '5f109c97-9f6f-4330-bb9f-a29d1d18fad9' attached to encounter 'f647ef65-07e6-42ff-9e1c-cb6e45f8ed3d'.</pre></td>\n\t\t\t</tr>\n\t\t</table>\n\t</div>"
  },
  "issue": [
    {
      "severity": "error",
      "code": "business-rule",
      "diagnostics": "The Immunization resource is required to be attached to an OpenMRS encounter involving a single encounter provider with the role 'Clinician'. This is not the case for immunization '5f109c97-9f6f-4330-bb9f-a29d1d18fad9' attached to encounter 'f647ef65-07e6-42ff-9e1c-cb6e45f8ed3d'."
    }
  ]
}

Not sure if this answers you but all it is saying here is that the immunization resource you are creating which is attached to the encounter above doesn't involve an encounter provider with the role 'Clinician' so i think you might need to create a visit then an encounter then encounter provider in that order -> see this https://github.com/openmrs/openmrs-module-fhir2/blob/de31a6838324ba2546b6eb71a69cdd77f36aa168/test-data/src/main/resources/org/openmrs/module/fhir2/api/dao/impl/FhirImmunizationDaoImplTest_initial_data.xml#L28-L36

@brandones
Copy link
Contributor

@jayasanka-sack Well, the error is being produced by OpenMRS business logic, so it's not anything weird about how GitHub Actions works. There's probably just some difference between that server's setup and dev3 and the Docker setup. Maybe the user doesn't have the Clinician role, or maybe some UUIDs are different, or maybe the encounter isn't getting created the same way.

@ibacher
Copy link
Member

ibacher commented Aug 20, 2024

The encounter should be an encounter and not a visit. I think it can be left blank. Granted that's probably less than ideal.

@jayasanka-sack
Copy link
Member

The encounter should be an encounter and not a visit. I think it can be left blank. Granted that's probably less than ideal.

Ohhh that's the issue! @Vijaykv5 could you please fix this?

@ibacher
Copy link
Member

ibacher commented Aug 23, 2024

We should probably ticket this for the FHIR2 module, though. It should be possible to specify a visit and just create the encounter if required.

@brandones
Copy link
Contributor

Ping @Vijaykv5

@brandones
Copy link
Contributor

Ping @Vijaykv5 , CC @jayasanka-sack

@Vijaykv5
Copy link
Contributor Author

@jayasanka-sack @denniskigen may you could help me with creating an order encounter to get the encounter ID?
I've been trying to follow this, but found it difficult

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants