Search in sources :

Example 26 with APIException

use of org.openmrs.api.APIException in project openmrs-core by openmrs.

the class ProcessHL7InQueueTask method execute.

/**
 * Process the next form entry in the database and then remove the form entry from the database.
 */
@Override
public void execute() {
    Context.openSession();
    try {
        log.debug("Processing HL7 queue ... ");
        processor.processHL7InQueue();
    } catch (HL7Exception e) {
        log.error("Error running hl7 in queue task", e);
        throw new APIException("Hl7inQueue.error.running", null, e);
    } finally {
        Context.closeSession();
    }
}
Also used : APIException(org.openmrs.api.APIException) HL7Exception(ca.uhn.hl7v2.HL7Exception)

Example 27 with APIException

use of org.openmrs.api.APIException in project openmrs-core by openmrs.

the class TestInstallUtil method getResourceInputStream.

/**
 * @param url
 * @param openmrsUsername
 * @param openmrsPassword
 * @return input stream
 * @throws MalformedURLException
 * @throws IOException
 */
protected static InputStream getResourceInputStream(String url, String openmrsUsername, String openmrsPassword) throws MalformedURLException, IOException, APIException {
    HttpURLConnection connection = createConnection(url);
    OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8);
    out.write(encodeCredentials(openmrsUsername, openmrsPassword));
    out.flush();
    out.close();
    log.info("Http response message: {}, Code: {}", connection.getResponseMessage(), connection.getResponseCode());
    if (connection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
        throw new APIAuthenticationException("Invalid username or password");
    } else if (connection.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) {
        throw new APIException("error.occurred.on.remote.server", (Object[]) null);
    }
    return connection.getInputStream();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) APIException(org.openmrs.api.APIException) APIAuthenticationException(org.openmrs.api.APIAuthenticationException) OutputStreamWriter(java.io.OutputStreamWriter)

Example 28 with APIException

use of org.openmrs.api.APIException in project openmrs-core by openmrs.

the class Concept method setFullySpecifiedName.

/**
 * Sets the specified name as the fully specified name for the locale and the current fully
 * specified (if any) ceases to be the fully specified name for the locale.
 *
 * @param fullySpecifiedName the new fully specified name to set
 * @should set the concept name type of the specified name to fully specified
 * @should convert the previous fully specified name if any to a synonym
 * @should add the name to the list of names if it not among them before
 */
public void setFullySpecifiedName(ConceptName fullySpecifiedName) {
    if (fullySpecifiedName == null || fullySpecifiedName.getLocale() == null) {
        throw new APIException("Concept.name.locale.null", (Object[]) null);
    } else if (fullySpecifiedName.getVoided()) {
        throw new APIException("Concept.error.fullySpecifiedName.null", (Object[]) null);
    }
    ConceptName oldFullySpecifiedName = getFullySpecifiedName(fullySpecifiedName.getLocale());
    if (oldFullySpecifiedName != null) {
        oldFullySpecifiedName.setConceptNameType(null);
    }
    fullySpecifiedName.setConceptNameType(ConceptNameType.FULLY_SPECIFIED);
    // add this name, if it is new or not among this concept's names
    if (fullySpecifiedName.getConceptNameId() == null || !getNames().contains(fullySpecifiedName)) {
        addName(fullySpecifiedName);
    }
}
Also used : APIException(org.openmrs.api.APIException)

Example 29 with APIException

use of org.openmrs.api.APIException in project openmrs-core by openmrs.

the class Concept method setPreferredName.

/**
 * Sets the preferred name /in this locale/ to the specified conceptName and its Locale, if
 * there is an existing preferred name for this concept in the same locale, this one will
 * replace the old preferred name. Also, the name is added to the concept if it is not already
 * among the concept names.
 *
 * @param preferredName The name to be marked as preferred in its locale
 * @should only allow one preferred name
 * @should add the name to the list of names if it not among them before
 * @should fail if the preferred name to set to is an index term
 */
public void setPreferredName(ConceptName preferredName) {
    if (preferredName == null || preferredName.getVoided() || preferredName.isIndexTerm()) {
        throw new APIException("Concept.error.preferredName.null", (Object[]) null);
    } else if (preferredName.getLocale() == null) {
        throw new APIException("Concept.name.locale.null", (Object[]) null);
    }
    // first revert the current preferred name(if any) from being preferred
    ConceptName oldPreferredName = getPreferredName(preferredName.getLocale());
    if (oldPreferredName != null) {
        oldPreferredName.setLocalePreferred(false);
    }
    preferredName.setLocalePreferred(true);
    // add this name, if it is new or not among this concept's names
    if (preferredName.getConceptNameId() == null || !getNames().contains(preferredName)) {
        addName(preferredName);
    }
}
Also used : APIException(org.openmrs.api.APIException)

Example 30 with APIException

use of org.openmrs.api.APIException in project openmrs-core by openmrs.

the class HL7ServiceImpl method migrateHL7InArchive.

/**
 * moves data to the filesystem from an HL7InArchive
 *
 * @param archive
 * @throws APIException
 */
private void migrateHL7InArchive(HL7InArchive archive) throws APIException {
    if (archive == null) {
        throw new APIException("Hl7Service.migrate.null.archive", (Object[]) null);
    }
    if (!OpenmrsUtil.nullSafeEquals(archive.getMessageState(), HL7Constants.HL7_STATUS_PROCESSED)) {
        throw new APIException("Hl7Service.migrate.archive.state", (Object[]) null);
    }
    try {
        URI uri = writeHL7InArchiveToFileSystem(archive);
        archive.setHL7Data(uri.toString());
        archive.setMessageState(HL7Constants.HL7_STATUS_MIGRATED);
        saveHL7InArchive(archive);
    } catch (APIException e) {
        throw new APIException("Hl7Service.migrate.archive", null, e);
    }
}
Also used : APIException(org.openmrs.api.APIException) URI(java.net.URI)

Aggregations

APIException (org.openmrs.api.APIException)84 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 File (java.io.File)9 Obs (org.openmrs.Obs)7 List (java.util.List)6 Map (java.util.Map)6 FileInputStream (java.io.FileInputStream)5 FileOutputStream (java.io.FileOutputStream)5 Concept (org.openmrs.Concept)5 OpenmrsObject (org.openmrs.OpenmrsObject)5 User (org.openmrs.User)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