Search in sources :

Example 1 with OpenmrsMetadata

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

the class CreateCoreUuids method getUUIDs.

// @Test
@SkipBaseSetup
public void getUUIDs() throws Exception {
    Context.authenticate("admin", "test");
    System.out.println("db: " + OpenmrsConstants.DATABASE_NAME);
    Map<String, List<? extends OpenmrsMetadata>> coremetadatas = new LinkedHashMap<>();
    coremetadatas.put("field_type", Context.getFormService().getAllFieldTypes(true));
    coremetadatas.put("person_attribute_type", Context.getPersonService().getAllPersonAttributeTypes(true));
    coremetadatas.put("encounter_type", Context.getEncounterService().getAllEncounterTypes(true));
    coremetadatas.put("concept_datatype", Context.getConceptService().getAllConceptDatatypes(true));
    coremetadatas.put("concept_class", Context.getConceptService().getAllConceptClasses(true));
    coremetadatas.put("patient_identifier_type", Context.getPatientService().getAllPatientIdentifierTypes(true));
    coremetadatas.put("location", Context.getLocationService().getAllLocations(true));
    coremetadatas.put("hl7_source", Context.getHL7Service().getAllHL7Sources());
    for (Map.Entry<String, List<? extends OpenmrsMetadata>> entry : coremetadatas.entrySet()) {
        System.out.println("new table: " + entry.getKey());
        for (OpenmrsMetadata obj : entry.getValue()) {
            String output = "<update tableName=\"" + entry.getKey() + "\"><column name=\"uuid\" value=\"" + obj.getUuid() + "\"/><where>" + entry.getKey() + "_id" + "= '" + obj.getId() + "' and name = '" + obj.getName().replace("'", "\\'") + "'</where></update>";
            System.out.println(output);
        }
    }
    // /////////////////////////////////////
    // exceptions:
    // 
    // relationship types
    System.out.println("Relationship type");
    for (RelationshipType type : Context.getPersonService().getAllRelationshipTypes()) {
        String output = "<update tableName=\"relationship_type\"><column name=\"uuid\" value=\"" + type.getUuid() + "\"/><where> relationship_type_id = '" + type.getRelationshipTypeId() + "' and a_is_to_b = '" + type.getaIsToB().replace("'", "\\'") + "' and b_is_to_a = '" + type.getbIsToA().replace("'", "\\'") + "'</where></update>";
        System.out.println(output);
    }
    // roles:
    System.out.println("Roles");
    for (Role role : Context.getUserService().getAllRoles()) {
        String output = "<update tableName=\"role\"><column name=\"uuid\" value=\"" + role.getUuid() + "\"/><where> role = '" + role.getRole().replace("'", "\\'") + "'</where></update>";
        System.out.println(output);
    }
    // user:
    System.out.println("Users");
    for (User user : Context.getUserService().getAllUsers()) {
        String output = "<update tableName=\"users\"><column name=\"uuid\" value=\"" + user.getUuid() + "\"/><where> user_id = '" + user.getUserId() + "' and system_id = '" + user.getSystemId().replace("'", "\\'") + "'</where></update>";
        System.out.println(output);
    }
}
Also used : Role(org.openmrs.Role) User(org.openmrs.User) RelationshipType(org.openmrs.RelationshipType) List(java.util.List) OpenmrsMetadata(org.openmrs.OpenmrsMetadata) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with OpenmrsMetadata

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

the class BaseMetadataDatatypeTest method doGetTextSummary_shouldUseTheNameInSummaryInstance.

/**
 * @see BaseMetadataDatatype#doGetTextSummary(org.openmrs.OpenmrsMetadata)
 */
@Test
public void doGetTextSummary_shouldUseTheNameInSummaryInstance() {
    OpenmrsMetadata location = new Location();
    String expectedSummary = "some summary";
    location.setName(expectedSummary);
    BaseMetadataDatatype datatype = new MockLocationDatatype();
    CustomDatatype.Summary summary = datatype.doGetTextSummary(location);
    Assert.assertEquals(expectedSummary, summary.getSummary());
    Assert.assertEquals(true, summary.isComplete());
}
Also used : CustomDatatype(org.openmrs.customdatatype.CustomDatatype) OpenmrsMetadata(org.openmrs.OpenmrsMetadata) Location(org.openmrs.Location) Test(org.junit.Test)

Example 3 with OpenmrsMetadata

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

the class HibernateSerializedObjectDAO method saveObject.

/**
 * @see SerializedObjectDAO#saveObject(OpenmrsObject, OpenmrsSerializer)
 */
@Override
public <T extends OpenmrsObject> T saveObject(T object, OpenmrsSerializer serializer) throws DAOException {
    Class<? extends OpenmrsObject> baseType = getRegisteredTypeForObject(object);
    if (baseType == null) {
        throw new DAOException("SerializedObjectDAO does not support saving objects of type <" + object.getClass() + ">");
    }
    SerializedObject serializedObject = getSerializedObject(object.getId());
    if (serializedObject == null) {
        serializedObject = new SerializedObject();
    }
    if (serializer == null) {
        serializer = getSerializer(serializedObject);
    }
    if (object instanceof Auditable) {
        Auditable auditableObj = (Auditable) object;
        if (auditableObj.getCreator() == null) {
            auditableObj.setCreator(Context.getAuthenticatedUser());
        }
        serializedObject.setCreator(auditableObj.getCreator());
        if (auditableObj.getDateCreated() == null) {
            auditableObj.setDateCreated(new Date());
        }
        serializedObject.setDateCreated(auditableObj.getDateCreated());
        serializedObject.setChangedBy(auditableObj.getChangedBy());
        serializedObject.setDateChanged(auditableObj.getDateChanged());
    }
    String data;
    try {
        data = serializer.serialize(object);
    } catch (SerializationException e) {
        throw new DAOException("Unable to save object <" + object + "> because serialization failed.", e);
    }
    serializedObject.setUuid(object.getUuid());
    serializedObject.setType(baseType.getName());
    serializedObject.setSubtype(object.getClass().getName());
    serializedObject.setSerializationClass(serializer.getClass());
    serializedObject.setSerializedData(data);
    if (object instanceof OpenmrsMetadata) {
        OpenmrsMetadata metaObj = (OpenmrsMetadata) object;
        serializedObject.setName(metaObj.getName());
        serializedObject.setDescription(metaObj.getDescription());
        serializedObject.setRetired(metaObj.getRetired());
        serializedObject.setRetiredBy(metaObj.getRetiredBy());
        serializedObject.setDateRetired(metaObj.getDateRetired());
        serializedObject.setRetireReason(metaObj.getRetireReason());
    }
    if (object instanceof OpenmrsData) {
        OpenmrsData dataObj = (OpenmrsData) object;
        serializedObject.setRetired(dataObj.getVoided());
        serializedObject.setRetiredBy(dataObj.getVoidedBy());
        serializedObject.setDateRetired(dataObj.getDateVoided());
        serializedObject.setRetireReason(dataObj.getVoidReason());
    }
    sessionFactory.getCurrentSession().saveOrUpdate(serializedObject);
    object.setId(serializedObject.getId());
    return object;
}
Also used : DAOException(org.openmrs.api.db.DAOException) Auditable(org.openmrs.Auditable) SerializedObject(org.openmrs.api.db.SerializedObject) SerializationException(org.openmrs.serialization.SerializationException) OpenmrsData(org.openmrs.OpenmrsData) OpenmrsMetadata(org.openmrs.OpenmrsMetadata) Date(java.util.Date)

Aggregations

OpenmrsMetadata (org.openmrs.OpenmrsMetadata)3 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Test (org.junit.Test)1 Auditable (org.openmrs.Auditable)1 Location (org.openmrs.Location)1 OpenmrsData (org.openmrs.OpenmrsData)1 RelationshipType (org.openmrs.RelationshipType)1 Role (org.openmrs.Role)1 User (org.openmrs.User)1 DAOException (org.openmrs.api.db.DAOException)1 SerializedObject (org.openmrs.api.db.SerializedObject)1 CustomDatatype (org.openmrs.customdatatype.CustomDatatype)1 SerializationException (org.openmrs.serialization.SerializationException)1