Skip to content

Commit

Permalink
Merge 5fcb778 into df4734e
Browse files Browse the repository at this point in the history
  • Loading branch information
fruether committed Aug 29, 2018
2 parents df4734e + 5fcb778 commit bbb4f3a
Show file tree
Hide file tree
Showing 8 changed files with 388 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
* , supporting standard CRUD operations
*/
@Resource(name = RestConstants.VERSION_1 + "/order", supportedClass = Order.class, supportedOpenmrsVersions = { "1.10.*",
"1.11.*", "1.12.*", "2.0.*", "2.1.*", "2.2.*" })
"1.11.*", "1.12.*", "2.0.*", "2.1.*" })
public class OrderResource1_10 extends OrderResource1_8 {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/

package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2;

import org.openmrs.Order;

public class FulfillerDetails {

private Order.FulfillerStatus fulfillerStatus;

private String fulfillerComment;

private Order order;

public FulfillerDetails() {

}

public Order.FulfillerStatus getFulfillerStatus() {
return fulfillerStatus;
}

public String getFulfillerComment() {
return fulfillerComment;
}

public Order getOrder() {
return order;
}

public void setFulfillerStatus(Order.FulfillerStatus fulfillerStatus) {
this.fulfillerStatus = fulfillerStatus;
}

public void setFulfillerComment(String fulfillerComment) {
this.fulfillerComment = fulfillerComment;
}

public void setOrder(Order order) {
this.order = order;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2;

import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.StringProperty;
import org.openmrs.Order;
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.docs.swagger.core.property.EnumProperty;
import org.openmrs.module.webservices.rest.web.RequestContext;
import org.openmrs.module.webservices.rest.web.RestConstants;
import org.openmrs.module.webservices.rest.web.annotation.Resource;
import org.openmrs.module.webservices.rest.web.annotation.SubResource;
import org.openmrs.module.webservices.rest.web.representation.Representation;
import org.openmrs.module.webservices.rest.web.resource.api.PageableResult;
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource;
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
import org.openmrs.module.webservices.rest.web.response.ResponseException;

/**
* {@link Resource} for Order, supporting standard CRUD operations on fulfiller_comment and
* fulfiller_status
*/
@SubResource(parent = OrderResource2_2.class, path = "fulfillerdetails", supportedClass = FulfillerDetails.class, supportedOpenmrsVersions = {
"2.2.*" })
public class FulfillerDetailsResource2_2 extends DelegatingSubResource<FulfillerDetails, Order, OrderResource2_2> {

@Override
public FulfillerDetails newDelegate() {
return new FulfillerDetails();
}

@Override
public FulfillerDetails save(FulfillerDetails delegate) {
Context.getOrderService().updateOrderFulfillerStatus(delegate.getOrder(), delegate.getFulfillerStatus(),
delegate.getFulfillerComment());
return delegate;
}

@Override
public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
DelegatingResourceDescription delegatingResourceDescription = new DelegatingResourceDescription();
delegatingResourceDescription.addProperty("fulfillerStatus");
delegatingResourceDescription.addProperty("fulfillerComment");
return delegatingResourceDescription;
}

@Override
public Model getCREATEModel(Representation rep) {
return new ModelImpl()
.property("fulfillerComment", new StringProperty())
.property("fulfillerStatus", new EnumProperty(null));
}

@Override
public Order getParent(FulfillerDetails instance) {
return instance.getOrder();
}

@Override
public void setParent(FulfillerDetails instance, Order parent) {
instance.setOrder(parent);
}

@Override
public PageableResult doGetAll(Order parent, RequestContext context) throws ResponseException {
throw new ResourceDoesNotSupportOperationException();
}

@Override
public FulfillerDetails getByUniqueId(String uniqueId) {
throw new ResourceDoesNotSupportOperationException();
}

@Override
protected void delete(FulfillerDetails delegate, String reason, RequestContext context) throws ResponseException {
throw new ResourceDoesNotSupportOperationException();
}

@Override
public void purge(FulfillerDetails delegate, RequestContext context) throws ResponseException {
throw new ResourceDoesNotSupportOperationException();
}

@Override
public DelegatingResourceDescription getCreatableProperties() {
return getRepresentationDescription(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2;

import org.openmrs.Order;
import org.openmrs.module.webservices.rest.web.RestConstants;
import org.openmrs.module.webservices.rest.web.annotation.Resource;
import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
import org.openmrs.module.webservices.rest.web.representation.FullRepresentation;
import org.openmrs.module.webservices.rest.web.representation.Representation;
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10.OrderResource1_10;

@Resource(name = RestConstants.VERSION_1 + "/order", supportedClass = Order.class, supportedOpenmrsVersions = { "2.2.*" })
public class OrderResource2_2 extends OrderResource1_10 {

/**
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getRepresentationDescription(org.openmrs.module.webservices.rest.web.representation.Representation)
*/
@Override
public DelegatingResourceDescription getRepresentationDescription(Representation rep) {
DelegatingResourceDescription delegatingResourceDescription = super.getRepresentationDescription(rep);

if (delegatingResourceDescription != null && rep instanceof FullRepresentation) {
delegatingResourceDescription.addProperty("fulfillerStatus");
delegatingResourceDescription.addProperty("fulfillerComment");
}
return delegatingResourceDescription;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ public class RestTestConstants2_2 {
public final static String UPDATABLE_CODED_DIAGNOSIS_UUID = "59bf4fbc-fcdb-4a5b-97ea-0d5c4b4315a7";

public static final String DIAGNOSIS_TEST_DATA_XML = "patientDiagnosisDataSet.xml";

public static final String PERSON_UUID = "da7f524f-27ce-4bb2-86d6-6d1d05312bd5";

public final static String ORDER_UUID = "2c96f25c-4949-4f72-9931-d808fbc226df";

public final static String ORDER_UUID_Web = "2d96f25c-4949-4f72-9931-d808fbc226df";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2;

import org.junit.Test;
import static org.junit.Assert.assertEquals;

import org.openmrs.Order;
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.rest.SimpleObject;
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
import org.openmrs.module.webservices.rest.web.v1_0.RestTestConstants2_2;
import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest;
import org.springframework.mock.web.MockHttpServletRequest;

public class FulfillerDetailsController2_2Test extends MainResourceControllerTest {

@Test
public void test_shouldSetFulfillerDetailsOfOrderByPost() throws Exception {
Order.FulfillerStatus fulfillerStatus = Order.FulfillerStatus.RECEIVED;
String fillerComment = "An example comment from a filler";
SimpleObject post = new SimpleObject().add("fulfillerStatus", fulfillerStatus)
.add("fulfillerComment", fillerComment);
MockHttpServletRequest request = newPostRequest(getURI(), post);

handle(request);

Order order = Context.getOrderService().getOrderByUuid(RestTestConstants2_2.ORDER_UUID);
assertEquals(order.getFulfillerStatus(), fulfillerStatus);
assertEquals(order.getFulfillerComment(), fillerComment);
}

@Test(expected = ResourceDoesNotSupportOperationException.class)
public void shouldGetAll() throws Exception {
super.shouldGetAll();
}

@Test(expected = ResourceDoesNotSupportOperationException.class)
public void shouldGetDefaultByUuid() throws Exception {
super.shouldGetDefaultByUuid();
}

@Test(expected = ResourceDoesNotSupportOperationException.class)
public void shouldGetFullByUuid() throws Exception {
super.shouldGetFullByUuid();
}

@Test(expected = ResourceDoesNotSupportOperationException.class)
public void shouldGetRefByUuid() throws Exception {
super.shouldGetRefByUuid();
}

@Override
public String getURI() {
return "order/" + RestTestConstants2_2.ORDER_UUID + "/fulfillerdetails";
}

@Override
public String getUuid() {
return null;
}

@Override
public long getAllCount() {
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2;

import org.openmrs.Order;
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest;
import org.openmrs.module.webservices.rest.web.v1_0.RestTestConstants2_2;

import static org.junit.Assert.assertThat;
import static org.openmrs.module.webservices.rest.test.LinkMatcher.hasLink;

public class FulfillerDetailsResource2_2Test extends BaseDelegatingResourceTest<FulfillerDetailsResource2_2, FulfillerDetails> {

private String fulfillerComment = "Some example comment";

private Order.FulfillerStatus fulfillerStatus = Order.FulfillerStatus.RECEIVED;

/**
* @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest#newObject()
*/
@Override
public FulfillerDetails newObject() {

Order order = Context.getOrderService().getOrderByUuid(RestTestConstants2_2.ORDER_UUID);
FulfillerDetails fillerDetailsRepresentation = new FulfillerDetails();
fillerDetailsRepresentation.setOrder(order);
fillerDetailsRepresentation.setFulfillerComment(fulfillerComment);
fillerDetailsRepresentation.setFulfillerStatus(fulfillerStatus);

return fillerDetailsRepresentation;
}

/**
* @see BaseDelegatingResourceTest#validateDefaultRepresentation()
*/
@Override
public void validateDefaultRepresentation() throws Exception {
assertPropEquals("fulfillerStatus", fulfillerStatus);
assertPropEquals("fulfillerComment", fulfillerComment);
}

/**
* @see BaseDelegatingResourceTest#validateFullRepresentation()
*/
public void validateFullRepresentation() throws Exception {
assertPropEquals("fulfillerStatus", fulfillerStatus);
assertPropEquals("fulfillerComment", fulfillerComment);
}

/**
* @see BaseDelegatingResourceTest#validateRefRepresentation()
*/
public void validateRefRepresentation() throws Exception {
assertPropEquals("fulfillerStatus", fulfillerStatus);
assertPropEquals("fulfillerComment", fulfillerComment);
}

@Override
public String getDisplayProperty() {
return null;
}

@Override
public String getUuidProperty() {
return null;
}
}
Loading

0 comments on commit bbb4f3a

Please sign in to comment.