コード例 #1
0
        private void button1_Click_2(object sender, EventArgs e)
        {
            var endpoint = new Uri("http://fhirtest.uhn.ca/baseDstu2");
            var client   = new FhirClient(endpoint);

            // Create new value for observation
            SampledData     val     = new SampledData();
            CodeableConcept concept = new CodeableConcept();

            concept.Coding = new List <Coding>();

            if (conversionList.Text.Equals("age"))
            {
                val.Data = CurrentMeasurement.age.ToString();
                Coding code = new Coding();
                code.Code = "410668003";
                concept.Coding.Add(code);
            }
            else if (conversionList.Text.Equals("bmr"))
            {
                val.Data = CurrentMeasurement.bmr.ToString();
                Coding code = new Coding();
                code.Code = "60621009";
                concept.Coding.Add(code);
            }
            else if (conversionList.Text.Equals("height"))
            {
                val.Data = CurrentMeasurement.height.ToString();
                Coding code = new Coding();
                code.Code = "60621009"; //SNOMED CT code
                concept.Coding.Add(code);
            }
            else if (conversionList.Text.Equals("m_active_time"))
            {
                val.Data = CurrentMeasurement.m_active_time.ToString();
            }
            else if (conversionList.Text.Equals("m_calories"))
            {
                val.Data = CurrentMeasurement.m_calories.ToString();
            }
            else if (conversionList.Text.Equals("m_distance"))
            {
                val.Data = CurrentMeasurement.m_distance.ToString();
            }
            else if (conversionList.Text.Equals("m_inactive_time"))
            {
                val.Data = CurrentMeasurement.m_inactive_time.ToString();
            }
            else if (conversionList.Text.Equals("m_lcat"))
            {
                val.Data = CurrentMeasurement.m_lcat.ToString();
            }
            else if (conversionList.Text.Equals("m_lcit"))
            {
                val.Data = CurrentMeasurement.m_lcit.ToString();
            }
            else if (conversionList.Text.Equals("m_steps"))
            {
                val.Data = CurrentMeasurement.m_steps.ToString();
            }
            else if (conversionList.Text.Equals("m_total_calories"))
            {
                val.Data = CurrentMeasurement.m_total_calories.ToString();
            }
            else if (conversionList.Text.Equals("s_asleep_time"))
            {
                val.Data = CurrentMeasurement.s_asleep_time.ToString();
            }
            else if (conversionList.Text.Equals("s_awake"))
            {
                val.Data = CurrentMeasurement.s_awake.ToString();
            }
            else if (conversionList.Text.Equals("s_awake_time"))
            {
                val.Data = CurrentMeasurement.s_awake_time.ToString();
            }
            else if (conversionList.Text.Equals("s_awakenings"))
            {
                val.Data = CurrentMeasurement.s_awakenings.ToString();
            }
            else if (conversionList.Text.Equals("s_bedtime"))
            {
                val.Data = CurrentMeasurement.s_bedtime.ToString();
            }
            else if (conversionList.Text.Equals("s_clinical_deep"))
            {
                val.Data = CurrentMeasurement.s_clinical_deep.ToString();
            }
            else if (conversionList.Text.Equals("s_count"))
            {
                val.Data = CurrentMeasurement.s_count.ToString();
            }
            else if (conversionList.Text.Equals("s_duration"))
            {
                val.Data = CurrentMeasurement.s_duration.ToString();
            }
            else if (conversionList.Text.Equals("s_light"))
            {
                val.Data = CurrentMeasurement.s_light.ToString();
            }
            else if (conversionList.Text.Equals("s_quality"))
            {
                val.Data = CurrentMeasurement.s_quality.ToString();
            }
            else if (conversionList.Text.Equals("s_rem"))
            {
                val.Data = CurrentMeasurement.s_rem.ToString();
            }
            else if (conversionList.Text.Equals("weight"))
            {
                val.Data = CurrentMeasurement.weight.ToString();
            }
            else
            {
                val.Data = "E";  // Error
            }
            Console.WriteLine("Value data: " + val.Data);

            ResourceReference dev = new ResourceReference();

            dev.Reference = "Device/" + CurrentDevice.Id;

            ResourceReference pat = new ResourceReference();

            pat.Reference = "Patient/" + CurrentPatient.Id;

            Console.WriteLine("Patient reference: " + pat.Reference);

            Console.WriteLine("Conversion: " + conversionList.Text);

            CodeableConcept naam = new CodeableConcept();

            naam.Text = conversionList.Text;

            DateTime date = DateTime.ParseExact(CurrentMeasurement.date, "yyyymmdd", null);

            Console.WriteLine("" + date.ToString());
            var obs = new Observation()
            {
                Device = dev, Subject = pat, Value = val, Issued = date, Code = naam, Category = concept, Status = Observation.ObservationStatus.Final
            };

            client.Create(obs);

            conversionStatus.Text = "Done!";
        }
コード例 #2
0
        /// <summary>
        /// Given a observation POCO, maps the data to an Observation Resource.
        /// </summary>
        /// <param name="observation"></param>
        /// <returns></returns>
        public static Observation MapModel(POCO.Observation observation)
        {
            if (observation == null)
            {
                throw new ArgumentNullException("observation");
            }

            var resource = new Observation();

            resource.Id = observation.ObservationId.ToString("D");

            // Observation Status
            switch (observation.Status)
            {
            case ObsStatus.amended:
                resource.Status = ObservationStatus.Amended;
                break;

            case ObsStatus.cancelled:
                resource.Status = ObservationStatus.Cancelled;
                break;

            case ObsStatus.entered_in_error:
                resource.Status = ObservationStatus.EnteredInError;
                break;

            case ObsStatus.final:
                resource.Status = ObservationStatus.Final;
                break;

            case ObsStatus.preliminary:
                resource.Status = ObservationStatus.Preliminary;
                break;

            case ObsStatus.registered:
                resource.Status = ObservationStatus.Registered;
                break;

            case ObsStatus.unknown:
                resource.Status = ObservationStatus.Unknown;
                break;

            default:
                resource.Status = ObservationStatus.EnteredInError;
                break;
            }

            // Observation Category
            if (observation.CategoryCode[0] != string.Empty || observation.CategoryDisplay[0] != string.Empty || observation.CategorySystem[0] != string.Empty || observation.CategoryText != null)
            {
                CodeableConcept observationCategory = new CodeableConcept();
                List <Coding>   observationCodings  = new List <Coding>();

                if (observation.CategoryCode[0] != string.Empty || observation.CategoryDisplay[0] != string.Empty || observation.CategorySystem[0] != string.Empty)
                {
                    for (int i = 0; i < observation.CategoryCode.Count; i++)
                    {
                        Coding observationCoding = new Coding()
                        {
                            System  = observation.CategorySystem[i],
                            Display = observation.CategoryDisplay[i],
                            Code    = observation.CategoryCode[i]
                        };
                        observationCodings.Add(observationCoding);
                    }
                    observationCategory.Coding = observationCodings;
                }
                observationCategory.Text = observation.CategoryText;

                resource.Category = observationCategory;
            }

            // Observation Code
            if (observation.CodeCode[0] != string.Empty || observation.CodeDisplay[0] != string.Empty || observation.CodeSystem[0] != string.Empty || observation.CodeText != null)
            {
                CodeableConcept observationCode    = new CodeableConcept();
                List <Coding>   observationCodings = new List <Coding>();

                if (observation.CodeCode[0] != string.Empty || observation.CodeDisplay[0] != string.Empty || observation.CodeSystem[0] != string.Empty)
                {
                    for (int i = 0; i < observation.CodeCode.Count; i++)
                    {
                        Coding observationCoding = new Coding()
                        {
                            System  = observation.CodeSystem[i],
                            Display = observation.CodeDisplay[i],
                            Code    = observation.CodeCode[i]
                        };
                        observationCodings.Add(observationCoding);
                    }
                    observationCode.Coding = observationCodings;
                }
                observationCode.Text = observation.CategoryText;

                resource.Code = observationCode;
            }

            // Observation references to other resources
            if (observation.PatientReference != null)
            {
                resource.Subject           = new ResourceReference();
                resource.Subject.Reference = observation.PatientReference;
            }
            if (observation.DeviceReference != null)
            {
                resource.Device           = new ResourceReference();
                resource.Device.Reference = observation.DeviceReference;
            }

            if (observation.PerformerReferences[0] != string.Empty)
            {
                foreach (var reference in observation.PerformerReferences)
                {
                    ResourceReference performerReference = new ResourceReference();
                    performerReference.Reference = reference;
                    resource.Performer.Add(performerReference);
                }
            }

            // Observation Effective times
            // The choice of Type is DateTime.
            if (observation.EffectiveDateTime != null)
            {
                FhirDateTime dateTime = new FhirDateTime(observation.EffectiveDateTime);
                resource.Effective = dateTime;
            }
            // The choice of Type is Period.
            else
            {
                Period period = new Period
                {
                    Start = observation.EffectivePeriodStart.ToString(),
                    End   = observation.EffectivePeriodEnd.ToString()
                };
                resource.Effective = period;
            }

            resource.Issued = observation.Issued;

            // Observation Comments
            resource.Comments = observation.Comments;

            // Site of Body where Observation was made
            if (observation.BodySiteCode != null || observation.BodySiteDisplay != null || observation.BodySiteSystem != null || observation.BodySiteText != null)
            {
                CodeableConcept observationBodySite = new CodeableConcept();
                List <Coding>   observationCodings  = new List <Coding>();

                if (observation.BodySiteCode != null || observation.BodySiteDisplay != null || observation.BodySiteSystem != null)
                {
                    Coding observationCoding = new Coding()
                    {
                        System  = observation.BodySiteSystem,
                        Display = observation.BodySiteDisplay,
                        Code    = observation.BodySiteCode
                    };
                    observationCodings.Add(observationCoding);
                    observationBodySite.Coding = observationCodings;
                }
                observationBodySite.Text = observation.BodySiteText;

                resource.BodySite = observationBodySite;
            }

            // Observation Interpretation
            if (observation.InterpretationCode != null || observation.InterpretationDisplay != null || observation.InterpretationSystem != null || observation.InterpretationText != null)
            {
                CodeableConcept observationInterpretation = new CodeableConcept();
                List <Coding>   observationCodings        = new List <Coding>();

                if (observation.InterpretationCode != null || observation.InterpretationDisplay != null || observation.InterpretationSystem != null)
                {
                    Coding observationCoding = new Coding()
                    {
                        System  = observation.InterpretationSystem,
                        Display = observation.InterpretationDisplay,
                        Code    = observation.InterpretationCode
                    };
                    observationCodings.Add(observationCoding);
                    observationInterpretation.Coding = observationCodings;
                }
                observationInterpretation.Text = observation.InterpretationText;

                resource.Interpretation = observationInterpretation;
            }

            // Observation Values
            // Values are componentised
            if (observation.ComponentCodeCode[0] != string.Empty || observation.ComponentCodeText != null)
            {
                for (int i = 0; i < observation.ComponentCodeCode.Count; i++)
                {
                    ComponentComponent component = new ComponentComponent();
                    CodeableConcept    concept   = new CodeableConcept();
                    Coding             coding    = new Coding();
                    coding.Code    = observation.ComponentCodeCode[i];
                    coding.Display = observation.ComponentCodeDisplay[i];
                    coding.System  = observation.ComponentCodeSystem[i];
                    concept.Coding.Add(coding);
                    concept.Text   = observation.ComponentCodeText;
                    component.Code = concept;

                    resource.Component.Add(component);

                    // value is of Type Quantity
                    if (observation.ValueQuantityValue != null)
                    {
                        Quantity quantity = new Quantity();
                        quantity.Code   = observation.ValueQuantityCode[i];
                        quantity.System = observation.ValueQuantitySystem[i];
                        quantity.Unit   = observation.ValueQuantityUnit[i];
                        quantity.Value  = observation.ValueQuantityValue[i];

                        resource.Component[i].Value = quantity;
                    }
                    // value is of Type CodeableConcept
                    else if (observation.ValueCode[0] != string.Empty)
                    {
                        concept        = new CodeableConcept();
                        coding         = new Coding();
                        coding.Code    = observation.ValueCode[i];
                        coding.Display = observation.ValueDisplay[i];
                        coding.System  = observation.ValueSystem[i];

                        concept.Coding.Add(coding);
                        concept.Text = observation.ValueText[i];
                        resource.Component[i].Value = concept;
                    }
                    // value is of Type String
                    else if (observation.ValueString[0] != string.Empty)
                    {
                        FhirString fhirString = new FhirString();
                        fhirString.Value = observation.ValueString[i];

                        resource.Component[i].Value = fhirString;
                    }
                    // value is of Type SampledData
                    else if (observation.ValueSampledDataOriginValue != null)
                    {
                        SampledData    sampleData = new SampledData();
                        SimpleQuantity quantity   = new SimpleQuantity();
                        quantity.Code   = observation.ValueSampledDataOriginCode[i];
                        quantity.System = observation.ValueSampledDataOriginSystem[i];
                        quantity.Unit   = observation.ValueSampledDataOriginUnit[i];
                        quantity.Value  = observation.ValueSampledDataOriginValue[i];

                        sampleData.Origin     = quantity;
                        sampleData.Data       = observation.ValueSampledDataData[i];
                        sampleData.Dimensions = observation.ValueSampledDataDimensions[i];
                        sampleData.Period     = observation.ValueSampledDataPeriod[i];

                        resource.Component[i].Value = sampleData;
                    }
                    // value is of Type Period
                    else if (observation.ValuePeriodStart != null)
                    {
                        Period period = new Period();
                        period.Start = observation.ValuePeriodStart[i].ToString();
                        period.End   = observation.ValuePeriodEnd[i].ToString();

                        resource.Component[i].Value = period;
                    }
                    // No value provided
                    else
                    {
                        resource.Component[i].Value = null;
                    }
                }
            }
            //There is only one "set" of values
            else
            {
                // value is of Type Quantity
                if (observation.ValueQuantityValue != null)
                {
                    Quantity quantity = new Quantity();
                    quantity.Code   = observation.ValueQuantityCode[0];
                    quantity.System = observation.ValueQuantitySystem[0];
                    quantity.Unit   = observation.ValueQuantityUnit[0];
                    quantity.Value  = observation.ValueQuantityValue[0];

                    resource.Value = quantity;
                }
                // value is of Type CodeableConcept
                else if (observation.ValueCode[0] != string.Empty)
                {
                    CodeableConcept concept = new CodeableConcept();
                    Coding          coding  = new Coding();
                    coding.Code    = observation.ValueCode[0];
                    coding.Display = observation.ValueDisplay[0];
                    coding.System  = observation.ValueSystem[0];

                    concept.Coding.Add(coding);
                    concept.Text   = observation.ValueText[0];
                    resource.Value = concept;
                }
                // value is of Type String
                else if (observation.ValueString[0] != string.Empty)
                {
                    FhirString fhirString = new FhirString();
                    fhirString.Value = observation.ValueString[0];

                    resource.Value = fhirString;
                }
                // value is of Type SampledData
                else if (observation.ValueSampledDataOriginValue != null)
                {
                    SampledData    sampleData = new SampledData();
                    SimpleQuantity quantity   = new SimpleQuantity();
                    quantity.Code   = observation.ValueSampledDataOriginCode[0];
                    quantity.System = observation.ValueSampledDataOriginSystem[0];
                    quantity.Unit   = observation.ValueSampledDataOriginUnit[0];
                    quantity.Value  = observation.ValueSampledDataOriginValue[0];

                    sampleData.Origin     = quantity;
                    sampleData.Data       = observation.ValueSampledDataData[0];
                    sampleData.Dimensions = observation.ValueSampledDataDimensions[0];
                    sampleData.Period     = observation.ValueSampledDataPeriod[0];

                    resource.Value = sampleData;
                }
                // value is of Type Period
                else if (observation.ValuePeriodStart != null)
                {
                    Period period = new Period();
                    period.Start = observation.ValuePeriodStart[0].ToString();
                    period.End   = observation.ValuePeriodEnd[0].ToString();

                    resource.Value = period;
                }
                // No value provided.
                else
                {
                    resource.Value = null;
                }
            }

            return(resource);
        }