@Override public Model getUPDATEModel(Representation rep) { return getCREATEModel(rep); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getUpdatableProperties() */ @Override public DelegatingResourceDescription getUpdatableProperties() { return getCreatableProperties(); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#getByUniqueId(java.lang.String) */ @Override public PatientIdentifier getByUniqueId(String uniqueId) { return service().getPatientIdentifierByUuid(uniqueId); }
@Test public void shouldCreatePatientIdentifier_WhenTypeIsSpecifiedByUuid() throws Exception { String personAttributeJson = "{" + " \"identifier\": \"101-6\"," + " \"identifierType\": {" + " \"uuid\" : \"1a339fe9-38bc-4ab3-b180-320988c0b968\"" + " }," + " \"location\" : {" + " \"uuid\" : \"8d6c993e-c2cc-11de-8d13-0010c6dffd0f\"" + " }," + " \"preferred\": true" + " }"; SimpleObject personAttributeSimpleObject = new SimpleObject(); personAttributeSimpleObject.putAll(new ObjectMapper().readValue(personAttributeJson, HashMap.class)); SimpleObject created = (SimpleObject) resource.create("da7f524f-27ce-4bb2-86d6-6d1d05312bd5", personAttributeSimpleObject, new RequestContext()); Assert.assertEquals("101-6", created.get("identifier")); }
@Test public void shouldCreatePatientIdentifier_WhenTypeIsSpecifiedByName() throws Exception { String personAttributeJson = "{" + " \"identifier\": \"101-6\"," + " \"identifierType\": {" + " \"name\" : \"OpenMRS Identification Number\"" + " }," + " \"location\" : {" + " \"uuid\" : \"8d6c993e-c2cc-11de-8d13-0010c6dffd0f\"" + " }," + " \"preferred\": true" + " }"; SimpleObject personAttributeSimpleObject = new SimpleObject(); personAttributeSimpleObject.putAll(new ObjectMapper().readValue(personAttributeJson, HashMap.class)); SimpleObject created = (SimpleObject) resource.create("da7f524f-27ce-4bb2-86d6-6d1d05312bd5", personAttributeSimpleObject, new RequestContext()); Assert.assertEquals("101-6", created.get("identifier")); }
@Override protected void delete(PatientIdentifier delegate, String reason, RequestContext context) throws ResponseException { service().voidPatientIdentifier(delegate, reason); }
@Override public void purge(PatientIdentifier delegate, RequestContext context) throws ResponseException { Patient patient = delegate.getPatient(); patient.removeIdentifier(delegate); service().savePatient(patient); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceHandler#save(java.lang.Object) */ @Override public PatientIdentifier save(PatientIdentifier delegate) { if (delegate.isPreferred()) { for (PatientIdentifier pI : delegate.getPatient().getActiveIdentifiers()) { if (!pI.equals(delegate)) { pI.setPreferred(false); } } } boolean needToAdd = true; for (PatientIdentifier pi : delegate.getPatient().getActiveIdentifiers()) { if (pi.equals(delegate)) { needToAdd = false; break; } } if (needToAdd) { delegate.getPatient().addIdentifier(delegate); } service().savePatientIdentifier(delegate); return delegate; }