public static void SerializeDate(Hl7.Fhir.Model.Date value, IFhirWriter writer, bool summary)
 {
     writer.WriteStartComplexContent();
     
     // Serialize element value
     if(value.Value != null)
         writer.WritePrimitiveContents("value", value, XmlSerializationHint.Attribute);
     
     // 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();
     }
     
     
     writer.WriteEndComplexContent();
 }
Пример #2
0
        private List <Expression> ToExpressions(Hl7.Fhir.Model.Date element)
        {
            if (element == null || String.Empty.Equals(element.Value))
            {
                return(null);
            }

            FhirModel.FhirDateTime fdt = new FhirModel.FhirDateTime(element.Value);
            return(ToExpressions(fdt));
        }
Пример #3
0
        /// <summary>
        /// Parse date
        /// </summary>
        public static Hl7.Fhir.Model.Date ParseDate(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Date existingInstance = null)
        {
            Hl7.Fhir.Model.Date result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Date();
            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 _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element value
                else if (atName == "value")
                {
                    result.Value = Date.Parse(reader.ReadPrimitiveContents(typeof(Date))).Value;
                }

                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);
        }
Пример #4
0
        /// <summary>
        /// Generates a HL7 Patient class
        /// </summary>
        /// <param name="patientNumber"></param>
        /// <param name="practitioner"></param>
        /// <param name="state"></param>
        /// <param name="district"></param>
        /// <param name="postalCode"></param>
        /// <returns></returns>
        public HL7.Patient GeneratePatient(int patientNumber, int practitioner, string state, string district, string postalCode)
        {
            HL7.Patient genPat = new HL7.Patient();

            //give an id
            genPat.Id = patientNumber.ToString();

            ////give a name
            HL7.HumanName hName = new HL7.HumanName();
            hName.FamilyElement.Add(new HL7.FhirString("TESTLAST"));
            hName.GivenElement.Add(new HL7.FhirString("TESTFIRST"));
            genPat.Name.Add(hName);

            //add a care provider so we can filter for doctor facing app
            HL7.ResourceReference practRef = new HL7.ResourceReference();
            practRef.ReferenceElement = new HL7.FhirString("Practitioner/" + practitioner);
            genPat.CareProvider.Add(practRef);

            //give an address
            HL7.Address address = new HL7.Address();
            address.Use = HL7.Address.AddressUse.Home;
            address.LineElement.Add(new HL7.FhirString("123 Fake Street"));
            address.City       = "FAKETOWN";
            address.District   = district;
            address.State      = state;
            address.PostalCode = postalCode;
            genPat.Address.Add(address);

            //give a gender
            genPat.Gender = (rand.NextDouble() < .5) ? HL7.AdministrativeGender.Female : HL7.AdministrativeGender.Male;

            //give a DOB
            //randomly generate based on age range 0 - 17
            int      years = Convert.ToInt32(Math.Round(16 * rand.NextDouble())) + 1;
            int      days  = Convert.ToInt32(Math.Round(364 * rand.NextDouble()));
            DateTime dob   = new DateTime(2016 - years, 01, 01).AddDays(days);

            HL7.Date hl7DOB = new HL7.Date(dob.ToShortDateString());
            genPat.BirthDateElement = hl7DOB;

            return(genPat);
        }