Skip to content
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
4 changes: 4 additions & 0 deletions coding-scheme.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export type CodingSchemeProblemType =
| 'SOURCE_MISSING'
| 'INVALID_SOURCE'
| 'RULE_PARAMETER_COUNT_MISMATCH'
| 'RULE_REGEX_INVALID'
| 'RULE_PARAMETER_INVALID'
| 'RULE_NUMERIC_RANGE_INVALID'
| 'RULESET_VALUE_ARRAY_POS_INVALID'
| 'MORE_THAN_ONE_SOURCE'
| 'ONLY_ONE_SOURCE'
| 'VALUE_COPY_NOT_FROM_BASE';
Expand Down
6 changes: 3 additions & 3 deletions coding-scheme.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"id": {
"type": "string",
"description": "Identifier for the variable. In case of a scheme for a base variable, this id is identical with the source variable's id. All ids of a response scheme should be unique.",
"pattern": "^[0-9a-zA-Z_]+$"
"pattern": "^[0-9a-zA-Z_-]+$"
},
"alias": {
"type": "string",
"description": "Alternative identifier for the variable. In case of a scheme for a base variable, this id is identical with the source variable's alternative id. All alternative ids of a response scheme should be unique.",
"pattern": "^[0-9a-zA-Z_]+$"
"pattern": "^[0-9a-zA-Z_-]+$"
},
"label": {
"type": "string",
Expand Down Expand Up @@ -80,7 +80,7 @@
"type": "array",
"items": {
"type": "string",
"pattern": "^[0-9a-zA-Z_]+$"
"pattern": "^[0-9a-zA-Z_-]+$"
}
},
"processing": {
Expand Down
50 changes: 39 additions & 11 deletions coding-scheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,26 @@ export class CodingScheme {
const givenCodings = Array.isArray(transformedScheme) ?
transformedScheme :
transformedScheme.variableCodings || [];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
givenCodings.forEach((c: any) => {
this.variableCodings.forEach(vc => {
vc.codes?.forEach(code => {
if (code.id === null) code.id = 'INVALID';
});
});
let vc: VariableCodingData;
if (codingSchemeMajorVersion < 3) {
this.variableCodings.push(
CodingScheme.getCodeVersionLessThan3(c)
);
vc = CodingScheme.getCodeVersionLessThan3(c);
} else {
this.variableCodings.push(c);
vc = c;
}
CodingScheme.applyLegacyFixes(vc);
this.variableCodings.push(vc);
});
this.variableCodings.forEach(vc => {
vc.codes?.forEach(code => {
if (code.id === null) code.id = 'INVALID';
});
});
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private static getCodeVersionLessThan3(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
givenCoding: any
): VariableCodingData {
const codes: CodeData[] = [];
Expand Down Expand Up @@ -166,8 +168,8 @@ export class CodingScheme {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
givenCoding.codes.forEach((code: any) => {
if (code.ruleSets) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const elseRule = code.ruleSets.find(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(rs: any) => !!rs.rules.find((r: any) => r.method === 'ELSE')
);
if (elseRule) {
Expand Down Expand Up @@ -205,7 +207,33 @@ export class CodingScheme {
return newCoding;
}

private static applyLegacyFixes(vc: VariableCodingData): void {
if ((vc.codeModel as unknown as string) === 'NONE') {
const hasRules = vc.codes?.some(c => (c.ruleSets && c.ruleSets.length > 0));
const hasManualInstruction = !!vc.manualInstruction || vc.codes?.some(c => !!c.manualInstruction);
if (vc.sourceType === 'MANUAL') {
vc.codeModel = 'MANUAL_ONLY';
} else if (hasRules && hasManualInstruction) {
vc.codeModel = 'MANUAL_AND_RULES';
} else if (hasRules) {
vc.codeModel = 'RULES_ONLY';
} else if (hasManualInstruction) {
vc.codeModel = 'MANUAL_ONLY';
} else {
vc.codeModel = 'RULES_ONLY';
}
}
vc.codes?.forEach(c => {
if (c.ruleSets && Array.isArray(c.ruleSets)) {
c.ruleSets.forEach(rs => {
if ((rs.valueArrayPos as unknown as number) === -1) rs.valueArrayPos = 'ANY';
});
}
});
}

static checkVersion(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
givenScheme: any
): 'OK' | 'MAJOR_LESS' | 'MAJOR_GREATER' | 'MINOR_GREATER' {
const transformedScheme =
Expand Down
2 changes: 1 addition & 1 deletion package_npm.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@iqbspecs/coding-scheme",
"version": "3.3.1",
"version": "3.4",
"author": "IQB - Institut zur Qualitätsentwicklung im Bildungswesen",
"license": "CC0 1.0",
"description": "Data interface: coding-scheme",
Expand Down
9 changes: 9 additions & 0 deletions test/test_valid/valid-id-patterns.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
{
"id": "a",
"sourceType": "BASE"
},
{
"id": "var-with-hyphen",
"sourceType": "BASE"
},
{
"id": "v-123-abc",
"alias": "alias-with-hyphen-123",
"sourceType": "BASE"
}
]
}
Loading