Convert-Pheno
view release on metacpan or search on metacpan
t/01-api-bff-pxf.t view on Meta::CPAN
);
my $got = $convert->bff2pxf;
$got->{$_} = undef for qw(id metaData);
is_deeply( $got, $pxf, 'bff2pxf module conversion matches fixture' );
}
{
my $bff_records = load_json_file('t/pxf2bff/out/individuals.json');
my $source_pxf = load_json_file('t/pxf2bff/in/pxf.json');
my $before = JSON::XS->new->canonical->encode($bff_records);
my $roundtrip = build_convert(
in_textfile => 0,
data => $bff_records,
method => 'bff2pxf',
)->bff2pxf;
is(
scalar @{$roundtrip},
scalar @{$source_pxf},
'bff2pxf processes every record in the attributed Phenopackets fixture',
);
is_deeply(
$roundtrip->[8]{diseases}[0]{diseaseStage},
$source_pxf->[8]{diseases}[0]{diseaseStage},
'bff2pxf restores disease stage terms',
);
is_deeply(
$roundtrip->[8]{diseases}[0]{clinicalTnmFinding},
$source_pxf->[8]{diseases}[0]{clinicalTnmFinding},
'bff2pxf restores clinical TNM findings',
);
is_deeply(
$roundtrip->[8]{diseases}[0]{primarySite},
$source_pxf->[8]{diseases}[0]{primarySite},
'bff2pxf restores the disease primary site',
);
is_deeply(
$roundtrip->[8]{phenotypicFeatures}[0]{modifiers},
$source_pxf->[8]{phenotypicFeatures}[0]{modifiers},
'bff2pxf restores phenotypic feature modifiers',
);
is_deeply(
$roundtrip->[11]{phenotypicFeatures}[0]{severity},
$source_pxf->[11]{phenotypicFeatures}[0]{severity},
'bff2pxf restores phenotypic feature severity',
);
is(
JSON::XS->new->canonical->encode($bff_records),
$before,
'fixture round-trip leaves caller-owned BFF records unchanged',
);
}
{
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 1.541 second using v1.01-cache-2.11-cpan-c221a9de4ec )