Exemplo n.º 1
0
        /// <summary>
        /// Deserialize JSON into a FHIR NamingSystem
        /// </summary>
        public static void DeserializeJson(this NamingSystem current, ref Utf8JsonReader reader, JsonSerializerOptions options)
        {
            string propertyName;

            while (reader.Read())
            {
                if (reader.TokenType == JsonTokenType.EndObject)
                {
                    return;
                }

                if (reader.TokenType == JsonTokenType.PropertyName)
                {
                    propertyName = reader.GetString();
                    if (Hl7.Fhir.Serialization.FhirSerializerOptions.Debug)
                    {
                        Console.WriteLine($"NamingSystem >>> NamingSystem.{propertyName}, depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
                    }
                    reader.Read();
                    current.DeserializeJsonProperty(ref reader, options, propertyName);
                }
            }

            throw new JsonException($"NamingSystem: invalid state! depth: {reader.CurrentDepth}, pos: {reader.BytesConsumed}");
        }
        private static Resource GetRequest(string identifier, NameValueCollection queryParam)
        {
            if (string.IsNullOrEmpty(identifier))
            {
                return(OperationOutcome.ForMessage("No NamingSystem id or identifer in Request", OperationOutcome.IssueType.BusinessRule, OperationOutcome.IssueSeverity.Error));
            }

            NamingSystem namingSystem     = new NamingSystem();
            string       resourceFilePath = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath) + @"\Test Files\";

            FhirXmlParser fxp = new FhirXmlParser();

            if (identifier.ToUpper() == "NHI" || identifier == DIGITAL_HEALTH_NZ + "/id/nhi" || identifier == "2.16.840.1.113883.2.18.2")
            {
                namingSystem = fxp.Parse <NamingSystem>(File.ReadAllText(resourceFilePath + "NamingSystem_NHI.xml"));
            }
            else if (identifier.ToUpper() == "HPI-CPN" || identifier == DIGITAL_HEALTH_NZ + "/id/hpi-person" || identifier == "2.16.840.1.113883.2.18.3.1")
            {
                namingSystem = fxp.Parse <NamingSystem>(File.ReadAllText(resourceFilePath + "NamingSystem_HPI_CPN.xml"));
            }
            else if (identifier.ToUpper() == "HPI-FAC" || identifier == DIGITAL_HEALTH_NZ + "/id/hpi-facility" || identifier == "2.16.840.1.113883.2.18.3.2")
            {
                namingSystem = fxp.Parse <NamingSystem>(File.ReadAllText(resourceFilePath + "NamingSystem_HPI_FAC.xml"));
            }
            else if (identifier.ToUpper() == "HPI-ORG" || identifier == DIGITAL_HEALTH_NZ + "/id/hpi-organisation" || identifier == "2.16.840.1.113883.2.18.3.3")
            {
                namingSystem = fxp.Parse <NamingSystem>(File.ReadAllText(resourceFilePath + "NamingSystem_HPI_ORG.xml"));
            }
            else if (identifier.ToUpper() == "NZMT" || identifier == NzMt.URI || identifier == "2.16.840.1.113883.2.18.21")
            {
                namingSystem = fxp.Parse <NamingSystem>(File.ReadAllText(resourceFilePath + "NamingSystem_NZMT.xml"));
            }
            else if (identifier.ToUpper() == "NZ_ETHNICITY_LEVEL_1" || identifier == NzEthnicityL1.URI || identifier == "2.16.840.1.113883.2.18.11")
            {
                namingSystem = fxp.Parse <NamingSystem>(File.ReadAllText(resourceFilePath + "NamingSystem_NZ_ETHNICITY_LEVEL_1.xml"));
            }
            else if (identifier.ToUpper() == "NZ_ETHNICITY_LEVEL_2" || identifier == NzEthnicityL2.URI || identifier == "2.16.840.1.113883.2.18.11.1")
            {
                namingSystem = fxp.Parse <NamingSystem>(File.ReadAllText(resourceFilePath + "NamingSystem_NZ_ETHNICITY_LEVEL_2.xml"));
            }
            else if (identifier.ToUpper() == "NZ_ETHNICITY_LEVEL_3" || identifier == NzEthnicityL3.URI || identifier == "2.16.840.1.113883.2.18.11.2")
            {
                namingSystem = fxp.Parse <NamingSystem>(File.ReadAllText(resourceFilePath + "NamingSystem_NZ_ETHNICITY_LEVEL_3.xml"));
            }
            else if (identifier.ToUpper() == "NZ_ETHNICITY_LEVEL_4" || identifier == NzEthnicityL4.URI || identifier == "2.16.840.1.113883.2.18.11.5")
            {
                namingSystem = fxp.Parse <NamingSystem>(File.ReadAllText(resourceFilePath + "NamingSystem_NZ_ETHNICITY_LEVEL_4.xml"));
            }
            else
            {
                return(OperationOutcome.ForMessage("Naming System Not Recognised.", OperationOutcome.IssueType.Unknown, OperationOutcome.IssueSeverity.Error));
            }

            AddNarrative(namingSystem);

            return(namingSystem);
        }
        internal static NamingSystem AddNarrative(NamingSystem nameSys)
        {
            // create display text for Organisation Resource
            string textString = string.Empty;

            try
            {
                XNamespace ns = "http://www.w3.org/1999/xhtml";

                var summary = new XElement(ns + "div",
                                           new XElement(ns + "h2", nameSys.Name),
                                           new XElement(ns + "table",
                                                        new XElement(ns + "tr",
                                                                     new XElement(ns + "td", "Id"),
                                                                     new XElement(ns + "td", nameSys.Id)
                                                                     ),
                                                        new XElement(ns + "tr",
                                                                     new XElement(ns + "td", "Description"),
                                                                     new XElement(ns + "td", nameSys.Description.ToString())
                                                                     ),
                                                        new XElement(ns + "tr",
                                                                     new XElement(ns + "td", "Kind"),
                                                                     new XElement(ns + "td", nameSys.Kind.ToString())
                                                                     ),
                                                        new XElement(ns + "table",
                                                                     new XElement(ns + "tr",
                                                                                  new XElement(ns + "th", "Type"),
                                                                                  new XElement(ns + "th", "Value")
                                                                                  ),
                                                                     from ui in nameSys.UniqueId
                                                                     select new XElement(ns + "tr",
                                                                                         new XElement(ns + "td", ui.Type.ToString()),
                                                                                         new XElement(ns + "td", ui.Value)
                                                                                         )
                                                                     )
                                                        )
                                           );

                textString = summary.ToString();
            }
            catch
            { }

            nameSys.Text = new Narrative
            {
                Status = Narrative.NarrativeStatus.Generated,
                Div    = textString
            };

            return(nameSys);
        }
Exemplo n.º 4
0
        public async Task GivenResourceWithTypeValue_WhenSearchedWithTypeParam_ThenOnlyResourcesMatchingAllSearchParamsShouldBeReturned()
        {
            var          code    = Guid.NewGuid().ToString();
            NamingSystem library = await Client.CreateAsync(new NamingSystem
            {
                Name     = "test",
                Status   = PublicationStatus.Draft,
                Kind     = NamingSystem.NamingSystemType.Codesystem,
                Date     = "2019",
                UniqueId = new List <NamingSystem.UniqueIdComponent> {
                    new NamingSystem.UniqueIdComponent {
                        Type = NamingSystem.NamingSystemIdentifierType.Uri, Value = "https://localhost"
                    }
                },
                Type = new CodeableConcept("https://localhost/", code),
            });

            await ExecuteAndValidateBundle($"NamingSystem?type={code}", library);
        }
Exemplo n.º 5
0
        public void TestNamingSystemCanonical()
        {
            NamingSystem ns = new NamingSystem();

            Assert.IsNull(ns.Url);
            Assert.IsNull(ns.UrlElement);

            ns.UniqueId.Add(new NamingSystem.UniqueIdComponent {
                Value = "http://nu.nl"
            });
            ns.UniqueId.Add(new NamingSystem.UniqueIdComponent {
                Value = "http://dan.nl", Preferred = true
            });

            Assert.AreEqual("http://dan.nl", ns.Url);
            Assert.AreEqual("http://dan.nl", ns.UrlElement.Value);

            ns.UniqueId[1].Preferred = false;

            Assert.AreEqual("http://nu.nl", ns.Url);
            Assert.AreEqual("http://nu.nl", ns.UrlElement.Value);
        }
        private static Resource PreferredIdOperation(string id, NameValueCollection queryParam)
        {
            string nsType = Utilities.GetQueryValue("type", queryParam);

            if (string.IsNullOrEmpty(id))
            {
                throw new Exception(MISSING_NS_IDENTIFIER);
            }
            else if (string.IsNullOrEmpty(nsType))
            {
                throw new Exception(MISSING_NS_TYPE);
            }

            Parameters param  = new Parameters();
            string     prefID = string.Empty;

            // get resource
            NamingSystem namingSystem = (NamingSystem)GetRequest(id, queryParam);

            foreach (NamingSystem.UniqueIdComponent idComp in namingSystem.UniqueId)
            {
                if (idComp.Preferred == true && idComp.Type.GetLiteral() == nsType)
                {
                    prefID = idComp.Value;
                }
            }

            if (string.IsNullOrEmpty(prefID))
            {
                throw new Exception(UNFOUND_NS_IDENTIFIER);
            }
            else
            {
                param.Add("result", new FhirString(prefID));
            }

            return(param);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Serialize a FHIR NamingSystem into JSON
        /// </summary>
        public static void SerializeJson(this NamingSystem current, Utf8JsonWriter writer, JsonSerializerOptions options, bool includeStartObject = true)
        {
            if (includeStartObject)
            {
                writer.WriteStartObject();
            }
            writer.WriteString("resourceType", "NamingSystem");
            // Complex: NamingSystem, Export: NamingSystem, Base: DomainResource (DomainResource)
            ((Hl7.Fhir.Model.DomainResource)current).SerializeJson(writer, options, false);

            writer.WriteString("name", current.NameElement.Value);

            writer.WriteString("status", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.StatusElement.Value));

            writer.WriteString("kind", Hl7.Fhir.Utility.EnumUtility.GetLiteral(current.KindElement.Value));

            writer.WriteString("date", current.DateElement.Value);

            if (current.PublisherElement != null)
            {
                if (!string.IsNullOrEmpty(current.PublisherElement.Value))
                {
                    writer.WriteString("publisher", current.PublisherElement.Value);
                }
                if (current.PublisherElement.HasExtensions() || (!string.IsNullOrEmpty(current.PublisherElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_publisher", false, current.PublisherElement.Extension, current.PublisherElement.ElementId);
                }
            }

            if ((current.Contact != null) && (current.Contact.Count != 0))
            {
                writer.WritePropertyName("contact");
                writer.WriteStartArray();
                foreach (ContactDetail val in current.Contact)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (current.ResponsibleElement != null)
            {
                if (!string.IsNullOrEmpty(current.ResponsibleElement.Value))
                {
                    writer.WriteString("responsible", current.ResponsibleElement.Value);
                }
                if (current.ResponsibleElement.HasExtensions() || (!string.IsNullOrEmpty(current.ResponsibleElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_responsible", false, current.ResponsibleElement.Extension, current.ResponsibleElement.ElementId);
                }
            }

            if (current.Type != null)
            {
                writer.WritePropertyName("type");
                current.Type.SerializeJson(writer, options);
            }

            if (current.Description != null)
            {
                if (!string.IsNullOrEmpty(current.Description.Value))
                {
                    writer.WriteString("description", current.Description.Value);
                }
                if (current.Description.HasExtensions() || (!string.IsNullOrEmpty(current.Description.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_description", false, current.Description.Extension, current.Description.ElementId);
                }
            }

            if ((current.UseContext != null) && (current.UseContext.Count != 0))
            {
                writer.WritePropertyName("useContext");
                writer.WriteStartArray();
                foreach (UsageContext val in current.UseContext)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if ((current.Jurisdiction != null) && (current.Jurisdiction.Count != 0))
            {
                writer.WritePropertyName("jurisdiction");
                writer.WriteStartArray();
                foreach (CodeableConcept val in current.Jurisdiction)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (current.UsageElement != null)
            {
                if (!string.IsNullOrEmpty(current.UsageElement.Value))
                {
                    writer.WriteString("usage", current.UsageElement.Value);
                }
                if (current.UsageElement.HasExtensions() || (!string.IsNullOrEmpty(current.UsageElement.ElementId)))
                {
                    JsonStreamUtilities.SerializeExtensionList(writer, options, "_usage", false, current.UsageElement.Extension, current.UsageElement.ElementId);
                }
            }

            if ((current.UniqueId != null) && (current.UniqueId.Count != 0))
            {
                writer.WritePropertyName("uniqueId");
                writer.WriteStartArray();
                foreach (NamingSystem.UniqueIdComponent val in current.UniqueId)
                {
                    val.SerializeJson(writer, options, true);
                }
                writer.WriteEndArray();
            }

            if (includeStartObject)
            {
                writer.WriteEndObject();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Deserialize JSON into a FHIR NamingSystem
        /// </summary>
        public static void DeserializeJsonProperty(this NamingSystem current, ref Utf8JsonReader reader, JsonSerializerOptions options, string propertyName)
        {
            switch (propertyName)
            {
            case "name":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.NameElement = new FhirString();
                    reader.Skip();
                }
                else
                {
                    current.NameElement = new FhirString(reader.GetString());
                }
                break;

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

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

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

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

            case "_kind":
                if (current.KindElement == null)
                {
                    current.KindElement = new Code <Hl7.Fhir.Model.NamingSystem.NamingSystemType>();
                }
                ((Hl7.Fhir.Model.Element)current.KindElement).DeserializeJson(ref reader, options);
                break;

            case "date":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.DateElement = new FhirDateTime();
                    reader.Skip();
                }
                else
                {
                    current.DateElement = new FhirDateTime(reader.GetString());
                }
                break;

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

            case "publisher":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.PublisherElement = new FhirString();
                    reader.Skip();
                }
                else
                {
                    current.PublisherElement = new FhirString(reader.GetString());
                }
                break;

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

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

                current.Contact = new List <ContactDetail>();

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

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

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

            case "responsible":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.ResponsibleElement = new FhirString();
                    reader.Skip();
                }
                else
                {
                    current.ResponsibleElement = new FhirString(reader.GetString());
                }
                break;

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

            case "type":
                current.Type = new Hl7.Fhir.Model.CodeableConcept();
                ((Hl7.Fhir.Model.CodeableConcept)current.Type).DeserializeJson(ref reader, options);
                break;

            case "description":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.Description = new Markdown();
                    reader.Skip();
                }
                else
                {
                    current.Description = new Markdown(reader.GetString());
                }
                break;

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

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

                current.UseContext = new List <UsageContext>();

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

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

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

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

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

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

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

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

            case "usage":
                if (reader.TokenType == JsonTokenType.Null)
                {
                    current.UsageElement = new FhirString();
                    reader.Skip();
                }
                else
                {
                    current.UsageElement = new FhirString(reader.GetString());
                }
                break;

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

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

                current.UniqueId = new List <NamingSystem.UniqueIdComponent>();

                while (reader.TokenType != JsonTokenType.EndArray)
                {
                    Hl7.Fhir.Model.NamingSystem.UniqueIdComponent v_UniqueId = new Hl7.Fhir.Model.NamingSystem.UniqueIdComponent();
                    v_UniqueId.DeserializeJson(ref reader, options);
                    current.UniqueId.Add(v_UniqueId);

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

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

            // Complex: NamingSystem, Export: NamingSystem, Base: DomainResource
            default:
                ((Hl7.Fhir.Model.DomainResource)current).DeserializeJsonProperty(ref reader, options, propertyName);
                break;
            }
        }