Commit 3ce46267 authored by Jose Marquez Prieto's avatar Jose Marquez Prieto
Browse files

Merge branch 'Sample_id_baseclass_resolve' into 'develop'

Sample id baseclass (#945)

See merge request !755
parents e66f86e8 30121e62
Pipeline #137569 failed with stages
in 89 minutes and 16 seconds
......@@ -42,8 +42,8 @@ const ReferenceEditQuantity = React.memo(function ReferenceEditQuantity(props) {
const lane = useLane()
const browserAdaptorContext = useBrowserAdaptorContext(archive)
const context = lane?.adaptor?.context || browserAdaptorContext
const referencedSectionQualifiedName = useMemo(() => {
return quantityDef.type._referencedSection._qualifiedName
const referencedSectionQualifiedNames = useMemo(() => {
return [...quantityDef.type._referencedSection._allInheritingSections.map(section => section._qualifiedName), quantityDef.type._referencedSection._qualifiedName]
}, [quantityDef])
const fetchSuggestions = useCallback(input => {
if (fetchedSuggestionsFor.current === input) {
......@@ -55,10 +55,11 @@ const ReferenceEditQuantity = React.memo(function ReferenceEditQuantity(props) {
if (input !== '') {
query['entry_name.prefix'] = input
}
const sections = referencedSectionQualifiedNames?.map(qualifiedName => ({'sections': qualifiedName}))
api.post('entries/query', {
'owner': 'visible',
'query': {
'sections': referencedSectionQualifiedName,
'or': sections,
...query
},
'required': {
......@@ -73,7 +74,7 @@ const ReferenceEditQuantity = React.memo(function ReferenceEditQuantity(props) {
}).then(response => {
setSuggestions(response.data)
}).catch(raiseError)
}, [api, raiseError, fetchedSuggestionsFor, setSuggestions, referencedSectionQualifiedName])
}, [api, raiseError, fetchedSuggestionsFor, setSuggestions, referencedSectionQualifiedNames])
const fetchSuggestionsDebounced = useMemo(() => debounce(fetchSuggestions, 500), [fetchSuggestions])
useEffect(() => {
......
......@@ -18,8 +18,9 @@
from nomad import utils
from nomad.datamodel.data import EntryData, ArchiveSection
from nomad.metainfo.metainfo import SectionProxy
from nomad.datamodel.results import ELN, Results, Material
from nomad.metainfo import Package, Quantity, Datetime
from nomad.metainfo import Package, Quantity, Datetime, Reference
m_package = Package(name='material_library')
......@@ -186,4 +187,87 @@ class Measurement(ElnActivityBaseSecton):
pass
class SampleID(ArchiveSection):
''' A ELN base section that can be used for sample IDs.
If the `sample_owner`, `sample_short_name`, `ìnstitute`, and `creation_datetime`
quantities are provided, the sample_id will be automatically created as a combination
of these four quantities.'''
# m_def = Section(
# a_eln=dict(hide=['name', 'lab_id']))
institute = Quantity(
type=str,
description='Alias/short name of the home institute of the owner, i.e. *HZB*.',
a_eln=dict(component='StringEditQuantity'))
sample_owner = Quantity(
type=str,
shape=[],
description='Name or alias of the process operator, e.g. jmp',
a_eln=dict(component='StringEditQuantity'))
creation_datetime = Quantity(
type=Datetime,
description='Creation date of the sample.',
a_eln=dict(component='DateTimeEditQuantity'))
sample_short_name = Quantity(
type=str,
description='''A short name of the sample (the identifier scribed on the smaple,
or in the sample container), e.g. 4001-8, YAG-2-34.
This is to be managed and decided internally by the labs,
although we recomend to avoid the following characters on it: "_", "/", "\" and "."''',
a_eln=dict(component='StringEditQuantity'))
sample_id = Quantity(
type=str,
description='''Full sample id. Ideally a human readable sample id convention,
which is simple, understandable and still having chances of becoming unique.
If the `sample_owner`, `sample_short_name`, `ìnstitute`, and `creation_datetime`
are provided, this will be formed automatically by joining these components by an underscore (_).
Spaces in any of the individual components will be replaced with hyphens (-).
An example would be hzb_oah_20200602_4001-08''',
a_eln=dict(component='StringEditQuantity'))
children = Quantity(
type=Reference(SectionProxy('SampleID')),
shape=["*"],
descriptions='A reference to a sample which are children of this one.',
a_eln=dict(component='ReferenceEditQuantity'))
parents = Quantity(
type=Reference(SectionProxy('SampleID')),
descriptions='A reference to sample which are parents of this one.',
a_eln=dict(component='ReferenceEditQuantity'))
def normalize(self, archive, logger):
super().normalize(archive, logger)
if self.institute and self.sample_short_name and self.sample_owner and self.creation_datetime:
creation_date = self.creation_datetime.strftime('%Y%m%d')
sample_owner = self.sample_owner.replace(' ', '-')
sample_id_list = [self.institute, sample_owner, creation_date, self.sample_short_name]
self.sample_id = '_'.join(sample_id_list)
if isinstance(self, EntryData):
if archive.data == self and self.sample_id:
archive.metadata.entry_name = self.sample_id.replace('_', ' ')
EntryData.normalize(self, archive, logger)
if not archive.results:
archive.results = Results(eln=ELN())
if not archive.results.eln:
archive.results.eln = ELN()
if self.sample_id:
if not archive.results.eln.lab_ids:
archive.results.eln.lab_ids = []
archive.results.eln.lab_ids.append(self.sample_id.replace('_', ' '))
if not archive.results.eln.sections:
archive.results.eln.sections = []
archive.results.eln.sections.append(self.m_def.name)
m_package.__init_metainfo__()
......@@ -2154,7 +2154,9 @@ class ELN(MSection):
description='''
The laboratory specific id for any item, e.g. sample, chemical, instrument.
''',
a_elasticsearch=Elasticsearch(search_entry_type))
a_elasticsearch=[
Elasticsearch(search_entry_type),
Elasticsearch(suggestion='default')])
class Results(MSection):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment