public Patient getPatientForUpdate(String uuid, Map<String, Object> propertiesToUpdate) { Patient patient = getByUniqueId(uuid); PersonResource1_8 personResource = (PersonResource1_8) Context.getService(RestService.class) .getResourceBySupportedClass(Person.class); personResource.setConvertedProperties(patient, (Map<String, Object>) propertiesToUpdate.get("person"), personResource.getUpdatableProperties(), false); return patient; }
@Override public Model getCREATEModel(Representation rep) { return addNewProperties(super.getCREATEModel(rep), rep); }
@Override public Model getGETModel(Representation rep) { return addNewProperties(super.getGETModel(rep), rep); }
/** * Sets names and marks the first one as preferred if none is marked. It also makes sure that * only one name is marked as preferred and changes the rest to non-preferred. * <p/> * It takes the list so that the order is preserved. * * @param instance * @param names */ @PropertySetter("names") public static void setNames(Person instance, List<PersonName> names) { for (PersonName existingName : instance.getNames()) { existingName.setPreferred(false); } setFirstNameAsPreferred(names); for (PersonName name : names) { PersonName existingName = getMatchingName(name, instance.getNames()); if (existingName != null) { copyNameFields(existingName, name); } else { instance.addName(name); } } }
/** * Sets addresses and marks the first one as preferred if none is marked. It also makes sure * that only one address is marked as preferred and changes the rest to non-preferred. * <p/> * It takes the list so that the order is preserved. * * @param instance * @param addresses */ @PropertySetter("addresses") public static void setAddresses(Person instance, List<PersonAddress> addresses) { for (PersonAddress existingAddress : instance.getAddresses()) { existingAddress.setPreferred(false); } setFirstAddressAsPreferred(addresses); for (PersonAddress address : addresses) { PersonAddress existingAddress = getMatchingAddress(address, instance.getAddresses()); if (existingAddress != null) { copyAddressFields(existingAddress, address); } else { instance.addAddress(address); } } }
/** * @throws org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties() */ @Override public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException { DelegatingResourceDescription description = super.getUpdatableProperties(); description.addProperty("deathdateEstimated"); description.addProperty("birthtime"); return description; }
@Test public void getAttributes_shouldReturnAllAttributes() throws Exception { PersonResource1_8 resource = getResource(); List<PersonAttribute> attributes1 = PersonResource1_8.getAttributes(resource .getByUniqueId("df8ae447-6745-45be-b859-403241d9913c")); Assert.assertEquals(2, attributes1.size()); List<PersonAttribute> attributes2 = PersonResource1_8.getAttributes(resource .getByUniqueId("341b4e41-790c-484f-b6ed-71dc8da222de")); Assert.assertEquals(3, attributes2.size()); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getCreatableProperties() */ @Override public DelegatingResourceDescription getCreatableProperties() { DelegatingResourceDescription description = super.getCreatableProperties(); description.addProperty("deathdateEstimated"); description.addProperty("birthtime"); return description; }