コード例 #1
0
        //STUB PATIENTS;
        #region
        public IEnumerable<Patient> GenerateStubExamples()
        {
            //stub1
            var stub1 = new Patient();
            var name1 = new HumanName();
            name1.Family = new List<string> {"Odenkirk"};
            name1.Given = new List<string> { "Bob" };

            stub1.Name = new List<HumanName> { name1 };
            stub1.Id = "b3tter_c@ll_$@ul";
            stub1.Gender = AdministrativeGender.Male;

            //stub2
            var stub2 = new Patient();
            var name2 = new HumanName();
            name2.Family = new List<string> { "Saggot" };
            name2.Given = new List<string> { "Bob" };

            stub2.Name = new List<HumanName> { name2 };
            stub2.Id = "full_house789";
            stub2.Gender = AdministrativeGender.Male;

            //stub3
            var stub3 = new Patient();
            var name3 = new HumanName();
            name3.Family = new List<string> { "Jones" };
            name3.Given = new List<string> { "Jessica" };

            stub3.Name = new List<HumanName> { name3 };
            stub3.Id = "m@r3lou$";
            stub3.Gender = AdministrativeGender.Female;

            return new List<Patient> { stub1, stub2, stub3};
        }
コード例 #2
0
ファイル: Initializers.cs プロジェクト: tiloc/fhir-net-api
        public static HumanName ForFamily(string family)
        {
            var result = new HumanName();

            result.Family = new string[] { family };

            return result;
        }
コード例 #3
0
ファイル: Test.cs プロジェクト: TonyAbell/spark
 public static Patient Patient()
 {
     Patient patient = new Patient();
     patient.Id = "patient/1";
     HumanName h = new HumanName().WithGiven("Martijn");
     patient.Name = new List<HumanName>();
     patient.Name.Add(h);
     return patient;
 }
コード例 #4
0
        public static Patient NewPatient(string family, params string[] given)
        {
            Patient p = new Patient();
            HumanName n = new HumanName();
            foreach (string g in given) { n.WithGiven(g); }

            n.AndFamily(family);
            p.Name = new List<HumanName>();
            p.Name.Add(n);
            return p;
        }
コード例 #5
0
ファイル: ElementQueryTests.cs プロジェクト: Condeti/spark
        public void TestVisitOnePathOneMatch()
        {
            ElementQuery sut = new ElementQuery("Patient.name");

            Patient testPatient = new Patient();
            var hn = new HumanName().WithGiven("Sjors").AndFamily("Jansen");
            testPatient.Name = new List<HumanName> { hn };

            var result = new List<Object>();

            sut.Visit(testPatient, fd => result.Add(fd));

            Assert.AreEqual(testPatient.Name.Count, result.Where(ob => ob != null).Count());
            Assert.IsTrue(result.Contains(hn));
        }
コード例 #6
0
ファイル: ElementQueryTests.cs プロジェクト: Condeti/spark
        public void TestVisitOnePathTwoMatches()
        {
            ElementQuery sut = new ElementQuery("Patient.name");

            Patient testPatient = new Patient();
            var hn1 = new HumanName().WithGiven("A").AndFamily("B");
            var hn2 = new HumanName().WithGiven("Y").AndFamily("Z");
            testPatient.Name = new List<HumanName> { hn1, hn2 };

            var result = new List<Object>();

            sut.Visit(testPatient, fd => result.Add(fd));

            Assert.AreEqual(testPatient.Name.Count, result.Where(ob => ob != null).Count());
            Assert.IsTrue(result.Contains(hn1));
            Assert.IsTrue(result.Contains(hn2));
        }
コード例 #7
0
        private void cmdCreatePatient_Click(object sender, EventArgs e)
        {
            // Code for creating a patient here.
            // Patientidentifier variables
            var MyPatient = new Hl7.Fhir.Model.Patient();

            var PatientName = new Hl7.Fhir.Model.HumanName();

            PatientName.Use = Hl7.Fhir.Model.HumanName.NameUse.Official;

            string patientFirstName = txtFirstName.Text;
            string patientSurname   = txtSurname.Text;
            string patientTitle     = cmbPatientTitle.Text;
            string patientNumber    = txtPatientNum.Text;


            PatientName.Prefix = new string[] { patientTitle };
            PatientName.Given  = new string[] { patientFirstName };
            PatientName.Family = new string[] { patientSurname };

            MyPatient.Name = new List <Hl7.Fhir.Model.HumanName>();
            MyPatient.Name.Add(PatientName);

            // Institution patient identifiers
            var PatientIdentifier = new Hl7.Fhir.Model.Identifier();

            PatientIdentifier.System = "https://medical-test.net";
            PatientIdentifier.Value  = patientNumber;
            MyPatient.Identifier     = new List <Hl7.Fhir.Model.Identifier>();
            MyPatient.Identifier.Add(PatientIdentifier);

            string    xml  = Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToXml(MyPatient);
            XDocument xDoc = XDocument.Parse(xml);

            txtOutput.Text = xDoc.ToString();
        }
コード例 #8
0
 public void Write(Definition definition, HumanName name)
 {
     Write(definition, name.Given);
     Write(definition, name.Prefix);
     Write(definition, name.Family);
     Write(definition, name.Suffix);
     //Write(definition, name.Use.ToString());
 }
コード例 #9
0
        public static void SerializeHumanName(Hl7.Fhir.Model.HumanName value, IFhirWriter writer, bool summary)
        {
            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 use
            if (value.UseElement != null)
            {
                writer.WriteStartElement("use");
                CodeSerializer.SerializeCode <Hl7.Fhir.Model.HumanName.NameUse>(value.UseElement, writer, summary);
                writer.WriteEndElement();
            }

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

            // Serialize element family
            if (value.FamilyElement != null && value.FamilyElement.Count > 0)
            {
                writer.WriteStartArrayElement("family");
                foreach (var item in value.FamilyElement)
                {
                    writer.WriteStartArrayMember("family");
                    FhirStringSerializer.SerializeFhirString(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element given
            if (value.GivenElement != null && value.GivenElement.Count > 0)
            {
                writer.WriteStartArrayElement("given");
                foreach (var item in value.GivenElement)
                {
                    writer.WriteStartArrayMember("given");
                    FhirStringSerializer.SerializeFhirString(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element prefix
            if (value.PrefixElement != null && value.PrefixElement.Count > 0)
            {
                writer.WriteStartArrayElement("prefix");
                foreach (var item in value.PrefixElement)
                {
                    writer.WriteStartArrayMember("prefix");
                    FhirStringSerializer.SerializeFhirString(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element suffix
            if (value.SuffixElement != null && value.SuffixElement.Count > 0)
            {
                writer.WriteStartArrayElement("suffix");
                foreach (var item in value.SuffixElement)
                {
                    writer.WriteStartArrayMember("suffix");
                    FhirStringSerializer.SerializeFhirString(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

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


            writer.WriteEndComplexContent();
        }
コード例 #10
0
ファイル: ElementIndexerTests.cs プロジェクト: Condeti/spark
        public void HumanNameOnlyGivenMapTest()
        {
            var input = new HumanName();
            input.WithGiven("Pietje");

            var result = sut.Map(input);

            Assert.AreEqual(1, result.Count()); //2 line elements + city, country and postalcode.
            foreach (var res in result)
            {
                Assert.IsInstanceOfType(res, typeof(StringValue));
            }
            Assert.AreEqual(1, result.Where(r => (r as StringValue).Value == "Pietje").Count());
        }
コード例 #11
0
        /// <summary>
        /// Deserialize JSON into a FHIR Practitioner
        /// </summary>
        public static void DeserializeJsonProperty(this Practitioner current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "identifier":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"Practitioner error reading 'identifier' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Identifier = new List <Identifier>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.Identifier v_Identifier = new Hl7.Fhir.Model.Identifier();
                    v_Identifier.DeserializeJson(ref reader, options);
                    current.Identifier.Add(v_Identifier);

                    if (!reader.Read())
                    {
                        throw new JsonException($"Practitioner error reading 'identifier' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Identifier.Count == 0)
                {
                    current.Identifier = null;
                }
                break;

            case "active":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.ActiveElement = new FhirBoolean();
                    reader.Skip();
                }
                else
                {
                    current.ActiveElement = new FhirBoolean(reader.GetBoolean());
                }
                break;

            case "_active":
                if (current.ActiveElement == null)
                {
                    current.ActiveElement = new FhirBoolean();
                }
                ((Hl7.Fhir.Model.Element)current.ActiveElement).DeserializeJson(ref reader, options);
                break;

            case "name":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"Practitioner error reading 'name' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Name = new List <HumanName>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.HumanName v_Name = new Hl7.Fhir.Model.HumanName();
                    v_Name.DeserializeJson(ref reader, options);
                    current.Name.Add(v_Name);

                    if (!reader.Read())
                    {
                        throw new JsonException($"Practitioner error reading 'name' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Name.Count == 0)
                {
                    current.Name = null;
                }
                break;

            case "telecom":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"Practitioner error reading 'telecom' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Telecom = new List <ContactPoint>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.ContactPoint v_Telecom = new Hl7.Fhir.Model.ContactPoint();
                    v_Telecom.DeserializeJson(ref reader, options);
                    current.Telecom.Add(v_Telecom);

                    if (!reader.Read())
                    {
                        throw new JsonException($"Practitioner error reading 'telecom' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Telecom.Count == 0)
                {
                    current.Telecom = null;
                }
                break;

            case "address":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"Practitioner error reading 'address' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Address = new List <Address>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.Address v_Address = new Hl7.Fhir.Model.Address();
                    v_Address.DeserializeJson(ref reader, options);
                    current.Address.Add(v_Address);

                    if (!reader.Read())
                    {
                        throw new JsonException($"Practitioner error reading 'address' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Address.Count == 0)
                {
                    current.Address = null;
                }
                break;

            case "gender":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.GenderElement = new Code <Hl7.Fhir.Model.AdministrativeGender>();
                    reader.Skip();
                }
                else
                {
                    current.GenderElement = new Code <Hl7.Fhir.Model.AdministrativeGender>(Hl7.Fhir.Utility.EnumUtility.ParseLiteral <Hl7.Fhir.Model.AdministrativeGender>(reader.GetString()));
                }
                break;

            case "_gender":
                if (current.GenderElement == null)
                {
                    current.GenderElement = new Code <Hl7.Fhir.Model.AdministrativeGender>();
                }
                ((Hl7.Fhir.Model.Element)current.GenderElement).DeserializeJson(ref reader, options);
                break;

            case "birthDate":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.BirthDateElement = new Date();
                    reader.Skip();
                }
                else
                {
                    current.BirthDateElement = new Date(reader.GetString());
                }
                break;

            case "_birthDate":
                if (current.BirthDateElement == null)
                {
                    current.BirthDateElement = new Date();
                }
                ((Hl7.Fhir.Model.Element)current.BirthDateElement).DeserializeJson(ref reader, options);
                break;

            case "photo":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"Practitioner error reading 'photo' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Photo = new List <Attachment>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.Attachment v_Photo = new Hl7.Fhir.Model.Attachment();
                    v_Photo.DeserializeJson(ref reader, options);
                    current.Photo.Add(v_Photo);

                    if (!reader.Read())
                    {
                        throw new JsonException($"Practitioner error reading 'photo' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Photo.Count == 0)
                {
                    current.Photo = null;
                }
                break;

            case "qualification":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"Practitioner error reading 'qualification' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Qualification = new List <Practitioner.QualificationComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.Practitioner.QualificationComponent v_Qualification = new Hl7.Fhir.Model.Practitioner.QualificationComponent();
                    v_Qualification.DeserializeJson(ref reader, options);
                    current.Qualification.Add(v_Qualification);

                    if (!reader.Read())
                    {
                        throw new JsonException($"Practitioner error reading 'qualification' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Qualification.Count == 0)
                {
                    current.Qualification = null;
                }
                break;

            case "communication":
                if ((reader.TokenType != JsonTokenType.StartArray) || (!reader.Read()))
                {
                    throw new JsonException($"Practitioner error reading 'communication' expected StartArray, found {reader.TokenType}! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                }

                current.Communication = new List <CodeableConcept>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.CodeableConcept v_Communication = new Hl7.Fhir.Model.CodeableConcept();
                    v_Communication.DeserializeJson(ref reader, options);
                    current.Communication.Add(v_Communication);

                    if (!reader.Read())
                    {
                        throw new JsonException($"Practitioner error reading 'communication' array, read failed! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    if (reader.TokenType == JsonTokenType.EndObject)
                    {
                        reader.Read();
                    }
                }

                if (current.Communication.Count == 0)
                {
                    current.Communication = null;
                }
                break;

            // Complex: Practitioner, Export: Practitioner, Base: DomainResource
            default:
                ((Hl7.Fhir.Model.DomainResource)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }
コード例 #12
0
        /// <summary>
        /// Parse HumanName
        /// </summary>
        public static Hl7.Fhir.Model.HumanName ParseHumanName(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.HumanName existingInstance = null)
        {
            Hl7.Fhir.Model.HumanName result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.HumanName();
            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 use
                else if (atName == "use")
                {
                    result.UseElement = CodeParser.ParseCode <Hl7.Fhir.Model.HumanName.NameUse>(reader, errors);
                }

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

                // Parse element family
                else if (atName == "family")
                {
                    result.FamilyElement = new List <Hl7.Fhir.Model.FhirString>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "family"))
                    {
                        result.FamilyElement.Add(FhirStringParser.ParseFhirString(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element given
                else if (atName == "given")
                {
                    result.GivenElement = new List <Hl7.Fhir.Model.FhirString>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "given"))
                    {
                        result.GivenElement.Add(FhirStringParser.ParseFhirString(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element prefix
                else if (atName == "prefix")
                {
                    result.PrefixElement = new List <Hl7.Fhir.Model.FhirString>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "prefix"))
                    {
                        result.PrefixElement.Add(FhirStringParser.ParseFhirString(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element suffix
                else if (atName == "suffix")
                {
                    result.SuffixElement = new List <Hl7.Fhir.Model.FhirString>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "suffix"))
                    {
                        result.SuffixElement.Add(FhirStringParser.ParseFhirString(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element period
                else if (atName == "period")
                {
                    result.Period = PeriodParser.ParsePeriod(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);
        }
コード例 #13
0
        public void ResourceWithExtensionAndNarrative()
        {
            HumanName name = new HumanName().WithGiven("Wouter").WithGiven("Gert")
                .AndFamily("van der").AndFamily("Vlies");

            name.FamilyElement[0].AddExtension(new Uri("http://hl7.org/fhir/profile/@iso-21090#name-qualifier"),
                        new Code("VV"));

            Patient p = new Patient()
            {
                LocalId = "Ab4",
                Identifier = new List<Identifier> { new Identifier { Key = "3141" } },
                BirthDateElement = new FhirDateTime(1972, 11, 30),
                Name = new List<HumanName> { name },
                Text = new Narrative()
                 {
                     Status = Narrative.NarrativeStatus.Generated,
                     Div = "<div xmlns='http://www.w3.org/1999/xhtml'>Patient 3141 - Wouter Gert, nov. 30th, 1972</div>"
                 },

                 Contained = new List<Resource>() { new List() { Mode = List.ListMode.Snapshot } }
            };

            Assert.AreEqual(@"<?xml version=""1.0"" encoding=""utf-16""?>" +
                @"<Patient id=""Ab4"" xmlns=""http://hl7.org/fhir"">" +
                @"<text><status value=""generated"" /><div xmlns='http://www.w3.org/1999/xhtml'>Patient 3141 - Wouter Gert, nov. 30th, 1972</div></text>" +
                @"<contained><List><mode value=""snapshot"" /></List></contained>" +
                @"<identifier><key value=""3141"" /></identifier>" +
                @"<name>" +
                    @"<family value=""van der"">" +
                        @"<extension><url value=""http://hl7.org/fhir/profile/@iso-21090#name-qualifier"" /><valueCode value=""VV"" /></extension>" +
                    @"</family><family value=""Vlies"" /><given value=""Wouter"" /><given value=""Gert"" /></name>" +
                    @"<birthDate value=""1972-11-30"" />" +
                @"</Patient>", FhirSerializer.SerializeResourceToXml(p));

            Assert.AreEqual(@"{""Patient"":{""_id"":""Ab4""," +
                 @"""text"":{""status"":{""value"":""generated""},""div"":""<div xmlns='http://www.w3.org/1999/xhtml'>" +
                    @"Patient 3141 - Wouter Gert, nov. 30th, 1972</div>""},"+
                 @"""contained"":[{""List"":{""mode"":{""value"":""snapshot""}}}],"+
                @"""identifier"":[{""key"":{""value"":""3141""}}]," +
                @"""name"":[{""family"":[{""value"":""van der""," +
                    @"""extension"":[{""url"":{""value"":""http://hl7.org/fhir/profile/@iso-21090#name-qualifier""},""valueCode"":{""value"":""VV""}}]}," +
                    @"{""value"":""Vlies""}],""given"":[{""value"":""Wouter""},{""value"":""Gert""}]}],""birthDate"":{""value"":""1972-11-30""}" +
                @"}}", FhirSerializer.SerializeResourceToJson(p));
        }