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));
}
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));
}
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));
}
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;
}
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());
}
}
}
}
Aggregations