-1

FHIR server and FHIR client works in EU environment with locale "en-GB". both uses Hl7-R4 .NET version from Firely team.

if I set Patient's birth date something like that patientJson.BirthDate = "25-12-1970" and then sends the request to FHIR server I get an exception:

"'Partial is in an invalid format, should use ISO8601 YYYY-MM-DDThh:mm:ss+TZ notation'. (at Patient.birthDate[0])".

But if I set patientJson.BirthDate = "1970-12-25" everything is OK. I can't rely on that customers (most from EU) will remember to convert in US-format date before sending to fhir server. How can I set correct formatting (for example "en-GB") for HL7 serializer?

Tried to add this to Startup.cs

public virtual void Configure(IApplicationBuilder app)
{
    var supportedCultures = new[]
    {
        new CultureInfo("en-US"),
        new CultureInfo("en-GB"), 

       };

    app.UseRequestLocalization(new RequestLocalizationOptions
    {
        DefaultRequestCulture = new RequestCulture("en-GB"),
        // Formatting numbers, dates, etc.
        SupportedCultures = supportedCultures,
        // UI strings that we have localized.
        SupportedUICultures = supportedCultures
    });

it didn't help I've googled this code

public static PartialDateTime Parse(string value)
        {
            try
            {
                var dummy = XmlConvert.ToDateTimeOffset(value);
            }
            catch
            {
                throw new FormatException("Partial is in an invalid format, should use ISO8601 YYYY-MM-DDThh:mm:ss+TZ notation");
            }

but this code doesn't mean that it can not be set to use something like that "dd-mm-yyyy" for serializing/deserializing.

vadl
  • 9
  • 2
  • The HL7 format is probably XML and you must meet the schema requirements. if you are working with string dates than you can't change from US to GB. You MUST MEET the SCHEMA Requirements. If your customers are using a schema than everything should be ok. – jdweng Aug 21 '19 at 21:35
  • The transfer of data between computers should always be in standard ISO format.You should never have an issue at the server.Server will always get ISO format.Client should always store the classes as DateTime objects and the serialize method should take a DateTime object and serializing to ISO and the deserialize method should take ISO and producing a DateTime object.Your only issue is at the client side where users need to parse a string date to a DateTime Object.Errors will only occur when users are parsing strings to DateTime.If user have PC set to local culture there will not be any issues – jdweng Aug 21 '19 at 23:18

1 Answers1

1

YYYY-MM-DD is not a country-specific format. It's intended to be a generic format and must be used regardless of locale. I have no clue why patientJson.BirthDate = "12-25-1970" did not fail for you. It's certainly not valid. All date times, regardless of XML, JSON or RDF must adhere to the YYYY-MM-DD syntax.

Lloyd McKenzie
  • 6,345
  • 1
  • 13
  • 10
  • sure, you are right "1970-12-25" in the real code, I did a mistake when created the post. – vadl Aug 22 '19 at 07:01