/// <summary>
        /// Parse the TN from the XmlReader <paramref name="s"/>.
        /// </summary>
        /// <param name="s">XmlReader stream to parse from.</param>
        /// <returns>Parsed TN.</returns>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            ANYFormatter baseFormatter = new ANYFormatter();
            TN           tn            = baseFormatter.Parse <TN>(s, result);

            // Parse the mixed content and add it to the list.
            if (!s.IsEmptyElement)
            {
                string oldName = s.LocalName;
                ENXP   tnPart  = new ENXP("");
                while (s.Read() && s.NodeType != System.Xml.XmlNodeType.EndElement && s.LocalName != oldName)
                {
                    if (s.NodeType == System.Xml.XmlNodeType.Text || s.NodeType == System.Xml.XmlNodeType.CDATA)
                    {
                        tnPart.Value += s.Value;
                    }
                    else if (s.NodeType == System.Xml.XmlNodeType.Element)
                    {
                        result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning,
                                                                                     s.LocalName,
                                                                                     s.NamespaceURI,
                                                                                     s.ToString(), null));
                    }
                }
                tn.Part.Add(tnPart);
            }

            return(tn);
        }
Exemple #2
0
        public void PNInvalidQualifierTest()
        {
            PN   pn   = new PN();
            ENXP enxp = new ENXP();

            enxp.Value     = "Andria";
            enxp.Qualifier = new SET <CS <EntityNamePartQualifier> >(EntityNamePartQualifier.LegalStatus);
            pn.Part.Add(enxp);
            pn.NullFlavor = null;
            Assert.IsFalse(pn.Validate());
        }
Exemple #3
0
        public void PNNullQualifierTest()
        {
            PN   pn   = new PN();
            ENXP enxp = new ENXP();

            enxp.Value     = "Andria";
            enxp.Qualifier = null;
            pn.Part.Add(enxp);
            pn.NullFlavor = null;
            Assert.IsTrue(pn.Validate());
        }
Exemple #4
0
        public void ENXPValueCodeCodeSystemTest()
        {
            ENXP x = new ENXP();

            x.Value             = "Andria";
            x.Code              = "here";
            x.CodeSystem        = "there";
            x.CodeSystemVersion = null;
            x.NullFlavor        = null;
            Assert.IsTrue(x.Validate());
        }
Exemple #5
0
        public void PNValidQualifierTest()
        {
            PN   pn   = new PN();
            ENXP enxp = new ENXP();

            enxp.Value     = "Andria";
            enxp.Qualifier = new SET <CS <EntityNamePartQualifier> >(EntityNamePartQualifier.Nobility);
            pn.Part.Add(enxp);
            pn.NullFlavor = null;
            Assert.IsTrue(pn.Validate());
        }
Exemple #6
0
        public void ENXPnullTest()
        {
            ENXP x = new ENXP();

            x.Value             = null;
            x.Code              = null;
            x.CodeSystem        = null;
            x.CodeSystemVersion = null;
            x.NullFlavor        = null;
            Assert.IsFalse(x.Validate());
        }
Exemple #7
0
        public void ENXPValueNullFlavorTest()
        {
            ENXP x = new ENXP();

            x.Value             = "Andria";
            x.Code              = null;
            x.CodeSystem        = null;
            x.CodeSystemVersion = null;
            x.NullFlavor        = NullFlavor.NotAsked;
            Assert.IsFalse(x.Validate());
        }
        /// <summary>
        /// Gets the patient record.
        /// </summary>
        /// <param name="hdid">The patient id.</param>
        /// <returns>The patient model.</returns>
        public async System.Threading.Tasks.Task <Patient> GetPatient(string hdid)
        {
            // Create request
            HCIM_IN_GetDemographics request = this.CreateRequest(hdid);

            // Perform the request
            HCIM_IN_GetDemographicsResponse1 reply = await this.getDemographicsClient.HCIM_IN_GetDemographicsAsync(request).ConfigureAwait(true);

            // Verify that the reply contains a result
            string responseCode = reply.HCIM_IN_GetDemographicsResponse.controlActProcess.queryAck.queryResponseCode.code;

            if (responseCode.Contains("BCHCIM.GD.0.0013", System.StringComparison.InvariantCulture))
            {
                HCIM_IN_GetDemographicsResponseIdentifiedPerson retrievedPerson = reply.HCIM_IN_GetDemographicsResponse.controlActProcess.subject[0].target;

                // Extract the subject names
                List <string> givenNameList = new List <string>();
                List <string> lastNameList  = new List <string>();
                for (int i = 0; i < retrievedPerson.identifiedPerson.name[0].Items.Length; i++)
                {
                    ENXP name = retrievedPerson.identifiedPerson.name[0].Items[i];

                    if (name.GetType() == typeof(engiven))
                    {
                        givenNameList.Add(name.Text[0]);
                    }
                    else if (name.GetType() == typeof(enfamily))
                    {
                        lastNameList.Add(name.Text[0]);
                    }
                }

                string delimiter  = " ";
                string givenNames = givenNameList.Aggregate((i, j) => i + delimiter + j);
                string lastNames  = lastNameList.Aggregate((i, j) => i + delimiter + j);
                string phn        = ((II)retrievedPerson.identifiedPerson.id.GetValue(0)).extension;
                // For now, add the return message to the reply
                return(new Patient(hdid, phn, givenNames, lastNames));
            }
            else
            {
                this.logger.LogInformation("Client Registry did not return a person. Returned message code: " + responseCode);
                return(new Patient());
            }
        }
        /// <summary>
        /// Parse an ENXP from stream <paramref name="s"/>
        /// </summary>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse base (ANY) from the stream

            // Parse CS
            ENXP retVal            = base.Parse <ENXP>(s, result);
            EntityNamePartType?enp = null;

            if (s.GetAttribute("qualifier") != null)
            {
                retVal.Qualifier = Util.Convert <SET <CS <EntityNamePartQualifier> > >(s.GetAttribute("qualifier"));
            }
            if (s.GetAttribute("type") != null)
            {
                retVal.Type = Util.Convert <EntityNamePartType>(s.GetAttribute("type"));
            }
            else if (ENFormatter.reverseMapping.TryGetValue(s.LocalName, out enp)) // try mapping
            {
                retVal.Type = enp;
            }

            // Now parse our data out...
            if (!s.IsEmptyElement)
            {
                // Read next for text elemnt
                string sName = s.Name;
                s.Read();
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && sName == s.Name))
                {
                    if (s.NodeType == System.Xml.XmlNodeType.Text)
                    {
                        retVal.Value = s.Value;
                    }
                    s.Read();
                }
            }

            // Validation is handled by the EN formatter
            string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;

            //base.Validate(retVal, pathName, result);

            return(retVal);
        }
Exemple #10
0
        /// <summary>
        /// Grap the object to a stream
        /// </summary>
        public void Graph(System.Xml.XmlWriter s, object o, DatatypeFormatterGraphResult result)
        {
            ENXP instance = o as ENXP;

            // Start with part type and code attributes
            ANYFormatter baseFormatter = new ANYFormatter();

            baseFormatter.Graph(s, o, result);

            IResultDetail[] partTypeDetails = new IResultDetail[0];

            if (instance.NullFlavor != null)
            {
                return;
            }

            // Now format our data
            if (instance.Type != null && result.CompatibilityMode != DatatypeFormatterCompatibilityMode.ClinicalDocumentArchitecture)
            {
                s.WriteAttributeString("partType", Util.ToWireFormat(instance.Type));
            }
            if (instance.Qualifier != null && !instance.Qualifier.IsEmpty)
            {
                s.WriteAttributeString("qualifier", Util.ToWireFormat(instance.Qualifier));
            }
            if (instance.Code != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "Code", "ADXP", s.ToString()));
            }
            //s.WriteAttributeString("code", instance.Code);
            if (instance.Value != null)
            {
                s.WriteValue(instance.Value);
            }
            if (instance.CodeSystem != null) // Warn if there is no way to represent this in R1
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "CodeSystem", "ENXP", s.ToString()));
            }
            if (instance.CodeSystemVersion != null)
            {
                result.AddResultDetail(new UnsupportedDatatypeR1PropertyResultDetail(ResultDetailType.Warning, "CodeSystemVersion", "ENXP", s.ToString()));
            }
        }
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse result data
            var retVal = new ENXP();

            // Parse the supported data
            if (s.GetAttribute("nullFlavor") != null)
            {
                retVal.NullFlavor = Util.Convert <NullFlavor>(s.GetAttribute("nullFlavor"));
            }
            if (s.GetAttribute("value") != null)
            {
                retVal.Value = s.GetAttribute("value");
            }
            if (s.GetAttribute("code") != null)
            {
                retVal.Code = s.GetAttribute("code");
            }
            if (s.GetAttribute("codeSystem") != null)
            {
                retVal.CodeSystem = s.GetAttribute("codeSystem");
            }
            if (s.GetAttribute("codeSystemVersion") != null)
            {
                retVal.CodeSystemVersion = s.GetAttribute("codeSystemVersion");
            }
            if (s.GetAttribute("type") != null)
            {
                retVal.Type = Util.Convert <EntityNamePartType>(s.GetAttribute("type"));
            }
            if (s.GetAttribute("qualifier") != null)
            {
                retVal.Qualifier = Util.Convert <SET <CS <EntityNamePartQualifier> > >(s.GetAttribute("qualifier"));
            }
            if (s.GetAttribute("language") != null)
            {
                result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, "@language", null, s.ToString(), null));
            }

            // Return & validate
            new ANYFormatter().Validate(retVal, s.ToString(), result);
            return(retVal);
        }
Exemple #12
0
        /// <summary>
        /// Parse an ENXP from stream <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();

            // Parse CS
            ENXP retVal = baseFormatter.Parse <ENXP>(s, result);

            // Part Type is ignored by this formatter but qualifier is not
            if (s.GetAttribute("qualifier") != null)
            {
                retVal.Qualifier = Util.Convert <SET <CS <EntityNamePartQualifier> > >(s.GetAttribute("qualifier"));
            }

            // Now parse our data out...
            if (!s.IsEmptyElement)
            {
                // Read next for text elemnt
                string sName = s.Name;
                s.Read();
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && sName == s.Name))
                {
                    if (s.NodeType == System.Xml.XmlNodeType.Text)
                    {
                        retVal.Value = s.Value;
                    }
                    s.Read();
                }
            }

            // Validate
            string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;

            baseFormatter.Validate(retVal, pathName, result);


            return(retVal);
        }
Exemple #13
0
        /// <summary>
        /// Parse the TN from the XmlReader <paramref name="s"/>.
        /// </summary>
        /// <param name="s">XmlReader stream to parse from.</param>
        /// <returns>Parsed TN.</returns>
        public override object Parse(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
        {
            TN tn = base.Parse<TN>(s, result);

            // Parse the mixed content and add it to the list.
            if (!s.IsEmptyElement)
            {
                string oldName = s.LocalName;
                ENXP tnPart = new ENXP("");
                while (s.Read() && s.NodeType != System.Xml.XmlNodeType.EndElement && s.LocalName != oldName)
                {
                    if (s.NodeType == System.Xml.XmlNodeType.Text || s.NodeType == System.Xml.XmlNodeType.CDATA)
                        tnPart.Value += s.Value;
                    else if (s.NodeType == System.Xml.XmlNodeType.Element)
                        result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning,
                            s.LocalName,
                            s.NamespaceURI,
                            s.ToString(), null));
                }
                tn.Part.Add(tnPart);
            }

            return tn;
        }
Exemple #14
0
 public void ENXPnullTest()
 {
     ENXP x = new ENXP();
     x.Value = null;
     x.Code = null;
     x.CodeSystem = null;
     x.CodeSystemVersion = null;
     x.NullFlavor = null;
     Assert.IsFalse(x.Validate());
 }
        private RequestResult <PatientModel> ParseResponse(HCIM_IN_GetDemographicsResponse1 reply)
        {
            using (Source.StartActivity("ParsePatientResponse"))
            {
                this.logger.LogDebug($"Parsing patient response... {JsonSerializer.Serialize(reply)}");

                // Verify that the reply contains a result
                string responseCode = reply.HCIM_IN_GetDemographicsResponse.controlActProcess.queryAck.queryResponseCode.code;
                if (!responseCode.Contains("BCHCIM.GD.0.0013", StringComparison.InvariantCulture))
                {
                    PatientModel emptyPatient = new PatientModel();
                    this.logger.LogWarning($"Client Registry did not return a person. Returned message code: {responseCode}");
                    this.logger.LogDebug($"Finished getting patient. {JsonSerializer.Serialize(emptyPatient)}");
                    return(new RequestResult <PatientModel>()
                    {
                        ResultStatus = ResultType.Error,
                        ResultError = new RequestResultError()
                        {
                            ResultMessage = "Client Registry did not return a person", ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationExternal, ServiceType.ClientRegistries)
                        },
                    });
                }

                HCIM_IN_GetDemographicsResponseIdentifiedPerson retrievedPerson = reply.HCIM_IN_GetDemographicsResponse.controlActProcess.subject[0].target;

                // If the deceased indicator is set and true, return an empty person.
                bool deceasedInd = retrievedPerson.identifiedPerson.deceasedInd?.value ?? false;
                if (deceasedInd)
                {
                    PatientModel emptyPatient = new PatientModel();
                    this.logger.LogWarning($"Client Registry returned a person with the deceasedIndicator set to true. No PHN was populated. {deceasedInd}");
                    this.logger.LogDebug($"Finished getting patient. {JsonSerializer.Serialize(emptyPatient)}");
                    return(new RequestResult <PatientModel>()
                    {
                        ResultStatus = ResultType.Error,
                        ResultError = new RequestResultError()
                        {
                            ResultMessage = "Client Registry returned a person with the deceasedIndicator set to true", ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationExternal, ServiceType.ClientRegistries)
                        },
                    });
                }

                PN?nameSection = retrievedPerson.identifiedPerson.name.Where(x => x.use.Any(u => u == cs_EntityNameUse.C)).FirstOrDefault();

                if (nameSection == null)
                {
                    this.logger.LogWarning($"Client Registry returned a person with an invalid name.");
                    return(new RequestResult <PatientModel>()
                    {
                        ResultStatus = ResultType.ActionRequired,
                        ResultError = ErrorTranslator.ActionRequired(ErrorMessages.InvalidServicesCard, ActionType.InvalidName),
                    });
                }

                // Extract the subject names
                List <string> givenNameList = new List <string>();
                List <string> lastNameList  = new List <string>();
                for (int i = 0; i < nameSection.Items.Length; i++)
                {
                    ENXP name = nameSection.Items[i];

                    if (name.GetType() == typeof(engiven) && (name.qualifier == null || !name.qualifier.Contains(cs_EntityNamePartQualifier.CL)))
                    {
                        givenNameList.Add(name.Text[0]);
                    }
                    else if (name.GetType() == typeof(enfamily) && (name.qualifier == null || !name.qualifier.Contains(cs_EntityNamePartQualifier.CL)))
                    {
                        lastNameList.Add(name.Text[0]);
                    }
                }

                string   delimiter  = " ";
                string   givenNames = givenNameList.Aggregate((i, j) => i + delimiter + j);
                string   lastNames  = lastNameList.Aggregate((i, j) => i + delimiter + j);
                string?  dobStr     = ((TS)retrievedPerson.identifiedPerson.birthTime).value; // yyyyMMdd
                DateTime dob        = DateTime.ParseExact(dobStr, "yyyyMMdd", CultureInfo.InvariantCulture);
                string   genderCode = retrievedPerson.identifiedPerson.administrativeGenderCode.code;
                string   gender     = "NotSpecified";
                if (genderCode == "F")
                {
                    gender = "Female";
                }
                else if (genderCode == "M")
                {
                    gender = "Male";
                }

                PatientModel patient = new PatientModel()
                {
                    FirstName = givenNames, LastName = lastNames, Birthdate = dob, Gender = gender, EmailAddress = string.Empty
                };

                II?    identifiedPersonId   = (II?)retrievedPerson.identifiedPerson.id.GetValue(0);
                string?personIdentifierType = identifiedPersonId?.root;
                string personIdentifier     = identifiedPersonId?.extension ?? string.Empty;
                if (personIdentifierType == OIDType.HDID.ToString())
                {
                    patient.HdId = personIdentifier;
                }
                else if (personIdentifierType == OIDType.PHN.ToString())
                {
                    patient.PersonalHealthNumber = personIdentifier;
                }
                else
                {
                    this.logger.LogWarning($"Client Registry returned a person with a person identifier not recognized. No PHN or HDID was populated.");
                    return(new RequestResult <PatientModel>()
                    {
                        ResultStatus = ResultType.ActionRequired,
                        ResultError = ErrorTranslator.ActionRequired(ErrorMessages.InvalidServicesCard, ActionType.NoHdId),
                    });
                }

                II?    subjectId             = (II?)retrievedPerson.id.GetValue(0);
                string?subjectIdentifierType = subjectId?.root;
                string subjectIdentifier     = subjectId?.extension ?? string.Empty;
                if (subjectIdentifierType == OIDType.HDID.ToString())
                {
                    patient.HdId = subjectIdentifier;
                }
                else if (personIdentifierType == OIDType.PHN.ToString())
                {
                    patient.PersonalHealthNumber = subjectIdentifier;
                }
                else
                {
                    this.logger.LogWarning($"Client Registry returned a person with a subject identifier not recognized. No PHN or HDID was populated.");
                    return(new RequestResult <PatientModel>()
                    {
                        ResultStatus = ResultType.ActionRequired,
                        ResultError = ErrorTranslator.ActionRequired(ErrorMessages.InvalidServicesCard, ActionType.NoHdId),
                    });
                }

                return(new RequestResult <PatientModel>()
                {
                    ResultStatus = ResultType.Success,
                    ResourcePayload = patient,
                });
            }
        }
Exemple #16
0
 public void PNInvalidQualifierTest()
 {
     PN pn = new PN();
     ENXP enxp = new ENXP();
     enxp.Value = "Andria";
     enxp.Qualifier = new SET<CS<EntityNamePartQualifier>>(EntityNamePartQualifier.LegalStatus);
     pn.Part.Add(enxp);
     pn.NullFlavor = null;
     Assert.IsFalse(pn.Validate());
 }
Exemple #17
0
 public void PNNullQualifierTest()
 {
     PN pn = new PN();
     ENXP enxp = new ENXP();
     enxp.Value = "Andria";
     enxp.Qualifier = null;
     pn.Part.Add(enxp);
     pn.NullFlavor = null;
     Assert.IsTrue(pn.Validate());
 }
Exemple #18
0
public void ENXPValueNullFlavorTest()
{
    ENXP x = new ENXP();
    x.Value = "Andria";
    x.Code = null;
    x.CodeSystem = null;
    x.CodeSystemVersion = null;
    x.NullFlavor = NullFlavor.NotAsked;
    Assert.IsFalse(x.Validate());
}
Exemple #19
0
 public void PNValidQualifierTest()
 {
     PN pn = new PN();
     ENXP enxp = new ENXP();
     enxp.Value = "Andria";
     enxp.Qualifier = new SET<CS<EntityNamePartQualifier>>(EntityNamePartQualifier.Nobility);
     pn.Part.Add(enxp);
     pn.NullFlavor = null;
     Assert.IsTrue(pn.Validate());
 }
Exemple #20
0
 public void ENXPCastToStringTest()
 {
     string enxpString = new ENXP("Test");
     Assert.AreEqual("Test", enxpString);
 }
Exemple #21
0
 public void ENXPValueCodeCodeSystemTest()
 {
     ENXP x = new ENXP();
     x.Value = "Andria";
     x.Code = "here";
     x.CodeSystem = "there";
     x.CodeSystemVersion = null;
     x.NullFlavor = null;
     Assert.IsTrue(x.Validate());
 }
Exemple #22
0
        /// <summary>
        /// Gets the patient record.
        /// </summary>
        /// <param name="hdid">The patient id.</param>
        /// <returns>The patient model.</returns>
        public async System.Threading.Tasks.Task <RequestResult <Patient> > GetPatient(string hdid)
        {
            Stopwatch timer = new Stopwatch();

            timer.Start();
            this.logger.LogTrace($"Getting patient... {hdid}");
            Patient patient;

            // Create request
            HCIM_IN_GetDemographicsRequest request = this.CreateRequest(hdid);

            // Perform the request
            try
            {
                HCIM_IN_GetDemographicsResponse1 reply = await this.clientRegistriesDelegate.GetDemographicsAsync(request).ConfigureAwait(true);

                // Verify that the reply contains a result
                string responseCode = reply.HCIM_IN_GetDemographicsResponse.controlActProcess.queryAck.queryResponseCode.code;
                if (!responseCode.Contains("BCHCIM.GD.0.0013", StringComparison.InvariantCulture))
                {
                    patient = new Patient();
                    this.logger.LogWarning($"Client Registry did not return a person. Returned message code: {responseCode}");
                    this.logger.LogDebug($"Finished getting patient. {JsonSerializer.Serialize(patient)}");
                    return(new RequestResult <Patient>()
                    {
                        ResultStatus = ResultType.Error,
                        ResultError = new RequestResultError()
                        {
                            ResultMessage = "Client Registry did not return a person", ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationExternal, ServiceType.ClientRegistries)
                        },
                    });
                }

                HCIM_IN_GetDemographicsResponseIdentifiedPerson retrievedPerson = reply.HCIM_IN_GetDemographicsResponse.controlActProcess.subject[0].target;

                // If the deceased indicator is set and true, return an empty person.
                bool deceasedInd = retrievedPerson.identifiedPerson.deceasedInd?.value == true;
                if (deceasedInd)
                {
                    patient = new Patient();
                    this.logger.LogWarning($"Client Registry returned a person with the deceasedIndicator set to true. No PHN was populated. {deceasedInd}");
                    this.logger.LogDebug($"Finished getting patient. {JsonSerializer.Serialize(patient)}");
                    return(new RequestResult <Patient>()
                    {
                        ResultStatus = ResultType.Error,
                        ResultError = new RequestResultError()
                        {
                            ResultMessage = "Client Registry returned a person with the deceasedIndicator set to true", ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationExternal, ServiceType.ClientRegistries)
                        },
                    });
                }

                // Extract the subject names
                List <string> givenNameList = new List <string>();
                List <string> lastNameList  = new List <string>();
                for (int i = 0; i < retrievedPerson.identifiedPerson.name[0].Items.Length; i++)
                {
                    ENXP name = retrievedPerson.identifiedPerson.name[0].Items[i];

                    if (name.GetType() == typeof(engiven))
                    {
                        givenNameList.Add(name.Text[0]);
                    }
                    else if (name.GetType() == typeof(enfamily))
                    {
                        lastNameList.Add(name.Text[0]);
                    }
                }

                string   delimiter  = " ";
                string   givenNames = givenNameList.Aggregate((i, j) => i + delimiter + j);
                string   lastNames  = lastNameList.Aggregate((i, j) => i + delimiter + j);
                string   phn        = ((II)retrievedPerson.identifiedPerson.id.GetValue(0) !).extension;
                string?  dobStr     = ((TS)retrievedPerson.identifiedPerson.birthTime).value; // yyyyMMdd
                DateTime dob        = DateTime.ParseExact(dobStr, "yyyyMMdd", CultureInfo.InvariantCulture);
                patient = new Patient(hdid, phn, givenNames, lastNames, dob, string.Empty);

                timer.Stop();
                this.logger.LogDebug($"Finished getting patient. {JsonSerializer.Serialize(patient)} Time Elapsed: {timer.Elapsed}");
                return(new RequestResult <Patient>()
                {
                    ResultStatus = ResultType.Success,
                    ResourcePayload = patient,
                });
            }
            catch (CommunicationException e)
            {
                this.logger.LogError(e.ToString());
                return(new RequestResult <Patient>()
                {
                    ResultStatus = ResultType.Error,
                    ResultError = new RequestResultError()
                    {
                        ResultMessage = "Communication Exception when trying to retrieve the PHN", ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationExternal, ServiceType.ClientRegistries)
                    },
                });
            }
        }
        protected T Parse <T>(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
            where T : EN, new()
        {
            // Parse the address parts
            // Parse base (ANY) from the stream

            // Parse EN
            T retVal = base.Parse <T>(s, result);

            // Now parse our data out... Attributes
            if (s.GetAttribute("use") != null)
            {
                retVal.Use = (SET <CS <EntityNameUse> >)Util.FromWireFormat(s.GetAttribute("use"), typeof(SET <CS <EntityNameUse> >));
            }

            // Loop through content
            // Elements
            #region Elements
            if (!s.IsEmptyElement)
            {
                int    sDepth = s.Depth;
                string sName  = s.Name;

                s.Read();
                // string Name
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        EntityNamePartType?enxpType;                               // entity part type

                        if (reverseMapping.TryGetValue(s.LocalName, out enxpType)) // Reverse map exists, so this is a part
                        {
                            ENXPFormatter adxpFormatter = new ENXPFormatter();     // ENXP Formatter
                            adxpFormatter.Host = this.Host;
                            ENXP part = (ENXP)adxpFormatter.Parse(s, result);      // Parse
                            if (!part.Type.HasValue)
                            {
                                part.Type = enxpType;
                            }
                            base.Validate(part, s.ToString(), result);
                            retVal.Part.Add(part); // Add to EN
                        }
                        else if (s.LocalName == "validTime")
                        {
                            // Bug 2102 : Process valid time
                            var hostResult = this.Host.Parse(s, typeof(IVL <TS>));
                            result.AddResultDetail(hostResult.Details);
                            var ivlValid = hostResult.Structure as IVL <TS>;
                            if (ivlValid != null)
                            {
                                retVal.ValidTimeHigh = ivlValid.High;
                                retVal.ValidTimeLow  = ivlValid.Low;
                            }
                            else if (hostResult.Structure != null)
                            {
                                result.AddResultDetail(new NotImplementedResultDetail(
                                                           ResultDetailType.Warning,
                                                           String.Format("Cannot process type '{0}' for 'validTime' element", Util.CreateXSITypeName(hostResult.Structure.GetType())), s.ToString()));
                            }
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Text ||
                                 s.NodeType == System.Xml.XmlNodeType.CDATA)
                        {
                            retVal.Part.Add(new ENXP(s.Value));
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning,
                                                                                         s.LocalName,
                                                                                         s.NamespaceURI,
                                                                                         s.ToString(), null));
                        }
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e)); // Append details
                    }
                    finally
                    {
                        if (oldName == s.Name)
                        {
                            s.Read();                    // Read if we need to
                        }
                    }
                }
            }
            #endregion

            // Validate
            string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
            base.Validate(retVal, pathName, result);

            return(retVal);
        }
Exemple #24
0
        public void ENXPCastToStringTest()
        {
            string enxpString = new ENXP("Test");

            Assert.AreEqual("Test", enxpString);
        }
        public T Parse <T>(System.Xml.XmlReader s, DatatypeFormatterParseResult result)
            where T : EN, new()
        {
            // Parse the address parts
            // Parse base (ANY) from the stream
            ANYFormatter baseFormatter = new ANYFormatter();

            // Parse EN
            T retVal = baseFormatter.Parse <T>(s, result);

            // Now parse our data out... Attributes
            if (s.GetAttribute("use") != null)
            {
                retVal.Use = (SET <CS <EntityNameUse> >)Util.FromWireFormat(s.GetAttribute("use"), typeof(SET <CS <EntityNameUse> >));
            }

            // Loop through content
            // Elements
            #region Elements
            if (!s.IsEmptyElement)
            {
                int    sDepth = s.Depth;
                string sName  = s.Name;

                s.Read();
                // string Name
                while (!(s.NodeType == System.Xml.XmlNodeType.EndElement && s.Depth == sDepth && s.Name == sName))
                {
                    string oldName = s.Name; // Name
                    try
                    {
                        EntityNamePartType?enxpType;                               // entity part type

                        if (reverseMapping.TryGetValue(s.LocalName, out enxpType)) // Reverse map exists, so this is a part
                        {
                            ENXPFormatter adxpFormatter = new ENXPFormatter();     // ENXP Formatter
                            adxpFormatter.Host = this.Host;
                            ENXP part = (ENXP)adxpFormatter.Parse(s, result);      // Parse
                            part.Type = enxpType;
                            retVal.Part.Add(part);                                 // Add to EN
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Text ||
                                 s.NodeType == System.Xml.XmlNodeType.CDATA)
                        {
                            retVal.Part.Add(new ENXP(s.Value));
                        }
                        else if (s.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning,
                                                                                         s.LocalName,
                                                                                         s.NamespaceURI,
                                                                                         s.ToString(), null));
                        }
                    }
                    catch (MessageValidationException e)
                    {
                        result.AddResultDetail(new ResultDetail(ResultDetailType.Error, e.Message, s.ToString(), e)); // Append details
                    }
                    finally
                    {
                        if (oldName == s.Name)
                        {
                            s.Read();                    // Read if we need to
                        }
                    }
                }
            }
            #endregion

            // Validate
            string pathName = s is XmlStateReader ? (s as XmlStateReader).CurrentPath : s.Name;
            baseFormatter.Validate(retVal, pathName, result);

            return(retVal);
        }
Exemple #26
0
        /// <summary>
        /// Parse an object from <paramref name="s"/>
        /// </summary>
        public object Parse(System.Xml.XmlReader s, DatatypeR2FormatterParseResult result)
        {
            // Parse result data
            var retVal = new ENXP();

            // Parse the supported data
            if (s.GetAttribute("nullFlavor") != null)
                retVal.NullFlavor = Util.Convert<NullFlavor>(s.GetAttribute("nullFlavor"));
            if (s.GetAttribute("value") != null)
                retVal.Value = s.GetAttribute("value");
            if (s.GetAttribute("code") != null)
                retVal.Code = s.GetAttribute("code");
            if (s.GetAttribute("codeSystem") != null)
                retVal.CodeSystem = s.GetAttribute("codeSystem");
            if (s.GetAttribute("codeSystemVersion") != null)
                retVal.CodeSystemVersion = s.GetAttribute("codeSystemVersion");
            if (s.GetAttribute("type") != null)
                retVal.Type = Util.Convert<EntityNamePartType>(s.GetAttribute("type"));
            if (s.GetAttribute("qualifier") != null)
                retVal.Qualifier = Util.Convert<SET<CS<EntityNamePartQualifier>>>(s.GetAttribute("qualifier"));
            if (s.GetAttribute("language") != null)
                result.AddResultDetail(new NotImplementedElementResultDetail(ResultDetailType.Warning, "@language", null, s.ToString(), null));

            // Return & validate
            new ANYFormatter().Validate(retVal, s.ToString(), result);
            return retVal;
        }