Commits

Dan Connolly committed 2f5282e

script to make a sheet for coded values

Comments (0)

Files changed (1)

+import csv
+
+from dmtoterms import CDM, discrete_values
+
+
+def main(stdout):
+    rows = each_value()
+    sink = csv.DictWriter(stdout, rows[0].keys())
+    sink.writeheader()
+    sink.writerows(rows)
+
+
+def each_value():
+    val_fields = [field for field in CDM.fields()
+                  if field['VALUE_DESCRIPTION'].strip()]
+
+    return [
+        dict(TABLE_NAME=field['TABLE_NAME'],
+             FIELD_NAME=field['FIELD_NAME'],
+             CODE=code,
+             LABEL=label,
+             DESCRIPTION=field['DEFINITION'].encode('utf-8'))
+        for field in val_fields
+        for code, label in discrete_values(field['VALUE_DESCRIPTION'])]
+
+
+if __name__ == '__main__':
+    def trusted_top_level():
+        from sys import stdout
+        main(stdout)
+
+    trusted_top_level()