Let’s think about it
I’m creating an extension to load a custom fragment which contains a selector to select the locations. When the user selects the location using that selector, that selected location uuid will be stored as a person Attribute for that person. Extension as follows, { className : "location", .......}
Another user created an extension to load another custom fragment which contains a selector to select the roles. When the user selects the role using that selector, that selected role uuid will be stored as a person attribute for that person. Extension as follows, { className : "role", .......}
So finally I have these following records in the database
id | value | personAttributeTypeId | uuid
1 | 74dfv-de458-da57-asfe5 | 4 | 5s8ec-sa9d-cas95-asa569
2 | 78dc9-af545-sf28-89dc5 | 5 | 58d9c-56s9-sf596-c56956
So in the database, I have only uuids as the value of those objects. Anyhow, id=1 should represent the locationUuid, and id=2 should represents the roleUuid.
When I fetch these value from the database using the personAttribute.value
, I need to map this object to the original object with this uuid (value in here). So I’m using the extension configuration to map this object since I have the className information in the extension config.
So I need to map the id=1 with location class, and id=2 with role class. One way is using the IF conditions to get the actual objects like this following
if( extension.params.objectType == 'location') {
Context.getLocationService().getLocationByUuid(uuid);
}
else if( extension.params.objectType == 'patient') {
Context.getPatientService().getPatientByUuid(uuid);
}
else if( extension.params.objectType == 'person') {
Context.getPersonService().getPersonByUuid(uuid);
}
{
..... }
But I can’t use the IF condtions to check for all metadata objects in the OpenMRS. So I need to check wthere, are there any methods which can map the metadata objects from the className.
Some thing similar I want like,
MethodA.getObject(string className, uuid) --> Should return the object
Eg:
MethodA.getObject("location", "74dfv-de458-da57-asfe5") --> Should return the Location object
MethodA.getObject("role", " 78dc9-af545-sf28-89dc5") --> Should return the Role object
So I can get anmetadatata objects through this method. Please let me know, are there any ways like this to get the actual object from the uuid and the className.