/** * 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_8; import org.openmrs.OrderType; import org.openmrs.api.context.Context; 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.resource.impl.MetadataDelegatingCrudResource; import org.openmrs.module.webservices.rest.web.response.ResponseException; import org.openmrs.util.OpenmrsConstants; /** * */ @Resource(name = RestConstants.VERSION_1 + "/ordertype", supportedClass = OrderType.class, supportedOpenmrsVersions = { "1.8.*", "1.9.*" }) public class OrderTypeResource1_8 extends MetadataDelegatingCrudResource<OrderType> { /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String) */ @Override public OrderType getByUniqueId(String uniqueId) { return Context.getOrderService().getOrderTypeByUuid(uniqueId); } /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#newDelegate() */ @Override public OrderType newDelegate() { return new OrderType(); } /** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#save(java.lang.Object) */ @Override public OrderType save(OrderType delegate) { return Context.getOrderService().saveOrderType(delegate); } /** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#purge(java.lang.Object, * org.openmrs.module.webservices.rest.web.RequestContext) */ @Override public void purge(OrderType delegate, RequestContext context) throws ResponseException { if (delegate.getOrderTypeId().equals(OpenmrsConstants.ORDERTYPE_DRUG)) { throw new IllegalArgumentException("You are not allowed to delete the Drug ordertype"); } Context.getOrderService().purgeOrderType(delegate); } }