/** * Creates and returns a new empty patient record, setting the currently logged in user as the creator. * * @return the created patient record, or {@code null} if the user does not have the right to create a new patient * record or the creation fails */ public Patient create() { try { return this.internalService.create(); } catch (SecurityException ex) { return null; } }
/** * Create and return a new empty patient record. * * @return the created patient record, or {@code null} if the user does not have the right to create a new patient * record or the creation fails */ public Patient create() { try { return this.internalService.create(); } catch (SecurityException ex) { return null; } } }
/** * Import a new patient from its JSON representation. * * @param json the JSON representation of the new patient * @return the location of the newly created patient, if successful * @throws WebApplicationException if a {@link JSONObject} cannot be created * @throws NullPointerException if the patient was not created */ private Response addPatient(final String json) { JSONObject jsonObject; try { jsonObject = new JSONObject(json); } catch (Exception ex) { throw new WebApplicationException(Status.BAD_REQUEST); } final Patient patient = this.repository.create(); patient.updateFromJSON(jsonObject); return buildCreatedResponse(patient); }
private Patient create(User creator) { if (this.access.hasAccess(creator, Right.EDIT, this.currentResolver.resolve(Patient.DEFAULT_DATA_SPACE, EntityType.SPACE))) { return this.internalService.create(creator != null ? creator.getProfileDocument() : null); } throw new SecurityException("User not authorized to create new patients"); }
continue; Patient patient = this.repository.create(); patient.updateFromJSON(jsonObject); createdPatientUri.put(UriBuilder.fromUri(this.uriInfo.getBaseUri())
return Response.status(Status.FORBIDDEN).build(); final Patient patient = this.repository.create(); return updatePatientWithJsonData(patient, eid, patientJson); } catch (final JSONException ex) {
@Override public Response add(final String json) { this.slf4Jlogger.debug("Importing new patient from JSON via REST: {}", json); final User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.EDIT, this.currentResolver.resolve(Patient.DEFAULT_DATA_SPACE, EntityType.SPACE))) { throw new WebApplicationException(Status.UNAUTHORIZED); } try { final Response response; if (json != null) { response = json.startsWith("[") ? addPatients(json) : addPatient(json); } else { response = buildCreatedResponse(this.repository.create()); } return response; } catch (Exception ex) { this.slf4Jlogger.error("Could not process patient creation request: {}", ex.getMessage(), ex); return Response.status(Status.INTERNAL_SERVER_ERROR).build(); } }
/** * Creates a new patient iff {@code creator} has {@link Right#EDIT edit rights}. * * @param creator the {@link User} trying to create a new {@link Patient} * @return a new {@link SecurePatient} * @throws SecurityException if {@code creator} is not authorized to create new patients */ private Patient create(User creator) { if (this.access.hasAccess(creator, Right.EDIT, this.currentResolver.resolve(Patient.DEFAULT_DATA_SPACE, EntityType.SPACE))) { Patient patient = this.internalService.create(creator != null ? creator.getProfileDocument() : null); return createSecurePatient(patient); } throw new SecurityException("User not authorized to create new patients"); }
/** * Tries to create a patient with provided {@code label} and {@code id} and {@code json data}. Returns a * {@link Response} with no content if successful, an error code otherwise. * * @param label the name of the label * @param id the id value for the label; will be overwritten if a label/id pair is specified in {@code jsonInput} * @param jsonInput the incoming json from the request, used to update the created patient record * @return a {@link Response} with no content if successful, an error code otherwise */ private Response returnCreatePatientResponse(final String label, final String id, final JSONObject jsonInput) { this.logger.debug("Creating patient record with label [{}] and corresponding external ID [{}]", label, id); final User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.EDIT, this.currentResolver.resolve(Patient.DEFAULT_DATA_SPACE, EntityType.SPACE))) { this.logger.error("Edit access denied to user [{}].", currentUser); throw new WebApplicationException(Response.Status.FORBIDDEN); } if (!isLabelAllowed(label)) { this.logger.warn("Unknown label [{}], refusing to create new patient", label); throw new WebApplicationException(Response.Status.BAD_REQUEST); } final Patient patient = this.repository.create(); returnUpdatePatientResponse(patient, label, id, jsonInput, true, PatientWritePolicy.UPDATE); return buildCreatedResponse(patient); }
} else { affectedPatient = this.patientRepository.create(user.getProfileDocument());
} else { affectedPatient = this.patientRepository.create(user.getProfileDocument()); if (affectedPatient == null) { this.logger.error("Can not create new patient");