/** * @see org.openmrs.customdatatype.SingleCustomValue#setValueReferenceInternal(java.lang.String) * * @since 1.9 */ @Override public void setValueReferenceInternal(String valueToPersist) { setPropertyValue(valueToPersist); }
/** * @see org.openmrs.api.AdministrationService#updateGlobalProperty(java.lang.String, * java.lang.String) */ @Override public void updateGlobalProperty(String propertyName, String propertyValue) throws IllegalStateException { GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(propertyName); if (gp == null) { throw new IllegalStateException("Global property with the given propertyName does not exist" + propertyName); } gp.setPropertyValue(propertyValue); dao.saveGlobalProperty(gp); }
globalProperty.setPropertyValue(String.valueOf(gpNumericValue + 1));
/** * @see org.openmrs.api.db.AdministrationDAO#saveGlobalProperty(org.openmrs.GlobalProperty) */ @Override public GlobalProperty saveGlobalProperty(GlobalProperty gp) throws DAOException { GlobalProperty gpObject = getGlobalPropertyObject(gp.getProperty()); if (gpObject != null) { gpObject.setPropertyValue(gp.getPropertyValue()); gpObject.setDescription(gp.getDescription()); sessionFactory.getCurrentSession().update(gpObject); return gpObject; } else { sessionFactory.getCurrentSession().save(gp); return gp; } }
/** * @see ContextDAO#updateSearchIndex() */ @Override public void updateSearchIndex() { try { log.info("Updating the search index... It may take a few minutes."); Search.getFullTextSession(sessionFactory.getCurrentSession()).createIndexer().startAndWait(); GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject( OpenmrsConstants.GP_SEARCH_INDEX_VERSION); if (gp == null) { gp = new GlobalProperty(OpenmrsConstants.GP_SEARCH_INDEX_VERSION); } gp.setPropertyValue(OpenmrsConstants.SEARCH_INDEX_VERSION.toString()); Context.getAdministrationService().saveGlobalProperty(gp); log.info("Finished updating the search index"); } catch (Exception e) { throw new RuntimeException("Failed to update the search index", e); } }
/** * Convenience method to save a global property with the given value. Proxy privileges are added * so that this can occur at startup. * * @param key the property for this global property * @param value the value for this global property * @param desc the description * @see AdministrationService#saveGlobalProperty(GlobalProperty) */ private static void saveGlobalProperty(String key, String value, String desc) { try { AdministrationService as = Context.getAdministrationService(); GlobalProperty gp = as.getGlobalPropertyObject(key); if (gp == null) { gp = new GlobalProperty(key, value, desc); } else { gp.setPropertyValue(value); } as.saveGlobalProperty(gp); } catch (Exception e) { log.warn("Unable to save the global property", e); } }
/** * @see org.openmrs.api.AdministrationService#setGlobalProperty(java.lang.String, * java.lang.String) */ @Override public void setGlobalProperty(String propertyName, String propertyValue) throws APIException { GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(propertyName); if (gp == null) { gp = new GlobalProperty(); gp.setProperty(propertyName); } gp.setPropertyValue(propertyValue); Context.getAdministrationService().saveGlobalProperty(gp); }
/** * Creates a new Global Property to lock patient identifier types by setting its value * * @param propertyValue value for patient identifier types locked GP */ public void createPatientIdentifierTypeLockedGPAndSetValue(String propertyValue) { GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_IDENTIFIER_TYPES_LOCKED); gp.setPropertyValue(propertyValue); Context.getAdministrationService().saveGlobalProperty(gp); }
/** * Creates a new Global Property to lock forms by setting its value * @param propertyValue value for forms locked GP */ public void createFormsLockedGPAndSetValue(String propertyValue) { GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_FORMS_LOCKED); gp.setPropertyValue(propertyValue); Context.getAdministrationService().saveGlobalProperty(gp); }
/** * Creates a new Global Property to lock person attribute types by setting its value * @param propertyValue value for person attribute types locked GP */ public void createPersonAttributeTypeLockedGPAndSetValue(String propertyValue) { GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_PERSON_ATRIBUTE_TYPES_LOCKED); gp.setPropertyValue(propertyValue); Context.getAdministrationService().saveGlobalProperty(gp); }
/** * Utility method that allows tests to easily configure and save a global property * @param string the name of the property to save * @param value the value of the property to save */ public static void saveGlobalProperty(String name, String value) { GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject(name); if (gp == null) { gp = new GlobalProperty(name); } gp.setPropertyValue(value); Context.getAdministrationService().saveGlobalProperty(gp); }
/** * @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()); }
/** * @see EncounterService#unretireEncounterType(EncounterType) */ @Test(expected = EncounterTypeLockedException.class) public void unretireEncounterType_shouldThrowErrorWhenTryingToUnretireEncounterTypeWhenEncounterTypesAreLocked() { EncounterService encounterService = Context.getEncounterService(); EncounterType encounterType = Context.getEncounterService().getEncounterType(2); GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ENCOUNTER_TYPES_LOCKED); gp.setPropertyValue("true"); Context.getAdministrationService().saveGlobalProperty(gp); encounterService.unretireEncounterType(encounterType); }
@Test public void saveGlobalProperty_shouldOverwriteGlobalPropertyIfExists() { executeDataSet(ADMIN_INITIAL_DATA_XML); GlobalProperty gp = adminService.getGlobalPropertyObject("a_valid_gp_key"); assertEquals("correct-value", gp.getPropertyValue()); gp.setPropertyValue("new-even-more-correct-value"); adminService.saveGlobalProperty(gp); assertEquals("new-even-more-correct-value", adminService.getGlobalProperty("a_valid_gp_key")); }
/** * @see EncounterService#saveEncounterType(EncounterType) * @see EncounterService#checkIfEncounterTypesAreLocked() */ @Test(expected = EncounterTypeLockedException.class) public void saveEncounterType_shouldThrowErrorWhenTryingToSaveEncounterTypeWhenEncounterTypesAreLocked() { GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ENCOUNTER_TYPES_LOCKED); gp.setPropertyValue("true"); Context.getAdministrationService().saveGlobalProperty(gp); EncounterService encounterService = Context.getEncounterService(); EncounterType encounterType = Context.getEncounterService().getEncounterType(1); Assert.assertNotNull(encounterType); encounterService.saveEncounterType(encounterType); }
/** * @see EncounterService#retireEncounterType(EncounterType, String) */ @Test(expected = EncounterTypeLockedException.class) public void retireEncounterType_shouldThrowErrorWhenTryingToRetireEncounterTypeWhenEncounterTypesAreLocked() { GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ENCOUNTER_TYPES_LOCKED); gp.setPropertyValue("true"); Context.getAdministrationService().saveGlobalProperty(gp); EncounterService encounterService = Context.getEncounterService(); EncounterType encounterType = Context.getEncounterService().getEncounterType(1); Assert.assertNotNull(encounterType); encounterService.retireEncounterType(encounterType, "reason"); }
/** * @see EncounterService#purgeEncounterType(EncounterType) */ @Test(expected = EncounterTypeLockedException.class) public void purgeEncounterType_shouldThrowErrorWhenTryingToDeleteEncounterTypeWhenEncounterTypesAreLocked() { EncounterService encounterService = Context.getEncounterService(); EncounterType encounterType = Context.getEncounterService().getEncounterType(1); Assert.assertNotNull(encounterType); GlobalProperty gp = new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_ENCOUNTER_TYPES_LOCKED); gp.setPropertyValue("true"); Context.getAdministrationService().saveGlobalProperty(gp); encounterService.purgeEncounterType(encounterType); }
/** * @see EncounterService#saveEncounter(Encounter) */ @Test public void saveEncounter_shouldNotAssignEncounterToVisitIfTheNoAssignHandlerIsRegistered() { Encounter encounter = buildEncounter(); //We should have no visit assertNull(encounter.getVisit()); GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject( OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER); gp.setPropertyValue("org.openmrs.api.handler.NoVisitAssignmentHandler"); Context.getAdministrationService().saveGlobalProperty(gp); Context.getEncounterService().saveEncounter(encounter); //We should have no visit. assertNull(encounter.getVisit()); }
/** * @see EncounterService#saveEncounter(Encounter) */ @Test public void saveEncounter_shouldAssignEncounterToVisitIfTheAssignToExistingHandlerIsRegistered() { Encounter encounter = buildEncounter(); //We should have no visit assertNull(encounter.getVisit()); GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject( OpenmrsConstants.GP_VISIT_ASSIGNMENT_HANDLER); gp.setPropertyValue("org.openmrs.api.handler.ExistingVisitAssignmentHandler"); Context.getAdministrationService().saveGlobalProperty(gp); Context.getEncounterService().saveEncounter(encounter); //We should have a visit. assertNotNull(encounter.getVisit()); assertNotNull(encounter.getVisit().getVisitId()); }
/** * @see ConceptService#saveConcept(Concept) */ @Test public void saveConcept_shouldSetAPreferredNameForEachLocaleIfNoneIsMarked() { //add some other locales to locale.allowed.list for testing purposes GlobalProperty gp = Context.getAdministrationService().getGlobalPropertyObject( OpenmrsConstants.GLOBAL_PROPERTY_LOCALE_ALLOWED_LIST); gp.setPropertyValue(gp.getPropertyValue().concat(",fr,ja,en_GB")); Context.getAdministrationService().saveGlobalProperty(gp); Concept concept = new Concept(); concept.addName(new ConceptName("name1", Locale.ENGLISH)); concept.addName(new ConceptName("name2", Locale.ENGLISH)); concept.addName(new ConceptName("name3", Locale.FRENCH)); concept.addName(new ConceptName("name4", Locale.FRENCH)); concept.addName(new ConceptName("name5", Locale.JAPANESE)); concept.addName(new ConceptName("name6", Locale.JAPANESE)); concept.addDescription(new ConceptDescription("some description",null)); concept.setDatatype(new ConceptDatatype(1)); concept.setConceptClass(new ConceptClass(1)); concept = Context.getConceptService().saveConcept(concept); Assert.assertNotNull(concept.getPreferredName(Locale.ENGLISH)); Assert.assertNotNull(concept.getPreferredName(Locale.FRENCH)); Assert.assertNotNull(concept.getPreferredName(Locale.JAPANESE)); }