Skip to content

Commit

Permalink
Correct OPT path computation to include archetype ids.
Browse files Browse the repository at this point in the history
Add a new report for missing coding in templates.
  • Loading branch information
wolandscat committed Aug 29, 2024
1 parent cda879a commit f1dc766
Show file tree
Hide file tree
Showing 24 changed files with 611 additions and 31 deletions.
18 changes: 17 additions & 1 deletion apps/adlc/src/main/application.e
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ feature -- Commands

elseif opts.report then
generate_library_reports

extract_templates_missing_coding

elseif opts.inject_term_bindings then
inject_term_bindings

Expand Down Expand Up @@ -326,6 +327,21 @@ feature -- Commands
end
end

extract_templates_missing_coding
-- export all term bindings into one files per terminology namespace
-- Each file is a CSV file of the form
-- archetype_id, archetype_node_id, binding_value
local
action: TEMPLATES_MISSING_CODING
do
if opts.write_to_file_system and then attached opts.output_dir as att_op_dir then
create action.make (att_op_dir, agent report_std_out, agent report_std_err, agent :BOOLEAN do Result := error_reported end)
action.execute
else
report_std_err (get_msg ({ADL_MESSAGES_IDS}.ec_output_directory_required_err, <<>>))
end
end

clean_term_bindings
-- export all term bindings into one files per terminology namespace
-- Each file is a CSV file of the form
Expand Down
99 changes: 99 additions & 0 deletions apps/adlc/src/main/templates_missing_coding.e
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
note
component: "openEHR ADL Tools"
description :"Extract missing LOINC codes and missing value-sets for all templates"
keywords: "ADL, archetype, compiler, command line"
author: "Thomas Beale <[email protected]>"
support: "http://www.openehr.org/issues/browse/AWB"
copyright: "Copyright (c) 2024- Graphite Health <http://www.GraphiteHealth.io>"
license: "Apache 2.0 License <http://www.apache.org/licenses/LICENSE-2.0.html>"

class
TEMPLATES_MISSING_CODING

inherit
CLI_COMMAND
rename
make as make_cli
end

create
make

feature -- Initialization

make (an_output_dir: STRING; report_std_out_agt, report_std_err_agt: PROCEDURE [ANY, TUPLE[STRING]]; an_error_reported_agt: FUNCTION[ANY, TUPLE[], BOOLEAN])
do
make_cli (report_std_out_agt, report_std_err_agt, an_error_reported_agt)

output_dir := an_output_dir
if not file_system.is_absolute_pathname (output_dir) then
output_dir := file_system.pathname (file_system.current_working_directory, output_dir)
end
file_system.recursive_create_directory (output_dir)
if not file_system.directory_exists (output_dir) then
report_std_err (get_msg ({ADL_MESSAGES_IDS}.ec_invalid_output_directory, <<output_dir>>))
end
end

feature -- Commands

execute
-- export all term bindings into one files per terminology namespace
-- Each file is a CSV file of the form
-- archetype_id, archetype_node_id, binding_value
local
out_file: KI_TEXT_OUTPUT_FILE
output_filename: STRING
fac: JSON_SERIALIZATION_FACTORY
conv: JSON_SERIALIZATION
do
report_std_out ("--------- Exporting templates missing coding to " + output_dir + "---------")

current_library.do_for_all_templates (agent tpl_get_missing_codes)

output_filename := file_system.pathname (output_dir, "Template_missing_codes.json")
out_file := file_system.new_output_file (output_filename)

out_file.open_write
-- out_file.put_string (row_str)

conv := fac.smart_serialization
conv.set_pretty_printing
conv.context.serializer_context.set_is_type_name_included (False)

if attached conv.to_json_string (missing_codes_reports) as s then
out_file.put_string (s)
end

out_file.close

-- report_std_out (" Exported " + binding_count.out + " " + namespace + " bindings%N")
end

feature {NONE} -- Implementation

output_dir: STRING

missing_codes_reports: STRING_TABLE [STRING_TABLE [ARCHETYPE_MISSING_CODES_REPORT]]
-- reports of archetypes missing coding, keyed by template id
attribute
create Result.make(0)
end

tpl_get_missing_codes (aci: ARCH_LIB_TEMPLATE)
local
missing_codes_visitor: MISSING_CODES_VISITOR
c_iterator: OG_CONTENT_ITERATOR
do
if aci.is_valid then
create missing_codes_visitor
missing_codes_visitor.initialise (aci.opt)
create c_iterator.make (aci.opt.definition.representation, missing_codes_visitor)
c_iterator.do_all
missing_codes_visitor.finalise

missing_codes_reports.put (missing_codes_visitor.missing_codes_report, aci.id.as_string)
end
end

end
1 change: 1 addition & 0 deletions components/adl_compiler/src/interface/build_manager.e
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ feature -- Commands
end

build_artefact (ara: ARCH_LIB_ARCHETYPE)
-- just build a single artefact, don't do anything else
deferred
end

Expand Down
14 changes: 14 additions & 0 deletions components/archetype_repository/src/library/archetype_library.e
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,20 @@ feature -- Traversal
end
end

do_if_template (aci: ARCH_LIB_ITEM; action: PROCEDURE [ANY, TUPLE [ARCH_LIB_TEMPLATE]])
-- If `aci' is a template, perform `action' on it.
do
if attached {ARCH_LIB_TEMPLATE} aci as aca then
action.call ([aca])
end
end

do_for_all_templates (action: PROCEDURE [ANY, TUPLE [ARCH_LIB_TEMPLATE]])
-- On all templates, process all mentioned archetype with `action'
do
do_subtree (item_tree, agent do_if_template (?, action), Void)
end

do_archetype_lineage (aca: ARCH_LIB_ARCHETYPE; action: PROCEDURE [ANY, TUPLE [ARCH_LIB_ARCHETYPE]])
-- On all archetype nodes from top to `aca', execute `action'
local
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
note
component: "openEHR ADL Tools"
description: "Record missing codes for a templated archetype"
keywords: "export, archetype, ADL"
author: "Thomas Beale <[email protected]>"
support: "openEHR AWB project <http://www.openehr.org/issues/browse/AWB>"
copyright: "Copyright (c) 2024 Graphite Health"
license: "Apache 2.0 License <http://www.apache.org/licenses/LICENSE-2.0.html>"

class ARCHETYPE_MISSING_CODES

inherit
ADL_2_TERM_CODE_TOOLS
export
{NONE} all
end

create
make

feature -- Initialisation

make (an_archetype_root: C_COMPLEX_OBJECT; an_archetype_id, a_template_id, a_template_path: STRING)
do
archetype_root := an_archetype_root
archetype_id := an_archetype_id
template_id := a_template_id
template_path := a_template_path

create missing_id_code_bindings_table.make(0)
create missing_value_sets_table.make(0)

create missing_id_code_bindings.make(0)
create missing_value_sets.make(0)
end

feature -- Access

archetype_root: C_COMPLEX_OBJECT

archetype_id: STRING

template_id: STRING

template_path: STRING

missing_id_code_bindings: STRING_TABLE [STRING]
-- nodes with missing id-code bindings, keyed by id-code

missing_value_sets: STRING_TABLE [TUPLE [c_terminology_node_ac_code: STRING; value_set: detachable ARRAYED_LIST[STRING]]]
-- coded nodes with missing value-set bindings, keyed by id-code of owning object

add_missing_id_code_binding (a_c_node: C_OBJECT; a_term_desc: STRING)
do
missing_id_code_bindings_table.put ([a_c_node, a_term_desc], a_c_node.path_to_node (archetype_root))
missing_id_code_bindings.put (a_term_desc, a_c_node.path_to_node (archetype_root))
end

add_missing_value_set (a_c_terminology_node: C_TERMINOLOGY_CODE; identified_parent: C_COMPLEX_OBJECT; a_terminology: ARCHETYPE_TERMINOLOGY)
local
value_set_terms: ARRAYED_LIST[STRING]
identified_parent_term_desc: STRING
do
identified_parent_term_desc := a_terminology.term_definition (default_language, identified_parent.node_id).text
if a_terminology.value_sets.has (a_c_terminology_node.constraint) and attached a_terminology.value_sets.item (a_c_terminology_node.constraint) as vset then
create value_set_terms.make (0)
across vset.members as vset_csr loop
value_set_terms.extend (annotated_code (vset_csr.item, a_terminology.term_definition (a_terminology.default_language, vset_csr.item).text, ""))
end
end
missing_value_sets_table.put ([a_c_terminology_node, identified_parent_term_desc, value_set_terms], identified_parent.node_id)
missing_value_sets.put ([annotated_code (a_c_terminology_node.constraint, a_terminology.term_definition (default_language, a_c_terminology_node.constraint).text, ""), value_set_terms],
annotated_code (identified_parent.node_id, identified_parent_term_desc, ""))
end

as_report: ARCHETYPE_MISSING_CODES_REPORT
do
create Result.make (Current)
end

feature -- Status Report

is_empty: BOOLEAN
do
Result := missing_id_code_bindings_table.is_empty and missing_value_sets_table.is_empty
end

feature {NONE} -- Implementation

missing_id_code_bindings_table: STRING_TABLE [TUPLE [c_node: C_OBJECT; term_desc: STRING]]
-- nodes with missing id-code bindings, keyed by id-code

missing_value_sets_table: STRING_TABLE [TUPLE [c_terminology_node: C_TERMINOLOGY_CODE; term_desc: STRING; value_set: detachable ARRAYED_LIST[STRING]]]
-- coded nodes with missing value-set bindings, keyed by id-code of owning object

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
note
component: "openEHR ADL Tools"
description: "Record missing codes for a templated archetype"
keywords: "export, archetype, ADL"
author: "Thomas Beale <[email protected]>"
support: "openEHR AWB project <http://www.openehr.org/issues/browse/AWB>"
copyright: "Copyright (c) 2024 Graphite Health"
license: "Apache 2.0 License <http://www.apache.org/licenses/LICENSE-2.0.html>"

class ARCHETYPE_MISSING_CODES_REPORT

create
make

feature -- Initialisation

make (source: ARCHETYPE_MISSING_CODES)
do
archetype_id := source.archetype_id
missing_id_code_bindings := source.missing_id_code_bindings
missing_value_sets := source.missing_value_sets
end

feature -- Access

archetype_id: STRING

missing_id_code_bindings: STRING_TABLE [STRING]
-- nodes with missing id-code bindings, keyed by id-code

missing_value_sets: STRING_TABLE [TUPLE [c_terminology_node_ac_code: STRING; value_set: detachable ARRAYED_LIST[STRING]]]
-- coded nodes with missing value-set bindings, keyed by id-code of owning object

end
Loading

0 comments on commit f1dc766

Please sign in to comment.