Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pva/cdisc feedback part 4 #323

Merged
merged 8 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,28 +219,24 @@
</tr>
</ng-template>
<ng-template pTemplate="body" let-value let-i="rowIndex">
<tr [ngStyle]="{ 'background-color': i === 0 && !selectedSubset.isCdiscGrouper() ? 'lightblue' : 'transparent' }">
<tr [ngStyle]="{ 'background-color': i === 0 && selectedSubset.isCdiscCodeList() ? 'lightblue' : 'transparent' }">
<td class="w-10">
<a [routerLink]="[urlBase, terminology, value.code]" target="_top">
<!-- <i class="fa fa-external-link"
style="margin-left:0.2em;"></i> -->
{{ value.code }}
</a>
<span *ngIf="subsetCodes[value.code] && !selectedSubset.code === value.code"
><br />( <a [routerLink]="['/subset', terminology, value.code]" target="_top">view subset</a>)
<a [routerLink]="[urlBase, terminology, value.code]" target="_top">{{ value.code }}</a>
<span *ngIf="subsetCodes[value.code]"
><br />(<a [routerLink]="['/subset', terminology, value.code]" target="_top">view subset</a>)
</span>
</td>
<td class="w-10">
<span> {{ getCdiscCodelistCode() }}</span>
<span> {{ getCdiscCodelistCode() }}</span>
</td>
<td class="w-10">
<span *ngFor="let prop of value.properties">
<span *ngIf="prop.type == 'Extensible_List'">{{ prop.value }}</span>
</span>
</td>
<td class="w-20">{{ getCodelistName(value) }}</td>
<td class="w-20">{{ getCdiscCodelistName(value) }}</td>
<td class="w-10">{{ getCdiscSubmissionValue(value) }}</td>
<td class="w-20">
<td class="w-15">
<span *ngFor="let syn of value.getSynonymNames(cdiscSubsetSource, 'SY'); last as isLast">
<span
>{{ syn }} <span *ngIf="!isLast"><br /></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class SubsetDetailsComponent implements OnInit {
subsets: Array<Concept>;
avoidLazyLoading = true;
loading: boolean;
synonymSources: any;
termAutoSearch: string;
textSuggestions: string[] = [];
subsetFormat: string;
Expand Down Expand Up @@ -77,17 +76,13 @@ export class SubsetDetailsComponent implements OnInit {
this.subsets.push(new Concept(c, this.configService));
});
}
const synonymMap = new Array<Map<string, string>>();
this.subsetCodes = {};
this.subsetCodes[this.selectedSubset?.code] = 1;
this.subsets.forEach((c) => {
if (c && c['synonyms'].length > 0) {
synonymMap.push(this.getSynonymSources(c['synonyms']));
}
if (c && c['inverseAssociations'].length > 0 && c['inverseAssociations'].find((assoc) => assoc.type == 'Concept_In_Subset')) {
if (c && c.isSubset()) {
this.subsetCodes[c.code] = 1;
}
});
this.synonymSources = synonymMap;
this.termAutoSearch = '';

// getting the subs
Expand All @@ -102,12 +97,12 @@ export class SubsetDetailsComponent implements OnInit {
// CHECK FOR CDISC
else if (ContSource.some((entry) => entry.value.startsWith('CDISC') || entry.value.startsWith('MRCT-Ctr'))) {
this.subsetFormat = 'CDISC';
// For subsets there will be only one contributing source value, take the first
this.cdiscSubsetSource = ContSource[0].value;
if (!this.titleDesc) {
this.titleDesc = this.getSynonymNames(this.selectedSubset, 'CDISC', 'PT')[0];
}
if(!this.selectedSubset?.isCdiscGrouper())
// If this is a codelist, add the "blue" row at the top of the table
if (this.selectedSubset?.isCdiscCodeList()) {
this.subsets.unshift(this.selectedSubset);
}
} else if (ContSource.length === 1) {
this.subsetFormat = ContSource[0].value;
} else {
Expand Down Expand Up @@ -149,52 +144,28 @@ export class SubsetDetailsComponent implements OnInit {
.then((nodes) => {
this.hitsFound = nodes['total'];
this.subsets = new Array<Concept>();
if(!this.selectedSubset?.isCdiscGrouper())
if (this.selectedSubset?.isCdiscCodeList()) {
this.subsets.unshift(this.selectedSubset);
}
if (nodes['concepts']) {
nodes['concepts'].forEach((c) => {
this.subsets.push(new Concept(c, this.configService));
});
}

const synonymMap = new Array<Map<string, string>>();
this.subsetCodes = {};
this.subsetCodes[this.selectedSubset?.code] = 1;
this.subsets.forEach((c) => {
synonymMap.push(this.getSynonymSources(c['synonyms']));
if (c.inverseAssociations?.find((assoc) => assoc.type == 'Concept_In_Subset')) {
if (c && c.isSubset()) {
this.subsetCodes[c.code] = 1;
}
});
this.synonymSources = synonymMap;
});
this.fromRecord = fromRecord;
this.pageSize = event.rows;
}
}

// get synonym sources for a concept
getSynonymSources(synonyms) {
const synonymSourceMap = new Map<string, string>();
synonyms.forEach((synonym) => {
if (synonym['source'] === undefined) {
if (!synonymSourceMap.has('No Source')) {
synonymSourceMap.set('No Source', synonym['name']);
} else {
const key = synonymSourceMap.get('No Source') + ', ' + synonym['name'];
synonymSourceMap.set('No Source', key);
}
} else {
if (!synonymSourceMap.has(synonym['source'])) {
synonymSourceMap.set(synonym['source'], synonym['name']);
} else {
const key = synonymSourceMap.get(synonym['source']) + ', ' + synonym['name'];
synonymSourceMap.set(synonym['source'], key);
}
}
});
return synonymSourceMap;
}

// search for a concept
search(event, columnName = null) {
if (this.lastSearch !== event.query) {
Expand Down Expand Up @@ -228,21 +199,20 @@ export class SubsetDetailsComponent implements OnInit {
this.hitsFound = nodes['total'];
if (this.hitsFound > 0) {
this.subsets = new Array<Concept>();
if(!this.selectedSubset?.isCdiscGrouper())
if (this.selectedSubset?.isCdiscCodeList()) {
this.subsets.unshift(this.selectedSubset);
}
nodes['concepts'].forEach((c) => {
this.subsets.push(new Concept(c, this.configService));
});

const synonymMap = new Array<Map<string, string>>();
this.subsetCodes = {};
this.subsetCodes[this.selectedSubset?.code] = 1;
this.subsets.forEach((c) => {
synonymMap.push(this.getSynonymSources(c['synonyms']));
if (c.inverseAssociations?.find((assoc) => assoc.type == 'Concept_In_Subset')) {
if (c.isSubset()) {
this.subsetCodes[c.code] = 1;
}
});
this.synonymSources = synonymMap;
} else {
this.subsets = null;
}
Expand All @@ -266,8 +236,8 @@ export class SubsetDetailsComponent implements OnInit {
const pages = Math.ceil(Math.min(exportMax, this.hitsFound) / exportPageSize);
const pageList = Array.from(Array(pages).keys());

if (this.subsetFormat === 'CDISC') {
subsetText += this.exportCodeFormatter(this.selectedSubset, true);
if (this.subsetFormat === 'CDISC' && !this.selectedSubset.isCdiscGrouper()) {
subsetText += this.exportCodeFormatter(this.selectedSubset);
}
for (const page of pageList) {
await this.subsetDetailService
Expand All @@ -290,7 +260,7 @@ export class SubsetDetailsComponent implements OnInit {
}

// format the export file
exportCodeFormatter(concept: Concept, firstCDISC = false) {
exportCodeFormatter(concept: Concept) {
let rowText = '';
if (this.subsetFormat === 'NCIt') {
rowText += concept.code + '\t';
Expand Down Expand Up @@ -323,11 +293,11 @@ export class SubsetDetailsComponent implements OnInit {
const extensible = concept.properties.filter((prop) => prop.type == 'Extensible_List')[0]?.value;
rowText += (extensible ? extensible : '') + '\t';
// codelist name
rowText += this.getCodelistName(concept) + '\t';
rowText += this.getCdiscCodelistName(new Concept(concept, this.configService)) + '\t';
// cdisc submission value
rowText += this.getCdiscSubmissionValue(concept) + '\t';
rowText += this.getCdiscSubmissionValue(new Concept(concept, this.configService)) + '\t';
// cdisc synonyms
rowText += '"' + this.getSynonymNames(concept, 'CDISC', 'SY').join('\n') + '"' + '\t';
rowText += '"' + this.getSynonymNames(concept, this.cdiscSubsetSource, 'SY').join('\n') + '"' + '\t';
// cdisc definition
rowText += concept.definitions.filter((def) => def.source.startsWith('CDISC') || def.source.startsWith('MRCT-Ctr'))[0]?.definition + '\t';
// NCIt pref term
Expand Down Expand Up @@ -404,72 +374,87 @@ export class SubsetDetailsComponent implements OnInit {
}

getCdiscCodelistCode() {
if(this.selectedSubset.isCdiscGrouper()) {
return null;
if (this.selectedSubset.isCdiscGrouper()) {
return '';
} else {
return this.selectedSubset.code;
}
}

// Uses this.submissionValueCode to determine the submission value column for CDISC display
getCdiscSubmissionValue(concept: Concept): string {
if(concept.isCdiscGrouper()) {
return null;
// Groupers do not have a submission value
if (concept.isCdiscGrouper()) {
return '';
}

// Codelists have a submission value matching CDISC or MRCTPT
if (concept.isCdiscCodeList()) {
return concept.getCdiscPtName();
}

// if selected subset is a grouper, no value
if (this.selectedSubset.isCdiscGrouper()) {
return '';
}
// Kim's algorithm

// assumption: codelist only has one contributing source
// Otherwise our concept is just a regular value

// CDISC Submission Value algorithm

// ASSUMPTION: codelist only has one contributing source
var subsetContSource = this.selectedSubset.properties?.find((item) => item.type === 'Contributing_Source')?.value;
if(!subsetContSource) {
return "Unable to find submission value because codelist lacks contributing source";
if (!subsetContSource) {
return 'Unable to find submission value because codelist lacks contributing source';
}
// Find the matching contributing source PT
// ASSUMPTION: there will be at least 1
const cdiscSynonyms = concept.synonyms.filter((syn) => syn.source === subsetContSource && syn.termType === 'PT');
if (cdiscSynonyms.length == 0) {
return 'Unable to find submission value for ' + subsetContSource + '/PT';
}
const cdiscSynonyms = concept.synonyms.filter(
(syn) =>
syn.source === subsetContSource &&
syn.type === "FULL_SYN" &&
syn.termType === "PT"
);

// Check if there's exactly one unique synonym
var nci_ab = "";
var nci_ab = '';
if (cdiscSynonyms.length === 1) {
return cdiscSynonyms[0].name;
}
nci_ab = this.selectedSubset.synonyms.find(
(syn) =>
// no multiple MRCT
syn.source === "NCI" &&
syn.type === "FULL_SYN" &&
syn.termType === "AB"
)?.name;
if(nci_ab) {
const finalSynonym = cdiscSynonyms.find(
(syn) =>
syn.code === nci_ab
);
if(finalSynonym) {
return finalSynonym?.name;
} else {
return "Unable to find submission value (synonym that matches NCI source and AB term type)";
}
// Otherwise, find the NCI/AB of the codelist concept and find the CDISC/PT witha code matching the NCI/AB's name
nci_ab = this.selectedSubset.synonyms.find((syn) => syn.source === 'NCI' && syn.termType === 'AB')?.name;
if (nci_ab) {
const finalSynonym = cdiscSynonyms.find((syn) => syn.code === nci_ab);
if (finalSynonym) {
return finalSynonym.name;
}
// ASSUMPTION: there will be a final synonym
else {
return 'Unable to find submission value (synonym that matches NCI source and AB term type)';
}

}
return "Unable to find submission value";
return 'Unable to find submission value';
}

getCodelistName(value) {
if(!value.isSubset()) {
getCdiscCodelistName(concept: Concept) {
// For a regular entry in the table, the subset we are on is the codelist
if (!concept.isSubset()) {
if (this.selectedSubset.isCdiscGrouper()) {
return '';
}
return this.selectedSubset.name;

}

// If the subset we are on is a grouper
if (this.selectedSubset.isCdiscGrouper()) {
if(value.isCdiscGrouper()) {
return null;
} else {
return value.name;
// and the concept itself is a grouper, then don't show a name
if (concept.isCdiscGrouper()) {
return '';
}
// otherwise, the concept itself is a codelist entry, show its own name
else {
return concept.name;
}
} else {
return this.selectedSubset.name;
return this.selectedSubset.name;
}
}

Expand All @@ -480,5 +465,4 @@ export class SubsetDetailsComponent implements OnInit {
const desc = this.selectedSubset.properties.find((item) => item.type === 'Term_Browser_Value_Set_Description');
return this.selectedSubset.subsetLink !== undefined && desc !== undefined && !desc.value.includes(this.selectedSubset.subsetLink);
}

}
31 changes: 27 additions & 4 deletions web/frontend/src/app/model/concept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export class Concept {
}
}
}
return null;
return '';
}

// Get value from Concept_Status parameter
Expand Down Expand Up @@ -606,15 +606,38 @@ export class Concept {
}

isCdiscGrouper(): boolean {
return (this.code === "C61410" || ((this.name.startsWith("CDISC ") || this.name.startsWith("MRCT")) && !this.synonyms.some(syn => syn.source?.startsWith('CDISC') && syn.termType === 'SY'))) && this.inverseAssociations.some(invAssoc => invAssoc.type === "Concept_In_Subset");
// Only subsets can be groupers
if (!this.isSubset()) {
return false;
}

// CDISC subset without a CDISC/SY
return this.isCdiscSubset() && !this.hasCdiscSy();
}

isCdiscCodeList(): boolean {
return this.properties.some(prop => prop.type === "Publish_Value_Set" && prop.value === "true") && this.synonyms.some(syn => syn.source?.startsWith('CDISC') && syn.termType === 'SY');
// CDISC Subset with CDISC name a CDISC/SY
return this.isCdiscSubset() && this.hasCdiscSy();
}

hasCdiscSy(): boolean {
// source with CDISC* or MRCT* and termType = SY
return this.synonyms.some((syn) => syn.source && (syn.source.startsWith('CDISC') || syn.source.startsWith('MRCT-Ctr')) && syn.termType === 'SY');
}

getCdiscPtName(): string {
return this.synonyms?.find((syn) => syn.source && (syn.source.startsWith('CDISC') || syn.source.startsWith('MRCT-Ctr')) && syn.termType === 'PT')
?.name;
}

isCdiscSubset(): boolean {
// subset with a name starting with CDISC or MRCT
return this.code === 'C61410' || (this.isSubset() && (this.name.startsWith('CDISC ') || this.name.startsWith('MRCT-Ctr')));
}

isSubset(): boolean {
return this.inverseAssociations.some(invAssoc => invAssoc.type === "Concept_In_Subset");
// It's a subset if it has Publish_Value_Set=Yes
return this.properties.some((prop) => prop.type === 'Publish_Value_Set' && prop.value === 'Yes');
}

// Default string representation is the name
Expand Down
Loading