@@ -40,30 +40,16 @@ def __init__(
4040 async def load_all (self , resources : list [str ]) -> base .LoaderResults :
4141 # Are we doing a bulk FHIR export from a server?
4242 if self .root .protocol in ["http" , "https" ]:
43- results = await self .load_from_bulk_export (resources )
44- input_root = store .Root (results . path )
43+ bulk_dir = await self .load_from_bulk_export (resources )
44+ input_root = store .Root (bulk_dir . name )
4545 else :
4646 if self .export_to or self .since or self .until or self .resume :
4747 errors .fatal (
4848 "You provided FHIR bulk export parameters but did not provide a FHIR server" ,
4949 errors .ARGS_CONFLICT ,
5050 )
51-
52- results = base .LoaderResults (directory = self .root .path )
5351 input_root = self .root
5452
55- # Parse logs for export information
56- try :
57- parser = BulkExportLogParser (input_root )
58- results .group_name = parser .group_name
59- results .export_datetime = parser .export_datetime
60- except BulkExportLogParser .LogParsingError :
61- # Once we require group name & export datetime, we should warn about this.
62- # For now, just ignore any errors.
63- pass
64-
65- results .deleted_ids = self .read_deleted_ids (input_root )
66-
6753 # Copy the resources we need from the remote directory (like S3 buckets) to a local one.
6854 #
6955 # We do this even if the files are local, because the next step in our pipeline is the MS deid tool,
@@ -78,13 +64,12 @@ async def load_all(self, resources: list[str]) -> base.LoaderResults:
7864 filenames = common .ls_resources (input_root , set (resources ), warn_if_empty = True )
7965 for filename in filenames :
8066 input_root .get (filename , f"{ tmpdir .name } /" )
81- results .directory = tmpdir
8267
83- return results
68+ return self . read_loader_results ( input_root , tmpdir )
8469
8570 async def load_from_bulk_export (
8671 self , resources : list [str ], prefer_url_resources : bool = False
87- ) -> base . LoaderResults :
72+ ) -> common . Directory :
8873 """
8974 Performs a bulk export and drops the results in an export dir.
9075
@@ -109,12 +94,29 @@ async def load_from_bulk_export(
10994 except errors .FatalError as exc :
11095 errors .fatal (str (exc ), errors .BULK_EXPORT_FAILED )
11196
112- return base .LoaderResults (
113- directory = target_dir ,
114- group_name = bulk_exporter .group_name ,
115- export_datetime = bulk_exporter .export_datetime ,
97+ return target_dir
98+
99+ def read_loader_results (
100+ self , input_root : store .Root , results_dir : common .Directory
101+ ) -> base .LoaderResults :
102+ results = base .LoaderResults (
103+ directory = results_dir ,
104+ deleted_ids = self .read_deleted_ids (input_root ),
116105 )
117106
107+ # Parse logs for export information
108+ try :
109+ parser = BulkExportLogParser (input_root )
110+ results .group_name = parser .group_name
111+ results .export_datetime = parser .export_datetime
112+ results .export_url = parser .export_url
113+ except BulkExportLogParser .LogParsingError :
114+ # Once we require group name & export datetime, we should warn about this.
115+ # For now, just ignore any errors.
116+ pass
117+
118+ return results
119+
118120 def read_deleted_ids (self , root : store .Root ) -> dict [str , set [str ]]:
119121 """
120122 Reads any deleted IDs that a bulk export gave us.
0 commit comments