@Test(expected = IllegalArgumentException.class) public void shouldNotAllowSpecifyingDefaultTypeOnGetAll() throws Exception { context.setType("order"); resource.getAll(context); }
/** * Fetches an order by uuid or order number * * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#getByUniqueId(String) */ @Override public Order getByUniqueId(String uniqueId) { Order order = super.getByUniqueId(uniqueId); if (order == null) { order = Context.getOrderService().getOrderByOrderNumber(uniqueId); } return order; }
@Test public void shouldUsePropertySetterAndGetterFromSubclassHandler() throws Exception { HivDrugOrderSubclassHandler handler = new HivDrugOrderSubclassHandler(); resource.registerSubclassHandler(handler); HivDrugOrder o = handler.newDelegate(); // this will only work if the @PropertySetter method on the subclass handler is used resource.setProperty(o, "standardRegimenCode", "Peds-1a"); // this will only work if the @PropertyGetter method on the subclass handler is used Object valueSet = resource.getProperty(o, "standardRegimenCode"); Assert.assertEquals("Peds-1a", valueSet); }
PageableResult ret = (PageableResult) findAndInvokeSubclassHandlerMethod(context.getType(), "getOrdersByPatient", patient, context); if (ret != null) filterByType(orders, context.getType());
@Test public void shouldDeleteASuperclass() throws Exception { resource.delete(SUPERCLASS_UUID, "because", context); Order deleted = Context.getOrderService().getOrderByUuid(SUPERCLASS_UUID); Assert.assertTrue(deleted.isVoided()); }
@Test public void shouldCreateASuperclass() throws Exception { SimpleObject created = (SimpleObject) resource.create(buildSuperclass(), context); Util.log("Created superclass", created); Assert.assertEquals("order", created.get("type")); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#getCreatableProperties() */ @Override public DelegatingResourceDescription getCreatableProperties() { OrderResource1_8 orderResource = (OrderResource1_8) Context.getService(RestService.class) .getResourceBySupportedClass(Order.class); DelegatingResourceDescription d = orderResource.getCreatableProperties(); d.addProperty("dose"); d.addProperty("units"); d.addProperty("frequency"); d.addProperty("prn"); d.addProperty("complex"); d.addProperty("quantity"); d.addRequiredProperty("drug"); // DrugOrders have a specific hardcoded value for this property d.removeProperty("orderType"); return d; }
@Override public Model getCREATEModel(Representation rep) { OrderResource1_8 orderResource = (OrderResource1_8) Context.getService(RestService.class) .getResourceBySupportedClass(Order.class); ModelImpl orderModel = (ModelImpl) orderResource.getCREATEModel(rep); orderModel .property("dose", new DoubleProperty()) .property("units", new StringProperty()) .property("frequency", new StringProperty()) .property("prn", new BooleanProperty()) .property("complex", new BooleanProperty()) .property("quantity", new IntegerProperty()) .property("drug", new RefProperty("#/definitions/DrugCreate")); // DrugOrders have a specific hardcoded value for this property orderModel.getProperties().remove("orderType"); return orderModel; }
@Override public Model getGETModel(Representation rep) { OrderResource1_8 orderResource = (OrderResource1_8) Context.getService(RestService.class) .getResourceBySupportedClass(Order.class); ModelImpl orderModel = (ModelImpl) orderResource.getGETModel(rep); orderModel .property("dose", new DoubleProperty()) .property("units", new StringProperty()) .property("frequency", new StringProperty()) .property("prn", new BooleanProperty()) .property("complex", new BooleanProperty()) .property("quantity", new IntegerProperty()); if (rep instanceof DefaultRepresentation) { orderModel .property("drug", new RefProperty("#/definitions/DrugGetRef")); } else if (rep instanceof FullRepresentation) { orderModel .property("drug", new RefProperty("#/definitions/DrugGet")); } return orderModel; }
@Test public void shouldDeleteASubclass() throws Exception { resource.delete(SUBCLASS_UUID, "because", context); Order deleted = Context.getOrderService().getOrderByUuid(SUBCLASS_UUID); Assert.assertTrue(deleted.isVoided()); }
@Test public void shouldCreateASubclass() throws Exception { SimpleObject created = (SimpleObject) resource.create(buildSubclass(), context); Util.log("Created subclass", created); Assert.assertEquals("drugorder", created.get("type")); }
@Test public void shouldGetAll() throws Exception { SimpleObject all = resource.getAll(context); Util.log("Get all", all); Assert.assertEquals(6, Util.getResultsSize(all)); // ensure the type property gets added when we return multiple Object typeForFirst = Util.getByPath(all, "results[0]/type"); Assert.assertTrue("drugorder".equals(typeForFirst) || "order".equals(typeForFirst)); }
/** * @see OrderResource1_8#doGetAll(RequestContext) * @verifies return all Orders (including retired) if context.includeAll is set */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void doGetAll_shouldReturnAllOrdersIncludingRetiredIfContextincludeAllIsSet() throws Exception { OrderResource1_8 or = getResource(); RequestContext ctx = new RequestContext(); List<Object> orderList = (List) or.getAll(ctx).get("results"); Assert.assertEquals("getAll should return all not voided orders from sample data", 5, orderList.size()); voidOneOrder(); orderList = (List) or.getAll(ctx).get("results"); Assert.assertEquals("getAll should return all not voided orders from sample data", 4, orderList.size()); ctx.setIncludeAll(true); orderList = (List) or.getAll(ctx).get("results"); Assert.assertEquals("getAll should return all orders from sample data", 5, orderList.size()); }
@Test public void shouldGetAllOfSubclass() throws Exception { context.setType("drugorder"); SimpleObject all = resource.getAll(context); Util.log("Get all of subclass", all); Assert.assertEquals(5, Util.getResultsSize(all)); Assert.assertEquals("drugorder", Util.getByPath(all, "results[0]/type")); }