use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class PatientServiceImpl method processDeath.
/**
* This is the way to establish that a patient has died. In addition to exiting the patient from
* care (see above), this method will also set the appropriate patient characteristics to
* indicate that they have died, when they died, etc.
*
* @param patient - the patient who has died
* @param dateDied - the declared date/time of the patient's death
* @param causeOfDeath - the concept that corresponds with the reason the patient died
* @param otherReason - in case the causeOfDeath is 'other', a place to store more info
* @throws APIException
*/
@Override
public void processDeath(Patient patient, Date dateDied, Concept causeOfDeath, String otherReason) throws APIException {
if (patient != null && dateDied != null && causeOfDeath != null) {
// set appropriate patient characteristics
patient.setDead(true);
patient.setDeathDate(dateDied);
patient.setCauseOfDeath(causeOfDeath);
this.savePatient(patient);
saveCauseOfDeathObs(patient, dateDied, causeOfDeath, otherReason);
// exit from program
// first, need to get Concept for "Patient Died"
String strPatientDied = Context.getAdministrationService().getGlobalProperty("concept.patientDied");
Concept conceptPatientDied = Context.getConceptService().getConcept(strPatientDied);
if (conceptPatientDied == null) {
log.debug("ConceptPatientDied is null");
}
exitFromCare(patient, dateDied, conceptPatientDied);
} else {
if (patient == null) {
throw new APIException("Patient.invalid.dead", (Object[]) null);
}
if (dateDied == null) {
throw new APIException("Patient.no.valid.dateDied", (Object[]) null);
}
if (causeOfDeath == null) {
throw new APIException("Patient.no.valid.causeOfDeath", (Object[]) null);
}
}
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class AdministrationServiceImpl method saveGlobalProperty.
/**
* @see org.openmrs.api.AdministrationService#saveGlobalProperty(org.openmrs.GlobalProperty)
*/
@Override
@CacheEvict(value = "userSearchLocales", allEntries = true)
public GlobalProperty saveGlobalProperty(GlobalProperty gp) throws APIException {
// only try to save it if the global property has a key
if (gp.getProperty() != null && gp.getProperty().length() > 0) {
if (gp.getProperty().equals(OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST)) {
if (gp.getPropertyValue() != null) {
List<Locale> localeList = new ArrayList<>();
for (String localeString : gp.getPropertyValue().split(",")) {
localeList.add(LocaleUtility.fromSpecification(localeString.trim()));
}
if (!localeList.contains(LocaleUtility.getDefaultLocale())) {
gp.setPropertyValue(StringUtils.join(getAllowedLocales(), ", "));
throw new APIException(Context.getMessageSourceService().getMessage("general.locale.localeListNotIncludingDefaultLocale", new Object[] { LocaleUtility.getDefaultLocale() }, null));
}
}
} else if (gp.getProperty().equals(OpenmrsConstants.GLOBAL_PROPERTY_DEFAULT_LOCALE) && gp.getPropertyValue() != null) {
List<Locale> localeList = getAllowedLocales();
if (!localeList.contains(LocaleUtility.fromSpecification(gp.getPropertyValue().trim()))) {
String value = gp.getPropertyValue();
gp.setPropertyValue(LocaleUtility.getDefaultLocale().toString());
throw new APIException((Context.getMessageSourceService().getMessage("general.locale.defaultNotInAllowedLocalesList", new Object[] { value }, null)));
}
}
CustomDatatypeUtil.saveIfDirty(gp);
dao.saveGlobalProperty(gp);
notifyGlobalPropertyChange(gp);
return gp;
}
return gp;
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class ObsServiceImpl method handleExistingObsWithComplexConcept.
private void handleExistingObsWithComplexConcept(Obs obs) {
ComplexData complexData = obs.getComplexData();
Concept concept = obs.getConcept();
if (null != concept && concept.isComplex() && null != complexData && null != complexData.getData()) {
// save or update complexData object on this obs
// this is done before the database save so that the obs.valueComplex
// can be filled in by the handler.
ComplexObsHandler handler = getHandler(obs);
if (null != handler) {
handler.saveObs(obs);
} else {
throw new APIException("unknown.handler", new Object[] { concept });
}
}
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class EncounterServiceImpl method voidEncounter.
/**
* @see org.openmrs.api.EncounterService#voidEncounter(org.openmrs.Encounter, java.lang.String)
*/
@Override
public Encounter voidEncounter(Encounter encounter, String reason) {
// if authenticated user is not supposed to edit encounter of certain type
if (!canEditEncounter(encounter, null)) {
throw new APIException("Encounter.error.privilege.required.void", new Object[] { encounter.getEncounterType().getEditPrivilege() });
}
if (reason == null) {
throw new IllegalArgumentException("The argument 'reason' is required and so cannot be null");
}
ObsService os = Context.getObsService();
for (Obs o : encounter.getObsAtTopLevel(false)) {
if (!o.getVoided()) {
os.voidObs(o, reason);
}
}
OrderService orderService = Context.getOrderService();
for (Order o : encounter.getOrders()) {
if (!o.getVoided()) {
orderService.voidOrder(o, reason);
}
}
encounter.setVoided(true);
encounter.setVoidedBy(Context.getAuthenticatedUser());
// unvoid handler to work
if (encounter.getDateVoided() == null) {
encounter.setDateVoided(new Date());
}
encounter.setVoidReason(reason);
Context.getEncounterService().saveEncounter(encounter);
return encounter;
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class PersonSaveHandler method handle.
/**
* @see org.openmrs.api.handler.SaveHandler#handle(org.openmrs.OpenmrsObject, org.openmrs.User,
* java.util.Date, java.lang.String)
*/
@Override
public void handle(Person person, User creator, Date dateCreated, String other) {
// address collection
if (person.getAddresses() != null && !person.getAddresses().isEmpty()) {
for (PersonAddress pAddress : person.getAddresses()) {
if (pAddress.isBlank()) {
person.removeAddress(pAddress);
continue;
}
pAddress.setPerson(person);
}
}
// name collection
if (person.getNames() != null && !person.getNames().isEmpty()) {
for (PersonName pName : person.getNames()) {
pName.setPerson(person);
}
}
// attribute collection
if (person.getAttributes() != null && !person.getAttributes().isEmpty()) {
for (PersonAttribute pAttr : person.getAttributes()) {
pAttr.setPerson(person);
}
}
// if the patient was marked as dead and reversed, drop the cause of death
if (!person.getDead() && person.getCauseOfDeath() != null) {
person.setCauseOfDeath(null);
}
// do the checks for voided attributes (also in PersonVoidHandler)
if (person.getPersonVoided()) {
if (!StringUtils.hasLength(person.getPersonVoidReason())) {
throw new APIException("Person.voided.bit", new Object[] { person });
}
if (person.getPersonVoidedBy() == null) {
person.setPersonVoidedBy(creator);
}
if (person.getPersonDateVoided() == null) {
person.setPersonDateVoided(dateCreated);
}
} else {
// voided is set to false
person.setPersonVoidedBy(null);
person.setPersonDateVoided(null);
person.setPersonVoidReason(null);
}
}
Aggregations