Skip to content

Commit 417b277

Browse files
BAH-3439 | Added birthtime property in the openmrs webservice.rest module. (#593)
* Added birthtime property in the openmrs webservice.rest module. * Override getUpdatableProperties in PersonResource1_10 and add birthtime * Add testcase for update a person's birthtime. * BAH-3439 || Move testcase which is for update a person's birthtime to other class. * BAH-3439 || remove the commented part from PersonController2_2Test.java * BAH-3439 || Add an assertion that the birthtime was updated to the new value * BAH-3439 || Add an assertion that the birthtime was updated to the new value * BAH-3349 || Change timezone * BAH-3439 || Added space between methods in PersonController2_2Test.java * BAH-3439 || Add an assertion that the birthtime was updated to the new value * BAH-3439 || Add an updated assertion that the birthtime was updated to the new value.
1 parent 2c89d75 commit 417b277

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

omod-1.10/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/resource/openmrs1_10/PersonResource1_10.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.openmrs.module.webservices.rest.web.representation.Representation;
1717
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource;
1818
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
19+
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
1920
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PersonResource1_8;
2021

2122
/**
@@ -46,12 +47,19 @@ public DelegatingResourceDescription getCreatableProperties() {
4647
description.addProperty("birthtime");
4748
return description;
4849
}
49-
50+
51+
5052
/**
5153
* @throws org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException
5254
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties()
5355
*/
5456
@Override
57+
public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException {
58+
DelegatingResourceDescription description = super.getUpdatableProperties();
59+
description.addProperty("birthtime");
60+
return description;
61+
}
62+
@Override
5563
public Model getGETModel(Representation rep) {
5664
return addNewProperties(super.getGETModel(rep), rep);
5765
}

omod-2.2/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs2_2/PersonController2_2Test.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.openmrs.module.webservices.rest.web.v1_0.RestTestConstants2_2;
2121
import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest;
2222

23+
import java.text.SimpleDateFormat;
24+
2325
import static org.junit.Assert.assertEquals;
2426
import static org.junit.Assert.assertFalse;
2527
import static org.junit.Assert.assertNotNull;
@@ -75,6 +77,19 @@ public void shouldEditAPerson() throws Exception {
7577
assertTrue(person.isDead());
7678
assertNotNull(person.getCauseOfDeathNonCoded());
7779
}
80+
81+
@Test
82+
public void shouldEditAPersonBirthTime() throws Exception {
83+
Person person = service.getPersonByUuid(getUuid());
84+
assertNull(person.getBirthtime());
85+
String json = "{\"birthtime\": \"1971-02-08T20:20:00.000\"}";
86+
SimpleObject response = deserialize(handle(newPostRequest(getURI() + "/" + getUuid(), json)));
87+
assertNotNull(response);
88+
Object responsePersonContents = PropertyUtils.getProperty(response, "person");
89+
assertNotNull(person.getBirthtime());
90+
assertNotNull(responsePersonContents);
91+
assertEquals("1971-02-08 08:20:00", new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(person.getBirthtime()));
92+
}
7893

7994
@Test
8095
public void shouldCreatePersonWithBirthtime() throws Exception {

0 commit comments

Comments
 (0)