Skip to content

Commit

Permalink
Merge pull request #1850 from FirelyTeam/feature/603-add-fuent-prefix…
Browse files Browse the repository at this point in the history
…-suffix-humanname-initializers

Add fluent HumanName initializers for prefix and suffix
  • Loading branch information
mmsmits authored Aug 19, 2021
2 parents 5e40a39 + fa4d361 commit a409bfe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Hl7.Fhir.Core.Tests/Model/ModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.ComponentModel.DataAnnotations;
using Hl7.Fhir.Validation;
using Hl7.Fhir.Serialization;
using FluentAssertions;

namespace Hl7.Fhir.Tests.Model
{
Expand Down Expand Up @@ -629,5 +630,17 @@ public void TestCheckMinorVersionCompatibilityWithNull()
{
ModelInfo.CheckMinorVersionCompatibility(null);
}

[TestMethod]
public void TestHumanNameFluentInitializers()
{
var pat = new Patient();
pat.Name.Add(new HumanName().WithPrefix("Mr.").WithGiven("Henry").AndFamily("Levin").WithSuffix("The 7th"));

pat.Name.FirstOrDefault().Prefix.Should().ContainSingle("Mr.");
pat.Name.FirstOrDefault().Given.Should().ContainSingle("Henry");
pat.Name.FirstOrDefault().Family.Should().Be("Levin");
pat.Name.FirstOrDefault().Suffix.Should().ContainSingle("The 7th");
}
}
}
16 changes: 16 additions & 0 deletions src/Hl7.Fhir.Core/Model/Initializers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ public HumanName WithGiven(string given)
return this;
}

public HumanName WithPrefix(string prefix)
{
if (this.PrefixElement == null) this.PrefixElement = new List<FhirString>();
this.PrefixElement.Add(new FhirString(prefix));

return this;
}

public HumanName WithSuffix(string prefix)
{
if (this.SuffixElement == null) this.SuffixElement = new List<FhirString>();
this.SuffixElement.Add(new FhirString(prefix));

return this;
}

public HumanName AndFamily(string family)
{
this.Family = family;
Expand Down

0 comments on commit a409bfe

Please sign in to comment.