Exemplo n.º 1
0
        public static Extension BiometricException
        (
            string biometricExceptionMissingReason,
            string secretQuestion1,
            string secretAnswer1,
            string secretQuestion2,
            string secretAnswer2
        )
        {
            /*
             *  Example JSON FHIR Message
             *  Biometric Exception
             *  content:"content":
             *  {
             *      "extension":
             *      [
             *          {      "url": "Missing Reason",                 "valueString": I am permanently physically unable to provide fingerprints   },
             *          {      "url": "Question 1",                     "valueString": What is your mother’s maiden name?                           },
             *          {      "url": "Answer 1",                       "valueString": Rumpelstiltskin                                              },
             *          {      "url": "Question 2",                     "valueString": What street did you grow up on?                              },
             *          {      "url": "Answer 2",                       "valueString": Beale Street                                                 }
             *      ]
             *  }
             */
            Extension extCaptureSite = new Extension("Biometric Exception", new FhirString("Alternate Questions and Answers"));

            extCaptureSite.AddExtension("Missing Reason", new FhirString(biometricExceptionMissingReason));
            extCaptureSite.AddExtension("Question 1", new FhirString(secretQuestion1));
            extCaptureSite.AddExtension("Answer 1", new FhirString(secretAnswer1));
            extCaptureSite.AddExtension("Question 2", new FhirString(secretQuestion2));
            extCaptureSite.AddExtension("Answer 2", new FhirString(secretAnswer2));
            return(extCaptureSite);
        }
Exemplo n.º 2
0
        public static Extension CaptureSummaryExtension
        (
            string captureStringList,
            string ScannerName,
            int OriginalDPI,
            int OriginalHeight,
            int OriginalWidth
        )
        {
            /*
             *  Example JSON FHIR Message
             *  Capture Summary
             *  content:"content":
             *  {
             *      "extension":
             *      [
             *          {      "url": "Capture Site List",              "valueString": Left Index and Right Index   },
             *          {      "url": "Scanner Name",                   "valueString": U.are.U 4500                 },
             *          {      "url": "Original DPI",                   "valueInt": 500                             },
             *          {      "url": "Original Height",                "valueInt": 300                             },
             *          {      "url": "Original Width",                 "valueInt": 200                             }
             *      ]
             *  }
             */
            Extension extCaptureSite = new Extension("Capture Summary", new FhirString("Biometric Site Capture Summary"));

            extCaptureSite.AddExtension("Capture Site List", new FhirString(captureStringList));
            extCaptureSite.AddExtension("Scanner Name", new FhirString(ScannerName));
            extCaptureSite.AddExtension("Original DPI", new FhirString(OriginalDPI.ToString()));
            extCaptureSite.AddExtension("Original Height", new FhirString(OriginalHeight.ToString()));
            extCaptureSite.AddExtension("Original Width", new FhirString(OriginalWidth.ToString()));
            return(extCaptureSite);
        }
Exemplo n.º 3
0
        public static Extension FingerPrintMediaExtension(string PositionX, string PositionY, string Direction, string Type)
        {
            /*
             *  Example JSON FHIR Message
             *  Media
             *  content:"content":
             *  {
             *      "extension":
             *      [
             *          {      "url": "PositionX",      "valueInteger": 1    },
             *          {      "url": "PositionY",      "valueInteger": 2    },
             *          {      "url": "Direction",      "valueInteger": 3    },
             *          {      "url": "Type",           "valueInteger": 4    }
             *      ]
             *  }
             */

            Extension extMinutiaPoint     = new Extension("Minutia", new FhirString("Points"));
            Extension extMinutiaPositionX = extMinutiaPoint.AddExtension("PositionX", new FhirString(PositionX));
            Extension extMinutiaPositionY = extMinutiaPoint.AddExtension("PositionY", new FhirString(PositionY));
            Extension extMinutiaDirection = extMinutiaPoint.AddExtension("Direction", new FhirString(Direction));
            Extension extMinutiaType      = extMinutiaPoint.AddExtension("Type", new FhirString(Type));

            return(extMinutiaPoint);
        }
        internal static FhirMedication ToFhirInternal(HVMedication hvMedication, FhirMedication fhirMedication)
        {
            fhirMedication.Code = hvMedication.Name.ToFhir();

            if (hvMedication.GenericName != null || hvMedication.Strength != null)
            {
                var medicationExtension = new Extension {
                    Url = HealthVaultExtensions.Medication
                };

                if (hvMedication.GenericName != null)
                {
                    var genericName = hvMedication.GenericName?.ToFhir();

                    medicationExtension.AddExtension(HealthVaultExtensions.MedicationGenericName,
                                                     genericName);
                }

                if (hvMedication.Strength != null)
                {
                    var strengthExtension = new Extension {
                        Url = HealthVaultExtensions.MedicationStrength
                    };

                    strengthExtension.AddExtension(HealthVaultExtensions.MedicationStrengthDisplay,
                                                   new FhirString(hvMedication.Strength.Display));

                    foreach (var structuredMeasurement in hvMedication.Strength.Structured)
                    {
                        var simpleQuantity = new SimpleQuantity()
                        {
                            Value = new decimal(structuredMeasurement.Value),
                            Unit  = structuredMeasurement.Units.Text
                        };

                        if (structuredMeasurement.Units.Any())
                        {
                            CodedValue measurementUnit = structuredMeasurement.Units.First();

                            simpleQuantity.Code   = measurementUnit.Value;
                            simpleQuantity.System = HealthVaultVocabularies.GenerateSystemUrl(measurementUnit.VocabularyName, measurementUnit.Family);
                        }

                        strengthExtension.AddExtension(HealthVaultExtensions.MedicationStrengthQuantity, simpleQuantity);
                    }

                    medicationExtension.Extension.Add(strengthExtension);
                }

                fhirMedication.Extension.Add(medicationExtension);
            }

            return(fhirMedication);
        }
        private static Extension PopulatePersonalExtension(Personal personal)
        {
            var personalExtension = new Extension
            {
                Url = HealthVaultExtensions.PatientPersonal
            };

            if (personal.BloodType != null)
            {
                personalExtension.AddExtension(HealthVaultExtensions.PatientBloodType, personal.BloodType.ToFhir());
            }

            if (!string.IsNullOrEmpty(personal.EmploymentStatus))
            {
                personalExtension.AddExtension(HealthVaultExtensions.PatientEmploymentStatus, new FhirString(personal.EmploymentStatus));
            }

            if (personal.Ethnicity != null)
            {
                personalExtension.AddExtension(HealthVaultExtensions.PatientEthnicity, personal.Ethnicity.ToFhir());
            }

            if (personal.HighestEducationLevel != null)
            {
                personalExtension.AddExtension(HealthVaultExtensions.PatientHighestEducationLevel, personal.HighestEducationLevel.ToFhir());
            }

            if (personal.IsDisabled.HasValue)
            {
                personalExtension.AddExtension(HealthVaultExtensions.PatientIsDisabled, new FhirBoolean(personal.IsDisabled));
            }

            if (personal.IsVeteran.HasValue)
            {
                personalExtension.AddExtension(HealthVaultExtensions.PatientIsVeteran, new FhirBoolean(personal.IsVeteran));
            }

            if (personal.MaritalStatus != null)
            {
                personalExtension.AddExtension(HealthVaultExtensions.PatientMaritalStatus, personal.MaritalStatus.ToFhir());
            }

            if (!string.IsNullOrEmpty(personal.OrganDonor))
            {
                personalExtension.AddExtension(HealthVaultExtensions.PatientOrganDonor, new FhirString(personal.OrganDonor));
            }

            if (personal.Religion != null)
            {
                personalExtension.AddExtension(HealthVaultExtensions.PatientReligion, personal.Religion.ToFhir());
            }

            return(personalExtension);
        }
Exemplo n.º 6
0
        private static Extension CreateSegmentExtension(ExerciseSegment segment)
        {
            var extension = new Extension
            {
                Url = HealthVaultExtensions.ExerciseSegment
            };

            extension.AddExtension(HealthVaultExtensions.ExerciseSegmentActivity, segment.Activity.ToFhir());

            if (!string.IsNullOrEmpty(segment.Title))
            {
                extension.AddExtension(HealthVaultExtensions.ExerciseSegmentTitle, new FhirString(segment.Title));
            }

            if (segment.Duration.HasValue)
            {
                extension.AddExtension(HealthVaultExtensions.ExerciseSegmentDuration, new FhirDecimal((decimal)segment.Duration));
            }

            if (segment.Distance != null)
            {
                extension.AddExtension(HealthVaultExtensions.ExerciseSegmentDistance, new Quantity
                {
                    Value = (decimal)segment.Distance.Value,
                    Unit  = UnitAbbreviations.Meter
                });
            }

            if (segment.Offset.HasValue)
            {
                extension.AddExtension(HealthVaultExtensions.ExerciseSegmentOffset, new FhirDecimal((decimal)segment.Offset));
            }

            if (segment.Details != null)
            {
                foreach (var detail in segment.Details)
                {
                    extension.Extension.Add(CreateDetailExtension(detail.Key, detail.Value));
                }
            }

            return(extension);
        }
Exemplo n.º 7
0
        public static Extension ClinicLocationExtension(string ClinicArea, string DevicePhysicalLocation)
        {
            /*
             *  Example JSON FHIR Message
             *  Clinic and Location Extension
             *  content:"content":
             *  {
             *      "extension":
             *      [
             *          {      "url": "ClinicArea",                         "valueString": 200 Camp St, 2nd foor            }
             *          {      "url": "Physical",                           "valueString": Orthopedic Clinic                }
             *      ]
             *  }
             */
            Extension ext = new Extension("Location", new FhirString(ClinicArea));

            ext.AddExtension("ClinicArea", new FhirString(ClinicArea));
            ext.AddExtension("Physical", new FhirString(DevicePhysicalLocation));
            return(ext);
        }
Exemplo n.º 8
0
        public static Extension GenderAndTwinInfo(string genderChanged, string multipleBirth)
        {
            /*
             *  Example JSON FHIR Message
             *  Gender and Twin Info
             *  content:"content":
             *  {
             *      "extension":
             *      [
             *          {      "url": "GenderChanged",             "valueString": Yes                              }
             *      ]
             *  }
             */

            Extension ext = new Extension("Gender and Twin Info", new FhirString("GenderInfo"));

            ext.AddExtension("Gender Changed", new FhirString(genderChanged));
            ext.AddExtension("Multiple Birth", new FhirString(multipleBirth));
            return(ext);
        }
Exemplo n.º 9
0
        private static Extension CreateDetailExtension(string key, ExerciseDetail exerciseDetail)
        {
            var extension = new Extension
            {
                Url = HealthVaultExtensions.ExerciseDetail
            };

            extension.AddExtension(HealthVaultExtensions.ExerciseDetailName, new FhirString(key));

            extension.AddExtension(HealthVaultExtensions.ExerciseDetailType, exerciseDetail.Name.ToFhir());

            extension.AddExtension(HealthVaultExtensions.ExerciseDetailValue, new Quantity
            {
                Value  = (decimal)exerciseDetail.Value.Value,
                Unit   = exerciseDetail.Value.Units.Text,
                Code   = exerciseDetail.Value.Units[0].Value,
                System = HealthVaultVocabularies.GenerateSystemUrl(exerciseDetail.Value.Units[0].VocabularyName, exerciseDetail.Value.Units[0].Family),
            });
            return(extension);
        }
Exemplo n.º 10
0
        public static Extension NoIDHubInfo(string noIDHubName, string noIDHubPassword)
        {
            /*
             *  Example JSON FHIR Message
             *  NoID Hub Information
             *  content:"content":
             *  {
             *      "extension":
             *      [
             *          {      "url": "HubName",                        "valueString": First Hub South                              }
             *          {      "url": "PortalPassword",                 "valueString": <hashed>                                     }
             *      ]
             *  }
             */

            Extension ext = new Extension("HubInformation", new FhirString("HubInfo"));

            ext.AddExtension("HubName", new FhirString(noIDHubName));
            ext.AddExtension("PortalPassword", new FhirString(noIDHubPassword));
            return(ext);
        }
Exemplo n.º 11
0
        public static Extension OrganizationExtension(string organizationName, string domainName, string fhirServerName)
        {
            /*
             *  Example JSON FHIR Message
             *  Organization
             *  content:"content":
             *  {
             *      "extension":
             *      [
             *          {      "url": "Domain",                         "valueString": noidtest.net              },
             *          {      "url": "FHIR Server",                    "valueString": https://hn1.noidtest.net  }
             *      ]
             *  }
             */

            Extension ext = new Extension("Organization", new FhirString(organizationName));

            ext.AddExtension("Domain", new FhirString(domainName));
            ext.AddExtension("FHIR Server", new FhirString(fhirServerName));
            return(ext);
        }
        internal static Observation ToFhirInternal(BloodGlucose bg, Observation observation)
        {
            observation.Method = bg.GlucoseMeasurementType.ToFhir();

            var bloodGlucoseExtension = new Extension
            {
                Url = HealthVaultExtensions.BloodGlucose
            };

            if (bg.MeasurementContext != null)
            {
                bloodGlucoseExtension.AddExtension(HealthVaultExtensions.BloodGlucoseMeasurementContext, bg.MeasurementContext.ToFhir());
            }

            if (bg.OutsideOperatingTemperature.HasValue)
            {
                bloodGlucoseExtension.AddExtension(HealthVaultExtensions.OutsideOperatingTemperatureExtensionName, new FhirBoolean(bg.OutsideOperatingTemperature.Value));
            }

            if (bg.ReadingNormalcy.HasValue)
            {
                bloodGlucoseExtension.AddExtension(HealthVaultExtensions.ReadingNormalcyExtensionName, new FhirString(bg.ReadingNormalcy.Value.ToString()));
            }

            if (bg.IsControlTest.HasValue)
            {
                bloodGlucoseExtension.AddExtension(HealthVaultExtensions.IsControlTestExtensionName, new FhirBoolean(bg.IsControlTest.Value));
            }

            observation.Extension.Add(bloodGlucoseExtension);

            observation.Code = HealthVaultVocabularies.GenerateCodeableConcept(HealthVaultThingTypeNameCodes.BloodGlucose);

            var quantity = new Quantity((decimal)bg.Value.Value, UnitAbbreviations.MillimolesPerLiter);

            observation.Value     = quantity;
            observation.Effective = new FhirDateTime(bg.When.ToLocalDateTime().ToDateTimeUnspecified());

            return(observation);
        }
Exemplo n.º 13
0
        public static Extension MessageTypeExtension(string NoIDStatus, string NoIDType, string StartTime)
        {
            /*
             *  Example JSON FHIR Message
             *  Organization
             *  content:"content":
             *  {
             *      "extension":
             *      [
             *          {      "url": "Status",                         "valueString": pending, approved, denied, hold              }
             *          {      "url": "Type",                           "valueString": new, return, newflag, returnflag             }
             *          {      "url": "CheckinTime",                    "valueString": 2017-07-02 14:35:22-Z                        }
             *      ]
             *  }
             */

            Extension ext = new Extension("NoIDStatus", new FhirString(NoIDType));

            ext.AddExtension("Status", new FhirString(NoIDStatus)); //pending, approved, denied, hold.
            ext.AddExtension("Type", new FhirString(NoIDType));     //new, return, newflag, returnflag
            ext.AddExtension("CheckinTime", new FhirString(StartTime));
            return(ext);
        }
Exemplo n.º 14
0
        public static Extension CaptureSiteExtension
        (
            CaptureSiteSnoMedCode captureSite,
            LateralitySnoMedCode laterality,
            string ScannerName,
            int OriginalDPI,
            int OriginalHeight,
            int OriginalWidth
        )
        {
            /*
             *  Example JSON FHIR Message
             *  CaptureSite
             *  content:"content":
             *  {
             *      "extension":
             *      [
             *          {      "url": "Coding System",                  "valueString": SNOMED           },
             *          {      "url": "Capture Site Description",       "valueString": IndexFinger      },
             *          {      "url": "Laterality Code",                "valueString": 419161000        },
             *          {      "url": "Laterality Description",         "valueString": Left             },
             *          {      "url": "Scanner Name",                   "valueString": U.are.U 4500     },
             *          {      "url": "Original DPI",                   "valueInt": 500                 },
             *          {      "url": "Original Height",                "valueInt": 300                 },
             *          {      "url": "Original Width",                 "valueInt": 200                 }
             *      ]
             *  }
             */
            //TODO: Use bodysite instead of an extension but bodysite currently not working with Spark FHIR.
            int captureSiteCode = (int)captureSite;
            int lateralityCode  = (int)laterality;

            Extension extCaptureSite = new Extension("Capture Site", new FhirString(captureSiteCode.ToString()));

            Extension extCodingSystem           = extCaptureSite.AddExtension("Coding System", new FhirString("SNOMED"));
            Extension extCaptureSiteDescription = extCaptureSite.AddExtension("Capture Site Description", new FhirString(CaptureSiteToString(captureSite)));

            //
            extCaptureSite.AddExtension("Laterality Code", new FhirString(lateralityCode.ToString()));
            extCaptureSite.AddExtension("Laterality Description", new FhirString(LateralityToString(laterality)));
            //
            extCaptureSite.AddExtension("Scanner Name", new FhirString(ScannerName));
            extCaptureSite.AddExtension("Original DPI", new FhirString(OriginalDPI.ToString()));
            extCaptureSite.AddExtension("Original Height", new FhirString(OriginalHeight.ToString()));
            extCaptureSite.AddExtension("Original Width", new FhirString(OriginalWidth.ToString()));
            return(extCaptureSite);
        }
Exemplo n.º 15
0
        internal static Condition ToFhirInternal(HVCondition hvCondition, Condition fhirCondition)
        {
            var conditionExtension = new Extension
            {
                Url = HealthVaultExtensions.Condition
            };

            if (hvCondition.CommonData != null)
            {
                fhirCondition.AddNoteAsText(hvCondition.CommonData.Note);
                var note = new Annotation();
                note.Text          = hvCondition.CommonData.Note;
                fhirCondition.Note = new List <Annotation> {
                    note
                };
            }

            fhirCondition.Code = hvCondition.Name.ToFhir();

            if (hvCondition.Status != null)
            {
                fhirCondition.SetClinicalStatusCode(hvCondition.Status, conditionExtension);
            }

            if (hvCondition.StopDate != null)
            {
                fhirCondition.SetAbatement(hvCondition.StopDate);
            }

            if (hvCondition.OnsetDate != null)
            {
                fhirCondition.Onset = hvCondition.OnsetDate.ToFhir();
            }

            if (hvCondition.StopReason != null)
            {
                conditionExtension.AddExtension(HealthVaultExtensions.ConditionStopReason, new FhirString(hvCondition.StopReason));
            }

            fhirCondition.Extension.Add(conditionExtension);

            return(fhirCondition);
        }
Exemplo n.º 16
0
 private static void SetClinicalStatusCode(this Condition fhirCondition, ItemTypes.CodableValue status, Extension conditionExtension)
 {
     foreach (ItemTypes.CodedValue cValue in status)
     {
         Condition.ConditionClinicalStatusCodes clinicalStatusCode;
         if (cValue.Value != null)
         {
             if (Enum.TryParse(cValue.Value, true, out clinicalStatusCode))
             {
                 fhirCondition.ClinicalStatus = clinicalStatusCode;
                 return;
             }
             else
             {
                 conditionExtension.AddExtension(HealthVaultExtensions.ConditionOccurrence, new FhirString(cValue.Value));
                 return;
             }
         }
     }
 }
Exemplo n.º 17
0
        private static void SetAllergyIntoleranceCategory(this AllergyIntolerance allergyIntolerance, CodableValue allergenType, Extension allergyExtension)
        {
            List <AllergyIntoleranceCategory?> lstAllergyIntoleranceCategory = new List <AllergyIntoleranceCategory?>();
            string aValue = allergenType.FirstOrDefault().Value;
            AllergyIntoleranceCategory allergyIntoleranceCategory;

            if (aValue != null)
            {
                if (Enum.TryParse(aValue, true, out allergyIntoleranceCategory))
                {
                    lstAllergyIntoleranceCategory.Add(allergyIntoleranceCategory);
                }
                else
                {
                    allergyExtension.AddExtension(HealthVaultExtensions.AllergenType, new FhirString(aValue));
                }
            }

            if (lstAllergyIntoleranceCategory.Count > 0)
            {
                allergyIntolerance.Category = lstAllergyIntoleranceCategory;
            }
        }
Exemplo n.º 18
0
        internal static AllergyIntolerance ToFhirInternal(Allergy allergy, AllergyIntolerance allergyIntolerance)
        {
            var allergyExtension = new Extension
            {
                Url = HealthVaultExtensions.Allergy
            };

            allergyIntolerance.Code = allergy.Name.ToFhir();

            if (allergy.FirstObserved != null)
            {
                allergyIntolerance.Onset = allergy.FirstObserved.ToFhir();
            }

            if (allergy.AllergenType != null)
            {
                allergyIntolerance.SetAllergyIntoleranceCategory(allergy.AllergenType, allergyExtension);
            }

            if (allergy.Reaction != null)
            {
                allergyIntolerance.Reaction = new List <AllergyIntolerance.ReactionComponent>
                {
                    new AllergyIntolerance.ReactionComponent {
                        Manifestation = new List <CodeableConcept> {
                            allergy.Reaction.ToFhir()
                        },
                        Description = allergy.Reaction.Text
                    }
                };
            }

            if (allergy.TreatmentProvider != null)
            {
                allergyIntolerance.AddAsserter(allergy.TreatmentProvider.ToFhir());
            }

            if (allergy.Treatment != null)
            {
                allergyExtension.AddExtension(HealthVaultExtensions.AllergyTreatement, allergy.Treatment.ToFhir());
            }

            if (allergy.AllergenCode != null)
            {
                allergyExtension.AddExtension(HealthVaultExtensions.AllergenCode, allergy.AllergenCode.ToFhir());
            }

            if (allergy.IsNegated != null)
            {
                if (allergy.IsNegated.Value)
                {
                    allergyIntolerance.ClinicalStatus = AllergyIntoleranceClinicalStatus.Resolved;
                }
                else
                {
                    allergyIntolerance.ClinicalStatus = AllergyIntoleranceClinicalStatus.Active;
                }
            }

            if (allergy.CommonData != null && allergy.CommonData.Note != null)
            {
                var note = new Hl7.Fhir.Model.Annotation();
                note.Text = allergy.CommonData.Note;
                allergyIntolerance.Note = new List <Hl7.Fhir.Model.Annotation> {
                    note
                };
            }

            allergyIntolerance.Type = AllergyIntoleranceType.Allergy;
            allergyIntolerance.Extension.Add(allergyExtension);
            return(allergyIntolerance);
        }
Exemplo n.º 19
0
        /// <summary>
        /// Recursivly modify the genotype by mixing 50/50 the parents genetic material.
        /// </summary>
        /// <param name="child">The current extension of the child</param>
        /// <param name="parentA">The current extension of the parent a</param>
        /// <param name="parentB">The current extension of the parent b</param>
        private void recombinaison(Extension child, Extension parentA, Extension parentB)
        {
            // The structure recombination is done only for the first level.
            IEnumerator<Extension> t1 = (IEnumerator<Extension>)parentA.GetEnumerator();
            IEnumerator<Extension> t2 = (IEnumerator<Extension>)parentB.GetEnumerator();

            while (t1.MoveNext() && t2.MoveNext())
            {
                Extension e;
                if (Probability.Test(0.5))
                    e = (Extension)t1.Current.LocalClone();
                else
                    e = (Extension)t2.Current.LocalClone();

                child.AddExtension(e);

                recombinaison(e, t1.Current, t2.Current);
            }
        }
        internal static Patient ToFhirInternal(ItemTypes.BasicV2 basic, Patient patient)
        {
            var basicV2Extension = new Extension
            {
                Url = HealthVaultExtensions.PatientBasicV2
            };

            if (basic.Gender.HasValue)
            {
                switch (basic.Gender.Value)
                {
                case Gender.Male:
                    patient.Gender = AdministrativeGender.Male;
                    break;

                case Gender.Female:
                    patient.Gender = AdministrativeGender.Female;
                    break;

                case Gender.Unknown:
                    patient.Gender = AdministrativeGender.Unknown;
                    break;
                }
            }

            if (basic.BirthYear.HasValue)
            {
                basicV2Extension.AddExtension(HealthVaultExtensions.PatientBirthYear, new Integer(basic.BirthYear));
            }

            if (basic.FirstDayOfWeek.HasValue)
            {
                basicV2Extension.AddExtension(HealthVaultExtensions.PatientFirstDayOfWeek,
                                              new Coding
                {
                    Code    = ((int)basic.FirstDayOfWeek).ToString(),
                    Display = basic.FirstDayOfWeek.Value.ToString()
                });
            }

            if (basic.Languages != null && basic.Languages.Count > 0)
            {
                foreach (var language in basic.Languages)
                {
                    patient.Communication.Add(
                        new Patient.CommunicationComponent
                    {
                        Language  = language.SpokenLanguage.ToFhir(),
                        Preferred = language.IsPrimary
                    }
                        );
                }
            }

            var basicAddress = new Extension
            {
                Url = HealthVaultExtensions.PatientBasicAddress
            };

            basicAddress.AddExtension(HealthVaultExtensions.PatientBasicAddressCity, new FhirString(basic.City));
            basicAddress.AddExtension(HealthVaultExtensions.PatientBasicAddressState, basic.StateOrProvince.ToFhir());
            basicAddress.AddExtension(HealthVaultExtensions.PatientBasicAddressPostalCode, new FhirString(basic.PostalCode));
            basicAddress.AddExtension(HealthVaultExtensions.PatientBasicAddressCountry, basic.Country.ToFhir());
            basicV2Extension.Extension.Add(basicAddress);

            patient.Extension.Add(basicV2Extension);

            return(patient);
        }
        internal static Hl7.Fhir.Model.Immunization ToFhirInternal(ItemTypes.Immunization hvImmunization, Hl7.Fhir.Model.Immunization fhirImmunization)
        {
            fhirImmunization.VaccineCode = hvImmunization.Name.ToFhir();
            fhirImmunization.DateElement = hvImmunization.DateAdministrated.ToFhir();

            if (hvImmunization.Administrator != null)
            {
                fhirImmunization.Practitioner.Add(new Hl7.Fhir.Model.Immunization.PractitionerComponent
                {
                    Actor = AddContainedResource(fhirImmunization, hvImmunization.Administrator.ToFhir())
                });
            }

            if (hvImmunization.Manufacturer != null)
            {
                fhirImmunization.Manufacturer = AddContainedResource(fhirImmunization, new Hl7.Fhir.Model.Organization
                {
                    Name = hvImmunization.Manufacturer.Text
                });
            }

            fhirImmunization.LotNumber             = hvImmunization.Lot;
            fhirImmunization.Route                 = hvImmunization.Route.ToFhir();
            fhirImmunization.ExpirationDateElement = hvImmunization.ExpirationDate.ToFhir();

            if (!string.IsNullOrEmpty(hvImmunization.Sequence) ||
                !string.IsNullOrEmpty(hvImmunization.AdverseEvent) ||
                !string.IsNullOrEmpty(hvImmunization.Consent))
            {
                var immunizationExtension = new Extension
                {
                    Url = HealthVaultExtensions.ImmunizationDetail
                };

                if (!string.IsNullOrEmpty(hvImmunization.Sequence))
                {
                    immunizationExtension.AddExtension(HealthVaultExtensions.ImmunizationDetailSequence, new FhirString(hvImmunization.Sequence));
                }

                if (!string.IsNullOrEmpty(hvImmunization.Consent))
                {
                    immunizationExtension.AddExtension(HealthVaultExtensions.ImmunizationDetailConcent, new FhirString(hvImmunization.Consent));
                }

                if (!string.IsNullOrEmpty(hvImmunization.AdverseEvent))
                {
                    immunizationExtension.AddExtension(HealthVaultExtensions.ImmunizationDetailAdverseEvent, new FhirString(hvImmunization.AdverseEvent));
                }
                fhirImmunization.Extension.Add(immunizationExtension);
            }

            fhirImmunization.Site = hvImmunization.AnatomicSurface.ToFhir();

            fhirImmunization.Note.Add(new Hl7.Fhir.Model.Annotation {
                Text = hvImmunization.CommonData.Note
            });

            //Setting default values that is not available in HealthVault. Let's revisit when a good
            //approach is found for better fidelity between Fhir & HV
            fhirImmunization.Status        = Hl7.Fhir.Model.Immunization.ImmunizationStatusCodes.Completed;
            fhirImmunization.NotGiven      = false;
            fhirImmunization.PrimarySource = true;

            return(fhirImmunization);
        }