Documentation ¶
Index ¶
- Variables
- type Batch
- type ConceptIDStream
- type ConceptReferenceStream
- type ConceptStream
- type DescriptionStream
- type Descriptor
- type ExtendedDescriptionStream
- type Importer
- type Language
- type NoopStorer
- type Search
- type Statistics
- type Store
- type Storer
- type Svc
- func (svc *Svc) AllChildren(ctx context.Context, concept *snomed.Concept, maximum int) ([]*snomed.Concept, error)
- func (svc *Svc) AllChildrenIDs(ctx context.Context, conceptID int64, maximum int) (children []int64, err error)
- func (svc *Svc) AllParentIDs(conceptID int64) ([]int64, error)
- func (svc *Svc) AllParents(conceptID int64) ([]*snomed.Concept, error)
- func (svc *Svc) AvailableLanguages() ([]language.Tag, error)
- func (svc *Svc) ChildRelationships(conceptID int64) ([]*snomed.Relationship, error)
- func (svc *Svc) Children(conceptID int64) ([]int64, error)
- func (svc *Svc) ChildrenOfKind(conceptID int64, kind int64) ([]int64, error)
- func (svc *Svc) ClearPrecomputations() error
- func (svc *Svc) Close() error
- func (svc *Svc) ComponentFromReferenceSet(refset int64, component int64) ([]*snomed.ReferenceSetItem, error)
- func (svc *Svc) ComponentReferenceSets(referencedComponentID int64) ([]int64, error)
- func (svc *Svc) Concept(conceptID int64) (*snomed.Concept, error)
- func (svc *Svc) ConceptReference(conceptID int64, tags []language.Tag) (*snomed.ConceptReference, error)
- func (svc *Svc) Concepts(conceptIDs ...int64) ([]*snomed.Concept, error)
- func (svc *Svc) ConceptsForRelationship(rel *snomed.Relationship) (source *snomed.Concept, kind *snomed.Concept, target *snomed.Concept, ...)
- func (svc *Svc) Description(descriptionID int64) (*snomed.Description, error)
- func (svc *Svc) Descriptions(conceptID int64) (result []*snomed.Description, err error)
- func (svc *Svc) Export(lang string) error
- func (svc *Svc) ExtendedConcept(conceptID int64, tags []language.Tag) (result *snomed.ExtendedConcept, err error)
- func (svc *Svc) Extract(r *snomed.ExtractRequest, tags []language.Tag) (*snomed.ExtractResponse, error)
- func (svc *Svc) FullySpecifiedName(concept *snomed.Concept, tags []language.Tag) (*snomed.Description, error)
- func (svc *Svc) GenericiseTo(conceptID int64, includeParents bool, generics map[int64]struct{}) ([]int64, error)
- func (svc *Svc) GenericiseToBest(conceptID int64, generics map[int64]struct{}) (int64, error)
- func (svc *Svc) GenericiseToRoot(conceptID int64, root int64) (int64, error)
- func (svc *Svc) GetAssociations(conceptID int64, refsetID int64) ([]int64, error)
- func (svc *Svc) InstalledReferenceSets() (map[int64]struct{}, error)
- func (svc *Svc) IsA(concept *snomed.Concept, parent int64) bool
- func (svc *Svc) IsInReferenceSet(referencedComponentID int64, refsetID int64) (result bool, err error)
- func (svc *Svc) IsLateralisable(id int64) (bool, error)
- func (svc *Svc) IterateConcepts(ctx context.Context) <-chan ConceptStream
- func (svc *Svc) LongestPathToRoot(conceptID int64) (longest []int64, err error)
- func (svc *Svc) MapTarget(refset int64, target string) ([]*snomed.ReferenceSetItem, error)
- func (svc *Svc) MustGetFullySpecifiedName(concept *snomed.Concept, tags []language.Tag) *snomed.Description
- func (svc *Svc) MustGetPreferredSynonym(conceptID int64, tags []language.Tag) *snomed.Description
- func (svc *Svc) ParentIDsOfKind(conceptID int64, kinds ...int64) ([]int64, error)
- func (svc *Svc) ParentRelationships(conceptID int64) ([]*snomed.Relationship, error)
- func (svc *Svc) Parents(conceptID int64) ([]int64, error)
- func (svc *Svc) PathsToRoot(conceptID int64) ([][]int64, error)
- func (svc *Svc) PerformPrecomputations(ctx context.Context, batchSize int, verbose bool) error
- func (svc *Svc) PreferredSynonym(conceptID int64, tags []language.Tag) (*snomed.Description, error)
- func (svc *Svc) PreferredSynonymByReferenceSet(conceptID int64, refsetID int64, tags []language.Tag) (*snomed.Description, error)
- func (svc *Svc) Primitive(concept *snomed.Concept) (*snomed.Concept, error)
- func (svc *Svc) Put(context context.Context, components interface{}) error
- func (svc *Svc) ReferenceSetComponents(refset int64) (map[int64]struct{}, error)
- func (svc *Svc) ReferenceSetItem(itemID string) (*snomed.ReferenceSetItem, error)
- func (svc *Svc) Refinements(conceptID int64, limit int, tags []language.Tag) (*snomed.RefinementResponse, error)
- func (svc *Svc) Search(req *snomed.SearchRequest, tags []language.Tag) (*snomed.SearchResponse, error)
- func (svc *Svc) ShortestPathToRoot(conceptID int64) (shortest []int64, err error)
- func (svc *Svc) Siblings(conceptID int64) ([]int64, error)
- func (svc *Svc) Statistics(lang string, verbose bool) (Statistics, error)
- func (svc *Svc) StreamAllChildrenIDs(ctx context.Context, conceptID int64, maximum int) <-chan ConceptIDStream
- func (svc *Svc) StreamConceptReferences(ctx context.Context, concepts <-chan ConceptIDStream, nchannels int, ...) <-chan ConceptReferenceStream
Constants ¶
This section is empty.
Variables ¶
var ErrDatabaseNotInitialised = errors.New("database not initialised")
ErrDatabaseNotInitialised is the error when database not properly initialised
var ErrNotFound = errors.New("not found")
ErrNotFound is the error when something isn't found
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch interface { // Get an object from the specified bucket with the specified key Get(b bucket, key []byte, value proto.Message) error // Put and object into the specified bucket with the specified key, errors deferred until end of batch Put(b bucket, key []byte, value proto.Message) // Add an index entry for the specified bucket and key, errors deferred until end of batch AddIndexEntry(b bucket, key []byte, value []byte) // Does an index entry exist? CheckIndexEntry(b bucket, key []byte, value []byte) (bool, error) // Clear all entries in the bucket specified ClearIndexEntries(b bucket) // Get all index entries for the specified bucket and key GetIndexEntries(b bucket, key []byte) ([][]byte, error) // Iterate iterates through a bucket Iterate(b bucket, keyPrefix []byte, f func(key, value []byte) error) error }
Batch represents an abstract batch operation against the KV store
type ConceptIDStream ¶
ConceptIDStream wraps a concept identifier with an error, for use in streaming
type ConceptReferenceStream ¶
type ConceptReferenceStream struct { *snomed.ConceptReference Err error }
ConceptReferenceStream wraps a concept reference with an error, helpful when streaming via channels
type ConceptStream ¶
ConceptStream wraps a concept identifier with an error, for use in streaming
type DescriptionStream ¶
type DescriptionStream struct { *snomed.Description Err error }
DescriptionStream is for use in streaming descriptions
type Descriptor ¶
Descriptor provides a simple structure for file-backed database versioning and configuration.
type ExtendedDescriptionStream ¶
type ExtendedDescriptionStream struct { *snomed.ExtendedDescription Err error }
ExtendedDescriptionStream is for use in streaming extended descriptions
type Importer ¶
type Importer struct { snomed.ImportChannels // contains filtered or unexported fields }
Importer manages the import of SNOMED CT components from the filesystem
func NewImporter ¶
NewImporter creates a new Importer
type Language ¶
type Language int
Language defines a mapping between standard ISO language tags and the associated SNOMED-CT language reference sets TODO: add more supported languages TODO: check that the refset identifiers are correct TODO: add tests for other languages
func LanguageForTag ¶
LanguageForTag returns the language for the specified tag
func (Language) LanguageReferenceSetIdentifier ¶
LanguageReferenceSetIdentifier returns the SNOMED-CT identifier for the language reference set for this language
type NoopStorer ¶
type NoopStorer struct{}
NoopStorer is a no-op storer, which does nothing with the results. Useful for profiling.
type Search ¶
type Search interface { Index(eds []*snomed.ExtendedDescription) error Search(sr *snomed.SearchRequest) ([]int64, error) //TODO: rename autocomplete Statistics() (uint64, error) Close() error }
Search represents the backend opaque abstract SNOMED-CT search service.
type Statistics ¶
type Statistics struct {
// contains filtered or unexported fields
}
Statistics on the persistence store
func (Statistics) String ¶
func (st Statistics) String() string
type Store ¶
type Store interface { // View creates a read-only transaction View(func(Batch) error) error // Update creates a read and write transaction Update(func(Batch) error) error // Close closes any resources associated with the key-value store Close() error }
Store is an abstract key-value store divided into logical buckets of information.
type Storer ¶
Storer defines the behaviour of a service that can accept a batch of SNOMED components for storage.
type Svc ¶
type Svc struct { Descriptor // contains filtered or unexported fields }
Svc encapsulates concrete persistent and search services and extends it by providing semantic inference and a useful, practical SNOMED-CT API.
The current priority of development is correct behaviour rather than optimisation, although most operations are extremely fast already.
TODO(mw): once 'correct', profile and optimise the slowest paths, likely adding multiple caches for the most commonly derived data structures and putting more functionality within the backend transaction, when appropriate. It won't be until API complete that we'll understand the pinch points.
It is likely that the transitive closure lists will need more caching, but it is unclear whether that is a simple flat list or, more likely now with more complex logic for expressions, the individual paths to root.
func NewService ¶
NewService opens or creates a service at the specified location.
func (*Svc) AllChildren ¶
func (svc *Svc) AllChildren(ctx context.Context, concept *snomed.Concept, maximum int) ([]*snomed.Concept, error)
AllChildren fetches all children of the given concept recursively. Use with caution with concepts at high levels of the hierarchy.
func (*Svc) AllChildrenIDs ¶
func (svc *Svc) AllChildrenIDs(ctx context.Context, conceptID int64, maximum int) (children []int64, err error)
AllChildrenIDs returns all children for the specified concept. As this is potentially a very large number, you must specify an indicative maximum number.
func (*Svc) AllParentIDs ¶
AllParentIDs returns a list of the identifiers for all parents TODO(mw): switch to using transitive closure
func (*Svc) AllParents ¶
AllParents returns all of the parents (recursively) for a given concept
func (*Svc) AvailableLanguages ¶
AvailableLanguages returns the languages supported by the currently installed distribution Note: the sorting of the results is important for language matching, because the first matching language will be chosen, so we finish by sorting the result.
func (*Svc) ChildRelationships ¶
func (svc *Svc) ChildRelationships(conceptID int64) ([]*snomed.Relationship, error)
ChildRelationships returns the child relationships for this concept. Child relationships are relationships in which this concept is the destination.
func (*Svc) ChildrenOfKind ¶
ChildrenOfKind returns the relations of the specified kind (type) of the specified concept.
func (*Svc) ClearPrecomputations ¶
ClearPrecomputations clears all pre-computations and indices
func (*Svc) ComponentFromReferenceSet ¶
func (svc *Svc) ComponentFromReferenceSet(refset int64, component int64) ([]*snomed.ReferenceSetItem, error)
ComponentFromReferenceSet gets the specified components from the specified refset, or error
func (*Svc) ComponentReferenceSets ¶
ComponentReferenceSets returns the refset identifiers to which this component is a member
func (*Svc) ConceptReference ¶
func (svc *Svc) ConceptReference(conceptID int64, tags []language.Tag) (*snomed.ConceptReference, error)
ConceptReference creates a reference for the specified concept. This is generally more useful than simply getting the Concept itself!
func (*Svc) ConceptsForRelationship ¶
func (svc *Svc) ConceptsForRelationship(rel *snomed.Relationship) (source *snomed.Concept, kind *snomed.Concept, target *snomed.Concept, err error)
ConceptsForRelationship returns the concepts represented within a relationship
func (*Svc) Description ¶
func (svc *Svc) Description(descriptionID int64) (*snomed.Description, error)
Description returns the description with the given identifier
func (*Svc) Descriptions ¶
func (svc *Svc) Descriptions(conceptID int64) (result []*snomed.Description, err error)
Descriptions returns the descriptions for a concept
func (*Svc) Export ¶
Export exports all descriptions in delimited protobuf format to the command line.
func (*Svc) ExtendedConcept ¶
func (svc *Svc) ExtendedConcept(conceptID int64, tags []language.Tag) (result *snomed.ExtendedConcept, err error)
ExtendedConcept returns a denormalised representation of a SNOMED CT concept
func (*Svc) Extract ¶
func (svc *Svc) Extract(r *snomed.ExtractRequest, tags []language.Tag) (*snomed.ExtractResponse, error)
Extract using NLP to extract entities from a block of text using Amazon Comprehend's API
func (*Svc) FullySpecifiedName ¶
func (svc *Svc) FullySpecifiedName(concept *snomed.Concept, tags []language.Tag) (*snomed.Description, error)
FullySpecifiedName returns the FSN (fully specified name) for the given concept, from the language reference sets specified, in order of preference
func (*Svc) GenericiseTo ¶
func (svc *Svc) GenericiseTo(conceptID int64, includeParents bool, generics map[int64]struct{}) ([]int64, error)
GenericiseTo returns the matches for the given concept within the set specified, ordered from best to worst. It scores by looking at the paths from concept to root.
func (*Svc) GenericiseToBest ¶
GenericiseToBest returns the best match for the given concept in the set of concepts specified. The "best" is chosen as the closest match to the specified concept and so if there are generic concepts which relate to one another, it will be the most specific (closest) match to the concept. To determine this, we use the closest match of the longest path.
func (*Svc) GenericiseToRoot ¶
GenericiseToRoot walks the SNOMED-CT IS-A hierarchy to find the most general concept beneath the specified root. This finds the shortest path from the concept to the specified root and then returns one concept *down* from that root.
func (*Svc) GetAssociations ¶
GetAssociations returns the associations for the specified concept e.g. to get the SAME_AS associations for a concept, GetAssociations(conceptID, snomed.SameAsReferenceSet)
func (*Svc) InstalledReferenceSets ¶
InstalledReferenceSets returns a list of installed reference sets
func (*Svc) IsInReferenceSet ¶
func (svc *Svc) IsInReferenceSet(referencedComponentID int64, refsetID int64) (result bool, err error)
IsInReferenceSet returns whether the specified component is in the specified reference set
func (*Svc) IsLateralisable ¶
IsLateralisable finds out whether the specific concept is lateralisable
func (*Svc) IterateConcepts ¶
func (svc *Svc) IterateConcepts(ctx context.Context) <-chan ConceptStream
IterateConcepts is an iterator for all concepts, useful for pre-processing and pre-computations
func (*Svc) LongestPathToRoot ¶
LongestPathToRoot returns the longest path to the root concept from the specified concept
func (*Svc) MapTarget ¶
MapTarget returns the simple and complex maps for which the specified target, is the target
func (*Svc) MustGetFullySpecifiedName ¶
func (svc *Svc) MustGetFullySpecifiedName(concept *snomed.Concept, tags []language.Tag) *snomed.Description
MustGetFullySpecifiedName returns the FSN for the given concept, or panics if there is an error or it is missing from the language reference sets specified, in order of preference
func (*Svc) MustGetPreferredSynonym ¶
MustGetPreferredSynonym returns the preferred synonym for the specified concept, using the language preferences specified, in order of preference
func (*Svc) ParentIDsOfKind ¶
ParentIDsOfKind returns the active relations of the specified kinds (types) for the specified concept Unfortunately, SNOMED-CT isn't perfect and there are some duplicate relationships so we filter these and return only unique results
func (*Svc) ParentRelationships ¶
func (svc *Svc) ParentRelationships(conceptID int64) ([]*snomed.Relationship, error)
ParentRelationships returns the parent relationships for this concept. Parent relationships are relationships in which this concept is the source.
func (*Svc) PathsToRoot ¶
PathsToRoot returns the different possible paths to the root SNOMED-CT concept from this one. The passed in concept will be the first entry of each path, the SNOMED root will be the last.
func (*Svc) PerformPrecomputations ¶
PerformPrecomputations runs all pre-computations and generation of indices
func (*Svc) PreferredSynonym ¶
PreferredSynonym returns the preferred synonym the specified concept based on the language preferences specified, in order of preference
func (*Svc) PreferredSynonymByReferenceSet ¶
func (svc *Svc) PreferredSynonymByReferenceSet(conceptID int64, refsetID int64, tags []language.Tag) (*snomed.Description, error)
PreferredSynonymByReferenceSet determines the preferred synonym by virtue of member of the description in the specified (language) reference set. This is a more appropriate way of determining preferred synonym for concepts within, for example, the UK dm+d. See https://www.nhsbsa.nhs.uk/sites/default/files/2018-10/doc_SnomedCTUKDrugExtensionModel%20-%20v1.0.pdf and see references to the "dm+d realm description refset". This falls back to standard language based preferred term.
func (*Svc) Primitive ¶
Primitive finds the closest primitive for the specified concept in the hierarchy
func (*Svc) Put ¶
Put a slice of SNOMED-CT components into persistent storage. This is polymorphic but expects a slice of SNOMED CT components
func (*Svc) ReferenceSetComponents ¶
ReferenceSetComponents returns the components within a given reference set
func (*Svc) ReferenceSetItem ¶
func (svc *Svc) ReferenceSetItem(itemID string) (*snomed.ReferenceSetItem, error)
ReferenceSetItem returns the specified reference set item
func (*Svc) Refinements ¶
func (svc *Svc) Refinements(conceptID int64, limit int, tags []language.Tag) (*snomed.RefinementResponse, error)
Refinements determines the appropriate refinements for an arbitrary concept It is quite easy to do, we find the relationships and additionally determine whether the concept's attributes exist in the lateralisable reference set. TODO: this would be better deprecated in favour of using only expressions that would mean normalising any concept into an expression and *then* deriving possible refinements for that expression, instead.
func (*Svc) Search ¶
func (svc *Svc) Search(req *snomed.SearchRequest, tags []language.Tag) (*snomed.SearchResponse, error)
Search searches the SNOMED CT hierarchy
func (*Svc) ShortestPathToRoot ¶
ShortestPathToRoot returns the shortest path to the root concept from the specified concept
func (*Svc) Siblings ¶
Siblings returns the siblings of this concept, ie: those who share the same parents
func (*Svc) Statistics ¶
func (svc *Svc) Statistics(lang string, verbose bool) (Statistics, error)
Statistics returns statistics for the backend store
func (*Svc) StreamAllChildrenIDs ¶
func (svc *Svc) StreamAllChildrenIDs(ctx context.Context, conceptID int64, maximum int) <-chan ConceptIDStream
StreamAllChildrenIDs streams all of the children of the specified concept. The maximum is used as an indicative measure, rather than an absolutely exact target.
func (*Svc) StreamConceptReferences ¶
func (svc *Svc) StreamConceptReferences(ctx context.Context, concepts <-chan ConceptIDStream, nchannels int, tags []language.Tag) <-chan ConceptReferenceStream
StreamConceptReferences is a helper function to turn a stream of identifiers into a stream of (more useful) ConceptReferences.