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

add measure-set column #3

Merged
merged 11 commits into from
Aug 30, 2024
47 changes: 42 additions & 5 deletions src/data-dictionary/IgSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {logger} from '../util/logger';
import {ProfileGroupExtractor, ProfileGroups} from '../profile_groups';
import {
DataElementInformation,
DataElementInformationForSpreadsheet
DataElementInformationForSpreadsheet,
SpreadsheetColNames
} from '../elements/ProfileElement';
import {ProfileElementFactory} from '../elements/Factory';
import {
Expand Down Expand Up @@ -252,7 +253,12 @@ export class IgSummary {
public async generateSpreadsheet() {
// Get external dependencies
await this.getExternalDefs();

let excludeElements = [
karlnaden marked this conversation as resolved.
Show resolved Hide resolved
'DeviceRequest.modifierExtension',
'DeviceRequest.modifierExtension:doNotPerform',
'Task.output.value[x]',
'Encounter.reasonReference',
'Claim.extension:encounter'];
// Store data for CSV here
let profileElements: Array<DataElementInformationForSpreadsheet> = [];

Expand All @@ -263,9 +269,29 @@ export class IgSummary {
logger.error(`No profiles found in ${this.fhirDefFolder}.`);
return;
}

let usedByMeasureMap = new Map<string, string>();
let assoWithVSMap = new Map<string, string>();
for (const sd of _.uniqBy(this.defs.allProfiles(), 'id')) {
const snapshot = sd.snapshot;

const profileTitle = sd.title || sd.name;
// usedByMeasureMap and assoWithVSMap are temporary. Eventually extension flag can be included in DataElementInformation
for (const elemJson of snapshot.element.slice(1)) {
let flg1:boolean = false;
let flg2:boolean = false;
karlnaden marked this conversation as resolved.
Show resolved Hide resolved
elemJson.extension?.forEach((ext: any) => {
// console.log(ext.url);
if (ext.url.includes('/StructureDefinition/used-by-measure')) flg1 = true;
// if (ext.url.includes('/StructureDefinition/associated-with-valueset')) flg2 = true;
})
if (flg1) usedByMeasureMap.set(profileTitle+elemJson.id, 'true');
//if (flg2) assoWithVSMap.set(profileTitle+elemJson.id, 'true');
}
}

for (const sd of _.uniqBy(this.defs.allProfiles(), 'id')) {
const snapshot = sd.snapshot;

// Skip abstract profiles
if (sd.abstract === true) {
continue;
Expand All @@ -278,6 +304,11 @@ export class IgSummary {
// The `slice(1)` skips the first item in the array, which is information about the StructureDefinition
// that isn't needed.
for (const elemJson of snapshot.element.slice(1)) {
// console.log(elemJson.id);
if (excludeElements.includes(elemJson.id)) {
continue;
}

if (
this.settings.mode == DataDictionaryMode.MustSupport &&
!(
Expand All @@ -303,7 +334,7 @@ export class IgSummary {
[this.defs, this.externalDefs],
this.settings
);

const elemToJson = elem.toJSON();
// Filter down to unique elements -- there may be duplicates because extension ProfileElement objects
// automatically add sub-elements.
Expand All @@ -324,8 +355,14 @@ export class IgSummary {

if (deduplicatedElemToJson) profileElements = profileElements.concat(deduplicatedElemToJson);
}

}

profileElements.forEach(pe => {
pe[SpreadsheetColNames.UsedByMeasure] = usedByMeasureMap.get(pe[SpreadsheetColNames.ProfileTitle]+pe[SpreadsheetColNames.FHIRElement]);
// pe[SpreadsheetColNames.AssociatedWithValueSet] = assoWithVSMap.get(pe[SpreadsheetColNames.ProfileTitle]+pe[SpreadsheetColNames.FHIRElement]);
});

// Get list of profiles, extensions, and value sets
const allExtensions: DataDictionaryJsonSummaryRow[] = _.uniqBy(this.defs.allExtensions(), x => {
return x.url;
Expand Down Expand Up @@ -414,7 +451,7 @@ export class IgSummary {
size: 16
};
[
['', 'IG name', this.sushiConfig.title],
['', 'IG name', this.sushiConfig.name],
karlnaden marked this conversation as resolved.
Show resolved Hide resolved
['', 'IG URL', this.sushiConfig.url],
['', 'IG version', this.sushiConfig.version],
['', 'IG status', this.sushiConfig.status],
Expand Down
10 changes: 9 additions & 1 deletion src/elements/ProfileElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export enum SpreadsheetColNames {
FHIRElement = 'FHIR Element (R4)',
SourceProfileURI = 'Source Profile URI',
ElementStructureDefinitionURI = 'Element StructureDefinition URI',
UsedByMeasure = 'Used By Measure'
// AssociatedWithValueSet = 'Associated With Value Set'
}

// Non-optional version of DataElementInformation, with proper row names
Expand All @@ -47,6 +49,8 @@ export type DataElementInformationForSpreadsheet = {
[SpreadsheetColNames.FHIRElement]: string;
[SpreadsheetColNames.SourceProfileURI]: string;
[SpreadsheetColNames.ElementStructureDefinitionURI]: string;
[SpreadsheetColNames.UsedByMeasure]: string;
// [SpreadsheetColNames.AssociatedWithValueSet]: string;
[key: string]: string; // Adds an index signature to the type
};

Expand All @@ -71,6 +75,8 @@ export class ProfileElement {

// TODO this should not be `fhirtypes.Extension` -- this is the wrong type (even though it works)
protected _structureDefinition: fhirtypes.Extension;
public usedByMeasure: string;
public associatedWithValueSet: string;

constructor(
elem: fhirtypes.ElementDefinition,
Expand Down Expand Up @@ -468,7 +474,9 @@ export class ProfileElement {
[SpreadsheetColNames.ValueSetBinding]: this.valueSet.binding,
[SpreadsheetColNames.FHIRElement]: fhirPath,
[SpreadsheetColNames.SourceProfileURI]: this.dataElementInformation.sourceProfileURI,
[SpreadsheetColNames.ElementStructureDefinitionURI]: this.dataElementInformation.elementStructureDefinitionURI
[SpreadsheetColNames.ElementStructureDefinitionURI]: this.dataElementInformation.elementStructureDefinitionURI,
[SpreadsheetColNames.UsedByMeasure]: this.usedByMeasure
// [SpreadsheetColNames.AssociatedWithValueSet]: this.associatedWithValueSet
}
];

Expand Down