-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathcodonPython.html
More file actions
1227 lines (1076 loc) · 81.1 KB
/
Copy pathcodonPython.html
File metadata and controls
1227 lines (1076 loc) · 81.1 KB
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>codonPython package — codon 0.0.21 documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<!--[if lt IE 9]>
<script src="_static/js/html5shiv.min.js"></script>
<![endif]-->
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="prev" title="codonPython" href="modules.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="index.html" class="icon icon-home" alt="Documentation Home"> codon
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="modules.html">codonPython</a><ul class="current">
<li class="toctree-l2 current"><a class="current reference internal" href="#">codonPython package</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#submodules">Submodules</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-codonPython.age_bands">codonPython.age_bands module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#codonpython-check-consistent-measures-module">codonPython.check_consistent_measures module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#codonpython-check-consistent-submissions-module">codonPython.check_consistent_submissions module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#codonpython-check-nat-val-module">codonPython.check_nat_val module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#codonpython-check-null-module">codonPython.check_null module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#codonpython-datevalidator-module">codonPython.dateValidator module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-codonPython.file_utils">codonPython.file_utils module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-codonPython.mesh">codonPython.mesh module</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#requirements">Requirements</a></li>
<li class="toctree-l4"><a class="reference internal" href="#example-usage">Example usage</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#module-codonPython.nhsd_colours">codonPython.nhsd_colours module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-codonPython.nhsNumber">codonPython.nhsNumber module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-codonPython.ODS_lookup">codonPython.ODS_lookup module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-codonPython.suppression">codonPython.suppression module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-codonPython.tableFromSql">codonPython.tableFromSql module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#codonpython-tolerance-module">codonPython.tolerance module</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-codonPython">Module contents</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">codon</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html" class="icon icon-home"></a> »</li>
<li><a href="modules.html">codonPython</a> »</li>
<li>codonPython package</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/codonPython.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="codonpython-package">
<h1>codonPython package<a class="headerlink" href="#codonpython-package" title="Permalink to this headline">¶</a></h1>
<div class="section" id="submodules">
<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline">¶</a></h2>
</div>
<div class="section" id="module-codonPython.age_bands">
<span id="codonpython-age-bands-module"></span><h2>codonPython.age_bands module<a class="headerlink" href="#module-codonPython.age_bands" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="codonPython.age_bands.age_band_10_years">
<code class="sig-prename descclassname">codonPython.age_bands.</code><code class="sig-name descname">age_band_10_years</code><span class="sig-paren">(</span><em class="sig-param">age: int</em><span class="sig-paren">)</span> → str<a class="headerlink" href="#codonPython.age_bands.age_band_10_years" title="Permalink to this definition">¶</a></dt>
<dd><p>Place age into appropriate 10 year band</p>
<p>This function takes the age supplied as an argument and returns a string
representing the relevant 10 year banding.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>age</strong> (<em>int</em>) – Age of the person</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>out</strong> – The 10 year age band</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>str</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">age_band_10_years</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="go">'0-9'</span>
<span class="gp">>>> </span><span class="n">age_band_10_years</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>
<span class="go">'Age not known'</span>
<span class="gp">>>> </span><span class="n">age_band_10_years</span><span class="p">(</span><span class="mi">95</span><span class="p">)</span>
<span class="go">'90 and over'</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="codonPython.age_bands.age_band_5_years">
<code class="sig-prename descclassname">codonPython.age_bands.</code><code class="sig-name descname">age_band_5_years</code><span class="sig-paren">(</span><em class="sig-param">age: int</em><span class="sig-paren">)</span> → str<a class="headerlink" href="#codonPython.age_bands.age_band_5_years" title="Permalink to this definition">¶</a></dt>
<dd><p>Place age into appropriate 5 year band</p>
<p>This function takes the age supplied as an argument and returns a string
representing the relevant 5 year banding.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>age</strong> (<em>int</em>) – Age of the person</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>out</strong> – The 5 year age band</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>str</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">age_band_5_years</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="go">'0-4'</span>
<span class="gp">>>> </span><span class="n">age_band_5_years</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>
<span class="go">'Age not known'</span>
<span class="gp">>>> </span><span class="n">age_band_5_years</span><span class="p">(</span><span class="mi">95</span><span class="p">)</span>
<span class="go">'90 and over'</span>
</pre></div>
</div>
</dd></dl>
</div>
<div class="section" id="codonpython-check-consistent-measures-module">
<h2>codonPython.check_consistent_measures module<a class="headerlink" href="#codonpython-check-consistent-measures-module" title="Permalink to this headline">¶</a></h2>
</div>
<div class="section" id="codonpython-check-consistent-submissions-module">
<h2>codonPython.check_consistent_submissions module<a class="headerlink" href="#codonpython-check-consistent-submissions-module" title="Permalink to this headline">¶</a></h2>
</div>
<div class="section" id="codonpython-check-nat-val-module">
<h2>codonPython.check_nat_val module<a class="headerlink" href="#codonpython-check-nat-val-module" title="Permalink to this headline">¶</a></h2>
</div>
<div class="section" id="codonpython-check-null-module">
<h2>codonPython.check_null module<a class="headerlink" href="#codonpython-check-null-module" title="Permalink to this headline">¶</a></h2>
</div>
<div class="section" id="codonpython-datevalidator-module">
<h2>codonPython.dateValidator module<a class="headerlink" href="#codonpython-datevalidator-module" title="Permalink to this headline">¶</a></h2>
</div>
<div class="section" id="module-codonPython.file_utils">
<span id="codonpython-file-utils-module"></span><h2>codonPython.file_utils module<a class="headerlink" href="#module-codonPython.file_utils" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="codonPython.file_utils.compare">
<code class="sig-prename descclassname">codonPython.file_utils.</code><code class="sig-name descname">compare</code><span class="sig-paren">(</span><em class="sig-param">x, y, names=['x', 'y'], dups=False, same=False, comment=False</em><span class="sig-paren">)</span><a class="headerlink" href="#codonPython.file_utils.compare" title="Permalink to this definition">¶</a></dt>
<dd><p>This function returns a dictionary with:</p>
<blockquote>
<div><ol class="arabic simple">
<li><p>Same values between data frames x and y</p></li>
<li><p>Values in x, not in y</p></li>
<li><p>Values in y, not in x</p></li>
</ol>
<p>(optional):
(4) Duplicates of x
(5) Duplicates of y
(6) Boolean of whether x and y are the same</p>
</div></blockquote>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> (<em>pandas.DataFrame</em>) – DataFrame #1</p></li>
<li><p><strong>y</strong> (<em>pandas.DataFrame</em>) – DataFrame #2</p></li>
<li><p><strong>names</strong> (<em>list</em>) – a list of user preferred file names
e.g. [‘File1’, ‘File2’]
default = [‘x’,’y’]</p></li>
<li><p><strong>dups</strong> (<em>bool</em>) – True to include duplicates check for each file
default = False</p></li>
<li><p><strong>same</strong> (<em>bool</em>) – True to activate. Outputs True if DataFrames are the same
default = False</p></li>
<li><p><strong>comment</strong> (<em>bool</em>) – True to activate. Prints out statistics of the compariosn results
e.g. number of same valeus, number of duplicates, number of outliers and whether the DataFrames are the same
default = False</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>out</strong></p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>dict</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<p>‘>>> c = compare(df1, df2, names = [‘df1’,’df2’], dups = True, same = True, comment =True)’</p>
<p>There are 133891 same values
There are 16531 outliers in df1
There are 20937 outliers in df2
There are 48704 duplicates in df1
There are 0 duplicates in df2
The DataFrames are not the same</p>
<p>‘>>> c = compare(df2, df2, names = [‘df2’,’df2’], dups = True, same = True, comment =True)’</p>
<p>There are 154444 same values
There are 0 outliers in df2
There are 0 outliers in df2
There are 0 duplicates in df2
There are 0 duplicates in df2
The DataFrames are the same</p>
</dd></dl>
<dl class="function">
<dt id="codonPython.file_utils.file_search">
<code class="sig-prename descclassname">codonPython.file_utils.</code><code class="sig-name descname">file_search</code><span class="sig-paren">(</span><em class="sig-param">path='.', doctype='csv', like=[''], strict=False</em><span class="sig-paren">)</span><a class="headerlink" href="#codonPython.file_utils.file_search" title="Permalink to this definition">¶</a></dt>
<dd><p>This function creates a list of all files of a certain type, satisfying the criteria outlined
in like = […] parameter. The function only searches for files in the specified folder
of the current working directory that is set by the user.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>path</strong> (<em>string</em>) – Path to a folder in the current working directory
default = ‘.’, i.e. current working directory folder</p></li>
<li><p><strong>doctype</strong> (<em>string</em>) – Document format to search for
e.g. ‘csv’ or ‘xlsx’
default = ‘csv’</p></li>
<li><p><strong>like</strong> (<em>list</em>) – A list of words to filter the file search on
default = [‘’], i.e. no filter</p></li>
<li><p><strong>strict</strong> (<em>bool</em>) – Set True to search for filenames containing all words from ‘like’ list (
default = False</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>list</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">file_search</span><span class="p">(</span><span class="n">doctype</span> <span class="o">=</span> <span class="s1">'md'</span><span class="p">)</span>
<span class="go">['README.md', 'CONTRIBUTING.md']</span>
</pre></div>
</div>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">file_search</span><span class="p">(</span><span class="n">doctype</span> <span class="o">=</span> <span class="s1">'md'</span><span class="p">,</span> <span class="n">like</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'READ'</span><span class="p">])</span>
<span class="go">['README.md']</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="codonPython.file_utils.import_files">
<code class="sig-prename descclassname">codonPython.file_utils.</code><code class="sig-name descname">import_files</code><span class="sig-paren">(</span><em class="sig-param">path='.', doctype='csv', sheet='Sheet1', subdir=False, like=[''], strict=False</em><span class="sig-paren">)</span><a class="headerlink" href="#codonPython.file_utils.import_files" title="Permalink to this definition">¶</a></dt>
<dd><p>This function imports all documents of a given format to a dictionary
and returns this dictionary, keeping original file names.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>path</strong> (<em>string</em>) – Path to a folder in the current working directory
default = ‘.’, i.e. current working directory folder</p></li>
<li><p><strong>doctype</strong> (<em>string</em>) – Document format to search for
e.g. ‘csv’ or ‘xlsx’
default = ‘csv’</p></li>
<li><p><strong>sheet</strong> (<em>string</em>) – Sheet name of the xlsx file
default = ‘Sheet1’</p></li>
<li><p><strong>subdir</strong> (<em>bool</em>) – True to allow download all files, including the subdirectories
default = False</p></li>
<li><p><strong>like</strong> (<em>list</em>) – A list of words to filter the file search on
default = [‘’], i.e. no filter</p></li>
<li><p><strong>strict</strong> (<em>bool</em>) – Set True to search for filenames containing all words from ‘like’ list
default = False</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>out</strong></p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>dict</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<p>‘>>> import_files()’</p>
<p>File Data_AprF_2019 is successfully imported</p>
<p>File Data_AugF_2019 is successfully imported</p>
<p>File Data_JulF_2019 is successfully imported</p>
<p>File Data_JunF_2019_v1 is successfully imported</p>
<p>File Data_MayF_2019 is successfully imported</p>
<p>File Data_SepP_2019 is successfully imported</p>
<p>‘>>> import_files(like = [‘Aug’,’Sep’])’</p>
<p>File Data_AugF_2019 is successfully imported</p>
<p>File Data_SepP_2019 is successfully imported</p>
</dd></dl>
</div>
<div class="section" id="module-codonPython.mesh">
<span id="codonpython-mesh-module"></span><h2>codonPython.mesh module<a class="headerlink" href="#module-codonPython.mesh" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="codonPython.mesh.MESHConnection">
<em class="property">class </em><code class="sig-prename descclassname">codonPython.mesh.</code><code class="sig-name descname">MESHConnection</code><span class="sig-paren">(</span><em class="sig-param">mailbox: str</em>, <em class="sig-param">password: str</em>, <em class="sig-param">api_shared_key: str</em>, <em class="sig-param">cert_loc: str</em>, <em class="sig-param">key_loc: str</em>, <em class="sig-param">base_ca_loc: str</em>, <em class="sig-param">root_url: str = 'https://mesh-sync.national.ncrs.nhs.uk'</em>, <em class="sig-param">org: str = 'NHS Digital'</em><span class="sig-paren">)</span><a class="headerlink" href="#codonPython.mesh.MESHConnection" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Class for handling MESH API interactions.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>mailbox</strong> (<em>string</em>) – The MESH ID of the mailbox this client is for</p></li>
<li><p><strong>password</strong> (<em>string</em>) – The password to this mailbox</p></li>
<li><p><strong>api_shared_key</strong> (<em>string</em>) – The shared API key for the MESH environment the mailbox is in</p></li>
<li><p><strong>cert_loc</strong> (<em>string</em>) – Path to the MESH API certificate location</p></li>
<li><p><strong>key_loc</strong> (<em>string</em>) – Path to the MESH API certificate private key location</p></li>
<li><p><strong>base_ca_loc</strong> (<em>string</em>) – Path to the base MESH certificate authority certificate bundle.
Set to False to disable inbound SSL checks if necessary</p></li>
<li><p><strong>root_url</strong> (string, default = “<a class="reference external" href="https://mesh-sync.national.ncrs.nhs.uk">https://mesh-sync.national.ncrs.nhs.uk</a>”) – Root MESH URL. Default value is the live MESH service</p></li>
<li><p><strong>org</strong> (<em>string</em><em>, </em><em>default = "NHS Digital"</em>) – Name of organisation owning the mailbox</p></li>
</ul>
</dd>
</dl>
<dl class="method">
<dt id="codonPython.mesh.MESHConnection.check_authentication">
<code class="sig-name descname">check_authentication</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → bool<a class="headerlink" href="#codonPython.mesh.MESHConnection.check_authentication" title="Permalink to this definition">¶</a></dt>
<dd><p>Check authentication with the MESH API.
This should be done at the start of any session (per the API docs)</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>Indicates if authentication was successful or not</p>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>bool</p>
</dd>
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><p><a class="reference internal" href="#codonPython.mesh.MESHUnknownError" title="codonPython.mesh.MESHUnknownError"><strong>MESHUnknownError</strong></a> – There was an unexpected return status from the MESH API</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">client</span><span class="o">.</span><span class="n">check_authentication</span><span class="p">()</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="codonPython.mesh.MESHConnection.send_file">
<code class="sig-name descname">send_file</code><span class="sig-paren">(</span><em class="sig-param">dest_mailbox: str</em>, <em class="sig-param">message_location: str</em>, <em class="sig-param">workflow_id: str</em>, <em class="sig-param">message_subject: str = None</em>, <em class="sig-param">message_id: str = None</em>, <em class="sig-param">process_id: str = None</em>, <em class="sig-param">compress_message: bool = True</em>, <em class="sig-param">encrypted: bool = False</em><span class="sig-paren">)</span><a class="headerlink" href="#codonPython.mesh.MESHConnection.send_file" title="Permalink to this definition">¶</a></dt>
<dd><p>Send a file to the MESH API.
This will automatically chunk the message if required, splitting into chunks at 80MB (MESH API has a
chunk size limit of 100MB). If required, this will also compress the message before transmission using
gzip.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>dest_mailbox</strong> (<em>string</em>) – MESH Mailbox ID of the recipient</p></li>
<li><p><strong>message_location</strong> (<em>string</em>) – Path to the readable file to send as a message</p></li>
<li><p><strong>workflow_id</strong> (<em>string</em>) – DTS Workflow ID</p></li>
<li><p><strong>message_subject</strong> (<em>string</em><em>, </em><em>default = None</em>) – Optional subject line to use for the message, for SMTP (email) messages.</p></li>
<li><p><strong>message_id</strong> (<em>string</em><em>, </em><em>default = None</em>) – Optional local identifier for the message. Required to track the message later.</p></li>
<li><p><strong>process_id</strong> (<em>string</em><em>, </em><em>default = None</em>) – Optional process ID for the MESH message. Currently not used in MESH, but included to ensure
future compatibility.</p></li>
<li><p><strong>compress_message</strong> (<em>boolean</em><em>, </em><em>default = True</em>) – Indicates if the message should be compressed. If true, then the message will be compressed
using gzip before sending to MESH.</p></li>
<li><p><strong>encrypted</strong> (<em>boolean</em><em>, </em><em>default = False</em>) – Indicates if the file to send has been encrypted. This is solely used to pass a flag to MESH
and does not encrypt the file or otherwise alter processing.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><p>Dictionary of returned values from the MESH API</p>
<ul class="simple">
<li><p>messageID (str): value of the MESH internal ID assigned to the sent message</p></li>
</ul>
</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>dict</p>
</dd>
<dt class="field-even">Raises</dt>
<dd class="field-even"><ul class="simple">
<li><p><a class="reference internal" href="#codonPython.mesh.MESHAuthenticationError" title="codonPython.mesh.MESHAuthenticationError"><strong>MESHAuthenticationError</strong></a> – There was an authentication error accessing this page. Either the SSL certificate used is invalid,
or the client provided the wrong Mailbox ID, Password, or Shared Key.</p></li>
<li><p><a class="reference internal" href="#codonPython.mesh.MESHInvalidRecipient" title="codonPython.mesh.MESHInvalidRecipient"><strong>MESHInvalidRecipient</strong></a> – The mailbox ID provided is not a valid recipient for this message</p></li>
<li><p><a class="reference internal" href="#codonPython.mesh.MESHUnknownError" title="codonPython.mesh.MESHUnknownError"><strong>MESHUnknownError</strong></a> – There was an unexpected return status from the MESH API</p></li>
</ul>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">client</span><span class="o">.</span><span class="n">send_file</span><span class="p">(</span><span class="s2">"TEST"</span><span class="p">,</span> <span class="s1">'c:/test/test.txt'</span><span class="p">,</span> <span class="s1">'test_flow'</span><span class="p">)</span>
<span class="go">{'messageID': '20200211115928515346_9359E2'}</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="codonPython.mesh.MESHConnection.send_message">
<code class="sig-name descname">send_message</code><span class="sig-paren">(</span><em class="sig-param">dest_mailbox: str</em>, <em class="sig-param">message: bytes</em>, <em class="sig-param">filename: str</em>, <em class="sig-param">workflow_id: str</em>, <em class="sig-param">message_subject: str = None</em>, <em class="sig-param">message_id: str = None</em>, <em class="sig-param">process_id: str = None</em>, <em class="sig-param">compress_message: bool = True</em>, <em class="sig-param">encrypted: bool = False</em><span class="sig-paren">)</span><a class="headerlink" href="#codonPython.mesh.MESHConnection.send_message" title="Permalink to this definition">¶</a></dt>
<dd><p>Send a message to the MESH API.
This will automatically chunk the message if required, splitting into chunks at 80MB (MESH API has a
chunk size limit of 100MB). If required, this will also compress the message before transmission using
gzip.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>dest_mailbox</strong> (<em>string</em>) – MESH Mailbox ID of the recipient</p></li>
<li><p><strong>message</strong> (<em>bytes</em>) – Bytes representation of the file to transmit</p></li>
<li><p><strong>filename</strong> (<em>string</em>) – Original filename for the message being transmitted</p></li>
<li><p><strong>workflow_id</strong> (<em>string</em>) – DTS Workflow ID</p></li>
<li><p><strong>message_subject</strong> (<em>string</em><em>, </em><em>default = None</em>) – Optional subject line to use for the message, for SMTP (email) messages.</p></li>
<li><p><strong>message_id</strong> (<em>string</em><em>, </em><em>default = None</em>) – Optional local identifier for the message. Required to track the message later.</p></li>
<li><p><strong>process_id</strong> (<em>string</em><em>, </em><em>default = None</em>) – Optional process ID for the MESH message. Currently not used in MESH, but included to ensure
future compatibility.</p></li>
<li><p><strong>compress_message</strong> (<em>boolean</em><em>, </em><em>default = True</em>) – Indicates if the message should be compressed. If true, then the message will be compressed
using gzip before sending to MESH.</p></li>
<li><p><strong>encrypted</strong> (<em>boolean</em><em>, </em><em>default = False</em>) – Indicates if the file to send has been encrypted. This is solely used to pass a flag to MESH
and does not encrypt the file or otherwise alter processing.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><p>Dictionary of returned values from the MESH API</p>
<ul class="simple">
<li><p>messageID (str): value of the MESH internal ID assigned to the sent message</p></li>
</ul>
</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>dict</p>
</dd>
<dt class="field-even">Raises</dt>
<dd class="field-even"><ul class="simple">
<li><p><a class="reference internal" href="#codonPython.mesh.MESHAuthenticationError" title="codonPython.mesh.MESHAuthenticationError"><strong>MESHAuthenticationError</strong></a> – There was an authentication error accessing this page. Either the SSL certificate used is invalid,
or the client provided the wrong Mailbox ID, Password, or Shared Key.</p></li>
<li><p><a class="reference internal" href="#codonPython.mesh.MESHInvalidRecipient" title="codonPython.mesh.MESHInvalidRecipient"><strong>MESHInvalidRecipient</strong></a> – The mailbox ID provided is not a valid recipient for this message</p></li>
<li><p><a class="reference internal" href="#codonPython.mesh.MESHUnknownError" title="codonPython.mesh.MESHUnknownError"><strong>MESHUnknownError</strong></a> – There was an unexpected return status from the MESH API</p></li>
</ul>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">client</span><span class="o">.</span><span class="n">send_message</span><span class="p">(</span><span class="s2">"TEST"</span><span class="p">,</span> <span class="sa">b</span><span class="s1">'test'</span><span class="p">,</span> <span class="s1">'test.txt'</span><span class="p">,</span> <span class="s1">'test_flow'</span><span class="p">)</span>
<span class="go">{'messageID': '20200211115928515346_9359E2'}</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="codonPython.mesh.MESHConnection.check_message_status">
<code class="sig-name descname">check_message_status</code><span class="sig-paren">(</span><em class="sig-param">message_id: str</em><span class="sig-paren">)</span> → dict<a class="headerlink" href="#codonPython.mesh.MESHConnection.check_message_status" title="Permalink to this definition">¶</a></dt>
<dd><p>Check status of a sent message.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>message_id</strong> (<em>string</em>) – The local message ID, eg. as provided to send_message. Does NOT work with MESH Message IDs, only
the local ID optionally provided on sending the message.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The full response from the MESH API for this local ID. For details, consult the MESH API documentation</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>dict</p>
</dd>
<dt class="field-even">Raises</dt>
<dd class="field-even"><ul class="simple">
<li><p><a class="reference internal" href="#codonPython.mesh.MESHAuthenticationError" title="codonPython.mesh.MESHAuthenticationError"><strong>MESHAuthenticationError</strong></a> – There was an authentication error accessing this page. Either the SSL certificate used is invalid,
or the client provided the wrong Mailbox ID, Password, or Shared Key.</p></li>
<li><p><a class="reference internal" href="#codonPython.mesh.MESHMultipleMatches" title="codonPython.mesh.MESHMultipleMatches"><strong>MESHMultipleMatches</strong></a> – There are multiple messages in the outbox with this local ID</p></li>
<li><p><a class="reference internal" href="#codonPython.mesh.MESHUnknownError" title="codonPython.mesh.MESHUnknownError"><strong>MESHUnknownError</strong></a> – There was an unexpected return status from the MESH API</p></li>
</ul>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">client</span><span class="o">.</span><span class="n">check_message_status</span><span class="p">(</span><span class="n">test</span><span class="p">)</span>
<span class="go">{"statusSuccess": ...}</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="codonPython.mesh.MESHConnection.check_inbox">
<code class="sig-name descname">check_inbox</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → list<a class="headerlink" href="#codonPython.mesh.MESHConnection.check_inbox" title="Permalink to this definition">¶</a></dt>
<dd><p>Determine the MESH IDs of the contents of the inbox.
This will return at most 500 entries, owing to the limitations of the API.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>The MESH IDs of the messages in the inbox (str)</p>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>list</p>
</dd>
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><ul class="simple">
<li><p><a class="reference internal" href="#codonPython.mesh.MESHAuthenticationError" title="codonPython.mesh.MESHAuthenticationError"><strong>MESHAuthenticationError</strong></a> – There was an authentication error accessing this page. Either the SSL certificate used is invalid,
or the client provided the wrong Mailbox ID, Password, or Shared Key.</p></li>
<li><p><a class="reference internal" href="#codonPython.mesh.MESHUnknownError" title="codonPython.mesh.MESHUnknownError"><strong>MESHUnknownError</strong></a> – There was an unexpected return status from the MESH API</p></li>
</ul>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">client</span><span class="o">.</span><span class="n">check_inbox</span><span class="p">()</span>
<span class="go">["20200211115754892283_BC7B68", "20200211115928515346_9359E2"]</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="codonPython.mesh.MESHConnection.check_inbox_count">
<code class="sig-name descname">check_inbox_count</code><span class="sig-paren">(</span><span class="sig-paren">)</span> → int<a class="headerlink" href="#codonPython.mesh.MESHConnection.check_inbox_count" title="Permalink to this definition">¶</a></dt>
<dd><p>Determine how many messages are in the MESH mailbox to download.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>The number of messages ready to download</p>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>int</p>
</dd>
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><ul class="simple">
<li><p><a class="reference internal" href="#codonPython.mesh.MESHAuthenticationError" title="codonPython.mesh.MESHAuthenticationError"><strong>MESHAuthenticationError</strong></a> – There was an authentication error accessing this page. Either the SSL certificate used is invalid,
or the client provided the wrong Mailbox ID, Password, or Shared Key.</p></li>
<li><p><a class="reference internal" href="#codonPython.mesh.MESHUnknownError" title="codonPython.mesh.MESHUnknownError"><strong>MESHUnknownError</strong></a> – There was an unexpected return status from the MESH API</p></li>
</ul>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">client</span><span class="o">.</span><span class="n">check_inbox_count</span><span class="p">()</span>
<span class="go">2</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="codonPython.mesh.MESHConnection.check_and_download">
<code class="sig-name descname">check_and_download</code><span class="sig-paren">(</span><em class="sig-param">save_folder: str = None</em>, <em class="sig-param">recursive: bool = True</em><span class="sig-paren">)</span> → Optional[Generator[[dict, None], None]]<a class="headerlink" href="#codonPython.mesh.MESHConnection.check_and_download" title="Permalink to this definition">¶</a></dt>
<dd><p>Download all messages in the inbox.
This will automatically handle reconstructing chunked messages, and automatically decompress any messages
which have Content-Encoding value of gzip.
WARNING: each downloaded message will be fully reconstructed and decompressed if needed. This may cause
issue for machines with very limited memory if there are very large files to download.</p>
<p>If save_folder is provided, then downloaded files will be saved into that folder with their original filenames
(and non-delivery receipts will be saved there). This may cause issue if there are multiple files with the
same filename.</p>
<p>If no save_folder is provided, then this function will return a generator which will yield each message in turn.
When the generator yields a message, it will send an acknowledgement to the MESH API for the previous
message; it is important that processing of the messages be complete and any required final outputs saved
before this - once acknowledged a message cannot be downloaded from MESH again.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>save_folder</strong> (<em>string</em><em>, </em><em>default = None</em>) – <p>If provided, the folder to save all downloaded files to when this function is called. The function
will not yield intermediate results.</p>
<ul>
<li><p>For data files, the file will be saved in this folder with its original filename.</p></li>
<li><p>For non-delivery reports, there will be a file created in the folder with filename
‘Non delivery report: (MESH message ID of failed delivery).txt’, and with
content ‘Message not delivered. All known details below’ followed by the full
dictionary of headers from the download response.</p></li>
</ul>
<p>If not provided, then this function will instead yield results as documented below.</p>
</p></li>
<li><p><strong>recursive</strong> (<em>boolean</em><em>, </em><em>default = True</em>) – If true, then this method will be called recursively so long as there are more than 500 messages
in the inbox, the maximum number of messages the MESH API will provide IDs for at once. If false,
then only one call will be made to retrieve inbox contents, and at most 500 messages will be downloaded.</p></li>
</ul>
</dd>
<dt class="field-even">Yields</dt>
<dd class="field-even"><p><em>dict</em> – Dictionary of details about the downloaded file.</p>
<ul class="simple">
<li><p>filename (str): Filename of the original file (if provided).</p></li>
<li><p>contents (bytes): Contents of the file (reconstructed and decompressed if necessary).</p></li>
<li><p>headers (dict): Dictionary of headers returned by MESH on the initial download request.
For full details see the MESH API documentation.</p></li>
<li><p>datafile (boolean): Indicates if this was a data file or a non-delivery report.</p></li>
</ul>
</dd>
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><ul class="simple">
<li><p><a class="reference internal" href="#codonPython.mesh.MESHAuthenticationError" title="codonPython.mesh.MESHAuthenticationError"><strong>MESHAuthenticationError</strong></a> – There was an authentication error accessing the inbox. Either the SSL certificate used is invalid,
or the client provided the wrong Mailbox ID, Password, or Shared Key.</p></li>
<li><p><a class="reference internal" href="#codonPython.mesh.MESHUnknownError" title="codonPython.mesh.MESHUnknownError"><strong>MESHUnknownError</strong></a> – There was an unexpected return status from the MESH API when accessing the inbox</p></li>
<li><p><a class="reference internal" href="#codonPython.mesh.MESHDownloadErrors" title="codonPython.mesh.MESHDownloadErrors"><strong>MESHDownloadErrors</strong></a> – There were errors during the download process. This exception has the attribute ‘exceptions’,
which contains a full list of messages which generated exceptions, along with the exception.
This is only raised after completion of all non-error downloads, and downloads which raise
an exception are not acknowledged to the MESH API.</p></li>
</ul>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">client</span><span class="o">.</span><span class="n">check_and_download</span><span class="p">(</span><span class="s2">"C:/Test Folder/"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">message</span> <span class="ow">in</span> <span class="n">client</span><span class="o">.</span><span class="n">check_and_download</span><span class="p">():</span>
<span class="gp">>>> </span> <span class="nb">print</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
<span class="go">{'filename': 'test.txt', 'contents': b'test_message', 'headers': {...}, datafile: True}</span>
<span class="go">{'filename': 'test2.txt', 'contents': b'test_message_2', 'headers': {...}, datafile: True}</span>
<span class="go">{'filename': None, 'contents': b'', 'headers': {'Mex-Linkedmsgid': '1234567890', ...}, datafile: False}</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="codonPython.mesh.MESHConnection.download_message">
<code class="sig-name descname">download_message</code><span class="sig-paren">(</span><em class="sig-param">message_id: str</em>, <em class="sig-param">save_folder: str = None</em><span class="sig-paren">)</span> → dict<a class="headerlink" href="#codonPython.mesh.MESHConnection.download_message" title="Permalink to this definition">¶</a></dt>
<dd><p>Request a message from the MESH API.
This will automatically handle reconstructing chunked messages, and automatically decompress any messages
which have Content-Encoding value of gzip.
WARNING: the full, reconstructed message will be held in memory, including after decompression. This may
cause problems, if you are using the API to download very large files on a machine with very limited memory.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>message_id</strong> (<em>string</em>) – The internal MESH ID of the message to download</p></li>
<li><p><strong>save_folder</strong> (<em>string</em><em>, </em><em>default = None</em>) – <p>Optional, the folder to save the downloaded message to. If not provided, then the files are not saved.</p>
<ul>
<li><p>For data files, the file will be saved in this folder with its original filename.</p></li>
<li><p>For non-delivery reports, there will be a file created in the folder with filename
‘Non delivery report: (MESH message ID of failed delivery).txt’, and with
content ‘Message not delivered. All known details below’ followed by the full
dictionary of headers from the download response.</p></li>
</ul>
</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><p>Dictionary of details about the downloaded file.</p>
<ul class="simple">
<li><p>filename (str): Filename of the original file (if provided).</p></li>
<li><p>contents (bytes): Contents of the file (reconstructed and decompressed if necessary).</p></li>
<li><p>headers (dict): Dictionary of headers returned by MESH on the initial download request.
For full details see the MESH API documentation.</p></li>
<li><p>datafile (boolean): Indicates if this was a data file or a non-delivery report.</p></li>
</ul>
</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>dict</p>
</dd>
<dt class="field-even">Raises</dt>
<dd class="field-even"><ul class="simple">
<li><p><a class="reference internal" href="#codonPython.mesh.MESHAuthenticationError" title="codonPython.mesh.MESHAuthenticationError"><strong>MESHAuthenticationError</strong></a> – There was an authentication error accessing this page. Either the SSL certificate used is invalid,
or the client provided the wrong Mailbox ID, Password, or Shared Key.</p></li>
<li><p><a class="reference internal" href="#codonPython.mesh.MESHMessageMissing" title="codonPython.mesh.MESHMessageMissing"><strong>MESHMessageMissing</strong></a> – There is no message with the provided message ID in the mailbox</p></li>
<li><p><a class="reference internal" href="#codonPython.mesh.MESHMessageAlreadyDownloaded" title="codonPython.mesh.MESHMessageAlreadyDownloaded"><strong>MESHMessageAlreadyDownloaded</strong></a> – The message with the provided message ID has already been downloaded and acknowledged</p></li>
<li><p><a class="reference internal" href="#codonPython.mesh.MESHUnknownError" title="codonPython.mesh.MESHUnknownError"><strong>MESHUnknownError</strong></a> – There was an unexpected return status from the MESH API</p></li>
</ul>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">client</span><span class="o">.</span><span class="n">download_message</span><span class="p">(</span><span class="s2">"20200211115754892283_BC7B68"</span><span class="p">,</span> <span class="s2">"C:/Test Folder/"</span><span class="p">)</span>
<span class="go">{'filename': 'test.txt', 'contents': b'test_message', 'headers': {'Mex-Filename': 'test.txt', ...}, data: True}</span>
<span class="gp">>>> </span><span class="n">client</span><span class="o">.</span><span class="n">download_message</span><span class="p">(</span><span class="s2">"20200211115754892283_BC7B69"</span><span class="p">)</span>
<span class="go">{'filename': None, 'contents': b'', 'headers': {'Mex-Linkedmsgid': '1234567890', ...}, data: False}</span>
</pre></div>
</div>
</dd></dl>
<dl class="method">
<dt id="codonPython.mesh.MESHConnection.ack_download_message">
<code class="sig-name descname">ack_download_message</code><span class="sig-paren">(</span><em class="sig-param">message_id: str</em><span class="sig-paren">)</span> → None<a class="headerlink" href="#codonPython.mesh.MESHConnection.ack_download_message" title="Permalink to this definition">¶</a></dt>
<dd><p>Send acknowledgement to the MESH API that a message has finished downloading.
This should only be done after the message has successfully been saved -
once sent, the message is remvoed from the MESH server.
Per the API, this must be sent once a message has been successfully processed.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>message_id</strong> (<em>string</em>) – The internal MESH ID of the downloaded message</p>
</dd>
<dt class="field-even">Raises</dt>
<dd class="field-even"><ul class="simple">
<li><p><a class="reference internal" href="#codonPython.mesh.MESHAuthenticationError" title="codonPython.mesh.MESHAuthenticationError"><strong>MESHAuthenticationError</strong></a> – There was an authentication error accessing this page. Either the SSL certificate used is invalid,
or the client provided the wrong Mailbox ID, Password, or Shared Key.</p></li>
<li><p><a class="reference internal" href="#codonPython.mesh.MESHUnknownError" title="codonPython.mesh.MESHUnknownError"><strong>MESHUnknownError</strong></a> – There was an unexpected return status from the MESH API</p></li>
</ul>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">client</span><span class="o">.</span><span class="n">ack_download_message</span><span class="p">(</span><span class="s2">"20200211115754892283_BC7B68"</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
</dd></dl>
<dl class="function">
<dt id="codonPython.mesh.generate_authorization">
<code class="sig-prename descclassname">codonPython.mesh.</code><code class="sig-name descname">generate_authorization</code><span class="sig-paren">(</span><em class="sig-param">mailbox: str</em>, <em class="sig-param">password: str</em>, <em class="sig-param">api_shared_key: str</em><span class="sig-paren">)</span> → str<a class="headerlink" href="#codonPython.mesh.generate_authorization" title="Permalink to this definition">¶</a></dt>
<dd><p>Generate an authorization string as specified by the MESH API documentation v1.14</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>mailbox</strong> (<em>string</em>) – The mailbox ID to generate authorization for</p></li>
<li><p><strong>password</strong> (<em>string</em>) – The password for the mailbox</p></li>
<li><p><strong>api_shared_key</strong> (<em>string</em>) – The shared API key for the MESH environment the request is being made to</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The generated authentication string</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>string</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">generate_authorization</span><span class="p">(</span><span class="s2">"TEST_BOX"</span><span class="p">,</span> <span class="s2">"TEST_PW"</span><span class="p">,</span> <span class="s2">"TEST_KEY"</span><span class="p">)</span>
<span class="go">"NHSMESH TEST_BOX:ccd54b96-ee41-4d34-9700-7f9ec63d0720:1:202002120857:763 ... 872c"</span>
<span class="gp">>>> </span><span class="n">generate_authorization</span><span class="p">(</span><span class="s2">"NEW_BOX"</span><span class="p">,</span> <span class="s2">"NEW_PW"</span><span class="p">,</span> <span class="s2">"TEST_KEY"</span><span class="p">)</span>
<span class="go">"NHSMESH NEW_BOX:662c4ffa-c85c-4858-bae8-7327e09aeeb5:1:202002120858:7f1 ... 0d95"</span>
</pre></div>
</div>
</dd></dl>
<dl class="exception">
<dt id="codonPython.mesh.MESHAuthenticationError">
<em class="property">exception </em><code class="sig-prename descclassname">codonPython.mesh.</code><code class="sig-name descname">MESHAuthenticationError</code><span class="sig-paren">(</span><em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#codonPython.mesh.MESHAuthenticationError" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">requests.exceptions.ConnectionError</span></code></p>
<p>The MESH request authentication was invalid</p>
</dd></dl>
<dl class="exception">
<dt id="codonPython.mesh.MESHDownloadErrors">
<em class="property">exception </em><code class="sig-prename descclassname">codonPython.mesh.</code><code class="sig-name descname">MESHDownloadErrors</code><span class="sig-paren">(</span><em class="sig-param">exceptions</em><span class="sig-paren">)</span><a class="headerlink" href="#codonPython.mesh.MESHDownloadErrors" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">Exception</span></code></p>
<p>There were errors downloading MESH messages</p>
</dd></dl>
<dl class="exception">
<dt id="codonPython.mesh.MESHInvalidRecipient">
<em class="property">exception </em><code class="sig-prename descclassname">codonPython.mesh.</code><code class="sig-name descname">MESHInvalidRecipient</code><span class="sig-paren">(</span><em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#codonPython.mesh.MESHInvalidRecipient" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">requests.exceptions.ConnectionError</span></code></p>
<p>The recipient is unknown or otherwise invalid</p>
</dd></dl>
<dl class="exception">
<dt id="codonPython.mesh.MESHMessageAlreadyDownloaded">
<em class="property">exception </em><code class="sig-prename descclassname">codonPython.mesh.</code><code class="sig-name descname">MESHMessageAlreadyDownloaded</code><span class="sig-paren">(</span><em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#codonPython.mesh.MESHMessageAlreadyDownloaded" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">requests.exceptions.ConnectionError</span></code></p>
<p>The MESH request has already been downloaded</p>
</dd></dl>
<dl class="exception">
<dt id="codonPython.mesh.MESHMessageMissing">
<em class="property">exception </em><code class="sig-prename descclassname">codonPython.mesh.</code><code class="sig-name descname">MESHMessageMissing</code><span class="sig-paren">(</span><em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#codonPython.mesh.MESHMessageMissing" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">requests.exceptions.ConnectionError</span></code></p>
<p>The message requested does not exist</p>
</dd></dl>
<dl class="exception">
<dt id="codonPython.mesh.MESHMultipleMatches">
<em class="property">exception </em><code class="sig-prename descclassname">codonPython.mesh.</code><code class="sig-name descname">MESHMultipleMatches</code><span class="sig-paren">(</span><em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#codonPython.mesh.MESHMultipleMatches" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">requests.exceptions.ConnectionError</span></code></p>
<p>There are multiple messages with the provided local ID</p>
</dd></dl>
<dl class="exception">
<dt id="codonPython.mesh.MESHUnknownError">
<em class="property">exception </em><code class="sig-prename descclassname">codonPython.mesh.</code><code class="sig-name descname">MESHUnknownError</code><span class="sig-paren">(</span><em class="sig-param">*args</em>, <em class="sig-param">**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#codonPython.mesh.MESHUnknownError" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">requests.exceptions.ConnectionError</span></code></p>
<p>There was an unknown error with the connection</p>
</dd></dl>
<div class="section" id="requirements">
<h3>Requirements<a class="headerlink" href="#requirements" title="Permalink to this headline">¶</a></h3>
<p>Using the MESH API requires a valid API certificate issued by DIR (for live environments) or Platforms (for development/test environments).
Guidance on obtaining a certificate can be found <a class="reference external" href="https://digital.nhs.uk/services/message-exchange-for-social-care-and-health-mesh/mesh-guidance-hub/certificate-guidance">in the MESH guidance hub</a>.
The module requires the certificate be in PEM format; the certificate enrolment tool produces a java keystore which the valid certificate can be extracted from if needs be.
Due to limitations inherited from the Requests library, the private key <em>must</em> be unencrypted.</p>
<p>The keystore will also contain root authority certificates; these should also be extracted and combined into a certificate bundle for use in confirming the identity of the endpoint being communicated with. This check <em>can</em> be disabled, but this is not recommended.</p>
<p>Finally, use of the MESH API requires the API secret key, which can be requested from Platforms.</p>
</div>
<div class="section" id="example-usage">
<h3>Example usage<a class="headerlink" href="#example-usage" title="Permalink to this headline">¶</a></h3>
<p>Use of the MESH API will generally follow one of a few standard patterns.</p>
<p>Upload file pattern:</p>
<ul class="simple">
<li><p>Check Authentication with the MESH API endpoint</p></li>
<li><p>Send one or more files (chunked if needed)</p></li>
</ul>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">codonPython.mesh</span> <span class="kn">import</span> <span class="n">MESHConnection</span>
<span class="n">mesh_client</span> <span class="o">=</span> <span class="n">MESHConnection</span><span class="p">(</span>
<span class="n">mailbox</span> <span class="o">=</span> <span class="s1">'test'</span>
<span class="n">password</span> <span class="o">=</span> <span class="s1">'test'</span>
<span class="n">api_shared_key</span> <span class="o">=</span> <span class="s1">'test'</span>
<span class="n">cert_loc</span> <span class="o">=</span> <span class="s1">'./certs/test.cert'</span>
<span class="n">key_loc</span> <span class="o">=</span> <span class="s1">'./certs/test.key'</span>
<span class="n">base_ca_loc</span> <span class="o">=</span> <span class="s1">'./certs/test.ca-bundle'</span><span class="p">)</span>
<span class="k">if</span> <span class="n">mesh_client</span><span class="o">.</span><span class="n">check_authentication</span><span class="p">():</span>
<span class="n">mesh_client</span><span class="o">.</span><span class="n">send_file</span><span class="p">(</span><span class="s1">'test_recipient'</span><span class="p">,</span> <span class="s1">'./test/test_20200224_1100.txt.dat'</span><span class="p">,</span> <span class="s1">'test_workflow'</span><span class="p">)</span>
</pre></div>
</div>
<p>Download file pattern:</p>
<ul class="simple">
<li><p>Check Authentication with the MESH API endpoint</p></li>
<li><p>Request a list of files to download from the endpoint</p></li>
<li><p>Download and process each in turn (downloading chunked files if needed)</p></li>
<li><p>After each file has been <em>successfully</em> processed, send acknowledgement to the MESH API for that file</p></li>
<li><p>Repeat as needed until there are no more files which can be processed. Note that the MESH API will return at most 500 message IDs at a time.</p></li>
</ul>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">codonPython.mesh</span> <span class="kn">import</span> <span class="n">MESHConnection</span>
<span class="n">mesh_client</span> <span class="o">=</span> <span class="n">MESHConnection</span><span class="p">(</span>
<span class="n">mailbox</span> <span class="o">=</span> <span class="s1">'test'</span>
<span class="n">password</span> <span class="o">=</span> <span class="s1">'test'</span>
<span class="n">api_shared_key</span> <span class="o">=</span> <span class="s1">'test'</span>
<span class="n">cert_loc</span> <span class="o">=</span> <span class="s1">'./certs/test.cert'</span>
<span class="n">key_loc</span> <span class="o">=</span> <span class="s1">'./certs/test.key'</span>
<span class="n">base_ca_loc</span> <span class="o">=</span> <span class="s1">'./certs/test.ca-bundle'</span><span class="p">)</span>
<span class="k">if</span> <span class="n">mesh_client</span><span class="o">.</span><span class="n">check_authentication</span><span class="p">():</span>
<span class="c1"># To save all messages to a folder</span>
<span class="n">mesh_client</span><span class="o">.</span><span class="n">check_and_download</span><span class="p">(</span><span class="s1">'./inbox'</span><span class="p">)</span>
<span class="c1"># To perform more complex processing on each</span>
<span class="k">for</span> <span class="n">message</span> <span class="ow">in</span> <span class="n">mesh_client</span><span class="o">.</span><span class="n">check_and_download</span><span class="p">():</span>
<span class="n">process</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
<span class="c1"># To perform the flow manually instead of using the check_and_download helper method</span>
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">inbox_messages</span> <span class="o">=</span> <span class="n">mesh_client</span><span class="o">.</span><span class="n">check_inbox</span><span class="p">()</span>
<span class="k">for</span> <span class="n">message_id</span> <span class="ow">in</span> <span class="n">inbox_messages</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">message</span> <span class="o">=</span> <span class="n">mesh_client</span><span class="o">.</span><span class="n">download_message</span><span class="p">(</span><span class="n">message_id</span><span class="p">,</span> <span class="s1">'./inbox'</span><span class="p">)</span>
<span class="n">process</span><span class="p">(</span><span class="n">message</span><span class="p">)</span>
<span class="n">mesh_client</span><span class="o">.</span><span class="n">ack_download_message</span><span class="p">(</span><span class="n">message_id</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
</pre></div>
</div>
<p>NB:
The regular MESH client has strict restrictions on filename and type. The API does not have any such restrictions, however it is likely that the system files are being sent to expects files to be in this format.
Unless you know otherwise files should be sent with .dat extension, with filename pattern Organisation_Date_Time.ext.dat where .ext is the original file extension.</p>
</div>
</div>
<div class="section" id="module-codonPython.nhsd_colours">
<span id="codonpython-nhsd-colours-module"></span><h2>codonPython.nhsd_colours module<a class="headerlink" href="#module-codonPython.nhsd_colours" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="codonPython.nhsd_colours.nhsd_colours">
<code class="sig-prename descclassname">codonPython.nhsd_colours.</code><code class="sig-name descname">nhsd_colours</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#codonPython.nhsd_colours.nhsd_colours" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a dictionary full of the different official NHSD colours from the
style guide:
<a class="reference external" href="https://digital.nhs.uk/about-nhs-digital/corporate-information-and-documents/nhs-digital-style-guidelines/how-we-look/colour-palette">https://digital.nhs.uk/about-nhs-digital/corporate-information-and-documents/nhs-digital-style-guidelines/how-we-look/colour-palette</a></p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>None</strong> – </p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>colour_dict</strong> – A dictionary containing sets of official NHS Digital branding colours
(Hexidecimal format) and fonts.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>dict (Python dictionary)</p>
</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="codonPython.nhsd_colours.nhsd_seaborn_style">
<code class="sig-prename descclassname">codonPython.nhsd_colours.</code><code class="sig-name descname">nhsd_seaborn_style</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#codonPython.nhsd_colours.nhsd_seaborn_style" title="Permalink to this definition">¶</a></dt>
<dd><p>Sets the seaborn style to be inline with NHSD guidlines. This means your
graphs in Seaborn, or in Matplotlib will come out looking as per the NHSD
style guide. Simply run this function.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>None</strong> – </p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p></p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>None</p>
</dd>
</dl>
</dd></dl>
</div>
<div class="section" id="module-codonPython.nhsNumber">
<span id="codonpython-nhsnumber-module"></span><h2>codonPython.nhsNumber module<a class="headerlink" href="#module-codonPython.nhsNumber" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="codonPython.nhsNumber.nhsNumberGenerator">
<code class="sig-prename descclassname">codonPython.nhsNumber.</code><code class="sig-name descname">nhsNumberGenerator</code><span class="sig-paren">(</span><em class="sig-param">to_generate: int</em>, <em class="sig-param">random_state: int = None</em><span class="sig-paren">)</span> → list<a class="headerlink" href="#codonPython.nhsNumber.nhsNumberGenerator" title="Permalink to this definition">¶</a></dt>
<dd><p>Generates up to 1M random NHS numbers compliant with modulus 11 checks as recorded
in the data dictonary.
<a class="reference external" href="https://www.datadictionary.nhs.uk/data_dictionary/attributes/n/nhs/nhs_number_de.asp?shownav=1">https://www.datadictionary.nhs.uk/data_dictionary/attributes/n/nhs/nhs_number_de.asp?shownav=1</a></p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>to_generate</strong> (<em>int</em>) – number of NHS numbers to generate</p></li>
<li><p><strong>random_state</strong> (<em>int</em><em>, </em><em>default : None</em>) – Optional seed for random number generation, for testing and reproducibility.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><strong>generated</strong> – List of randomly generated NHS numbers</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>list</p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">nhsNumberGenerator</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">random_state</span><span class="o">=</span><span class="mi">42</span><span class="p">)</span>
<span class="go">[8429141456, 2625792787]</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="codonPython.nhsNumber.nhsNumberValidator">
<code class="sig-prename descclassname">codonPython.nhsNumber.</code><code class="sig-name descname">nhsNumberValidator</code><span class="sig-paren">(</span><em class="sig-param">number: int</em><span class="sig-paren">)</span> → bool<a class="headerlink" href="#codonPython.nhsNumber.nhsNumberValidator" title="Permalink to this definition">¶</a></dt>
<dd><p>Validate NHS Number according to modulus 11 checks as recorded in the data dictionary.
<a class="reference external" href="https://www.datadictionary.nhs.uk/data_dictionary/attributes/n/nhs/nhs_number_de.asp?shownav=1">https://www.datadictionary.nhs.uk/data_dictionary/attributes/n/nhs/nhs_number_de.asp?shownav=1</a></p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>