@Test public void shouldVoidASimpleAttribute() { executeDataSet(VISITS_ATTRIBUTES_XML); Visit visit = visitService.getVisit(1); VisitAttributeType attrType = visitService.getVisitAttributeType(1); List<VisitAttribute> attributes = visit.getActiveAttributes(attrType); assertTrue(attributes.size() > 0); VisitAttribute attribute = attributes.get(0); attribute.setVoided(true); visitService.saveVisit(visit); assertNotNull(attribute.getVoidedBy()); assertNotNull(attribute.getDateVoided()); }
/** * @see VisitValidator#validate(Object,Errors) */ @Test // This test will throw org.hibernate.PropertyValueException: not-null property references a null or transient value: org.openmrs.VisitAttribute.valueReference // This is a general problem, i.e. that validators on Customizable can't really be called unless you set Hibernate's flushMode to MANUAL. // Once we figure it out, this test can be un-Ignored @Ignore public void validate_shouldFailIfAnAttributeIsBad() { Visit visit = visitService.getVisit(1); visit.addAttribute(makeAttribute(new Date())); visit.addAttribute(makeAttribute("not a date")); visit.getActiveAttributes(); Errors errors = new BindException(visit, "visit"); new VisitValidator().validate(visit, errors); assertEquals(true, errors.hasFieldErrors("attributes")); }
@PropertyGetter("attributes") public Collection<VisitAttribute> getActiveAttributes(Visit visit) { return visit.getActiveAttributes(); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingSubResource#doGetAll(java.lang.Object, * org.openmrs.module.webservices.rest.web.RequestContext) */ @Override public NeedsPaging<VisitAttribute> doGetAll(Visit parent, RequestContext context) throws ResponseException { if (context.getIncludeAll()) { List<VisitAttribute> attrs = new ArrayList<VisitAttribute>(); for (VisitAttribute visitAttribute : parent.getAttributes()) { attrs.add(visitAttribute); } return new NeedsPaging<VisitAttribute>(attrs, context); } return new NeedsPaging<VisitAttribute>((List<VisitAttribute>) parent.getActiveAttributes(), context); }
/** * @see org.openmrs.module.webservices.rest.web.v1_0.controller.MainResourceControllerTest#getAllCount() */ @Override public long getAllCount() { return service.getVisitByUuid(RestTestConstants1_9.VISIT_UUID).getActiveAttributes().size(); }
assertTrue(existingVisit.getActiveAttributes(vat).isEmpty()); SimpleObject toAdd = new SimpleObject(); toAdd.add("attributeType", vat.getUuid()); assertEquals(originalActiveCount + 1, existingVisit.getActiveAttributes().size()); assertEquals(newValue, toEditAttribute.getValueReference());
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#save(java.lang.Object) */ @Override public VisitAttribute save(VisitAttribute delegate) { if (delegate.getAttributeType().getMaxOccurs() != null && delegate.getAttributeType().getMaxOccurs() == 1) { // there is a convencience method for this case, that avoids the client having to make two calls (to void and create) delegate.getVisit().setAttribute(delegate); } else { // make sure it has not already been added to the visit boolean needToAdd = true; for (VisitAttribute pa : delegate.getVisit().getActiveAttributes()) { if (pa.equals(delegate)) { needToAdd = false; break; } } if (needToAdd) { delegate.getVisit().addAttribute(delegate); } } Context.getVisitService().saveVisit(delegate.getVisit()); return delegate; }