Пример #1
0
        /// <summary>
        /// Generates a condition (Hypertension)
        /// </summary>
        /// <param name="conditionNumber"></param>
        /// <param name="patient"></param>
        /// <returns></returns>
        public HL7.Condition GenerateCondition(int conditionNumber, HL7.Patient patient)
        {
            HL7.Condition genCond = new HL7.Condition();

            //give an id
            genCond.Id = conditionNumber.ToString();

            //give a patient association
            HL7.ResourceReference patRefence = new HL7.ResourceReference();
            patRefence.ReferenceElement = new HL7.FhirString("Patient/" + Int32.Parse(patient.Id));
            genCond.Patient             = patRefence;

            //add a code
            genCond.Code = new HL7.CodeableConcept("http://snomed.info/sct", "59621000", "Essential hypertension");

            //add an onset time
            TimeSpan age       = new TimeSpan((long)(DateTime.Now.Subtract(DateTime.Parse(patient.BirthDate)).Ticks *rand.NextDouble()));
            DateTime onsetDate = DateTime.Now.Subtract(age);

            genCond.Onset = new HL7.FhirDateTime(onsetDate.Year, onsetDate.Month, onsetDate.Day);

            return(genCond);
        }
Пример #2
0
        public static void SerializeCondition(Hl7.Fhir.Model.Condition value, IFhirWriter writer, bool summary)
        {
            writer.WriteStartRootObject("Condition");
            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 && !summary)
            {
                writer.WriteStartElement("subject");
                ResourceReferenceSerializer.SerializeResourceReference(value.Subject, writer, summary);
                writer.WriteEndElement();
            }

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

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

            // Serialize element dateAsserted
            if (value.DateAssertedElement != null && !summary)
            {
                writer.WriteStartElement("dateAsserted");
                DateSerializer.SerializeDate(value.DateAssertedElement, writer, summary);
                writer.WriteEndElement();
            }

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

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

            // Serialize element status
            if (value.StatusElement != null && !summary)
            {
                writer.WriteStartElement("status");
                CodeSerializer.SerializeCode <Hl7.Fhir.Model.Condition.ConditionStatus>(value.StatusElement, writer, summary);
                writer.WriteEndElement();
            }

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

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

            // Serialize element onset
            if (value.Onset != null && !summary)
            {
                writer.WriteStartElement(SerializationUtil.BuildPolymorphicName("onset", value.Onset.GetType()));
                FhirSerializer.SerializeElement(value.Onset, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element abatement
            if (value.Abatement != null && !summary)
            {
                writer.WriteStartElement(SerializationUtil.BuildPolymorphicName("abatement", value.Abatement.GetType()));
                FhirSerializer.SerializeElement(value.Abatement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element stage
            if (value.Stage != null && !summary)
            {
                writer.WriteStartElement("stage");
                ConditionSerializer.SerializeConditionStageComponent(value.Stage, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element evidence
            if (value.Evidence != null && !summary && value.Evidence.Count > 0)
            {
                writer.WriteStartArrayElement("evidence");
                foreach (var item in value.Evidence)
                {
                    writer.WriteStartArrayMember("evidence");
                    ConditionSerializer.SerializeConditionEvidenceComponent(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element location
            if (value.Location != null && !summary && value.Location.Count > 0)
            {
                writer.WriteStartArrayElement("location");
                foreach (var item in value.Location)
                {
                    writer.WriteStartArrayMember("location");
                    ConditionSerializer.SerializeConditionLocationComponent(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element relatedItem
            if (value.RelatedItem != null && !summary && value.RelatedItem.Count > 0)
            {
                writer.WriteStartArrayElement("relatedItem");
                foreach (var item in value.RelatedItem)
                {
                    writer.WriteStartArrayMember("relatedItem");
                    ConditionSerializer.SerializeConditionRelatedItemComponent(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();
        }
        /// <summary>
        /// Parse Condition
        /// </summary>
        public static Hl7.Fhir.Model.Condition ParseCondition(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Condition existingInstance = null)
        {
            Hl7.Fhir.Model.Condition result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Condition();
            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 encounter
                else if (atName == "encounter")
                {
                    result.Encounter = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

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

                // Parse element dateAsserted
                else if (atName == "dateAsserted")
                {
                    result.DateAssertedElement = DateParser.ParseDate(reader, errors);
                }

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

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

                // Parse element status
                else if (atName == "status")
                {
                    result.StatusElement = CodeParser.ParseCode <Hl7.Fhir.Model.Condition.ConditionStatus>(reader, errors);
                }

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

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

                // Parse element onset
                else if (atName.StartsWith("onset"))
                {
                    result.Onset = FhirParser.ParseElement(reader, errors);
                }

                // Parse element abatement
                else if (atName.StartsWith("abatement"))
                {
                    result.Abatement = FhirParser.ParseElement(reader, errors);
                }

                // Parse element stage
                else if (atName == "stage")
                {
                    result.Stage = ConditionParser.ParseConditionStageComponent(reader, errors);
                }

                // Parse element evidence
                else if (atName == "evidence")
                {
                    result.Evidence = new List <Hl7.Fhir.Model.Condition.ConditionEvidenceComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "evidence"))
                    {
                        result.Evidence.Add(ConditionParser.ParseConditionEvidenceComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element location
                else if (atName == "location")
                {
                    result.Location = new List <Hl7.Fhir.Model.Condition.ConditionLocationComponent>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "location"))
                    {
                        result.Location.Add(ConditionParser.ParseConditionLocationComponent(reader, errors));
                    }

                    reader.LeaveArray();
                }

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

                    while (ParserUtils.IsAtArrayElement(reader, "relatedItem"))
                    {
                        result.RelatedItem.Add(ConditionParser.ParseConditionRelatedItemComponent(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);
        }
Пример #4
0
        /// <summary>
        /// Generate data to supplement server data
        /// </summary>
        /// <returns></returns>
        public CreatedDataContainer CreateData()
        {
            //read the state data
            DataTable stateData = ReadStateData();

            DataTable states = stateData.DefaultView.ToTable(true, "State");

            //parameters for the size of the generated data set
            int maxPerState       = 10;
            int minPerState       = 10;
            int maxObsPerPatient  = 5;
            int minObsPerPatien   = 1;
            int maxCondPerPatient = 1;

            double conditionProb = 0.15;


            //set the starting patient number
            int patientNumber     = 100000;
            int observationNumber = 100000;
            int conditionNumber   = 100000;

            //lists to store the generated data
            List <HL7.Patient>     patList  = new List <HL7.Patient>();
            List <HL7.Observation> obsList  = new List <HL7.Observation>();
            List <HL7.Condition>   condList = new List <HL7.Condition>();


            //do patient generation per state
            foreach (DataRow state in states.Rows)
            {
                //get the countys for the given state
                List <DataRow> counties =
                    (from county in stateData.AsEnumerable()
                     where county.Field <string>("State").Equals(state.Field <string>("State"))
                     select county).ToList <DataRow>();

                //randomly determine the number of patients per state
                int patientCount = Convert.ToInt32(Math.Round(rand.NextDouble() * (maxPerState - minPerState))) + minPerState;

                for (int i = 0; i < patientCount; i++)
                {
                    //generate a practitioner id
                    //currently using IDs 1 - 5
                    int practId = rand.Next(1, 5);

                    //select a county
                    DataRow thisCounty = counties[rand.Next(counties.Count())];
                    //generate the new patient
                    HL7.Patient thisPatient = GeneratePatient(patientNumber, practId, thisCounty["State"].ToString(), thisCounty["County"].ToString(), thisCounty["Postal Code"].ToString());
                    //add to the list
                    patList.Add(thisPatient);
                    patientNumber++;
                }
            }

            //generate observations for each patient
            foreach (var patient in patList)
            {
                int obsCount = rand.Next(0, maxObsPerPatient);
                for (int i = 0; i < obsCount; i++)
                {
                    HL7.Observation thisObservation = GenerateObservation(observationNumber, patient, i);
                    obsList.Add(thisObservation);
                    observationNumber++;
                }
            }

            //generate conditions for each patient
            foreach (var patient in patList)
            {
                double condPct = rand.NextDouble();
                if (condPct < conditionProb)
                {
                    HL7.Condition thisCondition = GenerateCondition(conditionNumber, patient);
                    condList.Add(thisCondition);
                    conditionNumber++;
                }
            }

            return(new CreatedDataContainer(patList, condList, obsList));
        }