use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class UserServiceImpl method changePasswordUsingSecretAnswer.
@Override
public void changePasswordUsingSecretAnswer(String secretAnswer, String pw) throws APIException {
User user = Context.getAuthenticatedUser();
if (!isSecretAnswer(user, secretAnswer)) {
throw new APIException("secret.answer.not.correct", (Object[]) null);
}
updatePassword(user, pw);
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class UserServiceImpl method saveUserProperty.
@Override
public User saveUserProperty(String key, String value) {
User user = Context.getAuthenticatedUser();
if (user == null) {
throw new APIException("no.authenticated.user.found", (Object[]) null);
}
user.setUserProperty(key, value);
return dao.saveUser(user, null);
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class EncounterServiceImpl method unvoidEncounter.
/**
* @see org.openmrs.api.EncounterService#unvoidEncounter(org.openmrs.Encounter)
*/
@Override
public Encounter unvoidEncounter(Encounter encounter) throws APIException {
// if authenticated user is not supposed to edit encounter of certain type
if (!canEditEncounter(encounter, null)) {
throw new APIException("Encounter.error.privilege.required.unvoid", new Object[] { encounter.getEncounterType().getEditPrivilege() });
}
String voidReason = encounter.getVoidReason();
if (voidReason == null) {
voidReason = "";
}
ObsService os = Context.getObsService();
for (Obs o : encounter.getObsAtTopLevel(true)) {
if (voidReason.equals(o.getVoidReason())) {
os.unvoidObs(o);
}
}
OrderService orderService = Context.getOrderService();
for (Order o : encounter.getOrders()) {
if (voidReason.equals(o.getVoidReason())) {
orderService.unvoidOrder(o);
}
}
encounter.setVoided(false);
encounter.setVoidedBy(null);
encounter.setDateVoided(null);
encounter.setVoidReason(null);
Context.getEncounterService().saveEncounter(encounter);
return encounter;
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class EncounterServiceImpl method getActiveEncounterVisitHandler.
/**
* @see org.openmrs.api.EncounterService#getActiveEncounterVisitHandler()
*/
@Override
@Transactional(readOnly = true)
public EncounterVisitHandler getActiveEncounterVisitHandler() throws APIException {
String handlerGlobalValue = Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER, null);
if (StringUtils.isBlank(handlerGlobalValue)) {
return null;
}
EncounterVisitHandler handler;
// convention = [NamePrefix:beanName] or [className]
String namePrefix = OpenmrsConstants.REGISTERED_COMPONENT_NAME_PREFIX;
if (handlerGlobalValue.startsWith(namePrefix)) {
String beanName = handlerGlobalValue.substring(namePrefix.length());
handler = Context.getRegisteredComponent(beanName, EncounterVisitHandler.class);
} else {
Object instance;
try {
instance = OpenmrsClassLoader.getInstance().loadClass(handlerGlobalValue).newInstance();
} catch (Exception ex) {
throw new APIException("failed.instantiate.assignment.handler", new Object[] { handlerGlobalValue }, ex);
}
if (instance instanceof EncounterVisitHandler) {
handler = (EncounterVisitHandler) instance;
} else {
throw new APIException("assignment.handler.should.implement.EncounterVisitHandler", (Object[]) null);
}
}
return handler;
}
use of org.openmrs.api.APIException in project openmrs-core by openmrs.
the class EncounterServiceImpl method purgeEncounter.
/**
* @see org.openmrs.api.EncounterService#purgeEncounter(Encounter, boolean)
*/
@Override
public void purgeEncounter(Encounter encounter, boolean cascade) throws APIException {
// if authenticated user is not supposed to edit encounter of certain type
if (!canEditEncounter(encounter, null)) {
throw new APIException("Encounter.error.privilege.required.purge", new Object[] { encounter.getEncounterType().getEditPrivilege() });
}
if (cascade) {
ObsService obsService = Context.getObsService();
List<Encounter> justThisEncounter = new ArrayList<>();
justThisEncounter.add(encounter);
List<Obs> observations = new ArrayList<>(obsService.getObservations(null, justThisEncounter, null, null, null, null, null, null, null, null, null, true));
for (Obs o : observations) {
obsService.purgeObs(o);
}
Set<Order> orders = encounter.getOrders();
for (Order o : orders) {
Context.getOrderService().purgeOrder(o);
}
}
Context.getEncounterService().purgeEncounter(encounter);
}
Aggregations