From 0e26499c6048ef76e67f61eb6632d0e297b3a3a3 Mon Sep 17 00:00:00 2001 From: Tamara Slosarek Date: Thu, 6 Jun 2024 14:23:38 +0200 Subject: [PATCH] feat(scripts): add script to unstage all data --- pharme.code-workspace | 2 ++ scripts/README.md | 8 ++++++++ scripts/common/constants.py | 1 + scripts/reset.py | 11 ----------- scripts/unstage.py | 14 ++++++++++++++ 5 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 scripts/unstage.py diff --git a/pharme.code-workspace b/pharme.code-workspace index a801571c..e19a5fdb 100644 --- a/pharme.code-workspace +++ b/pharme.code-workspace @@ -77,6 +77,8 @@ "tacrolimus", "tramadol", "unscrollable", + "unstage", + "unstaged", "userdata", "voriconazole" ] diff --git a/scripts/README.md b/scripts/README.md index 361b9d70..7fc36147 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -38,6 +38,14 @@ by deleting the history data and published data. Run `python reset.py .base64` to receive `_reset_.base64`. +## Unstage data + +This is probably a use case only relevant once, we want to unstage all data and +do a second review. + +Run `python unstage.py .base64` to receive +`_reset_.base64`. + ## Migrate data Run `pyhthon migrate.py [.json|.base64]` to receive diff --git a/scripts/common/constants.py b/scripts/common/constants.py index e5844644..d98f9e77 100644 --- a/scripts/common/constants.py +++ b/scripts/common/constants.py @@ -12,6 +12,7 @@ 'encode': '_encoded', 'correct': '_corrected', 'reset': '_reset', + 'unstage': '_unstaged', } DRUG_COLLECTION_NAME = 'Drug' diff --git a/scripts/reset.py b/scripts/reset.py index 6b637fe2..f48d384b 100644 --- a/scripts/reset.py +++ b/scripts/reset.py @@ -1,18 +1,7 @@ -import copy - from common.get_data import get_data -from common.get_data import get_information_key -from common.get_data import get_guidelines_by_ids -from common.get_data import get_phenotype_value_lengths -from common.get_data import get_phenotype_value -from common.get_data import get_phenotype_key from common.write_data import write_data -from common.constants import DRUG_COLLECTION_NAME -from common.constants import GUIDELINE_COLLECTION_NAME from common.constants import SCRIPT_POSTFIXES -from common.cpic_data import get_phenotype_map from common.remove_history import remove_history -from common.mongo import get_object_id # Migrate data def reset_data(): diff --git a/scripts/unstage.py b/scripts/unstage.py new file mode 100644 index 00000000..1f1b1eab --- /dev/null +++ b/scripts/unstage.py @@ -0,0 +1,14 @@ +from common.get_data import get_data +from common.write_data import write_data +from common.constants import SCRIPT_POSTFIXES + +def unstage_data(): + data = get_data() + for table_name in data.keys(): + for item in data[table_name]: + if 'isStaged' in item.keys(): + item['isStaged'] = False + write_data(data, postfix=SCRIPT_POSTFIXES['unstage']) + +if __name__ == '__main__': + unstage_data() \ No newline at end of file