Convert-Pheno
view release on metacpan or search on metacpan
t/01-api-bff-pxf.t view on Meta::CPAN
{
name => 'pxf2jsonf',
method => 'pxf2jsonf',
in_file => 't/pxf2bff/in/pxf.json',
out_file => 't/pxf2jsonf/out/pxf.fold.json',
writer => 'json',
},
);
for my $case (@cases) {
my $tmp_file = temp_output_file(
suffix => $case->{writer} eq 'csv' ? '.csv' : '.json'
);
my $convert = build_convert(
in_file => $case->{in_file},
out_file => $tmp_file,
method => $case->{method},
);
if ( $case->{writer} eq 'csv' ) {
my $data = $convert->${ \$case->{method} };
my $headers = get_headers($data);
write_csv_rows( $tmp_file, $headers, $data );
}
else {
my $suffix = $case->{out_file} =~ /\.ya?ml$/ ? '.yaml' : '.json';
$tmp_file =~ s/\.[^.]+$/$suffix/;
write_json_file( $tmp_file, $convert->${ \$case->{method} } );
}
my $match =
$case->{writer} eq 'csv'
? Test::ConvertPheno::json_files_match( $case->{out_file}, $tmp_file )
: structured_files_match( $case->{out_file}, $tmp_file );
ok( $match, $case->{name} );
}
{
my $bff = read_first_json_object('t/bff2pxf/in/individuals.json');
my $pxf = read_first_json_object('t/bff2pxf/out/pxf.json');
$pxf->{$_} = undef for qw(id metaData);
my $convert = build_convert(
in_textfile => 0,
data => $bff,
method => 'bff2pxf',
);
my $got = $convert->bff2pxf;
$got->{$_} = undef for qw(id metaData);
is_deeply( $got, $pxf, 'bff2pxf module conversion matches fixture' );
}
{
my $gender = load_json_file('t/openehr2bff/in/gecco_personendaten.json');
my $ips = load_json_file('t/openehr2bff/in/ips_canonical.json');
my $lab = load_json_file('t/openehr2bff/in/laboratory_report.json');
my $corona = load_json_file('t/openehr2bff/in/compo_corona.json');
my $convert = build_convert(
method => 'openehr2pxf',
data => {
patient => { id => 'openehr-patient-2' },
compositions => [ $gender, $ips, $lab, $corona ],
},
in_textfile => 0,
);
my $tmp_file = temp_output_file( suffix => '.json' );
write_json_file( $tmp_file, $convert->openehr2pxf );
ok(
structured_files_match( 't/openehr2pxf/out/pxf.json', $tmp_file ),
'openehr2pxf module conversion matches fixture'
);
}
{
my $patient_a = load_json_file('t/openehr2bff/in/gecco_personendaten.json');
my $patient_b = load_json_file('t/openehr2bff/in/gecco_personendaten.json');
$patient_a->{subject} = {
_type => 'PARTY_SELF',
external_ref => {
id => { _type => 'GENERIC_ID', value => 'patient-a', scheme => 'PMI' },
namespace => 'PMI',
type => 'PERSON',
},
};
$patient_b->{subject} = {
_type => 'PARTY_SELF',
external_ref => {
id => { _type => 'GENERIC_ID', value => 'patient-b', scheme => 'PMI' },
namespace => 'PMI',
type => 'PERSON',
},
};
my $convert = build_convert(
method => 'openehr2pxf',
data => [
{ compositions => [$patient_a] },
{ compositions => [$patient_b] },
],
in_textfile => 0,
);
my $pxf = $convert->openehr2pxf;
is( ref($pxf), 'ARRAY', 'openehr2pxf returns an array for multi-patient input' );
is( scalar @{$pxf}, 2, 'openehr2pxf emits one phenopacket per patient bucket' );
}
{
my $bff = {
id => 'subject-1',
sex => { id => 'NCIT:C20197', label => 'male' },
info => {
phenopacket => {
dateOfBirth => '1980-01-02',
biosamples => [ { id => 'bio-1' } ],
interpretations => [ { id => 'int-1' } ],
files => [ { uri => 'file://example' } ],
genes => [ { id => 'HGNC:5' } ],
variants => [ { id => 'var-1' } ],
pedigree => { id => 'ped-1' },
( run in 0.671 second using v1.01-cache-2.11-cpan-39bf76dae61 )