Search in sources :

Example 51 with GlobalProperty

use of org.openmrs.GlobalProperty in project openmrs-module-mirebalais by PIH.

the class HibernateMirebalaisHospitalDAO method getNextRadiologyOrderNumberSeedSequenceValue.

/**
 * @see org.openmrs.api.db.OrderDAO#getNextRadiologyOrderNumberSeedSequenceValue()
 */
@Override
public Long getNextRadiologyOrderNumberSeedSequenceValue() {
    Criteria searchCriteria = sessionFactory.getCurrentSession().createCriteria(GlobalProperty.class);
    searchCriteria.add(Restrictions.eq("property", MirebalaisConstants.GP_NEXT_RADIOLOGY_ORDER_NUMBER_SEED));
    GlobalProperty globalProperty = (GlobalProperty) sessionFactory.getCurrentSession().get(GlobalProperty.class, MirebalaisConstants.GP_NEXT_RADIOLOGY_ORDER_NUMBER_SEED, LockOptions.UPGRADE);
    if (globalProperty == null) {
        throw new APIException("Missing global property named: " + MirebalaisConstants.GP_NEXT_RADIOLOGY_ORDER_NUMBER_SEED);
    }
    String gpTextValue = globalProperty.getPropertyValue();
    if (StringUtils.isBlank(gpTextValue)) {
        throw new APIException("Invalid value for global property named: " + MirebalaisConstants.GP_NEXT_RADIOLOGY_ORDER_NUMBER_SEED);
    }
    Long gpNumericValue = null;
    try {
        gpNumericValue = Long.parseLong(gpTextValue);
    } catch (NumberFormatException ex) {
        throw new APIException("Invalid value for global property named: " + MirebalaisConstants.GP_NEXT_RADIOLOGY_ORDER_NUMBER_SEED);
    }
    globalProperty.setPropertyValue(String.valueOf(gpNumericValue + 1));
    sessionFactory.getCurrentSession().save(globalProperty);
    return gpNumericValue;
}
Also used : APIException(org.openmrs.api.APIException) Criteria(org.hibernate.Criteria) GlobalProperty(org.openmrs.GlobalProperty)

Example 52 with GlobalProperty

use of org.openmrs.GlobalProperty in project openmrs-module-pihcore by PIH.

the class ConfigurationSetup method updateGlobalProperty.

private void updateGlobalProperty(String name, Object value) {
    AdministrationService administrationService = Context.getAdministrationService();
    GlobalProperty gp = administrationService.getGlobalPropertyObject(name);
    if (gp == null) {
        throw new RuntimeException("Failed to get global property object '" + name + "'. Cannot set it to " + value);
    } else {
        gp.setPropertyValue(value == null ? "" : value.toString());
        administrationService.saveGlobalProperty(gp);
    }
}
Also used : AdministrationService(org.openmrs.api.AdministrationService) GlobalProperty(org.openmrs.GlobalProperty)

Example 53 with GlobalProperty

use of org.openmrs.GlobalProperty in project openmrs-module-pihcore by PIH.

the class CauseOfDeathListTagHandlerComponentTest method setUp.

@Before
public void setUp() throws Exception {
    ConceptSource ciel = conceptSource("CIEL", "Columbia International eHealth Laboratory concept ID", null, CoreConceptMetadataBundle.ConceptSources.CIEL);
    conceptService.saveConceptSource(ciel);
    // for some reason, one of the other tests leaves the context dirty, and the locale set to "fr", which causes the tests to fail when matching obs
    Context.setLocale(new Locale("en"));
    unknownConcept = testData.concept().datatype("N/A").conceptClass("Misc").name("Unknown Concept").save();
    administrationService.saveGlobalProperty(new GlobalProperty(HtmlFormEntryConstants.GP_UNKNOWN_CONCEPT, unknownConcept.getUuid()));
    codedCauseConcept = testData.concept().datatype("Coded").conceptClass("Misc").name("CAUSE OF DEATH FROM DEATH CERTIFICATE").mapping("SAME-AS", "CIEL:1814").save();
    nonCodedCauseConcept = testData.concept().datatype("Text").conceptClass("Misc").name("Probable cause of death (text)").mapping("SAME-AS", "CIEL:160218").save();
    sequenceConcept = testData.conceptNumeric().datatype("Numeric").conceptClass("Misc").name("DIAGNOSIS SEQUENCE NUMBER").mapping("SAME-AS", "CIEL:1815").save();
    groupingConcept = testData.concept().datatype("N/A").conceptClass("Misc").name("CAUSES OF DEATH FROM DEATH CERTIFICATE").mapping("SAME-AS", "CIEL:1816").setMembers(codedCauseConcept, nonCodedCauseConcept, sequenceConcept).save();
    HtmlFormSetup.setupHtmlFormEntryTagHandlers();
}
Also used : Locale(java.util.Locale) ConceptSource(org.openmrs.ConceptSource) GlobalProperty(org.openmrs.GlobalProperty) Before(org.junit.Before)

Example 54 with GlobalProperty

use of org.openmrs.GlobalProperty in project openmrs-module-pihcore by PIH.

the class PihCoreDAO method getNextRadiologyOrderNumberSeedSequenceValue.

/**
 * @see OrderDAO#getNextOrderNumberSeedSequenceValue() ()
 */
public Long getNextRadiologyOrderNumberSeedSequenceValue() {
    String gp = PihCoreConstants.GP_NEXT_RADIOLOGY_ORDER_NUMBER_SEED;
    Criteria searchCriteria = sessionFactory.getCurrentSession().createCriteria(GlobalProperty.class);
    searchCriteria.add(Restrictions.eq("property", gp));
    GlobalProperty globalProperty = (GlobalProperty) sessionFactory.getCurrentSession().get(GlobalProperty.class, gp, LockOptions.UPGRADE);
    if (globalProperty == null) {
        throw new APIException("Missing global property named: " + gp);
    }
    String gpTextValue = globalProperty.getPropertyValue();
    if (StringUtils.isBlank(gpTextValue)) {
        throw new APIException("Invalid value for global property named: " + gp);
    }
    Long gpNumericValue;
    try {
        gpNumericValue = Long.parseLong(gpTextValue);
    } catch (NumberFormatException ex) {
        throw new APIException("Invalid value for global property named: " + gp);
    }
    globalProperty.setPropertyValue(String.valueOf(gpNumericValue + 1));
    sessionFactory.getCurrentSession().save(globalProperty);
    return gpNumericValue;
}
Also used : APIException(org.openmrs.api.APIException) Criteria(org.hibernate.Criteria) GlobalProperty(org.openmrs.GlobalProperty)

Example 55 with GlobalProperty

use of org.openmrs.GlobalProperty in project openmrs-module-mirebalais by PIH.

the class MirebalaisHospitalActivator method updateGlobalProperty.

private void updateGlobalProperty(String name, Object value) {
    AdministrationService administrationService = Context.getAdministrationService();
    GlobalProperty gp = administrationService.getGlobalPropertyObject(name);
    gp.setPropertyValue(value == null ? "" : value.toString());
    administrationService.saveGlobalProperty(gp);
}
Also used : AdministrationService(org.openmrs.api.AdministrationService) GlobalProperty(org.openmrs.GlobalProperty)

Aggregations

GlobalProperty (org.openmrs.GlobalProperty)110 Test (org.junit.Test)80 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)77 Locale (java.util.Locale)14 OrderUtilTest (org.openmrs.order.OrderUtilTest)14 Encounter (org.openmrs.Encounter)12 ArrayList (java.util.ArrayList)11 User (org.openmrs.User)11 Patient (org.openmrs.Patient)10 AdministrationService (org.openmrs.api.AdministrationService)10 BindException (org.springframework.validation.BindException)10 DrugOrder (org.openmrs.DrugOrder)9 Errors (org.springframework.validation.Errors)9 CareSetting (org.openmrs.CareSetting)7 OrderType (org.openmrs.OrderType)7 Date (java.util.Date)6 EncounterType (org.openmrs.EncounterType)5 APIException (org.openmrs.api.APIException)5 MutableMessageSource (org.openmrs.messagesource.MutableMessageSource)4 MutableResourceBundleMessageSource (org.openmrs.messagesource.impl.MutableResourceBundleMessageSource)4