Skip to content

Commit

Permalink
Merge pull request #658 from wmrutten/feature-dstu2/650-ArtifactSumma…
Browse files Browse the repository at this point in the history
…ryScanner-harvest-root-definition

#650 ArtifactSummarySource should also extract root element definition from StructDef
  • Loading branch information
ewoutkramer committed Aug 2, 2018
2 parents b57137e + ec874a3 commit 0f07199
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
Expand Up @@ -121,6 +121,11 @@ public void TestProfilesTypesJson()
Assert.AreEqual(StructureDefinition.StructureDefinitionKind.Datatype.GetLiteral(), summary.GetStructureDefinitionKind());
// If this is a constraining StructDef, then Base should also be specified
Assert.IsTrue(summary.GetStructureDefinitionConstrainedType() == null || summary.GetStructureDefinitionBase() != null);

// [WMR 20180725] Also harvest root element definition text
// [WMR 20180801] Disabled; included version of profiles-types.json does NOT contain definitions...
// var rootDefinition = summary.GetStructureDefinitionRootDefinition();
// Assert.IsNotNull(rootDefinition);
}
}

Expand Down Expand Up @@ -166,6 +171,10 @@ public void TestProfilesResourcesXml()

// [WMR 20171218] Maturity Level extension
Assert.IsNotNull(summary.GetStructureDefinitionMaturityLevel());

// [WMR 20180725] Also harvest root element definition text
var rootDefinition = summary.GetStructureDefinitionRootDefinition();
Assert.IsNotNull(rootDefinition);
}

}
Expand Down
Expand Up @@ -33,13 +33,13 @@ namespace Hl7.Fhir.Specification.Source
/// </remarks>
public static class ArtifactSummaryProperties
{
public const string OriginKey = "Origin";
public const string FileSizeKey = "Size";
public const string LastModifiedKey = "LastModified";
public const string SerializationFormatKey = "Format";
public const string PositionKey = "Position";
public const string TypeNameKey = "TypeName";
public const string ResourceUriKey = "Uri";
public static readonly string OriginKey = "Origin";
public static readonly string FileSizeKey = "Size";
public static readonly string LastModifiedKey = "LastModified";
public static readonly string SerializationFormatKey = "Format";
public static readonly string PositionKey = "Position";
public static readonly string TypeNameKey = "TypeName";
public static readonly string ResourceUriKey = "Uri";

/// <summary>Try to retrieve the property value for the specified key.</summary>
/// <param name="properties">An artifact summary property bag.</param>
Expand Down Expand Up @@ -233,6 +233,8 @@ public static class StructureDefinitionSummaryProperties
public static readonly string FmmExtensionUrl = @"http://hl7.org/fhir/StructureDefinition/structuredefinition-fmm";
public static readonly string MaturityLevelKey = "StructureDefinition.maturityLevel";

public static readonly string RootDefinitionKey = "StructureDefinition.rootDefinition";

/// <summary>Determines if the specified instance represents summary information about a <see cref="StructureDefinition"/> resource.</summary>
public static bool IsStructureDefinitionSummary(this IArtifactSummaryPropertyBag properties)
=> properties.GetTypeName() == StructureDefinitionTypeName;
Expand All @@ -255,6 +257,21 @@ public static bool Harvest(IElementNavigator nav, ArtifactSummaryPropertyBag pro
nav.HarvestValue(properties, ConstrainedTypeKey, "constrainedType");
nav.HarvestValue(properties, ContextTypeKey, "contextType");
nav.HarvestValue(properties, BaseKey, "base");

// [WMR 20180725] Also harvest definition property from (first) root element in snapshot/differential
// HL7 FHIR website displays this text as introduction on top of each resource/datatype page
if ((nav.Find("snapshot") || nav.Find("differential")))
{
if (nav.MoveToFirstChild("element") && Navigation.ElementDefinitionNavigator.IsRootPath(nav.Name))
{
var childNav = nav.Clone();
if (childNav.MoveToFirstChild())
{
childNav.HarvestValue(properties, RootDefinitionKey, "definition");
}
}
}

}
return true;
}
Expand Down Expand Up @@ -302,6 +319,14 @@ public static string GetStructureDefinitionBase(this IArtifactSummaryPropertyBag
/// </remarks>
public static string GetStructureDefinitionMaturityLevel(this IArtifactSummaryPropertyBag properties)
=> properties.GetValueOrDefault<string>(MaturityLevelKey);
/// <summary>Get the value of the root element definition from the specified artifact summary property bag, if available.</summary>
/// <remarks>
/// Returns the definition text of the root element.
/// Only applies to summaries of <see cref="StructureDefinition"/> resources.
/// </remarks>
public static string GetStructureDefinitionRootDefinition(this IArtifactSummaryPropertyBag properties)
=> properties.GetValueOrDefault<string>(RootDefinitionKey);

}

/// <summary>For harvesting specific summary information from a <see cref="ValueSet"/> resource.</summary>
Expand Down

0 comments on commit 0f07199

Please sign in to comment.