Skip to content

Commit

Permalink
Merge pull request #3 from brianpos/feature/alpha
Browse files Browse the repository at this point in the history
New release of the public FHIR client
  • Loading branch information
brianpos authored Jul 11, 2019
2 parents 8f170d0 + 3d5fd70 commit df58aad
Show file tree
Hide file tree
Showing 11 changed files with 1,364 additions and 1,277 deletions.
27 changes: 17 additions & 10 deletions UWP/FhirPathTesterUWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<DefaultLanguage>en-US</DefaultLanguage>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.16299.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.15063.0</TargetPlatformMinVersion>
<TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion>
<MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Expand Down Expand Up @@ -182,6 +182,9 @@
<Content Include="Assets\Wide\Wide310x150Logo.scale-150.png" />
<Content Include="Assets\Wide\Wide310x150Logo.scale-200.png" />
<Content Include="Assets\Wide\Wide310x150Logo.scale-400.png" />
<None Include="Package.xml">
<SubType>Designer</SubType>
</None>
<Content Include="Properties\Default.rd.xml" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\SplashScreen.scale-200.png" />
Expand All @@ -203,33 +206,37 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Hl7.Fhir.DSTU2">
<Version>0.96.0</Version>
<Version>1.3.0</Version>
</PackageReference>
<PackageReference Include="Hl7.Fhir.R4">
<Version>0.96.1</Version>
<Version>1.3.0</Version>
</PackageReference>
<PackageReference Include="Hl7.Fhir.Serialization">
<Version>1.3.0</Version>
</PackageReference>
<PackageReference Include="Hl7.Fhir.Specification.DSTU2">
<Version>0.96.0</Version>
<Version>1.3.0</Version>
<ExcludeAssets>contentFiles</ExcludeAssets>
<IncludeAssets>runtime; compile; build; native; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Hl7.Fhir.Specification.STU3">
<Version>0.96.0</Version>
<Version>1.3.0</Version>
<!--<ExcludeAssets>contentFiles</ExcludeAssets>-->
</PackageReference>
<PackageReference Include="Hl7.Fhir.STU3">
<Version>0.96.0</Version>
<Version>1.3.0</Version>
</PackageReference>
<PackageReference Include="Hl7.FhirPath">
<Version>0.96.1</Version>
<Version>1.3.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.1.7</Version>
<Version>6.2.8</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI">
<Version>4.0.0</Version>
<Version>5.1.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls">
<Version>4.0.0</Version>
<Version>5.1.1</Version>
</PackageReference>
</ItemGroup>
<Target Name="ChangeAliasesOfStrongNameAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
Expand Down
8 changes: 4 additions & 4 deletions UWP/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,8 @@ public ExpressionElementContext Child(string propertyName)
}
else
{
if (item.ElementType != typeof(string)) // (only occurs for extension.url and elementdefinition.id)
newContext._cm3.Add(stu3::Hl7.Fhir.Introspection.ClassMapping.Create(item.ElementType));
if (item.ImplementingType != typeof(string)) // (only occurs for extension.url and elementdefinition.id)
newContext._cm3.Add(stu3::Hl7.Fhir.Introspection.ClassMapping.Create(item.ImplementingType));
}
}
catch
Expand Down Expand Up @@ -704,8 +704,8 @@ public ExpressionElementContext Child(string propertyName)
}
else
{
if (item.ElementType != typeof(string)) // (only occurs for extension.url and elementdefinition.id)
newContext._cm2.Add(dstu2::Hl7.Fhir.Introspection.ClassMapping.Create(item.ElementType));
if (item.ImplementingType != typeof(string)) // (only occurs for extension.url and elementdefinition.id)
newContext._cm2.Add(dstu2::Hl7.Fhir.Introspection.ClassMapping.Create(item.ImplementingType));
}
}
catch
Expand Down
4 changes: 2 additions & 2 deletions UWP/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.3.0")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyVersion("1.0.4.0")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: ComVisible(false)]
8 changes: 0 additions & 8 deletions WPF/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,10 @@
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Hl7.FhirPath" publicKeyToken="d706911480550fc3" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.96.1.0" newVersion="0.96.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Hl7.Fhir.Support" publicKeyToken="d706911480550fc3" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.96.1.0" newVersion="0.96.1.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
96 changes: 40 additions & 56 deletions WPF/CustomFluentPathFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,84 +29,64 @@ static public SymbolTable Scope
// Custom function that returns the name of the property, rather than its value
_st.Add("propname", (object f) =>
{
if (f is IEnumerable<IElementNavigator>)
if (f is IEnumerable<ITypedElement>)
{
object[] bits = (f as IEnumerable<IElementNavigator>).Select(i =>
object[] bits = (f as IEnumerable<ITypedElement>).Select(i =>
{
if (i is stu3.Hl7.Fhir.ElementModel.PocoNavigator)
{
return (i as stu3.Hl7.Fhir.ElementModel.PocoNavigator).Name;
}
if (i is dstu2.Hl7.Fhir.ElementModel.PocoNavigator)
{
return (i as dstu2.Hl7.Fhir.ElementModel.PocoNavigator).Name;
}
return "?";
return i.Name;
}).ToArray();
return FhirValueList.Create(bits);
return FhirValueListCreate(bits);
}
return FhirValueList.Create(new object[] { "?" } );
return FhirValueListCreate(new object[] { "?" } );
});
_st.Add("pathname", (object f) =>
{
if (f is IEnumerable<IElementNavigator>)
if (f is IEnumerable<ITypedElement>)
{
object[] bits = (f as IEnumerable<IElementNavigator>).Select(i =>
object[] bits = (f as IEnumerable<ITypedElement>).Select(i =>
{
if (i is stu3.Hl7.Fhir.ElementModel.PocoNavigator)
{
return (i as stu3.Hl7.Fhir.ElementModel.PocoNavigator).Location;
}
if (i is dstu2.Hl7.Fhir.ElementModel.PocoNavigator)
{
return (i as dstu2.Hl7.Fhir.ElementModel.PocoNavigator).Location;
}
return "?";
return i.Location;
}).ToArray();
return FhirValueList.Create(bits);
return FhirValueListCreate(bits);
}
return FhirValueList.Create(new object[] { "?" });
return FhirValueListCreate(new object[] { "?" });
});
_st.Add("shortpathname", (object f) =>
{
if (f is IEnumerable<IElementNavigator>)
if (f is IEnumerable<ITypedElement>)
{
object[] bits = (f as IEnumerable<IElementNavigator>).Select(i =>
object[] bits = (f as IEnumerable<ITypedElement>).Select(i =>
{
if (i is stu3.Hl7.Fhir.ElementModel.PocoNavigator)
if (i is IShortPathGenerator spg)
{
return (i as stu3.Hl7.Fhir.ElementModel.PocoNavigator).ShortPath;
}
if (i is dstu2.Hl7.Fhir.ElementModel.PocoNavigator)
{
return (i as dstu2.Hl7.Fhir.ElementModel.PocoNavigator).ShortPath;
return spg.ShortPath;
}
return "?";
}).ToArray();
return FhirValueList.Create(bits);
return FhirValueListCreate(bits);
}
return FhirValueList.Create(new object[] { "?" });
});
_st.Add("commonpathname", (object f) =>
{
if (f is IEnumerable<IElementNavigator>)
{
object[] bits = (f as IEnumerable<IElementNavigator>).Select(i =>
{
if (i is stu3.Hl7.Fhir.ElementModel.PocoNavigator)
{
return (i as stu3.Hl7.Fhir.ElementModel.PocoNavigator).CommonPath;
}
if (i is dstu2.Hl7.Fhir.ElementModel.PocoNavigator)
{
return (i as dstu2.Hl7.Fhir.ElementModel.PocoNavigator).CommonPath;
}
return "?";
}).ToArray();
return FhirValueList.Create(bits);
}
return FhirValueList.Create(new object[] { "?" });
return FhirValueListCreate(new object[] { "?" });
});
//_st.Add("commonpathname", (object f) =>
//{
// if (f is IEnumerable<ITypedElement>)
// {
// object[] bits = (f as IEnumerable<ITypedElement>).Select(i =>
// {
// if (i is stu3.Hl7.Fhir.ElementModel.PocoElementNode)
// {
// return (i as stu3.Hl7.Fhir.ElementModel.PocoElementNode).CommonPath;
// }
// if (i is dstu2.Hl7.Fhir.ElementModel.PocoElementNode)
// {
// return (i as dstu2.Hl7.Fhir.ElementModel.PocoElementNode).CommonPath;
// }
// return "?";
// }).ToArray();
// return FhirValueListCreate(bits);
// }
// return FhirValueListCreate(new object[] { "?" });
//});

// Custom function for evaluating the date operation (custom Healthconnex)
_st.Add("dateadd", (PartialDateTime f, string field, long amount) =>
Expand Down Expand Up @@ -141,6 +121,10 @@ static public SymbolTable Scope
}
}

private static object FhirValueListCreate(object[] values)
{
return ElementNode.CreateList(values);
}
}

public static class Luhn
Expand Down
127 changes: 127 additions & 0 deletions WPF/FhirPathExpressionProcessing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
extern alias stu3;
// using Hl7.FhirPath.Expressions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Expressions;

namespace FhirPathTester
{
public class QuestionnaireExpressionProcessing
{
private Expression CheckExpression(Hl7.FhirPath.Expressions.Expression expr, Type T, List<string> namedProps)
{
if (expr is Hl7.FhirPath.Expressions.ChildExpression ce)
{
var focusContext = CheckExpression(ce.Focus, T, namedProps);
var cm = stu3.Hl7.Fhir.Introspection.ClassMapping.Create(T);
var childContext = Expression.Property(focusContext, cm.FindMappedElementByName(ce.ChildName).Name);
if (childContext != null)
return childContext;
throw new ArgumentException("Failed to find parameter", ce.ChildName);
}
if (expr is Hl7.FhirPath.Expressions.FunctionCallExpression func)
{
var funcs = _compiler.Symbols.Filter(func.FunctionName, func.Arguments.Count() + 1);
if (funcs.Count() == 0 && !(expr is Hl7.FhirPath.Expressions.BinaryExpression))
{
// AppendResults($"{prefix}{func.FunctionName} *invalid function name*", true);
}
else
{
AppendResults($"{prefix}{func.FunctionName}");
}
var focusContext = CheckExpression(func.Focus, context);

if (func.FunctionName == "binary.as")
{
if (func.Arguments.Count() != 2)
{
AppendResults($"{prefix}{func.FunctionName} INVALID AS Operation", true);
return focusContext;
}
var argContextResult = CheckExpression(func.Arguments.First(), focusContext);
var typeArg = func.Arguments.Skip(1).FirstOrDefault() as Hl7.FhirPath.Expressions.ConstantExpression;
string typeCast = typeArg?.Value as string;
argContextResult.RestrictToType(typeCast);
return argContextResult;
}
else if (func.FunctionName == "resolve")
{
// need to check what the available outcomes of resolving this are, and switch types to this
}
else
{
// if this is a where operation and the context inside is a linkId = , then check that the linkId is in context
if (func.FunctionName == "where" && func.Arguments.Count() == 1 && (func.Arguments.First() as Hl7.FhirPath.Expressions.BinaryExpression)?.Op == "=")
{
var op = func.Arguments.First() as Hl7.FhirPath.Expressions.BinaryExpression;
var argContextResult = CheckExpression(op, focusContext);

// Filter the values that are not in this set
focusContext._2gs = argContextResult._2gs;
focusContext._2qs = argContextResult._2qs;
}
else
{
foreach (var item in func.Arguments)
{
var argContextResult = CheckExpression(item, focusContext);
}
}
if (func.FunctionName == "binary.=")
{
Hl7.FhirPath.Expressions.ChildExpression prop = (Hl7.FhirPath.Expressions.ChildExpression)func.Arguments.Where(a => a is Hl7.FhirPath.Expressions.ChildExpression).FirstOrDefault();
Hl7.FhirPath.Expressions.ConstantExpression value = (Hl7.FhirPath.Expressions.ConstantExpression)func.Arguments.Where(a => a is Hl7.FhirPath.Expressions.ConstantExpression).FirstOrDefault();
if (prop?.ChildName == "linkId" && value != null)
{
var groupLinkIds = focusContext._2gs?.Select(i => i.LinkId).ToArray();
var questionLinkIds = focusContext._2qs?.Select(i => i.LinkId).ToArray();

// filter out all of the other linkIds from the list
focusContext._2gs?.RemoveAll(g => g.LinkId != value.Value as string);
focusContext._2qs?.RemoveAll(q => q.LinkId != value.Value as string);

// Validate that there is an item with this value that is reachable
if (focusContext._2gs?.Count() == 0 || focusContext._2qs?.Count() == 0)
{
// this linkId didn't exist in this context!
string toolTip = "Available LinkIds:";
if (groupLinkIds != null)
toolTip += $"\r\nGroup: {String.Join(", ", groupLinkIds)}";
if (questionLinkIds != null)
toolTip += $"\r\nQuestion: {String.Join(", ", questionLinkIds)}";
AppendResults($"{prefix}{func.FunctionName} LinkId is not valid in this context", true, toolTip);
}
}
}
}

return focusContext;
}
//else if (expr is BinaryExpression)
//{
// var func = expr as BinaryExpression;
// sb.AppendLine(func.FunctionName);
// CheckExpression(func.Left, sb);
// sb.AppendLine(func.Op);
// CheckExpression(func.Right, sb);
// return;
//}
else if (expr is Hl7.FhirPath.Expressions.ConstantExpression constExpr)
{
return Expression.Constant(constExpr.Value); // context doesn't propagate from this
}
else if (expr is Hl7.FhirPath.Expressions.VariableRefExpression vref)
{
// sb.AppendFormat("{0}{1} (variable ref)\r\n", prefix, func.Name);
return context;
}
// AppendResults(expr.GetType().ToString());
return context;
}

}
}
Loading

0 comments on commit df58aad

Please sign in to comment.