Search in sources :

Example 31 with ConceptNumeric

use of org.openmrs.ConceptNumeric in project openmrs-core by openmrs.

the class OpenmrsUtilUnitTest method isInNormalNumericRange_shouldReturnFalseIfHiNormalIsNull.

@Test
public void isInNormalNumericRange_shouldReturnFalseIfHiNormalIsNull() {
    ConceptNumeric concept = new ConceptNumeric();
    concept.setHiNormal(null);
    assertFalse(OpenmrsUtil.isInNormalNumericRange(5.67f, concept));
}
Also used : ConceptNumeric(org.openmrs.ConceptNumeric) Test(org.junit.Test)

Example 32 with ConceptNumeric

use of org.openmrs.ConceptNumeric in project openmrs-core by openmrs.

the class OpenmrsUtilUnitTest method isValidNumericValue_shouldReturnTrueIfValueIsEqualToLowRangeLimit.

@Test
public void isValidNumericValue_shouldReturnTrueIfValueIsEqualToLowRangeLimit() {
    ConceptNumeric concept = new ConceptNumeric();
    concept.setHiCritical(14.34d);
    concept.setLowCritical(4.34d);
    assertFalse(OpenmrsUtil.isInAbsoluteNumericRange(4.34f, concept));
}
Also used : ConceptNumeric(org.openmrs.ConceptNumeric) Test(org.junit.Test)

Example 33 with ConceptNumeric

use of org.openmrs.ConceptNumeric in project openmrs-core by openmrs.

the class OpenmrsUtilUnitTest method isInAbsoluteNumericRange_shouldReturnFalseIfLowAbsoluteIsNull.

@Test
public void isInAbsoluteNumericRange_shouldReturnFalseIfLowAbsoluteIsNull() {
    ConceptNumeric concept = new ConceptNumeric();
    concept.setLowAbsolute(null);
    assertFalse(OpenmrsUtil.isInAbsoluteNumericRange(5.67f, concept));
}
Also used : ConceptNumeric(org.openmrs.ConceptNumeric) Test(org.junit.Test)

Example 34 with ConceptNumeric

use of org.openmrs.ConceptNumeric in project openmrs-core by openmrs.

the class HibernateConceptDAO method getConceptNumeric.

/**
 * @see org.openmrs.api.db.ConceptDAO#getConceptNumeric(java.lang.Integer)
 */
@Override
public ConceptNumeric getConceptNumeric(Integer i) {
    ConceptNumeric cn;
    Object obj = sessionFactory.getCurrentSession().get(ConceptNumeric.class, i);
    // and re-fetch it as a ConceptNumeric
    if (obj != null && !obj.getClass().equals(ConceptNumeric.class)) {
        // remove from cache
        sessionFactory.getCurrentSession().evict(obj);
        // session.get() did not work here, we need to perform a query to get a ConceptNumeric
        Query query = sessionFactory.getCurrentSession().createQuery("from ConceptNumeric where conceptId = :conceptId").setParameter("conceptId", i);
        obj = query.uniqueResult();
    }
    cn = (ConceptNumeric) obj;
    return cn;
}
Also used : SQLQuery(org.hibernate.SQLQuery) Query(org.hibernate.Query) LuceneQuery(org.openmrs.api.db.hibernate.search.LuceneQuery) ConceptNumeric(org.openmrs.ConceptNumeric) OpenmrsObject(org.openmrs.OpenmrsObject)

Example 35 with ConceptNumeric

use of org.openmrs.ConceptNumeric in project openmrs-core by openmrs.

the class HibernateConceptDAO method insertRowIntoSubclassIfNecessary.

/**
 * Convenience method that will check this concept for subtype values (ConceptNumeric,
 * ConceptDerived, etc) and insert a line into that subtable if needed. This prevents a
 * hibernate ConstraintViolationException
 *
 * @param concept the concept that will be inserted
 */
private void insertRowIntoSubclassIfNecessary(Concept concept) {
    // check the concept_numeric table
    if (concept instanceof ConceptNumeric) {
        String select = "SELECT 1 from concept_numeric WHERE concept_id = :conceptId";
        Query query = sessionFactory.getCurrentSession().createSQLQuery(select);
        query.setInteger("conceptId", concept.getConceptId());
        // Converting to concept numeric:  A single concept row exists, but concept numeric has not been populated yet.
        if (query.uniqueResult() == null) {
            // we have to evict the current concept out of the session because
            // the user probably had to change the class of this object to get it
            // to now be a numeric
            // (must be done before the "insert into...")
            sessionFactory.getCurrentSession().clear();
            // Just in case this was changed from concept_complex to numeric
            // We need to add a delete line for each concept sub class that is not concept_numeric
            deleteSubclassConcept("concept_complex", concept.getConceptId());
            String insert = "INSERT INTO concept_numeric (concept_id, precise) VALUES (:conceptId, false)";
            query = sessionFactory.getCurrentSession().createSQLQuery(insert);
            query.setInteger("conceptId", concept.getConceptId());
            query.executeUpdate();
        } else {
            // hence row should be deleted from the concept_numeric
            if (!concept.isNumeric()) {
                deleteSubclassConcept("concept_numeric", concept.getConceptId());
            }
        }
    } else // check the concept complex table
    if (concept instanceof ConceptComplex) {
        String select = "SELECT 1 FROM concept_complex WHERE concept_id = :conceptId";
        Query query = sessionFactory.getCurrentSession().createSQLQuery(select);
        query.setInteger("conceptId", concept.getConceptId());
        // Converting to concept complex:  A single concept row exists, but concept complex has not been populated yet.
        if (query.uniqueResult() == null) {
            // we have to evict the current concept out of the session because
            // the user probably had to change the class of this object to get it
            // to now be a ConceptComplex
            // (must be done before the "insert into...")
            sessionFactory.getCurrentSession().clear();
            // Just in case this was changed from concept_numeric to complex
            // We need to add a delete line for each concept sub class that is not concept_complex
            deleteSubclassConcept("concept_numeric", concept.getConceptId());
            // Add an empty row into the concept_complex table
            String insert = "INSERT INTO concept_complex (concept_id) VALUES (:conceptId)";
            query = sessionFactory.getCurrentSession().createSQLQuery(insert);
            query.setInteger("conceptId", concept.getConceptId());
            query.executeUpdate();
        } else {
            // hence row should be deleted from the concept_complex
            if (!concept.isComplex()) {
                deleteSubclassConcept("concept_complex", concept.getConceptId());
            }
        }
    }
}
Also used : SQLQuery(org.hibernate.SQLQuery) Query(org.hibernate.Query) LuceneQuery(org.openmrs.api.db.hibernate.search.LuceneQuery) ConceptNumeric(org.openmrs.ConceptNumeric) ConceptComplex(org.openmrs.ConceptComplex)

Aggregations

ConceptNumeric (org.openmrs.ConceptNumeric)39 Test (org.junit.Test)36 Concept (org.openmrs.Concept)7 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)7 OpenmrsMatchers.hasConcept (org.openmrs.test.OpenmrsMatchers.hasConcept)5 ConceptDatatype (org.openmrs.ConceptDatatype)4 ConceptDescription (org.openmrs.ConceptDescription)4 ConceptName (org.openmrs.ConceptName)4 ConceptClass (org.openmrs.ConceptClass)3 ConceptComplex (org.openmrs.ConceptComplex)3 Query (org.hibernate.Query)2 SQLQuery (org.hibernate.SQLQuery)2 LuceneQuery (org.openmrs.api.db.hibernate.search.LuceneQuery)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1