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

TRUNK-5350: Introduce new REST APIs for the Condition domain object. #327

Merged
merged 1 commit into from
Mar 22, 2018

Conversation

Arthur236
Copy link
Contributor

@Arthur236 Arthur236 commented Feb 27, 2018

Description of what I changed

Changed 1 file for this task:

  • omod-2.2/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/RestTestConstants2_2.java

Added 5 files for this task:

  • omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/ConditionResource2_2.java
  • omod-2.2/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_2/ConditionController2_2Test.java
  • omod-2.2/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_2/ConditionResource2_2Test.java
  • omod-2.2/src/test/resources/conditionTestDataset.xml
  • omod-2.2/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/converter/openmrs2_2/CodedOrFreeTextConverter.java

Issue I worked on

See https://issues.openmrs.org/browse/TRUNK-5350

Checklist: I completed these to help reviewers :)

  • My pull request only contains ONE single commit
    (the number above, next to the 'Commits' tab is 1).

    No? -> read here on how to squash multiple commits into one

  • 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

@Test
public void shouldCreateACondition() throws Exception {
long originalCount = getAllCount();

Copy link
Member

Choose a reason for hiding this comment

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

Can you add more tests for voiding, unvoiding, and purging a condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added 👍🏼

@@ -0,0 +1,9 @@
<?xml version='1.0' encoding='UTF-8'?>
Copy link
Contributor

Choose a reason for hiding this comment

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

Remember to add License header to this file too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted. Thanks.

@Arthur236 Arthur236 force-pushed the TRUNK-5350 branch 2 times, most recently from 70f80a6 to ead3fb0 Compare February 27, 2018 09:25
*/
@Override
public DelegatingResourceDescription getRepresentationDescription(Representation representation) {
if (representation instanceof DefaultRepresentation) {
Copy link
Member

Choose a reason for hiding this comment

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

Do you wanna add one for the RefRepresentation?


SimpleObject attributes = new SimpleObject();
attributes.add("voided", false);
attributes.add("void_reason", "");
Copy link
Member

Choose a reason for hiding this comment

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

Why do you pass these if they just contain empty strings?

Copy link
Member

Choose a reason for hiding this comment

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

Add a voided condition to the test dataset. Then unvoid it.

req.addParameter("purge", "");
handle(req);

Assert.assertNull(conditionService.getConditionByUuid(getUuid()));
Copy link
Member

Choose a reason for hiding this comment

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

Can you assertNotNull before purging?


@Override
public void validateDefaultRepresentation() throws Exception {
super.validateDefaultRepresentation();
Copy link
Member

Choose a reason for hiding this comment

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

Can you also add a test for the ref representation?

DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addProperty("uuid");
description.addProperty("condition");
description.addProperty("clinicalStatus");
Copy link
Member

Choose a reason for hiding this comment

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

Can you also add the display property to all the representations?

Copy link
Member

Choose a reason for hiding this comment

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

Can you also add the voided property to the representations?

Copy link
Member

Choose a reason for hiding this comment

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

Did you see my comment about the display property?

DelegatingResourceDescription description = new DelegatingResourceDescription();
description.addProperty("uuid");
description.addProperty("condition");
description.addProperty("clinicalStatus");
Copy link
Member

Choose a reason for hiding this comment

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

Can you also add the auditInfo property to the full representation?

description.addProperty("previousVersion");
description.addProperty("onsetDate");
description.addProperty("voided");
description.addProperty("void_reason");
Copy link
Member

Choose a reason for hiding this comment

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

Remove void reason

description.addProperty("verificationStatus");
description.addProperty("previousVersion");
description.addProperty("onsetDate");
description.addProperty("voided");
Copy link
Member

Choose a reason for hiding this comment

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

Remove void reason

description.addProperty("onsetDate");
description.addProperty("additionalDetail");
description.addProperty("voided");
description.addProperty("void_reason");
Copy link
Member

Choose a reason for hiding this comment

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

Remove void reason and date voided

SimpleObject newConditionSource = deserialize(handle(req));

Assert.assertNotNull(PropertyUtils.getProperty(newConditionSource, "uuid"));
Assert.assertEquals(originalCount + 1, getAllCount());
Copy link
Member

@dkayiwa dkayiwa Feb 27, 2018

Choose a reason for hiding this comment

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

Can you also assert the property values you created above? That way, it is more than just creating a condition, but with the expected values too.

handle(req);

Condition unvoidedCondition = conditionService.getConditionByUuid(getUuid());
Assert.assertEquals(false, unvoidedCondition.getVoided());
Copy link
Member

Choose a reason for hiding this comment

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

I have not seen any assertion proving that this was originally voided.

*/
@Override
public DelegatingResourceDescription getRepresentationDescription(Representation representation) {
if (representation instanceof RefRepresentation) {
Copy link
Member

Choose a reason for hiding this comment

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

For now, let us drop the branch for the RefRepresentation because we are not adding any value. 😊


SimpleObject conditionSource = new SimpleObject();
conditionSource.add("condition_id", 2);
conditionSource.add("condition_coded", 1);
Copy link
Member

Choose a reason for hiding this comment

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

The property names you are using here do not match those in the default or full representations

@Test
public void unvoidCondition_shouldUnvoidACondition() throws Exception {

Condition condition = conditionService.getConditionByUuid(getUuid());
Copy link
Member

Choose a reason for hiding this comment

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

How can this same condition be voided here and then not voided in the previous test?

description.addProperty("previousVersion");
description.addProperty("onsetDate");
description.addProperty("additionalDetail");
description.addProperty("voided");
Copy link
Member

Choose a reason for hiding this comment

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

Remove voided by

assertPropEquals("onsetDate", getObject().getOnsetDate());
assertPropEquals("additionalDetail", getObject().getAdditionalDetail());
assertPropEquals("voided", getObject().getVoided());
assertPropEquals("voided_by", getObject().getVoidedBy());
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure this test will pass?

*/
@Override
public void purge(Condition condition, RequestContext requestContext) throws ResponseException {
Context.getConditionService().purgeService(condition);
Copy link
Member

Choose a reason for hiding this comment

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

Can you use the real method in the ConditionService?


public final static String CONDITION_UUID = "c804ee60-ecbc-4d70-abda-1e4f6f64e5b5";

public static final String CONDITION_TEST_DATA_XML = "conditionTestDataSet.xml";
Copy link
Member

Choose a reason for hiding this comment

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

This file will not be found. It needs the full path as here openmrs/openmrs-core@d4981cd#diff-0d16b7abc7a5851414804ac8d1b34bb9R31

@Arthur236 Arthur236 force-pushed the TRUNK-5350 branch 3 times, most recently from f3783c3 to 46898d8 Compare March 13, 2018 09:01
<concept_name concept_id="111" name="mg" concept_name_id="1111" locale="en" creator="1"
date_created="2008-08-15 13:52:53.0" concept_name_type="FULLY_SPECIFIED" locale_preferred="1"
voided="false" uuid="cf215350-7863-11e3-981f-0800200c9a66"/>
<patient patient_id="2" creator="1" date_created="2005-01-01 00:00:00.0" voided="false"
Copy link
Member

Choose a reason for hiding this comment

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

The patient table does not have a uuid property

@Arthur236 Arthur236 force-pushed the TRUNK-5350 branch 4 times, most recently from 04ac1e1 to a1c1a3d Compare March 14, 2018 08:35
@Override
protected PageableResult doGetAll(RequestContext context) {
String patientUuid = context.getRequest().getParameter("patient");

Copy link
Member

Choose a reason for hiding this comment

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

Getting a patient from uuid is as simple as Context.getPatientService().getPatientByUuid(uuid)

Copy link
Member

@dkayiwa dkayiwa Mar 14, 2018

Choose a reason for hiding this comment

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

Can we get rid of this method? I mean the doGetAll() method as i said on email.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On it.


List<Condition> activeConditions = new ArrayList<Condition>();

if (patient != null)
Copy link
Member

Choose a reason for hiding this comment

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

If patient is null, then you should not silently ignore this. Throw an exception

@Arthur236 Arthur236 force-pushed the TRUNK-5350 branch 4 times, most recently from 7d0e9b0 to a753ba6 Compare March 14, 2018 17:43
.property("verificationStatus", new StringProperty())
.property("previousVersion", new StringProperty())
.property("onsetDate", new StringProperty())
.required("condition").required("onsetDate");
Copy link
Member

Choose a reason for hiding this comment

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

What does the above line mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It specifies the required properties that must be set

.property("previousVersion", new StringProperty())
.property("onsetDate", new StringProperty())
.property("voided", new StringProperty())
.required("condition").required("onsetDate");
Copy link
Member

Choose a reason for hiding this comment

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

What does the above line mean?

@coveralls
Copy link

coveralls commented Mar 15, 2018

Coverage Status

Coverage increased (+0.2%) to 41.399% when pulling 8ec507e on Arthur236:TRUNK-5350 into 3aab806 on openmrs:master.

String uuid = newConditionSource.get("uuid");
Assert.assertNotNull(conditionService.getConditionByUuid(uuid));

Condition condition = conditionService.getConditionByUuid(uuid);
Copy link
Member

Choose a reason for hiding this comment

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

Can you add assertions for all the properties you set before saving?

req.setContent(json.getBytes());

SimpleObject newConditionSource = deserialize(handle(req));
Util.log("Created condition", newConditionSource);
Copy link
Member

Choose a reason for hiding this comment

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

Are you using the above log for anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was using it to show that the Condition was being created correctly.

@dkayiwa
Copy link
Member

dkayiwa commented Mar 22, 2018

@Arthur236 have you looked at the above travis failure?

@dkayiwa
Copy link
Member

dkayiwa commented Mar 22, 2018

Can you also make the CodedOrFreeTextConverter look like this? https://pastebin.com/MMC2cPy5

@Arthur236
Copy link
Contributor Author

Yes I have @dkayiwa. Currently working on fixing it.


Condition condition = conditionService.getConditionByUuid(uuid);

Assert.assertEquals(nonCoded.get("nonCoded"), condition.getCondition().getNonCoded());
Copy link
Member

@dkayiwa dkayiwa Mar 22, 2018

Choose a reason for hiding this comment

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

Shouldn't the above assert be using the newConditionSource as the rest?

Copy link
Member

Choose a reason for hiding this comment

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

Oh seen it. :)

@dkayiwa dkayiwa merged commit 97fe285 into openmrs:master Mar 22, 2018
@Arthur236 Arthur236 deleted the TRUNK-5350 branch March 23, 2018 08:24
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