Assigned to: raff
Background
OpenMRS has a mechanism to map concepts to external sources (concept_map
tables); however, OpenMRS does not yet have a means to map metadata to external sources. We have tried using UUIDs to uniquely (and globally) specify metadata across systems; however, this has failed us in several ways: (1) UUIDs end up needing to be manually entered by developers and implementers; (2) there are many cases where metadata created separately (with different UUIDs) are actually referring to the same thing; and, (3) modules introducing their own metadata have a difficult time properly working with existing metadata.
...
Data Model Design
The following design was proposed on is based on the proposal of the Design Forum 2015-06-22:
Gliffy |
---|
name | Metadata Mapping Table Design |
---|
|
Note that in this diagram, the one-to-one mapping between metadata_source
and openmrs_metadata
, for example, indicates an inheritance in object design terms: MetadataSource inherits the fields of OpenmrsMetadata. In the database schema, this relationship will be implemented so that the relation metadata_source
, for example, includes all the columns of openmrs_metadata
.
Notes on data model design
...
metadata_source
is used to define a unique source (authority) for each namespace of metadata terms.name
should be fully qualified and universally unique.
metadata_term
table _mapping
table provides both the term and its mapping to local metadata.code
should be unique within the given source.metadata_class
refers to the Java class for the metadata.metadata_reference
is a unique reference to the metadata within the class (e.g., uuid)
metadata_set
is used to define relating grouping of metadata similar to what OpenMRS has traditionally done within global properties and similar to FHIR's ValueSet for metadata terms.sort_weight
is used to optionally give members of a metadata set a reliable sequence.
...
Retire term:
Code Block |
---|
|
List<MetadataTerm>List<MetadataTermMapping> termstermMappings = metadataService.getMetadataTermsgetMetadataTermMappings(location);
metadataService.retireMapping(termstermMappings.get(0), "some reason"); |
Create term:
Code Block |
---|
|
MetadataSource source = metadataService.getSourceByName("SOME-SOURCE");
MetadataTermMetadataTermMapping termtermMapping = new MetadataTermMetadataTermMapping(source, "CODE", location);
metadataService.saveMetadataTermsaveMetadataTermMapping(termtermMapping); |
Create terms in bulk:
Code Block |
---|
|
List<MetadataTerm>List<MetadataTermMapping> termstermMappings = Arrays.asList(mapping1, mapping2, mapping3);
metadataService.saveMetadataTermssaveMetadataTermMappings(termstermMappings); |
Get term by source and code:
Code Block |
---|
|
MetadataTermMetadataTermMapping termtermMapping = metadataService.getMetdataTermgetMetadataTermMapping(mappingSource, "CODE"); |
Get terms by source:
Code Block |
---|
|
List<MetadataTerm>List<MetadataTermMapping> termstermMappings = metadataService.getMetadataTermsgetMetadataTermMappings(source); |
Get term by uuid:
Code Block |
---|
|
MetadataTermMetadataTermMapping mappingtermMapping = metadataService.getMetadataTermByUuidgetMetadataTermMappingByUuid(String uuid); |
Get source by uuid:
Code Block |
---|
|
MetadataSource source = metadataService.getMetadataSourceByUuid(String uuid); |
...
MetadataTermMapping, MetadataSource, MetadataSet should support all CRUD operations.