rxome-generator 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Tom Kamphans, GeneTalk GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,484 @@
1
+ # rxome-qrcode-generator
2
+ Generates QR codes containing medical information for use with the RxOME database.
3
+
4
+ **Right now, it works only with the test API**
5
+
6
+ This package offers a JavaScript library for generating QR codes from medical data as well as
7
+ a command line tool as front end to this library. Both expect the medical data in JSON format
8
+ according to a subset of the PhenoPacket standard (with some additions), see below.
9
+ The medical data will be encrypted before generating the QR code. This encrypted data can be decrypted
10
+ by the database backend only. The meta data is transmitted unencrypted.
11
+
12
+ Every QR code is tagged with a unique pseudonym that is downloaded from the RxOME server. Thus, the tools
13
+ require an active internet connection. Furthermore, the user or the facility applying the QR generator has to sign up to the RxOME server. The communication to the server API is secured with a protocol that uses an
14
+ asymmetric pair of keys, a private key (the API access key) is used to sign the API enquiry,
15
+ a public key is uploaded to the server and used to verify the signature,
16
+ see generating user credentials.
17
+
18
+ When generating a QR code and, thus, downloading a pseudonym, the user needs to specify the
19
+ corresponding credentials (keyID and key) for accessing the RxOME server.
20
+ The command line tool offers command line options for the API access credentials. Further, they
21
+ can be specified in the input JSON file (see 'MetaData and credentials' below),
22
+ where the command line options precede the data in the JSON file.
23
+
24
+ In case the patient already has a pseudonym that will be used for the QR code,
25
+ the known pseudonym can be specified in the MetaData section of the input JSON data.
26
+ Additionally, the command line tool
27
+ offers a command line argument, `-p`, for specifying a known pseudonym.
28
+
29
+ By default, the keywords in the JSON file are expected to be noted in camelCase. However, the tool
30
+ can convert snake_case to camelCase (command line: -s, library: function convertToCamelCase).
31
+
32
+
33
+ ## Basic Usage
34
+
35
+ ###Command Line Tool
36
+
37
+ Generate a QR code *inputfile*.png from a JSON file *inputfile*.json containing all medical data in PhenoPacket format, meta data and credentials (using camelCase for keywords):
38
+
39
+ > `rxcode g` *inputfile*.json
40
+
41
+ For detailed descriptions see
42
+ > `rxcode g --help`
43
+
44
+ ###Library Functions
45
+ Import the library with
46
+ > `const Coder = require( 'rxome-generator' );`
47
+
48
+ The following two async library functions generate QR codes:
49
+ > `Coder.writeQR( filename, data, api = RXAPI )`
50
+
51
+ > *filename*: name for PNG file with the QR code<br/>
52
+ > *data*: object containing medical data, meta data, and credentials (format: see below)<br/>
53
+ > *api*: omit in production mode, set to `Coder.TESTAPI` in test mode.
54
+
55
+ This function creates the QR code from the given data and writes it as PNG file specified by *filename*.
56
+ The credentials for accessing the RxOME API (i.e., fetching a pseudonym and the encryption key) have to be
57
+ part of the data object (see below). Returns the pseudonym used to generate the QR code.
58
+
59
+ > `Coder.makeQR( data, api = RXAPI, apiEntry = APIENTRY )`
60
+
61
+ Generates a QR code object as Data URL that can be placed on a web page. As above, the credentials are specified as part of the data object. Returns an object:
62
+
63
+ ```
64
+ {
65
+ qr_code: (QR code),
66
+ pseudonym: (pseudonym used to generate the QR code)
67
+ }
68
+ ```
69
+
70
+ Both `writeQR` and `makeQR` take care
71
+ of the preprocessing steps (sanitizing, compessing, encoding). However, converting the keys in the data object to camelCase is *not* part of the preprocessing.
72
+ Use the following function to convert keys from snake_case to camelCase:
73
+
74
+ > `Coder.convertToCamelCase( data )`
75
+
76
+ Additionally, the data can be verified with
77
+
78
+ > `Coder.verify( data )`
79
+
80
+ Note that the credential information perhaps stored in the data package is *not* part of the PhenoPacket standard.
81
+
82
+ ## Modifications to the PhenoPacket Standard
83
+ ### Meta Data and Credentials
84
+ For convenience, all data needed to generate a QR code can be specified in one JSON file
85
+ (or, when using the library functions, one JavaScript object).
86
+ In addition to the medical data, the JSON files or objects accepted by rxcode and the
87
+ rxcode library may contain the credentials to access the RxOME API and - if existing -
88
+ the patients pseudonym from earlier issued QR codes.
89
+ Note that the information given in the credential section is mandatory
90
+ when using the library functions.
91
+ When using the command line, these data can be part of the input JSON
92
+ or specified using command line arguments.
93
+ Pleace specify *either* a file containing the API access key (keyFile, -k)
94
+ *or* the key itself (key, -s).
95
+
96
+ When a pseudonym is given (either in the meta data or with command line option `-P`),
97
+ the QR code will be generated using this pseudonym. Otherwise, a new one will be
98
+ fetched from the server. In both cases, the
99
+ pseudonym used will be part of the output for futher processing or storing.
100
+
101
+ ```
102
+ {
103
+ ...
104
+ metaData: {
105
+ ...
106
+ pseudonym: 'anonymous'
107
+ }
108
+ credentials: {
109
+ keyId: <lab-id/key-id, corresponding to private key>
110
+ key: <private key>
111
+ keyFile: <name of file containing private key> // please specify key OR keyFile
112
+ user: e.g., hans.motkamp@genetalk.de
113
+ }
114
+
115
+ }
116
+ ```
117
+
118
+ ### Phenotypic Features
119
+
120
+ The rxome library extends the PhenoPacket schema for storing phenotypicFeatures (HPO terms). In addition the notation suggested by PhenoPackets:
121
+
122
+ ```
123
+ "phenotypicFeatures": [
124
+ {
125
+ "type": {
126
+ "id": "HP:0003155"
127
+ }
128
+ },
129
+ {
130
+ "type": {
131
+ "id": "HP:0001249"
132
+ }
133
+ },
134
+ {
135
+ "type": {
136
+ "id": "HP:0001250"
137
+ }
138
+ }, {
139
+ "type": {
140
+ "id": "HP: 0031360"
141
+ },
142
+ "excluded": true
143
+ }
144
+ ]
145
+
146
+ ```
147
+
148
+ the terms can be stored in a shorter and more convenient form:
149
+
150
+ ```
151
+ "compressedFeatures": {
152
+ "included": [
153
+ "HP:0003155",
154
+ "HP:0001249",
155
+ "HP:0001250"
156
+ ],
157
+ "excluded": [
158
+ "HP:0031360"
159
+ ]
160
+ }
161
+ ```
162
+
163
+ ### Data Source
164
+
165
+ The type of genetic test performed to obtain a variant can be specified in an extension field to the genomic interpretation:
166
+
167
+ ```
168
+ "genomicInterpretations": [
169
+ [
170
+ {
171
+ "variantInterpretation": {
172
+ "acmgPathogenicityClassification": "Pathogenic",
173
+ "variationDescriptor": {
174
+ "geneContext": {
175
+ "expressions": [
176
+ {
177
+ "syntax": "hgvs.c",
178
+ "value": "NM_017837.4(PIGV):c.1022C>A (p.Ala341Glu)"
179
+ }
180
+ ],
181
+ "allelicState": {
182
+ "id": "GENO_0000136"
183
+ },
184
+ "extensions": [
185
+ {
186
+ "name": "Single gene sequencing"
187
+ }
188
+ ]
189
+ }
190
+ }
191
+ }
192
+ ]
193
+ ]
194
+ ```
195
+
196
+ ### Additional Remarks
197
+
198
+ Additional remarks can be specified in a *comment* field in the top level:
199
+
200
+ ```
201
+ {
202
+ "id": "QR-Code ID",
203
+ "comment": "useful remarks",
204
+ "subject": {
205
+ ...
206
+ ```
207
+
208
+ ### Whitelist Filter
209
+
210
+ Before packing the data, needless sections (that is, sections that are not evaluted by RxOME)
211
+ are removed. On top level, the following section will be passed over to the QR code:
212
+
213
+ * id
214
+ * comment
215
+ * subject
216
+ * phenotypicFeatures
217
+ * interpretations
218
+ * diagnosis
219
+ * metaData
220
+ * credentials (not passed to QR code, but also not removed by whitelist filtering)
221
+
222
+ ## Command-Line Tool
223
+
224
+ ### Overview
225
+
226
+ ```
227
+ RxOME.net QR Code generation tool
228
+
229
+ Usage: rxcode [options] [command]
230
+
231
+ Basic usage: rxcode g <input json file>: generates QR Code with the basefilename of the inputfile.
232
+ Before first use, please generate an API access key (rxcode -k) and deposit the public key
233
+ on the RxOME server.
234
+
235
+
236
+ Options:
237
+ -V, --version output the version number
238
+ -h, --help display help for command
239
+
240
+ Commands:
241
+ generate|g [options] [input file] generate QR Code from PhenoPacket JSON
242
+ convert|c [options] [input file] convert case style of keys in JSON files from snake_case
243
+ to camelCase (and vice versa)
244
+ preprocess|p [options] [input file] perform preprocessing steps
245
+ verify|v [input file] verify input file against phenopacket schema
246
+ apikeys|k [options] [file prefix] generate key pair for API access
247
+ ping|P [options] <id> <key> Ping API/check API credentials
248
+ encode|e [options] [input file] encrypt medical payload (just for testing)
249
+ decode|d [options] [input file] decode coded message
250
+ pheno2proto|E [options] [input file] encode PhenoPacket to protobuf (just for testing)
251
+ proto2pheno|D [options] [input file] decode protobuf to PhenoPacket (just for testing)
252
+ statistics|s [input file] print memory consuption for several stages and alternatives
253
+ rxome-keys [options] [file prefix] generate key pair for qr code data encryption
254
+ (just for testing)
255
+ help [command] display help for command
256
+ ```
257
+
258
+ ### Generating QR codes
259
+
260
+ Use the 'g' command for actually generating a QR code:
261
+
262
+ ```
263
+ RxOME.net QR Code generation tool
264
+
265
+ Usage: rxcode generate|g [options] [input file]
266
+
267
+ Generate QR Code from PhenoPacket JSON. The credential information keyId and either key or keyFile
268
+ are mandatory and can be specified either in the input JSON file or by command line arguments.
269
+ The command line arguments precede the data from the JSON input file.
270
+ Output: prints the given or new pseudonym.
271
+
272
+ Arguments:
273
+ input file Input JSON file (default: STDIN)
274
+
275
+ Options:
276
+ -o, --output <filename> Filename for the QR code (default: <inputfile>.png)
277
+ -p, --pseudonym Pseudonym for patient, if known. Otherwise a new is generated
278
+ -i, --keyId <id> API access ID (default: input file, credentials.keyId
279
+ or metaData.createdBy)
280
+ -k, --keyFile <filename> Filename with API access key (default: use -s)
281
+ -s, --key <key string> API access key (default: input file, credentials.key)
282
+ -u, --user <user string> API access user (default: credentials.user
283
+ or metaData.submittedBy or info@rxome.net)
284
+ -c, --created <date> Date (default: input file, metaData.created)
285
+ -l, --lab <lab> Laboratory name (default: input file, metaData.createdBy)
286
+ -e, --email <email> Laboratory email (default: input file, metaData.submittedBy)
287
+ -S, --snake Read payload formatted in snake_case (default: camelCase)
288
+ -t, --test Use test API instead of production API
289
+ -D, --debug Some output for debugging
290
+ -h, --help display help for command
291
+ ```
292
+
293
+ Writes the pseudonym used to generate the QR code to STDOUT.
294
+
295
+ ### Generating API Access Keys
296
+ To communicate with the server API you need access credentials, that is, an id for your lab (the keyId) and a pair of corresponding keys. First, generate a pair of keys with
297
+
298
+ ```
299
+ rxcode k myLabId
300
+ ```
301
+
302
+ This yields two files: `myLabId.private.apikey` and `myLabId.public.apikey`. Store the
303
+ private key safely.
304
+ Create a lab account on `www.rxome.net/lab` and upload the public key to your profile.
305
+ Afterwards, you should be able to access the API (see 'debugging' below).
306
+
307
+ ## Demo
308
+
309
+ ```
310
+ rxcode g -t -o qrcode.png demos/demo_data_full.json
311
+ ```
312
+
313
+ <img src="qrcode.png" width="400">
314
+
315
+ ## Debugging
316
+ To check the connection to the API on RxOME server API use
317
+
318
+ > `rxcode P -d ` *your_id* *your_key*
319
+
320
+ If you want to make sure that all data from your input is transmitted correctly, you can
321
+ use the `pheno2proto` and the corresponding `proto2pheno` commands to encode and decode your
322
+ file. Compare the output of `proto2pheno` with your original file:
323
+
324
+ ```
325
+ rxcode E -b my_file.json > my_file.pbuf
326
+ rxcode D -bp my_file.pbuf > my_new_file.json
327
+ diff my_new_file.json my_file.json
328
+ ```
329
+
330
+ ## Payload Example File
331
+
332
+ ```
333
+ {
334
+ "id": "QR-Code ID",
335
+ "comment": "useful remarks",
336
+ "subject": {
337
+ "id": "proband A",
338
+ "dateOfBirth": "1994-01-01T00:00:00Z",
339
+ "sex": "FEMALE"
340
+ },
341
+ "phenotypicFeatures": [
342
+ {
343
+ "type": {
344
+ "id": "HP:0030084"
345
+ }
346
+ },
347
+ {
348
+ "type": {
349
+ "id": "HP:0000555"
350
+ }
351
+ },
352
+ {
353
+ "type": {
354
+ "id": "HP:0000486"
355
+ }
356
+ },
357
+ {
358
+ "type": {
359
+ "id": "HP:0000541"
360
+ }
361
+ },
362
+ {
363
+ "type": {
364
+ "id": "HP:0084369"
365
+ }
366
+ },
367
+ {
368
+ "type": {
369
+ "id": "HP:0112358"
370
+ }
371
+ },
372
+ {
373
+ "type": {
374
+ "id": "HP:0000145"
375
+ }
376
+ },
377
+ {
378
+ "type": {
379
+ "id": "HP:1234567"
380
+ }
381
+ },
382
+ {
383
+ "type": {
384
+ "id": "HP:9876543"
385
+ }
386
+ },
387
+ {
388
+ "type": {
389
+ "id": "HP:5678912"
390
+ }
391
+ },
392
+ {
393
+ "type": {
394
+ "id": "HP:0031360"
395
+ },
396
+ "excluded": true
397
+ },
398
+ {
399
+ "type": {
400
+ "id": "HP:0001234",
401
+ },
402
+ "excluded": true
403
+ }
404
+ ],
405
+ "interpretations": [
406
+ {
407
+ "id": "interpretation.id",
408
+ "progressStatus": "SOLVED",
409
+ "diagnosis": {
410
+ "disease": {
411
+ "id": "OMIM:263750"
412
+ },
413
+ "genomicInterpretations": [
414
+ {
415
+ "variantInterpretation": {
416
+ "acmgPathogenicityClassification": "PATHOGENIC",
417
+ "variationDescriptor": {
418
+ "geneContext": {
419
+ "valueId": "HGNC:9884",
420
+ "symbol": "RB1"
421
+ },
422
+ "expressions": [
423
+ {
424
+ "syntax": "hgvs.c",
425
+ "value": "NM_000321.2:c.958C>T"
426
+ }
427
+ ],
428
+ "allelicState": {
429
+ "id": "GENO:0000135"
430
+ },
431
+ "extensions": [
432
+ {
433
+ "name": "test-type",
434
+ "value": "Exome, short read"
435
+ }
436
+ ]
437
+ }
438
+ }
439
+ },
440
+ {
441
+ "variantInterpretation": {
442
+ "acmgPathogenicityClassification": "LIKELY_PATHOGENIC",
443
+ "variationDescriptor": {
444
+ "geneContext": {
445
+ "valueId": "HGNC:9884",
446
+ "symbol": "RB1"
447
+ },
448
+ "expressions": [
449
+ {
450
+ "syntax": "hgvs.c",
451
+ "value": "NM_000321.2:c.1234A>G"
452
+ }
453
+ ],
454
+ "allelicState": {
455
+ "label": "heterozygous"
456
+ },
457
+ "extensions": [
458
+ {
459
+ "name": "test-type",
460
+ "value": "Exome, short read"
461
+ }
462
+ ]
463
+ }
464
+ }
465
+ }
466
+ ]
467
+ }
468
+ }
469
+ ],
470
+ "metaData": {
471
+ "created": "2021-05-14T10:35:00Z",
472
+ "createdBy": "MGZ",
473
+ "submittedBy": "abc@def.de",
474
+ "phenopacketSchemaVersion": "2.0"
475
+ }
476
+ }
477
+ ```
478
+
479
+ <!--
480
+ ## Acknowledgments
481
+ openpgp https://openpgpjs.org/
482
+ node-qrcode https://github.com/soldair/node-qrcode
483
+ noble-ed25519
484
+ -->
@@ -0,0 +1,149 @@
1
+ {
2
+ "id": "QR-Code ID",
3
+ "comment": "useful remarks De do do do de da da da",
4
+ "subject": {
5
+ "id": "proband A",
6
+ "dateOfBirth": "1994-01-01T00:00:00Z",
7
+ "sex": "FEMALE"
8
+ },
9
+ "phenotypicFeatures": [
10
+ {
11
+ "type": {
12
+ "id": "HP:0030084"
13
+ }
14
+ },
15
+ {
16
+ "type": {
17
+ "id": "HP:0000555"
18
+ }
19
+ },
20
+ {
21
+ "type": {
22
+ "id": "HP:0000486"
23
+ }
24
+ },
25
+ {
26
+ "type": {
27
+ "id": "HP:0000541"
28
+ }
29
+ },
30
+ {
31
+ "type": {
32
+ "id": "HP:0084369"
33
+ }
34
+ },
35
+ {
36
+ "type": {
37
+ "id": "HP:0112358"
38
+ }
39
+ },
40
+ {
41
+ "type": {
42
+ "id": "HP:0000145"
43
+ }
44
+ },
45
+ {
46
+ "type": {
47
+ "id": "HP:1234567"
48
+ }
49
+ },
50
+ {
51
+ "type": {
52
+ "id": "HP:9876543"
53
+ }
54
+ },
55
+ {
56
+ "type": {
57
+ "id": "HP:5678912"
58
+ }
59
+ },
60
+ {
61
+ "type": {
62
+ "id": "HP:0031360"
63
+ },
64
+ "excluded": true
65
+ },
66
+ {
67
+ "type": {
68
+ "id": "HP:0001234"
69
+ },
70
+ "excluded": true
71
+ }
72
+ ],
73
+ "interpretations": [
74
+ {
75
+ "id": "interpretation.id",
76
+ "progressStatus": "SOLVED",
77
+ "diagnosis": {
78
+ "disease": {
79
+ "id": "OMIM:263750"
80
+ },
81
+ "genomicInterpretations": [
82
+ {
83
+ "variantInterpretation": {
84
+ "acmgPathogenicityClassification": "PATHOGENIC",
85
+ "variationDescriptor": {
86
+ "geneContext": {
87
+ "valueId": "HGNC:9884",
88
+ "symbol": "RB1"
89
+ },
90
+ "expressions": [
91
+ {
92
+ "syntax": "hgvs.c",
93
+ "value": "NM_000321.2:c.958C>T"
94
+ }
95
+ ],
96
+ "allelicState": {
97
+ "id": "GENO:0000135"
98
+ },
99
+ "extensions": [
100
+ {
101
+ "name": "test-type",
102
+ "value": "Exome, short read"
103
+ }
104
+ ]
105
+ }
106
+ }
107
+ },
108
+ {
109
+ "variantInterpretation": {
110
+ "acmgPathogenicityClassification": "LIKELY_PATHOGENIC",
111
+ "variationDescriptor": {
112
+ "geneContext": {
113
+ "valueId": "HGNC:9884",
114
+ "symbol": "RB1"
115
+ },
116
+ "expressions": [
117
+ {
118
+ "syntax": "hgvs.c",
119
+ "value": "NM_000321.2:c.1234A>G"
120
+ }
121
+ ],
122
+ "allelicState": {
123
+ "label": "heterozygous"
124
+ },
125
+ "extensions": [
126
+ {
127
+ "name": "test-type",
128
+ "value": "Exome, short read"
129
+ }
130
+ ]
131
+ }
132
+ }
133
+ }
134
+ ]
135
+ }
136
+ }
137
+ ],
138
+ "metaData": {
139
+ "created": "2021-05-14T10:35:00Z",
140
+ "createdBy": "mgz",
141
+ "submittedBy": "a_clinician@mgz-muenchen.de",
142
+ "phenopacketSchemaVersion": "2.0"
143
+ },
144
+ "credentials": {
145
+ "key": "QhcoRruGBVP39XCh8BujCE+q42qCRy/tu2CQ4YmRBgg=",
146
+ "keyId": "mgz",
147
+ "user": "a_clinician@mgz-muenchen.de"
148
+ }
149
+ }