-
Notifications
You must be signed in to change notification settings - Fork 29
/
reference_old_to_new.py
25 lines (20 loc) · 1.11 KB
/
reference_old_to_new.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from django.core.management import BaseCommand
from core.collections.models import CollectionReference
from core.collections.parsers import CollectionReferenceExpressionStringParser
class Command(BaseCommand):
help = 'Reference Old to New Structure'
def handle(self, *args, **options):
for reference in CollectionReference.objects.filter(
expression__isnull=False, system__isnull=True, valueset__isnull=True):
print(f"Migrating {reference.uri}: {reference.expression}...")
parser = CollectionReferenceExpressionStringParser(expression=reference.expression)
parser.parse()
ref_struct = parser.to_reference_structure()[0]
reference.reference_type = ref_struct['reference_type']
reference.system = ref_struct['system']
reference.version = ref_struct['version']
reference.code = ref_struct['code']
reference.resource_version = ref_struct['resource_version']
reference.valueset = ref_struct['valueset']
reference.filter = ref_struct['filter']
reference.save()