Exemplo n.º 1
0
 private static void AddPerformer(FhirProcedure fhirProcedure, Practitioner practitioner)
 {
     if (practitioner != null)
     {
         practitioner.Id = $"#practitioner-{Guid.NewGuid()}";
         fhirProcedure.Contained.Add(practitioner);
         fhirProcedure.Performer.Add(new FhirProcedure.PerformerComponent
         {
             Actor = new ResourceReference
             {
                 Reference = practitioner.Id
             }
         });
     }
 }
Exemplo n.º 2
0
        internal static FhirProcedure ToFhirInternal(HVProcedure hvProcedure, FhirProcedure fhirProcedure)
        {
            //Status is a required field; however HealthVault doesn't have
            //an equivalent for this
            fhirProcedure.Status = EventStatus.Unknown;
            fhirProcedure.Code   = hvProcedure.Name.ToFhir();

            AddPerformer(fhirProcedure, hvProcedure.PrimaryProvider?.ToFhir());
            AddPerformer(fhirProcedure, hvProcedure.SecondaryProvider?.ToFhir());

            if (hvProcedure.AnatomicLocation != null)
            {
                fhirProcedure.BodySite.Add(hvProcedure.AnatomicLocation.ToFhir());
            }

            var fhirDate = hvProcedure.When?.ToFhir();

            if (fhirDate != null)
            {
                fhirProcedure.Performed = fhirDate;
            }

            return(fhirProcedure);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Parse Procedure
        /// </summary>
        public static Hl7.Fhir.Model.Procedure ParseProcedure(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Procedure existingInstance = null)
        {
            Hl7.Fhir.Model.Procedure result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Procedure();
            string currentElementName       = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element language
                else if (atName == "language")
                {
                    result.LanguageElement = CodeParser.ParseCode(reader, errors);
                }

                // Parse element text
                else if (atName == "text")
                {
                    result.Text = NarrativeParser.ParseNarrative(reader, errors);
                }

                // Parse element contained
                else if (atName == "contained")
                {
                    result.Contained = new List <Hl7.Fhir.Model.Resource>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "contained"))
                    {
                        result.Contained.Add(ParserUtils.ParseContainedResource(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element subject
                else if (atName == "subject")
                {
                    result.Subject = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element type
                else if (atName == "type")
                {
                    result.Type = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element bodySite
                else if (atName == "bodySite")
                {
                    result.BodySite = new List <Hl7.Fhir.Model.CodeableConcept>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "bodySite"))
                    {
                        result.BodySite.Add(CodeableConceptParser.ParseCodeableConcept(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element indication
                else if (atName == "indication")
                {
                    result.IndicationElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element performer
                else if (atName == "performer")
                {
                    result.Performer = new List <Hl7.Fhir.Model.Procedure.ProcedurePerformerComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "performer"))
                    {
                        result.Performer.Add(ProcedureParser.ParseProcedurePerformerComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element date
                else if (atName == "date")
                {
                    result.Date = PeriodParser.ParsePeriod(reader, errors);
                }

                // Parse element encounter
                else if (atName == "encounter")
                {
                    result.Encounter = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element outcome
                else if (atName == "outcome")
                {
                    result.OutcomeElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element report
                else if (atName == "report")
                {
                    result.Report = new List <Hl7.Fhir.Model.ResourceReference>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "report"))
                    {
                        result.Report.Add(ResourceReferenceParser.ParseResourceReference(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element complication
                else if (atName == "complication")
                {
                    result.ComplicationElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element followUp
                else if (atName == "followUp")
                {
                    result.FollowUpElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element relatedItem
                else if (atName == "relatedItem")
                {
                    result.RelatedItem = new List <Hl7.Fhir.Model.Procedure.ProcedureRelatedItemComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "relatedItem"))
                    {
                        result.RelatedItem.Add(ProcedureParser.ParseProcedureRelatedItemComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element notes
                else if (atName == "notes")
                {
                    result.NotesElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
Exemplo n.º 4
0
        public static void SerializeProcedure(Hl7.Fhir.Model.Procedure value, IFhirWriter writer, bool summary)
        {
            writer.WriteStartRootObject("Procedure");
            writer.WriteStartComplexContent();

            // Serialize element _id
            if (value.LocalIdElement != null)
            {
                writer.WritePrimitiveContents("_id", value.LocalIdElement, XmlSerializationHint.Attribute);
            }

            // Serialize element extension
            if (value.Extension != null && !summary && value.Extension.Count > 0)
            {
                writer.WriteStartArrayElement("extension");
                foreach (var item in value.Extension)
                {
                    writer.WriteStartArrayMember("extension");
                    ExtensionSerializer.SerializeExtension(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element language
            if (value.LanguageElement != null && !summary)
            {
                writer.WriteStartElement("language");
                CodeSerializer.SerializeCode(value.LanguageElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element text
            if (value.Text != null && !summary)
            {
                writer.WriteStartElement("text");
                NarrativeSerializer.SerializeNarrative(value.Text, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element contained
            if (value.Contained != null && !summary && value.Contained.Count > 0)
            {
                writer.WriteStartArrayElement("contained");
                foreach (var item in value.Contained)
                {
                    writer.WriteStartArrayMember("contained");
                    FhirSerializer.SerializeResource(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element subject
            if (value.Subject != null)
            {
                writer.WriteStartElement("subject");
                ResourceReferenceSerializer.SerializeResourceReference(value.Subject, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element type
            if (value.Type != null)
            {
                writer.WriteStartElement("type");
                CodeableConceptSerializer.SerializeCodeableConcept(value.Type, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element bodySite
            if (value.BodySite != null && value.BodySite.Count > 0)
            {
                writer.WriteStartArrayElement("bodySite");
                foreach (var item in value.BodySite)
                {
                    writer.WriteStartArrayMember("bodySite");
                    CodeableConceptSerializer.SerializeCodeableConcept(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element indication
            if (value.IndicationElement != null)
            {
                writer.WriteStartElement("indication");
                FhirStringSerializer.SerializeFhirString(value.IndicationElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element performer
            if (value.Performer != null && value.Performer.Count > 0)
            {
                writer.WriteStartArrayElement("performer");
                foreach (var item in value.Performer)
                {
                    writer.WriteStartArrayMember("performer");
                    ProcedureSerializer.SerializeProcedurePerformerComponent(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element date
            if (value.Date != null)
            {
                writer.WriteStartElement("date");
                PeriodSerializer.SerializePeriod(value.Date, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element encounter
            if (value.Encounter != null)
            {
                writer.WriteStartElement("encounter");
                ResourceReferenceSerializer.SerializeResourceReference(value.Encounter, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element outcome
            if (value.OutcomeElement != null)
            {
                writer.WriteStartElement("outcome");
                FhirStringSerializer.SerializeFhirString(value.OutcomeElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element report
            if (value.Report != null && !summary && value.Report.Count > 0)
            {
                writer.WriteStartArrayElement("report");
                foreach (var item in value.Report)
                {
                    writer.WriteStartArrayMember("report");
                    ResourceReferenceSerializer.SerializeResourceReference(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element complication
            if (value.ComplicationElement != null && !summary)
            {
                writer.WriteStartElement("complication");
                FhirStringSerializer.SerializeFhirString(value.ComplicationElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element followUp
            if (value.FollowUpElement != null && !summary)
            {
                writer.WriteStartElement("followUp");
                FhirStringSerializer.SerializeFhirString(value.FollowUpElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element relatedItem
            if (value.RelatedItem != null && !summary && value.RelatedItem.Count > 0)
            {
                writer.WriteStartArrayElement("relatedItem");
                foreach (var item in value.RelatedItem)
                {
                    writer.WriteStartArrayMember("relatedItem");
                    ProcedureSerializer.SerializeProcedureRelatedItemComponent(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element notes
            if (value.NotesElement != null && !summary)
            {
                writer.WriteStartElement("notes");
                FhirStringSerializer.SerializeFhirString(value.NotesElement, writer, summary);
                writer.WriteEndElement();
            }


            writer.WriteEndComplexContent();
            writer.WriteEndRootObject();
        }
        public void WhenHealthVaultProcedureTransformedToFhir_ThenValuesAndCodesEqual()
        {
            #region Settingup objects
            var now         = new LocalDateTime(2017, 09, 20, 16, 30, 10, 100);
            var personId    = Guid.NewGuid();
            var hvProcedure = new HVProcedure
            {
                When = new ApproximateDateTime
                {
                    ApproximateDate = new ApproximateDate(now.Year, now.Month, now.Day),
                    ApproximateTime = new ApproximateTime(now.Hour, now.Minute, now.Second, now.Millisecond)
                },
                Name             = new CodableValue("Operative procedure on fingers", new CodedValue("215000", "SnomedProcedures", "Snomed", "Jan2008")),
                AnatomicLocation = new CodableValue("Metacarpophalangeal joint structure of index finger", new CodedValue("289002", "SnomedBodyLocation", "Snomed", "Jan2008")),
                PrimaryProvider  = new PersonItem
                {
                    PersonType           = new CodableValue("Provider", new CodedValue("1", "person-types", "wc", "1")),
                    Name                 = new Name("John Doe", "John", "T", "Doe"),
                    Organization         = "Care Hospitals Inc",
                    PersonId             = personId.ToString(),
                    ProfessionalTraining = "Certified Medical Assistant",
                    ContactInformation   = new ContactInfo()
                },
                SecondaryProvider = new PersonItem
                {
                    PersonType = new CodableValue("Provider", new CodedValue("1", "person-types", "wc", "1")),
                    Name       = new Name("Justin Case", "Just", "in", "Case")
                }
            };

            var address1 = new HVAddress
            {
                City        = "John's Work City",
                State       = "John's Work State",
                County      = "John's Work County",
                PostalCode  = "J12309",
                Country     = "Kingdom of John",
                IsPrimary   = true,
                Description = "This is John's Primary (Work) Address"
            };
            address1.Street.Add("John's Clinic");
            address1.Street.Add("John's Lane");
            hvProcedure.PrimaryProvider.ContactInformation.Address.Add(address1);

            var address2 = new HVAddress
            {
                City        = "John's Home City",
                State       = "John's Home State",
                County      = "John's Home County",
                PostalCode  = "J12310",
                Country     = "Kingdom of John",
                Description = "This is John's Home Address"
            };
            address1.Street.Add("John's Home");
            hvProcedure.PrimaryProvider.ContactInformation.Address.Add(address2);
            #endregion

            FhirProcedure fhirProcedure = hvProcedure.ToFhir();

            Assert.IsNotNull(fhirProcedure);

            //Code
            Assert.IsFalse(fhirProcedure.Code.IsNullOrEmpty());
            Assert.AreEqual("Operative procedure on fingers", fhirProcedure.Code.Text);
            Assert.IsNotNull(fhirProcedure.Code.Coding.FirstOrDefault());
            Assert.AreEqual("215000", fhirProcedure.Code.Coding[0].Code);
            Assert.IsTrue(fhirProcedure.Code.Coding[0].System.EndsWith("Snomed/SnomedProcedures"));
            Assert.AreEqual("Jan2008", fhirProcedure.Code.Coding[0].Version);

            //Status - Since HV does not know which of the status values correctly applies here
            Assert.AreEqual(EventStatus.Unknown, fhirProcedure.Status);

            //Performed
            Assert.IsInstanceOfType(fhirProcedure.Performed, typeof(FhirDateTime));
            Assert.AreEqual(now.ToDateTimeUnspecified(), ((FhirDateTime)fhirProcedure.Performed).ToDateTimeOffset());

            //Performer
            Assert.IsFalse(fhirProcedure.Performer.IsNullOrEmpty());
            Assert.IsFalse(fhirProcedure.Contained.IsNullOrEmpty());
            Assert.AreEqual(2, fhirProcedure.Performer.Count);
            Assert.AreEqual(2, fhirProcedure.Contained.Where(resource => resource.GetType().Equals(typeof(Practitioner)) && resource.Id.StartsWith("#practitioner-")).Count());
            Assert.AreEqual(2, fhirProcedure.Performer.Where(performer => performer.Actor.Reference.StartsWith("#practitioner-")).Count());

            //BodySite
            Assert.IsFalse(fhirProcedure.BodySite.IsNullOrEmpty());
            Assert.AreEqual("Metacarpophalangeal joint structure of index finger", fhirProcedure.BodySite[0].Text);
            Assert.IsNotNull(fhirProcedure.BodySite[0].Coding.FirstOrDefault());
            Assert.AreEqual("289002", fhirProcedure.BodySite[0].Coding[0].Code);
            Assert.IsTrue(fhirProcedure.BodySite[0].Coding[0].System.EndsWith("Snomed/SnomedBodyLocation"));
            Assert.AreEqual("Jan2008", fhirProcedure.BodySite[0].Coding[0].Version);
        }