Skip to content

Commit

Permalink
add innolitics license and make generate script more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
lnogueir committed May 29, 2024
1 parent 221bd7f commit 17e30f5
Show file tree
Hide file tree
Showing 3 changed files with 5,179 additions and 5,149 deletions.
45 changes: 32 additions & 13 deletions pkg/tag/generate_tag_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@

INNOLITICS_VERSION_HASH = "8670abdd9ad16c61af5146ef857899699bdd9c5f" # rev2024b (please, update this comment when changing hash value)

INNOLITICS_CREDITS = f'''// This file's contents are derived from the innolitics json representation of the dicom standard.
// The innolitics source is licensed as follows:
// https://github.com/innolitics/dicom-standard/blob/{INNOLITICS_VERSION_HASH}/LICENSE.txt
//
// Copyright (c) 2017 Innolitics, LLC.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.'''

Tag = NamedTuple('Tag', [
('group', int),
('elem', int),
Expand Down Expand Up @@ -36,27 +60,22 @@ def read_tags_from_innolitics(version_hash: str) -> List[Tag]:
if (resolvable_tag_id := e["id"].replace("x", "0")) and len(e["keyword"]) > 0
]

def tagDictEntry(t: Tag) -> str:
wrap_in_quotes = lambda s: f'\"{s}\"'
start_indent = ' '
return f'{start_indent}{t.keyword}: Info{{{t.keyword}, []string{{{", ".join(map(wrap_in_quotes, t.vr))}}}, "{t.name}", "{t.keyword}", "{t.vm}", {str(t.retired).lower()}}},'

def generate(out: IO[str]):
tags = read_tags_from_innolitics(INNOLITICS_VERSION_HASH)
new_line = chr(10)
wrap_in_quotes = lambda s: f'\"{s}\"'
print(f'''// AUTO-GENERATED from generate_tag_definitions.py. DO NOT EDIT.
{INNOLITICS_CREDITS}
package tag
{new_line.join(f"var {t.keyword} = Tag{{0x{t.group:04x}, 0x{t.elem:04x}}}" for t in tags)}
var tagDict map[Tag]Info
func init() {{
maybeInitTagDict()
}}
func maybeInitTagDict() {{
if len(tagDict) > 0 {{
return
}}
tagDict = make(map[Tag]Info)
{new_line.join(f' tagDict[{t.keyword}] = Info{{{t.keyword}, []string{{{", ".join(map(wrap_in_quotes, t.vr))}}}, "{t.name}", "{t.keyword}", "{t.vm}", {str(t.retired).lower()}}}' for t in tags)}
var tagDict = map[Tag]Info{{
{new_line.join(tagDictEntry(t) for t in tags)}
}}''', file=out)

def main():
Expand Down
2 changes: 0 additions & 2 deletions pkg/tag/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ func GetVRKind(tag Tag, vr string) VRKind {
// Find finds information about the given tag. If the tag is not part of
// the DICOM standard, or is retired from the standard, it returns an error.
func Find(tag Tag) (Info, error) {
maybeInitTagDict()
entry, ok := tagDict[tag]
if !ok {
// (0000-u-ffff,0000) UL GenericGroupLength 1 GENERIC
Expand Down Expand Up @@ -198,7 +197,6 @@ func MustFind(tag Tag) Info {
//
// Example: FindTagByKeyword("TransferSyntaxUID")
func FindByKeyword(keyword string) (Info, error) {
maybeInitTagDict()
for _, ent := range tagDict {
if ent.Keyword == keyword || ent.Name == keyword {
return ent, nil
Expand Down
Loading

0 comments on commit 17e30f5

Please sign in to comment.