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; }
public Patient getPatient(SimpleObject propertiesToCreate) { Object personProperty = propertiesToCreate.get("person"); Person person = null; if (personProperty == null) { throw new ConversionException("The person property is missing"); } else if (personProperty instanceof String) { person = Context.getPersonService().getPersonByUuid((String) personProperty); Context.evictFromSession(person); } else if (personProperty instanceof Map) { person = (Person) ConversionUtil.convert(personProperty, Person.class); propertiesToCreate.put("person", ""); } Patient delegate = new Patient(person); setConvertedProperties(delegate, propertiesToCreate, getCreatableProperties(), true); return delegate; }
/** * The method is overwritten, because we need to create a patient from an existing person. In * the POST body only person and identifiers are provided and other properties must come from * the existing person. We need to promote the existing person to be a patient by overwriting it * and at the same time preserving all person properties. * * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#create(org.openmrs.module.webservices.rest.SimpleObject, * org.openmrs.module.webservices.rest.web.RequestContext) */ @Override public Object create(SimpleObject propertiesToCreate, RequestContext context) throws ResponseException { Patient delegate = getPatient(propertiesToCreate); ValidateUtil.validate(delegate); delegate = save(delegate); return ConversionUtil.convertToRepresentation(delegate, Representation.DEFAULT); }
@Override public Object update(String uuid, SimpleObject propertiesToUpdate, RequestContext context) throws ResponseException { if (propertiesToUpdate.get("person") == null) { return super.update(uuid, propertiesToUpdate, context); } Patient patient = getPatientForUpdate(uuid, propertiesToUpdate); ValidateUtil.validate(patient); patient = save(patient); return ConversionUtil.convertToRepresentation(patient, Representation.DEFAULT); }
@Override public void delete(Patient patient, String reason, RequestContext context) throws ResponseException { if (patient.isVoided()) { // DELETE is idempotent, so we return success here return; } VisitService visitService = Context.getVisitService(); List<Visit> visits = Context.getVisitService().getVisitsByPatient(patient); for (Visit visit : visits) { visitService.voidVisit(visit, "Patient deleted"); } super.delete(patient, reason, context); }
private Patient getPatient(String patientUniqueId) { Patient patient = ((PatientResource1_8) Context.getService(RestService.class).getResourceByName( RestConstants.VERSION_1 + "/patient")).getByUniqueId(patientUniqueId); if (patient == null) throw new ObjectNotFoundException(); return patient; }
Patient.class)).getByUniqueId(patientUuid);
@Override public PageableResult search(RequestContext context) throws ResponseException { String patientUuid = context.getRequest().getParameter("patient"); String encounterTypeUuid = context.getRequest().getParameter("encounterType"); String dateFrom = context.getRequest().getParameter(DATE_FROM); String dateTo = context.getRequest().getParameter(DATE_TO); Date fromDate = dateFrom != null ? (Date) ConversionUtil.convert(dateFrom, Date.class) : null; Date toDate = dateTo != null ? (Date) ConversionUtil.convert(dateTo, Date.class) : null; Patient patient = ((PatientResource1_8) Context.getService(RestService.class).getResourceBySupportedClass( Patient.class)).getByUniqueId(patientUuid); EncounterType encounterType = ((EncounterTypeResource1_8) Context.getService(RestService.class) .getResourceBySupportedClass(EncounterType.class)).getByUniqueId(encounterTypeUuid); if (patient != null) { List<Encounter> encounters = Context.getEncounterService().getEncounters(patient, null, fromDate, toDate, null, encounterType != null ? Arrays.asList(encounterType) : null, null, false); String order = context.getRequest().getParameter("order"); if ("desc".equals(order)) { Collections.reverse(encounters); } return new NeedsPaging<Encounter>(encounters, context); } return new EmptySearchResult(); }
Patient.class)).getByUniqueId(patientUuid);
/** * Gets problems for a given patient (paged according to context if necessary) only if a patient * parameter exists in the request set on the {@link RequestContext} * * @param context * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected PageableResult doSearch(RequestContext context) { String patientUuid = context.getRequest().getParameter("patient"); if (patientUuid != null) { Patient patient = ((PatientResource1_8) Context.getService(RestService.class).getResourceBySupportedClass( Patient.class)).getByUniqueId(patientUuid); if (patient == null) return new EmptySearchResult(); return new NeedsPaging<Problem>(Context.getPatientService().getProblems(patient), context); } //currently this is not supported since the superclass throws an exception return super.doSearch(context); }
/** * Gets allergies for a given patient (paged according to context if necessary) only if a * patient parameter exists in the request set on the {@link RequestContext} * * @param context * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(RequestContext) */ @Override protected PageableResult doSearch(RequestContext context) { String patientUuid = context.getRequest().getParameter("patient"); if (patientUuid != null) { Patient patient = ((PatientResource1_8) Context.getService(RestService.class).getResourceBySupportedClass( Patient.class)).getByUniqueId(patientUuid); if (patient == null) return new EmptySearchResult(); return new NeedsPaging<Allergy>(Context.getPatientService().getAllergies(patient), context); } //currently this is not supported since the superclass throws an exception return super.doSearch(context); }
Patient.class)).getByUniqueId(patientUuid); EncounterType encounterType = ((EncounterTypeResource1_8) Context.getService(RestService.class) .getResourceBySupportedClass(EncounterType.class)).getByUniqueId(encounterTypeUuid);
/** * Gets encounters for the given patient (paged according to context if necessary) only if a * patient parameter exists in the request set on the {@link RequestContext} otherwise searches * for encounters that match the specified query * * @param context * @see org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource#doSearch(org.openmrs.module.webservices.rest.web.RequestContext) */ @Override protected PageableResult doSearch(RequestContext context) { String patientUuid = context.getRequest().getParameter("patient"); if (patientUuid != null) { Patient patient = ((PatientResource1_8) Context.getService(RestService.class).getResourceBySupportedClass( Patient.class)).getByUniqueId(patientUuid); if (patient == null) return new EmptySearchResult(); List<Encounter> encs = Context.getEncounterService().getEncountersByPatient(patient); return new NeedsPaging<Encounter>(encs, context); } return new ServiceSearcher<Encounter>(EncounterService.class, "getEncounters", "getCountOfEncounters").search( context.getParameter("q"), context); }
if (patientUuid != null) { Patient patient = ((PatientResource1_8) Context.getService(RestService.class).getResourceBySupportedClass( Patient.class)).getByUniqueId(patientUuid); if (patient == null) return new EmptySearchResult();
if (patientUuid != null) { Patient patient = ((PatientResource1_8) Context.getService(RestService.class).getResourceBySupportedClass( Patient.class)).getByUniqueId(patientUuid); if (patient == null) { throw new ObjectNotFoundException();
if (patientUuid != null) { Patient patient = ((PatientResource1_8) Context.getService(RestService.class).getResourceBySupportedClass( Patient.class)).getByUniqueId(patientUuid); if (patient == null) return new EmptySearchResult();