Search in sources :

Example 61 with APIException

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);
}
Also used : User(org.openmrs.User) APIException(org.openmrs.api.APIException)

Example 62 with APIException

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);
}
Also used : User(org.openmrs.User) APIException(org.openmrs.api.APIException)

Example 63 with APIException

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;
}
Also used : Order(org.openmrs.Order) Obs(org.openmrs.Obs) APIException(org.openmrs.api.APIException) ObsService(org.openmrs.api.ObsService) OrderService(org.openmrs.api.OrderService)

Example 64 with APIException

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;
}
Also used : APIException(org.openmrs.api.APIException) EncounterVisitHandler(org.openmrs.api.handler.EncounterVisitHandler) APIException(org.openmrs.api.APIException) EncounterTypeLockedException(org.openmrs.api.EncounterTypeLockedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 65 with APIException

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);
}
Also used : Order(org.openmrs.Order) Obs(org.openmrs.Obs) APIException(org.openmrs.api.APIException) ArrayList(java.util.ArrayList) Encounter(org.openmrs.Encounter) ObsService(org.openmrs.api.ObsService)

Aggregations

APIException (org.openmrs.api.APIException)86 Date (java.util.Date)11 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 File (java.io.File)9 Obs (org.openmrs.Obs)7 List (java.util.List)6 Map (java.util.Map)6 User (org.openmrs.User)6 FileInputStream (java.io.FileInputStream)5 FileOutputStream (java.io.FileOutputStream)5 Concept (org.openmrs.Concept)5 OpenmrsObject (org.openmrs.OpenmrsObject)5 InputStream (java.io.InputStream)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 Order (org.openmrs.Order)4 FileNotFoundException (java.io.FileNotFoundException)3 OutputStreamWriter (java.io.OutputStreamWriter)3 MessageDigest (java.security.MessageDigest)3 HashMap (java.util.HashMap)3