| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
# Demonstrates how the Header information of biosig data can be read through |
| 4 |
# JSON header export |
| 5 |
# |
| 6 |
# References: |
| 7 |
# [1] https://www.hl7.org/fhir/references.html |
| 8 |
# [2] ÖNorm K2204:2015, GDF - A general data format for biomedical signals |
| 9 |
|
| 10 |
|
| 11 |
# |
| 12 |
# Copyright (C) 2016 Alois Schloegl <[email protected]> |
| 13 |
# This file is part of the BioSig repository at http://biosig.sf.net/ |
| 14 |
# |
| 15 |
# This program is free software; you can redistribute it and/or |
| 16 |
# modify it under the terms of the GNU General Public License |
| 17 |
# as published by the Free Software Foundation; either version 3 |
| 18 |
# of the License, or (at your option) any later version. |
| 19 |
# |
| 20 |
# This program is distributed in the hope that it will be useful, |
| 21 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
# GNU General Public License for more details. |
| 24 |
|
| 25 |
# You should have received a copy of the GNU General Public License |
| 26 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 27 |
|
| 28 |
use strict; |
| 29 |
use warnings; |
| 30 |
|
| 31 |
use JSON::XS; |
| 32 |
use Data::Dumper; |
| 33 |
|
| 34 |
my $EXT=''; |
| 35 |
if ("$^O" eq "MSWin32") { |
| 36 |
$EXT='.exe'; |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
# biosig_fhir_base64: |
| 41 |
# encodes a biosig file as a base64-encoded GDF [2] v3.0 stream |
| 42 |
sub biosig_fhir_base64 { |
| 43 |
my $cmd = "biosig_fhir$EXT -base64 '$_[0]' 2>/dev/null"; |
| 44 |
my $jsonhdr = `$cmd`; |
| 45 |
return $jsonhdr; |
| 46 |
} |
| 47 |
|
| 48 |
# biosig_fhir: makes a fhir_json_binary template |
| 49 |
sub biosig_fhir_json { |
| 50 |
my $cmd = "biosig_fhir$EXT -json '$_[0]' 2>/dev/null"; |
| 51 |
my $jsonhdr = `$cmd`; |
| 52 |
return $jsonhdr; |
| 53 |
} |
| 54 |
|
| 55 |
# biosig_fhir_xml: makes a fhir_xml_binary template |
| 56 |
sub biosig_fhir_xml { |
| 57 |
my $h = "biosig_fhir$EXT -xml $_[0] 2>/dev/null"; |
| 58 |
my $jsonhdr = `$h`; |
| 59 |
return $jsonhdr; |
| 60 |
} |
| 61 |
|
| 62 |
# get header (meta) information |
| 63 |
sub biosig_json_header { |
| 64 |
my $h = "save2gdf$EXT -JSON $_[0] 2>/dev/null"; |
| 65 |
my $jsonhdr = `$h`; |
| 66 |
return $jsonhdr; |
| 67 |
} |
| 68 |
|
| 69 |
# get header (meta) information in hash array |
| 70 |
sub biosig_header { |
| 71 |
return decode_json( biosig_json_header("$_[0]") ); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
my $filename='data/Newtest17-256.bdf'; |
| 77 |
|
| 78 |
### Hash array of header information through JSON interface |
| 79 |
my $HDR = biosig_header($filename); |
| 80 |
print Dumper($HDR); |
| 81 |
|
| 82 |
## generate JSON_BINARY_TEMPLATE |
| 83 |
my $FHIR_JSON_BINARY_TEMPLATE = biosig_fhir_json($filename); |
| 84 |
print $FHIR_JSON_BINARY_TEMPLATE; |
| 85 |
|
| 86 |
|