SET<TEL> Issue
psharp
#1 Posted : Monday, February 24, 2014 2:56:01 PM(UTC)
Rank: Member

Groups: Registered
Joined: 11/12/2013(UTC)
Posts: 19
Points: 57

Thanks: 3 times
Was thanked: 0 time(s) in 0 post(s)
Hi Everest,

I'm creating a SET<TEL> to be used with the PatientRole. I have 2 telephone numbers that have the same number but with different usages (Home: 555-555-5555 and MobileContact: 555-555-5555). When I create my TEL objects I set the value to the phone number string and set the Use to the TelecommunicationAddressUse. However when I go to add the 2nd TEL object to the set I get an error saying "Item already exists in the SET, items are only allowed to appear once in any given SET". It seems like the comparison of the TEL objects does not take the Use into account when checking to see if they are separate items. Can you advise on best course to take here?

Thanks,
Phil
justin.fyfe1
#2 Posted : Monday, February 24, 2014 6:03:27 PM(UTC)

Rank: Administration

Medals: Mobile Tech Grasshopper: Mobile Tech GrasshopperHealth Informatics MVP

Groups: Registered, Administrators
Joined: 7/22/2010(UTC)
Posts: 96
Points: 297
Man
Location: Hamilton, ON

Thanks: 2 times
Was thanked: 17 time(s) in 17 post(s)
Hi,

The default comparator for SET uses the semantic equality to determine if a duplicate item is included in the SET, technical semantic equality for TEL is defined as:

Code:

Two TEL instances are considered equal when their Value property is equal regardless of defining data type. The Use and UseableTime properties are not included when determining semantic equality.


So the behavior of SET is correct. If you'd like to represent a phone number in a SET with different uses you can do one of the following:

1. The best way to do this is to assign multiple uses to the one TEL instance, this could be done as follows:

Code:

    public static class SETOfTELExtensions
    {
        public static void AddOrUpdateUse(this SET<TEL> me, TEL instance)
        {
            if (me.Contains(instance))
                me[me.IndexOf(instance)].Use.Add(instance.Use.First);
            else
                me.Add(instance);
        }
    }

...

            setOfTel.AddOrUpdateUse(new TEL("tel:+1-905-575-1212;ext=3029", MARC.Everest.DataTypes.Interfaces.TelecommunicationAddressUse.Home));
            setOfTel.AddOrUpdateUse(new TEL("tel:+1-905-575-1212;ext=3029", MARC.Everest.DataTypes.Interfaces.TelecommunicationAddressUse.WorkPlace));



The result would look like this on the wire:

Code:

<tel value="tel:+1-905-575-1212;ext=3029" use="H WP"/>


2. You can change the comparator to use value equality instead of semantic equality, this is done like this:

Code:

SET<TEL> setOfTel = new SET<TEL>();
setOfTel.Comparator = (a, b) => {
    if (a != null && a.Equals(b) || a == b)
        return 0;
    else
        return 1;
};


#2 would be the easiest solution, while #1 would be the most appropriate according to the abstract datatypes specification (although the capabilities of your trading partners will dictate which approach is used Wink )
1 user thanked justin.fyfe1 for this useful post.
psharp on 2/25/2014(UTC)
psharp
#3 Posted : Tuesday, February 25, 2014 1:29:36 PM(UTC)
Rank: Member

Groups: Registered
Joined: 11/12/2013(UTC)
Posts: 19
Points: 57

Thanks: 3 times
Was thanked: 0 time(s) in 0 post(s)
Thanks Justin as usual it worked perfectly with your change.

I had to go with option #2 due to my spec saying only a single Use can be specified.

Will this cause any issues reading in the ClinicalDocument via Everest and the SET<TEL> created when the formatter parses the clinical document?
justin.fyfe1
#4 Posted : Friday, February 28, 2014 10:08:39 AM(UTC)

Rank: Administration

Medals: Mobile Tech Grasshopper: Mobile Tech GrasshopperHealth Informatics MVP

Groups: Registered, Administrators
Joined: 7/22/2010(UTC)
Posts: 96
Points: 297
Man
Location: Hamilton, ON

Thanks: 2 times
Was thanked: 17 time(s) in 17 post(s)
You're correct that this would only work on serialization. The only thing I can think of to get deserialization to work in 1.2.x series would be to set the DefaultComparator variable on SET<TEL>.

Code:

            SET<TEL>.DefaultComparator = (a, b) =>
            {
                if (a != null && a.Equals(b) || a == b)
                    return 0;
                else
                    return 1;
            };
            SET<TEL> setOfTel = new SET<TEL>();
            setOfTel.Add(new TEL("tel:+1-905-575-1212;ext=3029", MARC.Everest.DataTypes.Interfaces.TelecommunicationAddressUse.Home));
            setOfTel.Add(new TEL("tel:+1-905-575-1212;ext=3029", MARC.Everest.DataTypes.Interfaces.TelecommunicationAddressUse.WorkPlace));



This should (for the duration of your program) set any SET<TEL> to use the DefaultComparator of equals.

Cheers
-Justin
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

SoClean Theme By Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.111 seconds.