nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: FHIR/sushi
Pull request #714 (2021-01-06 13:05:34)

Log less confusing error on inline instance assignment
Fixes https://github.com/FHIR/sushi/issues/703 by slightly clarifying the error message we log when someone assigns an inline instance. I don't think there is a clear way here to guess the intent of the user. Even if the element is of type CodeableConcept, the user could be trying to assign an inline instance of a CodeableConcept to that element. So all this PR does is log the type of the element being assigned onto, if it is possible. I think this should potentially help people understand what is going wrong when they assign a value.

If this doesn't seem sufficient, and someone sees a better way to log this message and/or guess the intent of the user, let me know.

ngfreiter: Idk why but as of right now I can't add @jafeltra as a reviewer, so @jafeltra I'm not purposefully excluding you, please also review if you please!

Patch:
diff --git a/src/export/StructureDefinitionExporter.ts b/src/export/StructureDefinitionExporter.ts
index d85f2b5..a1235f3 100644
--- a/src/export/StructureDefinitionExporter.ts
+++ b/src/export/StructureDefinitionExporter.ts
@@ -163,7 +163,15 @@ export class StructureDefinitionExporter implements Fishable {
               const instanceExporter = new InstanceExporter(this.tank, this.pkg, this.fisher);
               const instance = instanceExporter.fishForFHIR(rule.value as string);
               if (instance == null) {
-                logger.error(`Cannot find definition for Instance: ${rule.value}. Skipping rule.`);
+                if (element.type?.length === 1) {
+                  logger.error(
+                    `Cannot assign Instance at path ${rule.path} to element of type ${element.type[0].code}. Definition not found for Instance: ${rule.value}.`
+                  );
+                } else {
+                  logger.error(
+                    `Cannot find definition for Instance: ${rule.value}. Skipping rule.`
+                  );
+                }
                 continue;
               }
               rule.value = instance;


Test patch:
diff --git a/test/export/StructureDefinitionExporter.test.ts b/test/export/StructureDefinitionExporter.test.ts
index 0f390fe..11998c7 100644
--- a/test/export/StructureDefinitionExporter.test.ts
+++ b/test/export/StructureDefinitionExporter.test.ts
@@ -1763,7 +1763,7 @@ describe('StructureDefinitionExporter', () => {
     expect(assignedAddress.patternAddress).toBeUndefined();
     expect(loggerSpy.getAllMessages('error')).toHaveLength(1);
     expect(loggerSpy.getLastMessage('error')).toMatch(
-      /Cannot find definition for Instance: FakeInstance. Skipping rule.\D*/s
+      /Cannot assign Instance at path address to element of type Address.*FakeInstance\D*/s
     );
   });
Repository: FHIR/sushi
Pull request #754 (2021-02-08 19:32:32)

Fix handling of empty string ruleset parameters
To manually test this (and see broken behavior vs fixed behavior

* Locally edit `regression/repos-select.txt` so it contains only one line:
  ```
  openhie/case-reporting#master
  ```
* Run regression: `npm run regression`

Note that in the results, the master branch produces 12 errors and this branch produces 0 errors.  Also note that in the diff, this branch's questionnaire instance contains many items missing from the master branch's instance.


Patch:
diff --git a/src/import/FSHImporter.ts b/src/import/FSHImporter.ts
index 85eb6be..0197397 100644
--- a/src/import/FSHImporter.ts
+++ b/src/import/FSHImporter.ts
@@ -1559,7 +1559,7 @@ export class FSHImporter extends FSHVisitor {
           // then, make all the replacements: closing parenthesis and comma
           return substrComma.replace(/\\\)/g, ')').replace(/\\,/g, ',');
         })
-        .filter(s => s); // Filter out any null values from incorrectly split escaped commas
+        .filter(s => s != null); // Filter out any null values from incorrectly split escaped commas
     });
     const paramList: string[] = [];
     // if splitComma has more than one list, that means we split on literal backslash


Test patch:
diff --git a/test/import/FSHImporter.Instance.test.ts b/test/import/FSHImporter.Instance.test.ts
index 1d15d9a..207d500 100644
--- a/test/import/FSHImporter.Instance.test.ts
+++ b/test/import/FSHImporter.Instance.test.ts
@@ -252,6 +252,31 @@ describe('FSHImporter', () => {
         expect(instance.rules).toHaveLength(1);
         assertInsertRule(instance.rules[0], 'MyRuleSet');
       });
+
+      it('should parse an insert rule with an empty parameter value', () => {
+        // Example taken from open-hie/case-reporting, which failed a regression in this area
+        const input = `
+        RuleSet: Question(context, linkId, text, type, repeats)
+        * {context}item[+].linkId = "{linkId}"
+        * {context}item[=].text = "{text}"
+        * {context}item[=].type = #{type}
+        * {context}item[=].repeats = {repeats}
+
+        Instance: case-reporting-questionnaire
+        InstanceOf: Questionnaire
+        * insert Question(,title, HIV Case Report, display, false)
+        `;
+        const result = importSingleText(input, 'Insert.fsh');
+        const instance = result.instances.get('case-reporting-questionnaire');
+        expect(instance.rules).toHaveLength(1);
+        assertInsertRule(instance.rules[0], 'Question', [
+          '',
+          'title',
+          'HIV Case Report',
+          'display',
+          'false'
+        ]);
+      });
     });
 
     describe('#instanceMetadata', () => {
Repository: FHIR/sushi
Pull request #765 (2021-02-22 16:58:25)

Support any type of whitespace in a code
Very small PR for supporting any type of whitespace in a code. This came out of a suggestion on a [GoFSH PR](https://github.com/FHIR/GoFSH/pull/99). This just adds the equivalent change to SUSHI. 


Patch:
diff --git a/src/fshtypes/FshCode.ts b/src/fshtypes/FshCode.ts
index 53b7a55..eb1c086 100644
--- a/src/fshtypes/FshCode.ts
+++ b/src/fshtypes/FshCode.ts
@@ -7,7 +7,7 @@ export class FshCode extends FshEntity {
   }
 
   toString(): string {
-    const str = `${this.system ?? ''}#${this.code.includes(' ') ? `"${this.code}"` : this.code}`;
+    const str = `${this.system ?? ''}#${/\s/.test(this.code) ? `"${this.code}"` : this.code}`;
     return this.display ? `${str} "${this.display}"` : str;
   }
 


Test patch:
diff --git a/test/fshtypes/FshCode.test.ts b/test/fshtypes/FshCode.test.ts
index edee649..8edac3c 100644
--- a/test/fshtypes/FshCode.test.ts
+++ b/test/fshtypes/FshCode.test.ts
@@ -35,10 +35,16 @@ describe('FshCode', () => {
       expect(result).toEqual('http://foo.com#my-code "Display"');
     });
 
-    it('should return string for code with code with spaces', () => {
+    it('should return string for code with spaces', () => {
       const code = new FshCode('my spacey code');
       const result = code.toString();
       expect(result).toEqual('#"my spacey code"');
     });
+
+    it('should return string for code with tabs', () => {
+      const code = new FshCode('my\ttabby\tcode');
+      const result = code.toString();
+      expect(result).toEqual('#"my\ttabby\tcode"');
+    });
   });
 });
Repository: FHIR/sushi
Pull request #808 (2021-04-26 16:52:22)

Deprecate ValueSet expansion
Addresses task [INT-999](https://standardhealthrecord.atlassian.net/browse/INT-999).

A warning is emitted when exporting a ValueSet if the ValueSet has the expansion parameters set. This function is being deprecated because it doesn't actually solve the problem it was intended to solve when sending ValueSet resources to the IG publisher. Keeping the feature in could be confusing, so it is being deprecated.


Patch:
diff --git a/src/export/ValueSetExporter.ts b/src/export/ValueSetExporter.ts
index f88c3fd..9492fdf 100644
--- a/src/export/ValueSetExporter.ts
+++ b/src/export/ValueSetExporter.ts
@@ -142,6 +142,9 @@ export class ValueSetExporter {
       parameter => parameter.name === 'sushi-generated' && parameter.valueBoolean === true
     );
     if (shouldExpand) {
+      logger.warn(
+        `ValueSet ${valueSet.name}: expansion is deprecated and will be removed in a future SUSHI release.`
+      );
       const errors: string[] = [];
       // the compose property must be defined
       if (!valueSet.compose) {


Test patch:
diff --git a/test/export/ValueSetExporter.test.ts b/test/export/ValueSetExporter.test.ts
index 1401a71..79c4409 100644
--- a/test/export/ValueSetExporter.test.ts
+++ b/test/export/ValueSetExporter.test.ts
@@ -37,6 +37,7 @@ describe('ValueSetExporter', () => {
     const pkg = new Package(input.config);
     const fisher = new TestFisher(input, defs, pkg);
     exporter = new ValueSetExporter(input, pkg, fisher);
+    loggerSpy.reset();
   });
 
   it('should output empty results with empty input', () => {
@@ -738,6 +739,26 @@ describe('ValueSetExporter', () => {
       defs.add(fragmentCsDef);
     });
 
+    it('should log a deprecation warning when expanding a value set', () => {
+      // ValueSet: MyValueSet
+      // * ^expansion.parameter.name = "sushi-generated"
+      // * ^expansion.parameter.valueBoolean = true
+      // * includes http://zoo.org/animals|1.0#bear
+      // * includes #tiger and #hippo from system http://zoo.org/animals|1.1
+      const includeBear = new ValueSetConceptComponentRule(true);
+      includeBear.concepts.push(new FshCode('bear', 'http://zoo.org/animals|1.0'));
+      includeBear.from.system = 'http://zoo.org/animals|1.0';
+      const includeTigerHippo = new ValueSetConceptComponentRule(true);
+      includeTigerHippo.concepts.push(
+        new FshCode('tiger', 'http://zoo.org/animals|1.1'),
+        new FshCode('hippo', 'http://zoo.org/animals|1.1')
+      );
+      includeTigerHippo.from.system = 'http://zoo.org/animals|1.1';
+      valueSet.rules.push(includeBear, includeTigerHippo);
+      exporter.exportValueSet(valueSet);
+      expect(loggerSpy.getLastMessage('warn')).toMatch('expansion is deprecated');
+    });
+
     it('should expand a value set that contains specific concepts', () => {
       // ValueSet: MyValueSet
       // * ^expansion.parameter.name = "sushi-generated"
Repository: FHIR/sushi
Pull request #824 (2021-06-03 17:22:51)

Support Indentation on AddElementRules
This adds support for indentation on AddElementRules, which enables indentation on `Logical` and `Resource` entities.


Patch:
diff --git a/src/import/FSHImporter.ts b/src/import/FSHImporter.ts
index b249e35..e53d69e 100644
--- a/src/import/FSHImporter.ts
+++ b/src/import/FSHImporter.ts
@@ -968,7 +968,7 @@ export class FSHImporter extends FSHVisitor {
   }
 
   visitAddElementRule(ctx: pc.AddElementRuleContext): AddElementRule {
-    const path = this.visitPath(ctx.path());
+    const path = this.getPathWithContext(this.visitPath(ctx.path()), ctx);
     const addElementRule = new AddElementRule(path)
       .withLocation(this.extractStartStop(ctx))
       .withFile(this.currentFile);


Test patch:
diff --git a/test/import/FSHImporter.context.test.ts b/test/import/FSHImporter.context.test.ts
index 74acac8..6aae0ba 100644
--- a/test/import/FSHImporter.context.test.ts
+++ b/test/import/FSHImporter.context.test.ts
@@ -10,7 +10,8 @@ import {
   assertObeysRule,
   assertValueSetConceptComponent,
   assertValueSetFilterComponent,
-  assertCodeCaretRule
+  assertCodeCaretRule,
+  assertAddElementRule
 } from '../testhelpers/asserts';
 import { FshCode } from '../../src/fshtypes';
 
@@ -309,6 +310,38 @@ describe('FSHImporter', () => {
       assertCaretValueRule(profile.rules[2], 'birthDate', 'short', 'foo', false);
     });
 
+    it('should apply context to AddElement rules', () => {
+      const input = `
+      Logical: Human
+      * family 0..1 BackboneElement "Family"
+        * mother 0..2 string "Mother"
+        * father 0..2 string "Father"
+    `;
+
+      const result = importSingleText(input, 'Context.fsh');
+      expect(loggerSpy.getAllMessages('error')).toHaveLength(0);
+      expect(loggerSpy.getAllMessages('warn')).toHaveLength(0);
+      expect(result.logicals.size).toBe(1);
+      const logical = result.logicals.get('Human');
+      expect(logical.name).toBe('Human');
+      expect(logical.rules.length).toBe(3);
+      assertAddElementRule(logical.rules[0], 'family', {
+        card: { min: 0, max: '1' },
+        types: [{ type: 'BackboneElement' }],
+        defs: { short: 'Family' }
+      });
+      assertAddElementRule(logical.rules[1], 'family.mother', {
+        card: { min: 0, max: '2' },
+        types: [{ type: 'string' }],
+        defs: { short: 'Mother' }
+      });
+      assertAddElementRule(logical.rules[2], 'family.father', {
+        card: { min: 0, max: '2' },
+        types: [{ type: 'string' }],
+        defs: { short: 'Father' }
+      });
+    });
+
     it('should log an error when a rule is indented below a rule without a path', () => {
       const input = `
       Profile: Foo
Repository: FHIR/sushi
Pull request #868 (2021-07-07 15:15:35)

Include hierarchy in FSH for ConceptRule
Completes task [CIMPL-785](https://standardhealthrecord.atlassian.net/browse/CIMPL-785).

The hierarchy on a `ConceptRule` is now used in the `toFSH()` method. Previously, hierarchy information was ignored by this method, which meant that incorrect FSH would be produced for any concept with a hierarchy. If a code in the hierarchy contains spaces, it is quoted so that the syntax is valid.


Patch:
diff --git a/src/fshtypes/rules/ConceptRule.ts b/src/fshtypes/rules/ConceptRule.ts
index ae3f0b5..d690b34 100644
--- a/src/fshtypes/rules/ConceptRule.ts
+++ b/src/fshtypes/rules/ConceptRule.ts
@@ -17,7 +17,10 @@ export class ConceptRule extends Rule {
   }
 
   toFSH(): string {
-    let line = `* #${/\s/.test(this.code) ? `"${this.code}"` : this.code}`;
+    const quotedCodes = [...this.hierarchy, this.code].map(code =>
+      /\s/.test(code) ? `#"${code}"` : `#${code}`
+    );
+    let line = `* ${quotedCodes.join(' ')}`;
     if (this.display) {
       line += ` "${fshifyString(this.display)}"`;
     }


Test patch:
diff --git a/test/fshtypes/rules/ConceptRule.test.ts b/test/fshtypes/rules/ConceptRule.test.ts
index 43ec9a6..3737045 100644
--- a/test/fshtypes/rules/ConceptRule.test.ts
+++ b/test/fshtypes/rules/ConceptRule.test.ts
@@ -80,5 +80,28 @@ describe('ConceptRule', () => {
       const result = rule.toFSH();
       expect(result).toBe(expectedResult);
     });
+
+    it('should produce FSH for a ConceptRule with one code in its hierarchy', () => {
+      const rule = new ConceptRule('platinum');
+      rule.display = 'platinum';
+      rule.definition = 'element with atomic number 78';
+      rule.hierarchy = ['metal'];
+
+      const expectedResult = '* #metal #platinum "platinum" "element with atomic number 78"';
+      const result = rule.toFSH();
+      expect(result).toBe(expectedResult);
+    });
+
+    it('should produce FSH for a ConceptRule with multiple codes in its hierarchy', () => {
+      const rule = new ConceptRule('platinum');
+      rule.display = 'platinum';
+      rule.definition = 'element with atomic number 78';
+      rule.hierarchy = ['physical', 'solid phase', 'metal'];
+
+      const expectedResult =
+        '* #physical #"solid phase" #metal #platinum "platinum" "element with atomic number 78"';
+      const result = rule.toFSH();
+      expect(result).toBe(expectedResult);
+    });
   });
 });
Repository: FHIR/sushi
Pull request #892 (2021-07-26 20:50:00)

Support quoted code without closing quote
While testing out PR #883, @mint-thompson noticed the following case wasn't working properly:

```
* code = http://example.org#"something
```
produced the following JSON:

```
{
  "code": "somethin",
  "system": "http://example.org"
}
```
This PR fixes this case so the same FSH now correctly produces the following JSON:

```
{
  "code": "\"something",
  "system": "http://example.org"
}
```


Patch:
diff --git a/src/import/parseCodeLexeme.ts b/src/import/parseCodeLexeme.ts
index 8ddd310..6f55395 100644
--- a/src/import/parseCodeLexeme.ts
+++ b/src/import/parseCodeLexeme.ts
@@ -19,7 +19,7 @@ export function parseCodeLexeme(conceptText: string): FshCode {
     code = conceptText.slice(splitPoint.index + splitPoint[0].length);
   }
   system = system.replace(/\\\\/g, '\\').replace(/\\#/g, '#');
-  if (code.startsWith('"')) {
+  if (code.startsWith('"') && code.endsWith('"')) {
     code = code
       .slice(1, code.length - 1)
       .replace(/\\\\/g, '\\')


Test patch:
diff --git a/test/import/FSHImporter.test.ts b/test/import/FSHImporter.test.ts
index 59fa5f3..7bb1eee 100644
--- a/test/import/FSHImporter.test.ts
+++ b/test/import/FSHImporter.test.ts
@@ -84,6 +84,21 @@ describe('FSHImporter', () => {
     assertAssignmentRule(profile.rules[2], 'bonusCode', expectedBonusCode);
   });
 
+  it('should parse a code that has an unmatched quote (") at the start of the code', () => {
+    const input = `
+    Profile: MismatchedQuote
+    Parent: Observation
+    * code = https://breakfast.com/goodfood#"potatoes
+    `;
+    const result = importSingleText(input, 'MismatchedQuote.fsh');
+    const profile = result.profiles.get('MismatchedQuote');
+    const expectedCode = new FshCode('"potatoes', 'https://breakfast.com/goodfood')
+      .withLocation([4, 14, 4, 53])
+      .withFile('MismatchedQuote.fsh');
+    expect(profile.rules).toHaveLength(1);
+    assertAssignmentRule(profile.rules[0], 'code', expectedCode);
+  });
+
   it('should parse a rule that uses non-breaking spaces in a concept string', () => {
     const input = leftAlign(`
     Profile: NonBreakingObservation
Repository: FHIR/sushi
Pull request #1035 (2022-03-03 21:55:33)

Update requirement for status and name
We only require `name` and `status` properties in the `sushi-config.yaml` file when you are creating an IG resource. That means when you have `FSHOnly: true` in your configuration, you should not have any logged errors saying those values are required but missing. This PR updates the import of the configuration to only require those properties if `FSHOnly` is not set to true. This follows the pattern we already had for `copyrightYear` and `releaseLabel` [here](https://github.com/FHIR/sushi/blob/master/src/import/importConfiguration.ts#L687-L692). It also updates the tests to check that no errors are logged.

This should fix [GoFSH Issue #164](https://github.com/FHIR/GoFSH/issues/164) by loosening the requirement for `status`. GoFSH does not _need_ to provide `status` if it cannot find it, but SUSHI should not be expecting to find it on `sushi-config` files that are FSHOnly. When this change is merged into SUSHI and SUSHI is released, that issue will be resolved.


Patch:
diff --git a/src/import/importConfiguration.ts b/src/import/importConfiguration.ts
index 5d5c53b..1b37d1d 100644
--- a/src/import/importConfiguration.ts
+++ b/src/import/importConfiguration.ts
@@ -132,10 +132,10 @@ export function importConfiguration(yaml: YAMLConfiguration | string, file: stri
     modifierExtension: yaml.modifierExtension,
     url: yaml.url ?? `${yaml.canonical}/ImplementationGuide/${yaml.id}`,
     version: normalizeToString(yaml.version), // minimum config property
-    name: required(yaml.name, 'name', file),
+    name: yaml.FSHOnly ? yaml.name : required(yaml.name, 'name', file),
     title: yaml.title,
     status: parseCodeWithRequiredValues(
-      required(yaml.status, 'status', file),
+      yaml.FSHOnly ? yaml.status : required(yaml.status, 'status', file),
       ['draft', 'active', 'retired', 'unknown'],
       'status',
       file


Test patch:
diff --git a/test/import/importConfiguration.test.ts b/test/import/importConfiguration.test.ts
index 1c4d212..d515d42 100644
--- a/test/import/importConfiguration.test.ts
+++ b/test/import/importConfiguration.test.ts
@@ -248,6 +248,7 @@ describe('importConfiguration', () => {
       minYAML.FSHOnly = true;
       const config = importConfiguration(minYAML, 'test-config.yaml');
       expect(config.id).toBeUndefined();
+      expect(loggerSpy.getAllMessages('error')).toHaveLength(0);
     });
   });
 
@@ -484,6 +485,7 @@ describe('importConfiguration', () => {
       minYAML.FSHOnly = true;
       const config = importConfiguration(minYAML, 'test-config.yaml');
       expect(config.name).toBeUndefined();
+      expect(loggerSpy.getAllMessages('error')).toHaveLength(0);
     });
   });
 
@@ -530,6 +532,7 @@ describe('importConfiguration', () => {
       minYAML.FSHOnly = true;
       const config = importConfiguration(minYAML, 'test-config.yaml');
       expect(config.status).toBeUndefined();
+      expect(loggerSpy.getAllMessages('error')).toHaveLength(0);
     });
   });
Repository: FHIR/sushi
Pull request #1064 (2022-04-11 22:23:54)

Changed structure definition to throw correctly when adding extensions to Bundle type
- Made changes to validateValueAtPath to make sure that extension can handle a null bracket. 
- Added test to check this case


Patch:
diff --git a/src/fhirtypes/StructureDefinition.ts b/src/fhirtypes/StructureDefinition.ts
index c47818e..047ff9b 100644
--- a/src/fhirtypes/StructureDefinition.ts
+++ b/src/fhirtypes/StructureDefinition.ts
@@ -534,7 +534,7 @@ export class StructureDefinition {
         const extensionPath = `${previousPath ? `${previousPath}.` : ''}${pathPart.base}`;
         const extensionElement = this.findElementByPath(extensionPath, fisher);
         // Get the extension being referred to
-        const extension = fisher.fishForMetadata(pathPart.brackets[0], Type.Extension);
+        const extension = fisher.fishForMetadata(pathPart.brackets?.[0], Type.Extension);
         if (extension && extensionElement) {
           // If the extension exists, add it as a slice to the SD so that we can assign it
           // This function is only called by InstanceExporter on copies of SDs, not those being exported


Test patch:
diff --git a/test/fhirtypes/StructureDefinition.test.ts b/test/fhirtypes/StructureDefinition.test.ts
index 15cdfac..aa42dc6 100644
--- a/test/fhirtypes/StructureDefinition.test.ts
+++ b/test/fhirtypes/StructureDefinition.test.ts
@@ -1349,9 +1349,11 @@ describe('StructureDefinition', () => {
     let structureDefinition: StructureDefinition;
     let respRate: StructureDefinition;
     let CSSPC: StructureDefinition;
+    let bundle: StructureDefinition;
     beforeEach(() => {
       structureDefinition = fisher.fishForStructureDefinition('StructureDefinition');
       respRate = fisher.fishForStructureDefinition('resprate');
+      bundle = fisher.fishForStructureDefinition('Bundle');
       CSSPC = fisher.fishForStructureDefinition('capabilitystatement-search-parameter-combination');
     });
 
@@ -2033,6 +2035,13 @@ describe('StructureDefinition', () => {
           'The element or path you referenced does not exist: resourceType'
         );
       });
+
+      // https://github.com/FHIR/sushi/issues/1020
+      it('should throw when attempting to access extension on a bundle', () => {
+        expect(() => bundle.validateValueAtPath('extension.url', 'test', fisher)).toThrow(
+          'The element or path you referenced does not exist: extension.url'
+        );
+      });
     });
   });