-
Notifications
You must be signed in to change notification settings - Fork 519
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
Conversation
@Test | ||
public void shouldCreateACondition() throws Exception { | ||
long originalCount = getAllCount(); | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'?> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted. Thanks.
70f80a6
to
ead3fb0
Compare
*/ | ||
@Override | ||
public DelegatingResourceDescription getRepresentationDescription(Representation representation) { | ||
if (representation instanceof DefaultRepresentation) { |
There was a problem hiding this comment.
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", ""); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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())); |
There was a problem hiding this comment.
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?
ead3fb0
to
4577cfd
Compare
|
||
@Override | ||
public void validateDefaultRepresentation() throws Exception { | ||
super.validateDefaultRepresentation(); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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?
4577cfd
to
568ccac
Compare
description.addProperty("previousVersion"); | ||
description.addProperty("onsetDate"); | ||
description.addProperty("voided"); | ||
description.addProperty("void_reason"); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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. 😊
568ccac
to
44d9ad2
Compare
|
||
SimpleObject conditionSource = new SimpleObject(); | ||
conditionSource.add("condition_id", 2); | ||
conditionSource.add("condition_coded", 1); |
There was a problem hiding this comment.
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
16ec2b0
to
45c8273
Compare
@Test | ||
public void unvoidCondition_shouldUnvoidACondition() throws Exception { | ||
|
||
Condition condition = conditionService.getConditionByUuid(getUuid()); |
There was a problem hiding this comment.
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?
45c8273
to
058d7dc
Compare
description.addProperty("previousVersion"); | ||
description.addProperty("onsetDate"); | ||
description.addProperty("additionalDetail"); | ||
description.addProperty("voided"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove voided by
058d7dc
to
d23f901
Compare
assertPropEquals("onsetDate", getObject().getOnsetDate()); | ||
assertPropEquals("additionalDetail", getObject().getAdditionalDetail()); | ||
assertPropEquals("voided", getObject().getVoided()); | ||
assertPropEquals("voided_by", getObject().getVoidedBy()); |
There was a problem hiding this comment.
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?
d23f901
to
5ffd858
Compare
*/ | ||
@Override | ||
public void purge(Condition condition, RequestContext requestContext) throws ResponseException { | ||
Context.getConditionService().purgeService(condition); |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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
f3783c3
to
46898d8
Compare
<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" |
There was a problem hiding this comment.
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
04ac1e1
to
a1c1a3d
Compare
@Override | ||
protected PageableResult doGetAll(RequestContext context) { | ||
String patientUuid = context.getRequest().getParameter("patient"); | ||
|
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
7d0e9b0
to
a753ba6
Compare
.property("verificationStatus", new StringProperty()) | ||
.property("previousVersion", new StringProperty()) | ||
.property("onsetDate", new StringProperty()) | ||
.required("condition").required("onsetDate"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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?
String uuid = newConditionSource.get("uuid"); | ||
Assert.assertNotNull(conditionService.getConditionByUuid(uuid)); | ||
|
||
Condition condition = conditionService.getConditionByUuid(uuid); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@Arthur236 have you looked at the above travis failure? |
Can you also make the CodedOrFreeTextConverter look like this? https://pastebin.com/MMC2cPy5 |
Yes I have @dkayiwa. Currently working on fixing it. |
|
||
Condition condition = conditionService.getConditionByUuid(uuid); | ||
|
||
Assert.assertEquals(nonCoded.get("nonCoded"), condition.getCondition().getNonCoded()); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh seen it. :)
Description of what I changed
Changed 1 file for this task:
Added 5 files for this task:
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 andadded 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