Search in sources :

Example 21 with GlobalProperty

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

the class AdministrationServiceTest method saveGlobalProperty_shouldOverwriteGlobalPropertyIfExists.

/**
 * @see AdministrationService#saveGlobalProperty(GlobalProperty)
 */
@Test
public void saveGlobalProperty_shouldOverwriteGlobalPropertyIfExists() {
    executeDataSet(ADMIN_INITIAL_DATA_XML);
    AdministrationService as = Context.getAdministrationService();
    GlobalProperty gp = as.getGlobalPropertyObject("a_valid_gp_key");
    Assert.assertEquals("correct-value", gp.getPropertyValue());
    gp.setPropertyValue("new-even-more-correct-value");
    as.saveGlobalProperty(gp);
    Assert.assertEquals("new-even-more-correct-value", as.getGlobalProperty("a_valid_gp_key"));
}
Also used : GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 22 with GlobalProperty

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

the class AdministrationServiceTest method saveGlobalProperty_shouldSaveAGlobalPropertyWhoseTypedValueIsHandledByACustomDatatype.

/**
 * @see AdministrationService#saveGlobalProperty(GlobalProperty)
 */
@Test
public void saveGlobalProperty_shouldSaveAGlobalPropertyWhoseTypedValueIsHandledByACustomDatatype() {
    GlobalProperty gp = new GlobalProperty();
    gp.setProperty("What time is it?");
    gp.setDatatypeClassname(DateDatatype.class.getName());
    gp.setValue(new Date());
    adminService.saveGlobalProperty(gp);
    Assert.assertNotNull(gp.getValueReference());
}
Also used : DateDatatype(org.openmrs.customdatatype.datatype.DateDatatype) Date(java.util.Date) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 23 with GlobalProperty

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

the class PersonNameValidatorTest method validate_shouldSkipRegexValidationIfValidationStringIsNull.

/**
 * @see PatientNameValidator#validatePersonName(java.lang.Object, org.springframework.validation.Errors, boolean, boolean)
 */
@Test
public void validate_shouldSkipRegexValidationIfValidationStringIsNull() {
    Context.getAdministrationService().saveGlobalProperty(new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_NAME_REGEX, null));
    personName.setFamilyName("asd123");
    validator.validatePersonName(personName, errors, false, true);
    assertThat(errors, not(hasFieldErrors("familyName")));
}
Also used : GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 24 with GlobalProperty

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

the class DrugOrderValidatorTest method saveOrder_shouldFailDrugOrderWithNeitherDrugNonCodedNorDrugAreSetForDrugOrderWhenDrugRequiredSet.

@Test
public void saveOrder_shouldFailDrugOrderWithNeitherDrugNonCodedNorDrugAreSetForDrugOrderWhenDrugRequiredSet() {
    Patient patient = Context.getPatientService().getPatient(7);
    CareSetting careSetting = Context.getOrderService().getCareSetting(2);
    OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "true");
    Context.getAdministrationService().saveGlobalProperty(gp);
    // place drug order
    DrugOrder order = new DrugOrder();
    Encounter encounter = Context.getEncounterService().getEncounter(3);
    order.setEncounter(encounter);
    order.setPatient(patient);
    order.setCareSetting(careSetting);
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setDateActivated(encounter.getEncounterDatetime());
    order.setOrderType(orderType);
    order.setDosingType(FreeTextDosingInstructions.class);
    order.setInstructions("None");
    order.setDosingInstructions("Test Instruction");
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertTrue(errors.hasFieldErrors());
    assertEquals("DrugOrder.error.drugIsRequired", errors.getFieldError("drug").getCode());
}
Also used : DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Example 25 with GlobalProperty

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

the class DrugOrderValidatorTest method saveOrder_shouldPassDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsFalse.

/**
 * @see org.openmrs.api.OrderService#saveOrder(org.openmrs.Order, org.openmrs.api.OrderContext)
 */
@Test
public void saveOrder_shouldPassDrugOrderWithoutADrugWhenDrugOrderRequireDrugGBIsFalse() {
    GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_DRUG_ORDER_REQUIRE_DRUG, "false");
    Context.getAdministrationService().saveGlobalProperty(gp);
    Patient patient = Context.getPatientService().getPatient(7);
    CareSetting careSetting = Context.getOrderService().getCareSetting(2);
    OrderType orderType = Context.getOrderService().getOrderTypeByName("Drug order");
    // place drug order
    DrugOrder order = new DrugOrder();
    Encounter encounter = Context.getEncounterService().getEncounter(3);
    order.setEncounter(encounter);
    order.setConcept(Context.getConceptService().getConcept(5497));
    order.setPatient(patient);
    order.setCareSetting(careSetting);
    order.setOrderer(Context.getProviderService().getProvider(1));
    order.setDateActivated(encounter.getEncounterDatetime());
    order.setOrderType(orderType);
    order.setDosingType(FreeTextDosingInstructions.class);
    order.setInstructions("None");
    order.setDosingInstructions("Test Instruction");
    Errors errors = new BindException(order, "order");
    new DrugOrderValidator().validate(order, errors);
    Assert.assertFalse(errors.hasFieldErrors());
}
Also used : DrugOrder(org.openmrs.DrugOrder) Errors(org.springframework.validation.Errors) OrderType(org.openmrs.OrderType) Patient(org.openmrs.Patient) CareSetting(org.openmrs.CareSetting) Encounter(org.openmrs.Encounter) BindException(org.springframework.validation.BindException) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest) OrderUtilTest(org.openmrs.order.OrderUtilTest)

Aggregations

GlobalProperty (org.openmrs.GlobalProperty)107 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 BindException (org.springframework.validation.BindException)10 DrugOrder (org.openmrs.DrugOrder)9 Errors (org.springframework.validation.Errors)9 AdministrationService (org.openmrs.api.AdministrationService)8 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)4 MutableMessageSource (org.openmrs.messagesource.MutableMessageSource)4 MutableResourceBundleMessageSource (org.openmrs.messagesource.impl.MutableResourceBundleMessageSource)4