-
Notifications
You must be signed in to change notification settings - Fork 0
/
PSEudamed.PS1
332 lines (287 loc) · 10.2 KB
/
PSEudamed.PS1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# verschiedene Powershell-Funktionen um die Eudamed abfragen zu können
Function Set-Culture([System.Globalization.CultureInfo] $culture)
{
[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
}
Function Get-EudamedPagedData {
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[String]$Url,
[switch]$OnlyTotalElements,
[switch]$JsonDirect
)
$page=0
$pages=1
$waitAfterPages=100
If ($OnlyTotalElements) {
$size = 1 # Daten auf ein Minimum reduzieren, kleiner 1 geht scheinbar nicht
} else {
$size=300 # scheinbar gehen nicht mehr als 300 maximal
}
$last=$false
while (-Not $last) {
If ($Url -match '\?') {
$NewUrl="$Url&page=$page&pageSize=$size&size=$size"
} else {
$NewUrl="$($Url)?page=$page&pageSize=$size&size=$size"
}
Write-Verbose "Aufruf: $NewUrl"
$r=Invoke-WebRequest $NewUrl -UseBasicParsing
$j=Convertfrom-json $r.content
If ($j.number -eq 0) {
Write-Verbose "TotalPages: $($j.totalPages)"
Write-Verbose "TotalElements: $($j.totalElements)"
$Pages = $j.totalPages
}
Write-Verbose "Page: $($j.number+1)/$Pages"
$last=$j.last
$page++
If (($WaitAfterPages -gt 0) -and ($page%$WaitAfterPages -eq 0)) {
Start-Sleep -Seconds 1
}
If ($OnlyTotalElements) {
$j.totalElements
$last = $true
} else {
If ($JsonDirect) {
$j
} else {
$j.content
}
}
}
}
Function Get-EudamedPagedDataCountry {
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[String]$Url,
[String]$Country='DE'
)
Get-EudamedPagedData -Url "$Url&countryIso2Code=$Country"
}
Function Get-EudamedEO {
[CmdletBinding()]
Param()
# mögliche Parameter: entityTypeCode=certificate.certificates
$Url = 'https://ec.europa.eu/tools/eudamed/api/eos/?languageIso2Code=de'
Get-EudamedPagedData -Url "$Url"
}
Function Get-EudamedNotifiedBodies {
[CmdletBinding()]
Param()
# mögliche Parameter: entityTypeCode=certificate.certificates
$Url = 'https://ec.europa.eu/tools/eudamed/api/ses/notifiedBodies?languageIso2Code=de'
Get-EudamedPagedData -Url "$Url" -JsonDirect
}
Function Get-EudamedCertificates {
[CmdletBinding()]
Param(
[Parameter(ParameterSetName='NotifiedBodySrn',Position=0,ValueFromPipelineByPropertyName,Mandatory=$false)]
[String]$NotifiedBodySrn
)
# mögliche Parameter: entityTypeCode=certificate.certificates
If ($NotifiedBodySrn) {
$Url = "https://ec.europa.eu/tools/eudamed/api/certificates/search/?languageIso2Code=de¬ifiedBodySrn=$NotifiedBodySrn"
} else {
$Url = 'https://ec.europa.eu/tools/eudamed/api/certificates/search/?languageIso2Code=de'
}
Get-EudamedPagedData -Url "$Url"
}
# Uuid liefert mehr Informationen
Function Get-EudamedCertificateDetail {
[CmdletBinding()]
Param(
[Parameter(ParameterSetName='Uuid',Position=0,ValueFromPipelineByPropertyName,Mandatory)]
[String]$Uuid
)
Process {
If ($PSCmdlet.ParameterSetName -eq 'Uuid') {
$Url = "https://ec.europa.eu/tools/eudamed/api/certificates/$Uuid/?languageIso2Code=de"
}
$r=Invoke-WebRequest "$Url" -UseBasicParsing
If ($PSCmdlet.ParameterSetName -eq 'Uuid') {
ConvertFrom-Json $r.Content
} else {
# (ConvertFrom-Json $r.Content).Content # Irgendwie nochmal geschachtelt, können srn Wildcards enthalten?!?!?
}
}
}
# Uuid muss eine Document UUID sein (z. B. von CertificateDetail)
Function Get-EudamedCertificateDownload {
[CmdletBinding()]
Param(
[Parameter(ParameterSetName='Uuid',Position=0,Mandatory)]
[String]$Uuid,
[Parameter(ParameterSetName='Uuid',Position=1)]
[Switch]$SaveFile,
[Parameter(ParameterSetName='Uuid',Position=2)]
[String]$Path
)
If ($PSCmdlet.ParameterSetName -eq 'Uuid') {
$Url = "https://ec.europa.eu/tools/eudamed/api/documents/$Uuid/?languageIso2Code=de"
}
If ($SaveFile) {
$Parameter = @{OutFile=$Path}
} else {
$Parameter = @{}
}
$r=Invoke-WebRequest "$Url" -UseBasicParsing @Parameter
If ($PSCmdlet.ParameterSetName -eq 'Uuid') {
If (-Not ($SaveFile)) {
$r.Content
}
} else {
# (ConvertFrom-Json $r.Content).Content # Irgendwie nochmal geschachtelt, können srn Wildcards enthalten?!?!?
}
}
Function Get-EudamedPagedDataCountryAndRole {
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[String]$Url,
[String]$Country='DE',
[ValidateSet('Manufacturer', 'Authorised-Representative', 'System-Procedure-Pack-Producer', 'Importer')]
[String]$Role='Manufacturer'
)
switch ($Role) {
'Manufacturer' {$atc = 'actorTypeCode=refdata.actor-type.manufacturer'}
'Authorised-Representative' {$atc = 'actorTypeCode=refdata.actor-type.authorised-representative'}
'System-Procedure-Pack-Producer' {$atc = 'actorTypeCode=refdata.actor-type.system-procedure-pack-producer'}
'Importer' {$atc = 'actorTypeCode=refdata.actor-type.importer'}
}
Get-EudamedPagedData -Url "$Url&$atc&countryIso2Code=$Country"
}
# ermittelt die Devices eines Herstellers nach seinem Namen, wenn der Name auf mehrere Hersteller zutrifft, werden Materialien von verschiedenen Herstellern zurückgegeben
Function Get-EudamedEODevicesByManufacturerName {
[CmdletBinding()]
Param(
[Parameter(Mandatory,ParameterSetName='Manufacturer',Position=0)]
[String]$ManufacturerName,
[switch]$OnlyTotalElements
)
# früher: $Url = "https://ec.europa.eu/tools/eudamed/api/devices/udiDiData?manufacturerName=$($ManufacturerName)&languageIso2Code=de"
# TODO: damit ist eigentlich die Namensgebung der Funktion dahin!!
$Url = "https://ec.europa.eu/tools/eudamed/api/devices/udiDiData?name=$([System.Uri]::EscapeUriString($ManufacturerName))&languageIso2Code=de"
Get-EudamedPagedData -Url $Url -OnlyTotalElements:$OnlyTotalElements
}
# Achtung die unterschiedlichen ParameterSets liefern unterschiedliche, nicht kompatible Strukturen zurück
# Uuid liefert mehr Informationen
Function Get-EudamedEODetail {
[CmdletBinding()]
Param(
[Parameter(Mandatory,ParameterSetName='Uuid',Position=0)]
[String]$Uuid,
[Parameter(Mandatory,ParameterSetName='Srn',Position=0)]
[String]$Srn
)
If ($PSCmdlet.ParameterSetName -eq 'Uuid') {
$Url = "https://ec.europa.eu/tools/eudamed/api/actors/$Uuid/publicInformation?languageIso2Code=de"
} else {
# ParameterSet Srn
$Url = "https://ec.europa.eu/tools/eudamed/api/eos?srn=$($srn)&languageIso2Code=de"
}
$r=Invoke-WebRequest "$Url" -UseBasicParsing
If ($PSCmdlet.ParameterSetName -eq 'Uuid') {
ConvertFrom-Json $r.Content
} else {
(ConvertFrom-Json $r.Content).Content # Irgendwie nochmal geschachtelt, können srn Wildcards enthalten?!?!?
}
}
Function Get-EudamedDevicesOfEO {
[CmdletBinding()]
Param(
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[String]$Srn,
[switch]$OnlyTotalElements
)
Process {
$Url = "https://ec.europa.eu/tools/eudamed/api/devices/udiDiData?iso2Code=en&srn=$srn&deviceStatusCode=refdata.device-model-status.on-the-market&languageIso2Code=de"
Get-EudamedPagedData -Url $Url -OnlyTotalElements:$OnlyTotalElements
}
}
# ermittelt alle Devices oder die Anzahl davon
Function Get-EudamedDevices {
[CmdletBinding()]
Param(
[String]$Name,
[String]$DeviceModel,
[switch]$OnlyTotalElements
)
Process {
$search = ""
If ($Name) {
$search += "&tradeName=$Name"
}
If ($DeviceModel) {
$search += "&deviceModel=$DeviceModel"
}
$Url = "https://ec.europa.eu/tools/eudamed/api/devices/udiDiData?iso2Code=en&deviceStatusCode=refdata.device-model-status.on-the-market&languageIso2Code=de$search"
Write-Host $url
Get-EudamedPagedData -Url $Url -OnlyTotalElements:$OnlyTotalElements
}
}
# Issue #2 beachten wegen Unterschiede beim Resultset! https://github.com/Delapro/EUDAMED/issues/2
Function Get-EudamedDeviceDetail {
[CmdletBinding()]
Param(
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='Uuid',Position=0)]
[String]$Uuid,
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='PrimaryDI',Position=0)]
[String]$PrimaryDI
)
Process {
If ($PSCmdlet.ParameterSetName -eq 'Uuid') {
$Url = "https://ec.europa.eu/tools/eudamed/api/devices/udiDiData/$($Uuid)?languageIso2Code=de"
} else {
# primaryDI-Set
$Url = "https://ec.europa.eu/tools/eudamed/api/devices/udiDiData?primaryDi=$([System.Web.HttpUtility]::UrlEncode($PrimaryDI))&languageIso2Code=de"
}
Write-Verbose "Url: $Url"
$r=Invoke-WebRequest $Url -UseBasicParsing
ConvertFrom-Json $r.Content
}
}
Function Get-EudamedEmdn {
[CmdletBinding()]
Param(
)
$Url = "https://webgate.ec.europa.eu/dyna2/emdn/api/nomenclature?id=%23"
Write-Verbose "Url: $Url"
$r=Invoke-WebRequest $Url -UseBasicParsing
ConvertFrom-Json $r.Content
}
Function Get-EudamedEmdnSearch {
[CmdletBinding()]
Param(
[Object]$emdn,
[String]$text
)
foreach ($entry in $emdn) {
If ($entry.text -match $text) {
[PSCustomObject]@{CndCode=($entry.id -replace 'node_',''); Text=$entry.text -replace "$($entry.id -replace 'node_','') - ", ''}
}
If ($entry.children.Count -gt 0) {
Get-EudamedEmdnSearch $entry.children -text $text
}
}
}
Function Get-EudamedDevicesOfCND {
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[String]$CndCode
)
$url = "https://ec.europa.eu/tools/eudamed/api/devices/udiDiData?iso2Code=en&cndCode=$CndCode&deviceStatusCode=refdata.device-model-status.on-the-market&languageIso2Code=de"
Get-EudamedPagedData -Url $Url
}
Function Get-EudamedVersion {
[CmdletBinding()]
Param(
)
$url = "https://ec.europa.eu/tools/eudamed/api/applicationInfo"
$r=Invoke-WebRequest -Uri $url -UseBasicParsing
$r.Content
}