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

RESTWS-939: DiagnosisResource should support formFieldPath property #609

Merged
merged 3 commits into from
Jul 25, 2024

Conversation

IamMujuziMoses
Copy link
Contributor

Issue I worked on

see https://issues.openmrs.org/browse/RESTWS-939

Checklist: I completed these to help reviewers :)

  • My IDE is configured to follow the code style of this project.

    No? Unsure? -> configure your IDE, format the code and add the changes with git add . && git commit --amend

  • I have added tests to cover my changes. (If you refactored
    existing code that was well tested you do not have to add tests)

    No? -> write tests and add them to this commit git add . && git commit --amend

  • I ran mvn clean package right before creating this pull request and
    added all formatting changes to my commit.

    No? -> execute above command

  • All new and existing tests passed.

    No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.

  • My pull request is based on the latest changes of the master branch.

    No? Unsure? -> execute command git pull --rebase upstream master

@IamMujuziMoses
Copy link
Contributor Author

@samuelmale @mseaton @dkayiwa please review

mseaton
mseaton previously requested changes Jun 4, 2024
Copy link
Member

@mseaton mseaton left a comment

Choose a reason for hiding this comment

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

My first reaction is that I would you think you could accomplish adding this support without adding a new omod-2.5 submodule. As far as I can see in the code, you never access this property directly, only via reflection (via the string property name). You should be able to simply wrap those statements in a check as to whether version 2.5+ of core is running, rather than have an entire new submodule to support.

If we do find we need to keep the submodule, then I have feedback about changes that would be needed, but I would think we can eliminate it altogether and keep this far simpler with just a few conditional changes to the existing DiagnosisResource2_2

@@ -98,6 +99,9 @@ public void purge(Diagnosis diagnosis, RequestContext requestContext) throws Res
public DelegatingResourceDescription getRepresentationDescription(Representation representation) {
if (representation instanceof DefaultRepresentation) {
DelegatingResourceDescription description = new DelegatingResourceDescription();
if (ModuleUtil.isOpenmrsVersionInVersions("2.5.* - 9.*")) {
description.addProperty("formNamespaceAndPath");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mseaton were you suggesting changes something like this?

Copy link
Member

Choose a reason for hiding this comment

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

Something like this, yes. Obviously you'd need to test this resource against version < 2.5 and versions >= 2.5 to ensure it works. It would be nice if there were other convenience methods in ModuleUtil that allowed you to just pass in the minimum version, but if this is the best available, that's fine. I'd at least create a convenience method in this class and use that (eg. supportsFormNamespaceAndPath() { return ModuleUtil.isOpenmrsVersionInVersions("2.5.* - 9.*") }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are there any convenience methods I could use to test this resource against versions >= 2.5?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mseaton please review

@IamMujuziMoses IamMujuziMoses force-pushed the RESTWS-939 branch 2 times, most recently from fcae774 to 8761201 Compare June 7, 2024 22:13
@samuelmale
Copy link
Member

@IamMujuziMoses are you still working on this?

@brandones
Copy link
Contributor

@samuelmale Looks like @IamMujuziMoses asked for a re-review from @mseaton four days ago. However the PIH team is about to be gone all of next week. I think it would be helpful if you, @dkayiwa , @ibacher , or someone else who understands REST WS code could provide a review (including ensuring that the concerns Mike raised are addressed).

@ibacher
Copy link
Member

ibacher commented Jun 28, 2024

I'm actually going to take the opposite view @mseaton took above. I think we should just create the 2.5 omod and go from there. Two reasons:

  1. We either need to use reflection or some other mechanism like used here to test if the "formNamespaceAndPath" property is added, whereas with a 2.5 OMOD, we do the version check once (or once-per-context refresh).
  2. The FormRecordable interface was added to more than just Diagnosis in 2.5. It was also added to: Order, Condition, Allergy, and PatientState so ideally, we'd cover all of those resources in a 2.5 OMOD, which I think gives us enough content to justify creating the new sub-module.

@ibacher
Copy link
Member

ibacher commented Jun 28, 2024

Code-wise, I think we're better-off exposing the formFieldNamespace and formFieldPath properties directly rather than the formFieldAndNamespace property for parity with the existing Obs resource, which also exposes them as two fields.

@IamMujuziMoses IamMujuziMoses force-pushed the RESTWS-939 branch 3 times, most recently from 05b4100 to 9181cb4 Compare July 2, 2024 16:11
@IamMujuziMoses
Copy link
Contributor Author

@ibacher please review

omod-2.5/pom.xml Show resolved Hide resolved
public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
DelegatingResourceDescription description = super.getRepresentationDescription(rep);
if (description != null) {
description.addProperty("formNamespaceAndPath");
Copy link
Member

Choose a reason for hiding this comment

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

Remember, we want to expose formNamespace and formPath, not formNamespaceAndPath

@brandones
Copy link
Contributor

@ibacher Could you please re-review when you have the chance?

Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks @IamMujuziMoses

@ibacher ibacher dismissed mseaton’s stale review July 25, 2024 16:59

Changes addressed

@ibacher ibacher merged commit 96a8cb0 into openmrs:master Jul 25, 2024
1 check passed
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.

5 participants