Search in sources :

Example 41 with GlobalProperty

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

the class ModuleFileParser method extractGlobalProperties.

private List<GlobalProperty> extractGlobalProperties(Element configRoot) {
    List<GlobalProperty> result = new ArrayList<>();
    NodeList propNodes = configRoot.getElementsByTagName("globalProperty");
    if (propNodes.getLength() == 0) {
        return result;
    }
    log.debug("# global properties: {}", propNodes.getLength());
    int i = 0;
    while (i < propNodes.getLength()) {
        Element gpElement = (Element) propNodes.item(i);
        GlobalProperty globalProperty = extractGlobalProperty(gpElement);
        if (globalProperty != null) {
            result.add(globalProperty);
        }
        i++;
    }
    return result;
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) GlobalProperty(org.openmrs.GlobalProperty)

Example 42 with GlobalProperty

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

the class ModuleFileParser method createGlobalPropertyWithDatatype.

private GlobalProperty createGlobalPropertyWithDatatype(String property, String defaultValue, String description, String datatypeClassname, String datatypeConfig) {
    GlobalProperty globalProperty = null;
    try {
        Class<CustomDatatype<?>> datatypeClazz = (Class<CustomDatatype<?>>) Class.forName(datatypeClassname).asSubclass(CustomDatatype.class);
        globalProperty = new GlobalProperty(property, defaultValue, description, datatypeClazz, datatypeConfig);
    } catch (ClassCastException ex) {
        log.error("The class specified by 'datatypeClassname' (" + datatypeClassname + ") must be a subtype of 'org.openmrs.customdatatype.CustomDatatype<?>'.", ex);
    } catch (ClassNotFoundException ex) {
        log.error("The class specified by 'datatypeClassname' (" + datatypeClassname + ") could not be found.", ex);
    }
    return globalProperty;
}
Also used : CustomDatatype(org.openmrs.customdatatype.CustomDatatype) GlobalProperty(org.openmrs.GlobalProperty)

Example 43 with GlobalProperty

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

the class PersonServiceImpl method savePersonAttributeType.

/**
 * @see org.openmrs.api.PersonService#savePersonAttributeType(org.openmrs.PersonAttributeType)
 */
@Override
public PersonAttributeType savePersonAttributeType(PersonAttributeType type) throws APIException {
    checkIfPersonAttributeTypesAreLocked();
    if (type.getSortWeight() == null) {
        List<PersonAttributeType> allTypes = Context.getPersonService().getAllPersonAttributeTypes();
        if (!allTypes.isEmpty()) {
            type.setSortWeight(allTypes.get(allTypes.size() - 1).getSortWeight() + 1);
        } else {
            type.setSortWeight(1.0);
        }
    }
    boolean updateExisting = false;
    if (type.getId() != null) {
        updateExisting = true;
        String oldTypeName = dao.getSavedPersonAttributeTypeName(type);
        String newTypeName = type.getName();
        if (!oldTypeName.equals(newTypeName)) {
            List<GlobalProperty> props = new ArrayList<>();
            AdministrationService as = Context.getAdministrationService();
            for (String propName : OpenmrsConstants.GLOBAL_PROPERTIES_OF_PERSON_ATTRIBUTES) {
                props.add(as.getGlobalPropertyObject(propName));
            }
            for (GlobalProperty prop : props) {
                if (prop != null) {
                    String propVal = prop.getPropertyValue();
                    if (propVal != null && propVal.contains(oldTypeName)) {
                        prop.setPropertyValue(propVal.replaceFirst(oldTypeName, newTypeName));
                        as.saveGlobalProperty(prop);
                    }
                }
            }
        }
    }
    PersonAttributeType attributeType = dao.savePersonAttributeType(type);
    if (updateExisting) {
        // we need to update index in case searchable property has changed
        Context.updateSearchIndexForType(PersonAttribute.class);
    }
    return attributeType;
}
Also used : AdministrationService(org.openmrs.api.AdministrationService) ArrayList(java.util.ArrayList) PersonAttributeType(org.openmrs.PersonAttributeType) GlobalProperty(org.openmrs.GlobalProperty)

Example 44 with GlobalProperty

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

the class HL7ServiceTest method processHL7InQueue_shouldCreateHL7InArchiveAfterSuccessfulParsing.

/**
 * @throws HL7Exception
 * @throws IOException
 * @see HL7Service#processHL7InQueue(HL7InQueue)
 */
@Test
public void processHL7InQueue_shouldCreateHL7InArchiveAfterSuccessfulParsing() throws HL7Exception, IOException {
    executeDataSet("org/openmrs/hl7/include/ORUTest-initialData.xml");
    File tempDir = new File(System.getProperty("java.io.tmpdir"), HL7Constants.HL7_ARCHIVE_DIRECTORY_NAME);
    if (tempDir.exists() && tempDir.isDirectory())
        Assert.assertEquals(true, OpenmrsUtil.deleteDirectory(tempDir));
    // set a global property for the archives directory as a temporary folder
    GlobalProperty gp = new GlobalProperty();
    gp.setProperty(OpenmrsConstants.GLOBAL_PROPERTY_HL7_ARCHIVE_DIRECTORY);
    gp.setPropertyValue(tempDir.getAbsolutePath());
    gp.setDescription("temp test dir");
    Context.getAdministrationService().saveGlobalProperty(gp);
    HL7Service hl7service = Context.getHL7Service();
    Assert.assertEquals(0, hl7service.getAllHL7InArchives().size());
    HL7InQueue queueItem = hl7service.getHL7InQueue(1);
    hl7service.processHL7InQueue(queueItem);
    Assert.assertEquals(1, hl7service.getAllHL7InArchives().size());
}
Also used : File(java.io.File) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 45 with GlobalProperty

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

the class ORUR01HandlerTest method processMessage_shouldSetValueAsBooleanForObsIfTheAnswerIs0Or1AndQuestionDatatypeIsBoolean.

/**
 * @see ORUR01Handler#processMessage(Message)
 */
@Test
public void processMessage_shouldSetValueAsBooleanForObsIfTheAnswerIs0Or1AndQuestionDatatypeIsBoolean() throws Exception {
    GlobalProperty trueConceptGlobalProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_TRUE_CONCEPT, "7", "Concept id of the concept defining the TRUE boolean concept");
    GlobalProperty falseConceptGlobalProperty = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_FALSE_CONCEPT, "8", "Concept id of the concept defining the TRUE boolean concept");
    Context.getAdministrationService().saveGlobalProperty(trueConceptGlobalProperty);
    Context.getAdministrationService().saveGlobalProperty(falseConceptGlobalProperty);
    ObsService os = Context.getObsService();
    Assert.assertNull(os.getObs(17));
    String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|18^FOOD ASSISTANCE^99DCT||0|||||||||20080206";
    // the expected question for the obs in the hl7 message has to be
    // Boolean
    Assert.assertEquals("Boolean", Context.getConceptService().getConcept(18).getDatatype().getName());
    List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(18));
    Message hl7message = parser.parse(hl7string);
    router.processMessage(hl7message);
    List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(18));
    Obs newObservation = null;
    for (Obs newObs : newList) {
        if (!oldList.contains(newObs) && !newObs.isObsGrouping()) {
            newObservation = newObs;
        }
    }
    Assert.assertEquals(false, newObservation.getValueBoolean());
}
Also used : Concept(org.openmrs.Concept) Obs(org.openmrs.Obs) Message(ca.uhn.hl7v2.model.Message) ObsService(org.openmrs.api.ObsService) Person(org.openmrs.Person) GlobalProperty(org.openmrs.GlobalProperty) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

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