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-920: Endpoint for OrderAttribute and OrderAttributeType. #587

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

slubwama
Copy link

@slubwama slubwama commented Sep 8, 2023

https://issues.openmrs.org/browse/RESTWS-920

Description of what I changed

  • Added OrderAttribute and OrderAttributeType

Issue I worked on

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

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

* We should not need to apply this fix in versions where TRUNK-5022 is fixed.
*/
@OpenmrsProfile(openmrsPlatformVersion = "2.5.* - 9.*")
public class InitPathMatcher2_5 implements ServletContextAware {
Copy link
Member

Choose a reason for hiding this comment

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

Is this in any way related to the changes required for your ticket?

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.xml.sax.InputSource;

public class RestControllerTestUtils extends BaseModuleWebContextSensitiveTest {
Copy link
Member

Choose a reason for hiding this comment

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

What is this for?

/**
* Facilitates testing controllers.
*/
public abstract class MainResourceControllerTest extends RestControllerTestUtils {
Copy link
Member

Choose a reason for hiding this comment

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

What is this for?

import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.xml.sax.InputSource;

public class RestControllerTestUtils extends BaseModuleWebContextSensitiveTest {
Copy link
Member

Choose a reason for hiding this comment

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

What is this for?

return "Dispensing Location: " + new SimpleDateFormat("yyyy-MM-dd").parse("2011-04-25");
}
catch (ParseException ex) {
ex.printStackTrace();
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

@dkayiwa done responding to all comments raised

Copy link
Member

@dkayiwa dkayiwa Sep 10, 2023

Choose a reason for hiding this comment

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

Can you also add an OrderAttributeController2_5Test?
And an OrderAttributeTypeController2_5Test?

<scope>test</scope>
</dependency>

<dependency>
Copy link
Member

Choose a reason for hiding this comment

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

Remove this dependency

omod-2.5/pom.xml Outdated

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-omod-1.8</artifactId>
Copy link
Member

Choose a reason for hiding this comment

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

Remove this dependency

omod-2.5/pom.xml Outdated

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-omod-1.9</artifactId>
Copy link
Member

Choose a reason for hiding this comment

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

Remove this dependency

omod-2.5/pom.xml Outdated

<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>${project.parent.artifactId}-omod-1.9</artifactId>
Copy link
Member

Choose a reason for hiding this comment

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

Remove this dependency

@dkayiwa
Copy link
Member

dkayiwa commented Sep 11, 2023

@slubwama for the ClassNotFoundException, in your pom.xml file, remove the webservices.rest 1.8-omod and 1.9-omod dependencies.

@dkayiwa
Copy link
Member

dkayiwa commented Sep 22, 2023

@slubwama because you extended OrderResource2_2, you need to change its supported platform versions such that they do not overlap with the new class that extends it. Does this make sense?

@dkayiwa
Copy link
Member

dkayiwa commented Nov 28, 2023

@slubwama did you abandon this?

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.

Few minor things, but this mostly LGTM

* @param <P> The parent/owning type for the type T
* @param <PR> The Resource for the parent/owning type P
*/
public abstract class BaseAttributeCrudResource2_5<T extends Attribute<?, ?>, P, PR> extends DelegatingSubResource<T, P, DelegatingCrudResource<P>> {
Copy link
Member

Choose a reason for hiding this comment

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

Why doesn't this just extend BaseAttributeCrudResource1_9?

Copy link
Member

Choose a reason for hiding this comment

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

It's also not entirely clear to me what this is adding to that class...

*
* @param <T>
*/
public abstract class BaseAttributeTypeCrudResource2_5<T extends AttributeType<?>> extends MetadataDelegatingCrudResource<T> {
Copy link
Member

Choose a reason for hiding this comment

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

It seems like this should extend BaseAttributeTypeCrudResource1_9.

Copy link
Member

Choose a reason for hiding this comment

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

I'm equally unsure that we even need this class at all.

Comment on lines 94 to 99
for (OrderAttribute orderAttribute : delegate.getOrder().getActiveAttributes()) {
if (orderAttribute.equals(delegate)) {
needToAdd = false;
break;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for (OrderAttribute orderAttribute : delegate.getOrder().getActiveAttributes()) {
if (orderAttribute.equals(delegate)) {
needToAdd = false;
break;
}
}
if (delegate.getOrder().getActiveAttributes().contains(delegate)) {
delegate.getOrder().addAttribute(delegate);
}

*/
@Override
protected void delete(OrderAttribute delegate, String reason, RequestContext context) throws ResponseException {
throw new UnsupportedOperationException("Cannot purge OrderAttribute");
Copy link
Member

Choose a reason for hiding this comment

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

Why not?

List<OrderAttributeType> allAttrs = service().getAllOrderAttributeTypes();
List<OrderAttributeType> queryResult = new ArrayList<OrderAttributeType>();
for (OrderAttributeType locAttr : allAttrs) {
if (Pattern.compile(Pattern.quote(context.getParameter("q")), Pattern.CASE_INSENSITIVE)
Copy link
Member

Choose a reason for hiding this comment

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

  1. We don't really need a regex here. You can just using locAttr.getName().toLowerCase().contains(context.getParameter("q").toLowerCase())
  2. If we do use a Regex here, do not call Pattern.compile() in a loop; lift it to outside the loop context.

/**
* Tests functionality of {@link OrderAttributeController}.
*/
public class OrderAttributeController2_5Test extends MainResourceControllerTest {
Copy link
Member

Choose a reason for hiding this comment

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

This is really a test for the OrderResource, so it should be OrderController2_5Test, no?

@slubwama
Copy link
Author

@dkayiwa need review on this again

@dkayiwa
Copy link
Member

dkayiwa commented Jun 13, 2024

@slubwama add this to your test class: https://pastebin.com/SRcYACN2

@mks-d mks-d changed the title RESTWS-920 Create API endpoint for OrderAttribute and OrderAttributeType RESTWS-920: Endpoint for OrderAttribute and OrderAttributeType. Jun 19, 2024
@slubwama
Copy link
Author

@dkayiwa @ibacher this is ready for a review again

Comment on lines +88 to +92
for (OrderAttributeType locAttr : allAttrs) {
if (locAttr.getName().toLowerCase().contains(context.getParameter("q").toLowerCase())) {
queryResult.add(locAttr);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

It would be ideal, I think, if we could extend the order server to handle this search for use. Anything where we're loading all database entries into memory is going to perform slowly.

Copy link
Member

Choose a reason for hiding this comment

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

We probably want the ability (and to default!) to not returning any retired order attributes without the user explicitly requesting it.

Copy link
Member

Choose a reason for hiding this comment

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

Finally, if possible, it might be nice to order the results so that prefix matches come before "containing" matches. (This shouldn't block the PR)

public String getResourceVersion() {
return RestConstants2_5.RESOURCE_VERSION;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}
}

* @param attrs
*/
@PropertySetter("attributes")
public static void setAttributes(Order instance, List<OrderAttribute> attrs) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm a little nervous about this. Shouldn't we try to ensure that we update any attributes that might've been updated? Or do we just delete everything (somewhere) and add everything on request?

@CynthiaKamau
Copy link

@slubwama looking forward to this so that we can explore using it to store lab orders sample data

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.

4 participants