@Test public void testCreateNewDrugPurchaseOrder() throws Exception { int before = service.getAllDrugPurchaseOrders().size(); String json = "{ \"name\":\"Test purchase order\",\"description\":\"Test purchase order\", \"provider\": \"68547121-1b70-465e-99ee-c9df45jf9j32\", \"received\": \"true\", \"inventories\": [{\"name\":\"Test inner Drug Inventory\",\"description\":\"Test drug inventory\", \"drug\": \"05ec820a-d297-44e3-be6e-698531d9dd3f\", \"quantity\": 500, \"location\": \"9356400c-a5a2-4532-8f2b-2361b3446eb8\", \"expiryDate\":\"Wed Sep 19 2012 00:00:00 GMT+0530 (India Standard Time)\"}, {\"name\":\"Test inner Drug Inventory 2\",\"description\":\"Test drug inventory2\", \"drug\": \"05ec820a-d297-44e3-be6e-698531d9dd3f\", \"quantity\": 500, \"supplier\": \"test supplier\", \"location\": \"9356400c-a5a2-4532-8f2b-2361b3446eb8\", \"expiryDate\":\"Sep 26, 2012 12:00:00 AM\"}]}"; SimpleObject post = new ObjectMapper().readValue(json, SimpleObject.class); controller.createNewDrugPurchaseOrder(post, request, response); int after = service.getAllDrugPurchaseOrders().size(); Provider p = Context.getProviderService().getProviderByUuid("68547121-1b70-465e-99ee-c9df45jf9j32"); List<DrugPurchaseOrder> dPOs = Context.getService(DrugPurchaseOrderService.class).getDrugPurchaseOrderByProvider( p.getId()); List<DrugInventory> dis = Context.getService(DrugInventoryService.class).getDrugInventoriesByLocation(2); Assert.assertNotNull(dis); Assert.assertEquals(2, dis.size()); Assert.assertEquals("Test inner Drug Inventory", dis.get(0).getName()); Assert.assertNotNull(dis.get(0).getExpiryDate()); Assert.assertEquals(dis.get(1).getSupplier(), "test supplier"); Assert.assertEquals(true, dPOs.get(0).isReceived()); Assert.assertEquals(before + 1, after); }
@RequestMapping(method = RequestMethod.POST) @WSDoc("Save New DrugPurchaseOrder") @ResponseBody public Object createNewDrugPurchaseOrder(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { initDrugPurchaseOrderController(); DrugPurchaseOrder purchaseOrder = setPostFields(post, new DrugPurchaseOrder()); DrugPurchaseOrder created; SimpleObject obj = obj = new SimpleObject(); if (!purchaseOrder.getName().equals(DrugPurchaseOrder.PRESCRIPTIONNAME)) { created = service.saveDrugPurchaseOrder(purchaseOrder); saveOrUpdateDrugInventories(post, purchaseOrder); obj.add("uuid", created.getUuid()); obj.add("name", created.getName()); return RestUtil.created(response, obj); } else { saveOrUpdateDrugInventories(post, purchaseOrder); return RestUtil.noContent(response); } }
DrugPurchaseOrderController extends BaseRestController { @RequestMapping(method = RequestMethod.POST) @WSDoc("Save New DrugPurchaseOrder") @ResponseBody public Object createNewDrugPurchaseOrder(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { initDrugPurchaseOrderController(); DrugPurchaseOrder purchaseOrder = setPostFields(post, new DrugPurchaseOrder()); DrugPurchaseOrder created; SimpleObject obj = obj = new SimpleObject(); if (!purchaseOrder.getName().equals(DrugPurchaseOrder.PRESCRIPTIONNAME)) { created = service.saveDrugPurchaseOrder(purchaseOrder); saveOrUpdateDrugInventories(post, purchaseOrder); obj.add("uuid", created.getUuid()); obj.add("name", created.getName()); return RestUtil.created(response, obj); } else { saveOrUpdateDrugInventories(post, purchaseOrder); return RestUtil.noContent(response); } } }
DrugPurchaseOrderController extends BaseRestController { @RequestMapping(method = RequestMethod.POST) @WSDoc("Save New DrugPurchaseOrder") @ResponseBody public Object createNewDrugPurchaseOrder(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { initDrugPurchaseOrderController(); DrugPurchaseOrder purchaseOrder = setPostFields(post, new DrugPurchaseOrder()); DrugPurchaseOrder created; SimpleObject obj = obj = new SimpleObject(); if (!purchaseOrder.getName().equals(DrugPurchaseOrder.PRESCRIPTIONNAME)) { created = service.saveDrugPurchaseOrder(purchaseOrder); saveOrUpdateDrugInventories(post, purchaseOrder); obj.add("uuid", created.getUuid()); obj.add("name", created.getName()); return RestUtil.created(response, obj); } else { saveOrUpdateDrugInventories(post, purchaseOrder); return RestUtil.noContent(response); } }  }
DrugPurchaseOrderController extends BaseRestController { @RequestMapping(method = RequestMethod.POST) @WSDoc("Save New DrugPurchaseOrder") @ResponseBody public Object createNewDrugPurchaseOrder(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { initDrugPurchaseOrderController(); DrugPurchaseOrder purchaseOrder = setPostFields(post, new DrugPurchaseOrder()); DrugPurchaseOrder created; SimpleObject obj = obj = new SimpleObject(); if (!purchaseOrder.getName().equals(DrugPurchaseOrder.PRESCRIPTIONNAME)) { created = service.saveDrugPurchaseOrder(purchaseOrder); saveOrUpdateDrugInventories(post, purchaseOrder); obj.add("uuid", created.getUuid()); obj.add("name", created.getName()); return RestUtil.created(response, obj); } else { saveOrUpdateDrugInventories(post, purchaseOrder); return RestUtil.noContent(response); } }  void initDrugPurchaseOrderController(); @RequestMapping(method = RequestMethod.POST) @WSDoc("Save New DrugPurchaseOrder") @ResponseBody Object createNewDrugPurchaseOrder(@RequestBody SimpleObject post, HttpServletRequest request,
	        HttpServletResponse response); @RequestMapping(value = "/{uuid}", method = RequestMethod.POST) @WSDoc("Updates an existing purchase order") @ResponseBody Object updateDrugPurchaseOrder(@PathVariable("uuid") String uuid, @RequestBody SimpleObject post,
	        HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = "/{uuid}", method = RequestMethod.GET) @WSDoc("Gets DrugPurchaseOrder for the uuid path") @ResponseBody() String getDrugPuchaseOrderByUuid(@PathVariable("uuid") String uuid, HttpServletRequest request); DrugPurchaseOrder setPostFields(SimpleObject post, DrugPurchaseOrder purchaseOrder); @RequestMapping(method = RequestMethod.GET) @WSDoc("Get All Unretired Drug Purchase Orders in the system") @ResponseBody() String getAllDrugPurchaseOrders(HttpServletRequest request, HttpServletResponse response); @RequestMapping(method = RequestMethod.GET, params = "stockLocation") @WSDoc("Fetch all non-retired drug purchase orders according to stockLocation") @ResponseBody() String searchByStockLocation(@RequestParam("stockLocation") String stockLocation, HttpServletRequest request); }
DrugPurchaseOrderController extends BaseRestController { @RequestMapping(method = RequestMethod.POST) @WSDoc("Save New DrugPurchaseOrder") @ResponseBody public Object createNewDrugPurchaseOrder(@RequestBody SimpleObject post, HttpServletRequest request, HttpServletResponse response) throws ResponseException { initDrugPurchaseOrderController(); DrugPurchaseOrder purchaseOrder = setPostFields(post, new DrugPurchaseOrder()); DrugPurchaseOrder created; SimpleObject obj = obj = new SimpleObject(); if (!purchaseOrder.getName().equals(DrugPurchaseOrder.PRESCRIPTIONNAME)) { created = service.saveDrugPurchaseOrder(purchaseOrder); saveOrUpdateDrugInventories(post, purchaseOrder); obj.add("uuid", created.getUuid()); obj.add("name", created.getName()); return RestUtil.created(response, obj); } else { saveOrUpdateDrugInventories(post, purchaseOrder); return RestUtil.noContent(response); } }  void initDrugPurchaseOrderController(); @RequestMapping(method = RequestMethod.POST) @WSDoc("Save New DrugPurchaseOrder") @ResponseBody Object createNewDrugPurchaseOrder(@RequestBody SimpleObject post, HttpServletRequest request,
	        HttpServletResponse response); @RequestMapping(value = "/{uuid}", method = RequestMethod.POST) @WSDoc("Updates an existing purchase order") @ResponseBody Object updateDrugPurchaseOrder(@PathVariable("uuid") String uuid, @RequestBody SimpleObject post,
	        HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = "/{uuid}", method = RequestMethod.GET) @WSDoc("Gets DrugPurchaseOrder for the uuid path") @ResponseBody() String getDrugPuchaseOrderByUuid(@PathVariable("uuid") String uuid, HttpServletRequest request); DrugPurchaseOrder setPostFields(SimpleObject post, DrugPurchaseOrder purchaseOrder); @RequestMapping(method = RequestMethod.GET) @WSDoc("Get All Unretired Drug Purchase Orders in the system") @ResponseBody() String getAllDrugPurchaseOrders(HttpServletRequest request, HttpServletResponse response); @RequestMapping(method = RequestMethod.GET, params = "stockLocation") @WSDoc("Fetch all non-retired drug purchase orders according to stockLocation") @ResponseBody() String searchByStockLocation(@RequestParam("stockLocation") String stockLocation, HttpServletRequest request);  }