generated from StanfordSpezi/SpeziTemplateApplication
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ab3df7
commit 040daef
Showing
13 changed files
with
261 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// This source file is part of the Stanford OwnYourData Application project | ||
// | ||
// SPDX-FileCopyrightText: 2023 Stanford University | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import CoreTransferable | ||
import OSLog | ||
|
||
|
||
struct ExportPackage: Transferable { | ||
static var transferRepresentation: some TransferRepresentation { | ||
FileRepresentation( | ||
exportedContentType: .zip, | ||
exporting: { document in | ||
try await SentTransferredFile(document.zipRepresentation) | ||
} | ||
) | ||
} | ||
|
||
|
||
let resources: [FHIRResource] | ||
|
||
private var directory: URL { | ||
FileManager.default.temporaryDirectory.appendingPathComponent( | ||
"edu.stanford.ownyourdate.export", | ||
isDirectory: true | ||
) | ||
} | ||
|
||
var zipRepresentation: URL { | ||
get async throws { | ||
if directory.exists { | ||
try FileManager.default.removeItem(at: directory) | ||
} | ||
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true, attributes: nil) | ||
|
||
for resource in resources { | ||
guard let id = resource.id else { | ||
os_log("Can not export resource named \(resource.displayName)") | ||
continue | ||
} | ||
|
||
let resourceJSONData = Data(resource.jsonDescription.utf8) | ||
try resourceJSONData.write(to: directory.appending(path: "\(id).json")) | ||
} | ||
|
||
let zipURL = try directory.zip() | ||
try FileManager.default.removeItem(at: directory) | ||
|
||
return zipURL | ||
} | ||
} | ||
|
||
|
||
func deleteZipRepresentation() throws { | ||
try FileManager.default.removeItem(at: directory.appendingPathExtension(".zip")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.