Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging;
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException;
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.DrugOrderSubclassHandler1_8;
//import org.openmrs.module.webservices.rest.web.representation.SimpleObject;
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
//import org.openmrs.module.webservices.rest.web.representation.SimpleObject;


/**
* Exposes the {@link org.openmrs.DrugOrder} subclass as a type in
Expand Down Expand Up @@ -67,7 +68,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
.getResourceBySupportedClass(Order.class);
DelegatingResourceDescription d = orderResource.getRepresentationDescription(rep);
d.addProperty("display");
d.addProperty("drug", Representation.REF);
d.addProperty("drug", Representation.DEFAULT);
d.addProperty("dosingType");
d.addProperty("dose");
d.addProperty("doseUnits", Representation.REF);
Expand All @@ -89,7 +90,7 @@ public DelegatingResourceDescription getRepresentationDescription(Representation
.getResourceBySupportedClass(Order.class);
DelegatingResourceDescription d = orderResource.getRepresentationDescription(rep);
d.addProperty("display");
d.addProperty("drug", Representation.REF);
d.addProperty("drug", Representation.DEFAULT);
d.addProperty("dosingType");
d.addProperty("dose");
d.addProperty("doseUnits", Representation.DEFAULT);
Expand Down Expand Up @@ -118,7 +119,7 @@ public DelegatingResourceDescription getCreatableProperties() {
OrderResource1_10 orderResource = (OrderResource1_10) Context.getService(RestService.class)
.getResourceBySupportedClass(Order.class);
DelegatingResourceDescription d = orderResource.getCreatableProperties();
d.addProperty("drug");
d.addProperty("drug", Representation.DEFAULT);
d.addProperty("dosingType");
d.addProperty("dose");
d.addProperty("doseUnits");
Expand Down Expand Up @@ -202,4 +203,5 @@ public static String getDisplay(DrugOrder delegate) {

return ret.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,23 @@
import org.openmrs.Drug;
import org.openmrs.DrugOrder;
import org.openmrs.Order;
import org.openmrs.api.OrderService;
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.rest.web.ConversionUtil;
import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation;
import org.openmrs.module.webservices.rest.web.representation.Representation;
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
import org.springframework.beans.factory.annotation.Autowired;
import org.junit.Before;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.is;
Copy link
Member

Choose a reason for hiding this comment

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



import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class DrugOrderSubclassHandler1_10Test {



@Test
public void getDisplayString_shouldNotFailForDcOrder() throws Exception {
Drug drug = new Drug();
Expand All @@ -31,4 +42,6 @@ public void getDisplayString_shouldNotFailForDcOrder() throws Exception {
String actual = DrugOrderSubclassHandler1_10.getDisplay(order);
assertThat(actual, is("(DISCONTINUE) Aspirin"));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* 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.openmrs1_10;

import org.junit.Before;
import org.junit.Test;
import org.openmrs.Drug;
import org.openmrs.DrugOrder;
import org.openmrs.Order;
import org.openmrs.OrderType;

import static org.junit.Assert.*;
Copy link
Member

Choose a reason for hiding this comment

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

We generally dont recommend wildcards. Have a look at the conventions at https://openmrs.atlassian.net/wiki/x/tL_EAQ


public class DrugOrderSubclassHandler1_10Test2 {

private DrugOrderSubclassHandler1_10 handler;

@Before
public void setup() {
handler = new DrugOrderSubclassHandler1_10();
}

@Test
public void shouldIncludeDrugStrengthInDisplay() {
// Create test drug
Drug drug = new Drug();
drug.setName("Aspirin");
drug.setStrength("325 mg");

// Create test order type
OrderType drugOrderType = new OrderType();
drugOrderType.setName("Drug order");

// Create test order
DrugOrder order = new DrugOrder();
order.setDrug(drug);
order.setOrderType(drugOrderType);
order.setAction(Order.Action.NEW);

// Test the display string
String display = DrugOrderSubclassHandler1_10.getDisplay(order);

// Verify results
assertNotNull("Display should not be null", display);
assertTrue("Display should contain drug name: " + display, display.contains("Aspirin"));
assertTrue("Display should contain strength: " + display, display.contains("325 mg"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.junit.Test;
import org.openmrs.CareSetting;
import org.openmrs.ConceptClass;
import org.openmrs.Drug;
import org.openmrs.DrugOrder;
import org.openmrs.Order;
import org.openmrs.OrderType;
import org.openmrs.Patient;
Expand All @@ -32,6 +34,8 @@
import org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest;
import org.springframework.mock.web.MockHttpServletRequest;



public class OrderController1_12Test extends MainResourceControllerTest {

protected static final String ORDER_ENTRY_DATASET_XML = "org/openmrs/api/include/OrderEntryIntegrationTest-other.xml";
Expand Down Expand Up @@ -138,4 +142,6 @@ public void shouldPlaceANewDrugOrder() throws Exception {
assertEquals(order.get("dispenseAsWritten"), Util.getByPath(newOrder, "dispenseAsWritten"));
assertEquals(order.get("drugNonCoded"), Util.getByPath(newOrder, "drugNonCoded"));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* 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.controller.openmrs1_12;

import org.junit.Before;
import org.junit.Test;
import org.openmrs.Drug;
import org.openmrs.DrugOrder;
import org.openmrs.Order;
import org.openmrs.OrderType;
import org.openmrs.api.OrderService;
import org.openmrs.api.context.Context;
import org.openmrs.module.webservices.rest.web.RestConstants;
import org.openmrs.module.webservices.rest.web.response.ResponseException;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;

import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class OrderController1_12Test2 {

private OrderService orderService;
private static final String ORDER_URI = "/rest/v1/order";

@Before
public void init() throws Exception {
orderService = Context.getOrderService();

// Setup minimal test data
OrderType drugOrderType = new OrderType();
drugOrderType.setName("Drug order");
orderService.saveOrderType(drugOrderType);
}

@Test
public void getOrder_shouldIncludeDrugStrength() throws Exception {
// Given
Drug drug = new Drug();
drug.setName("Aspirin");
drug.setStrength("325 mg");
DrugOrder order = createAndSaveDrugOrder(drug);

// When
MockHttpServletRequest request = newGetRequest(ORDER_URI + "/" + order.getUuid(),
new Parameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL));

MockHttpServletResponse response = new MockHttpServletResponse();
handle(request, response);

// Then
Map<String, Object> result = readResponse(response);
Map<String, Object> drugRep = (Map<String, Object>) result.get("drug");
assertNotNull("Drug representation should not be null", drugRep);
assertEquals("325 mg", drugRep.get("strength"));
}

private DrugOrder createAndSaveDrugOrder(Drug drug) throws ResponseException {
OrderType drugOrderType = orderService.getOrderTypeByName("Drug order");

DrugOrder order = new DrugOrder();
order.setDrug(drug);
order.setOrderType(drugOrderType);
order.setAction(Order.Action.NEW);

// Cast to DrugOrder is safe here since we're creating a DrugOrder
return (DrugOrder) orderService.saveOrder(order, null);
}

// Helper methods to replace BaseCrudControllerTest functionality
private MockHttpServletRequest newGetRequest(String uri, Parameter... parameters) {
MockHttpServletRequest request = new MockHttpServletRequest("GET", uri);
for (Parameter parameter : parameters) {
request.addParameter(parameter.getName(), parameter.getValue());
}
return request;
}

private void handle(MockHttpServletRequest request, MockHttpServletResponse response) throws Exception {
// Implementation would depend on your controller setup
// This is a placeholder for actual request handling
}

private Map<String, Object> readResponse(MockHttpServletResponse response) throws Exception {
// Implementation would parse the JSON response
// This is a placeholder for actual response parsing
return null;
}

public static class Parameter {
private final String name;
private final String value;

public Parameter(String name, String value) {
this.name = name;
this.value = value;
}

public String getName() {
return name;
}

public String getValue() {
return value;
}
}
}