Ejemplo n.º 1
0
        /// <summary>
        /// Construct the appropriate subclass of BaseMessage based on a FHIR Bundle.
        /// Clients can use the typeof operator to determine the type of message object returned.
        /// </summary>
        /// <param name="bundle">A FHIR Bundle</param>
        /// <returns>The message object of the appropriate message type</returns>
        public static BaseMessage Parse(Bundle bundle)
        {
            BaseMessage message = new BaseMessage(bundle, true, false);

            switch (message.MessageType)
            {
            case "http://nchs.cdc.gov/vrdr_submission":
                message = new DeathRecordSubmission(bundle, message);
                break;

            case "http://nchs.cdc.gov/vrdr_submission_update":
                message = new DeathRecordUpdate(bundle, message);
                break;

            case "http://nchs.cdc.gov/vrdr_acknowledgement":
                message = new AckMessage(bundle);
                break;

            case "http://nchs.cdc.gov/vrdr_submission_void":
                message = new VoidMessage(bundle);
                break;

            case "http://nchs.cdc.gov/vrdr_coding":
                message = new CodingResponseMessage(bundle);
                break;

            case "http://nchs.cdc.gov/vrdr_coding_update":
                message = new CodingUpdateMessage(bundle);
                break;

            case "http://nchs.cdc.gov/vrdr_extraction_error":
                message = new ExtractionErrorMessage(bundle, message);
                break;

            default:
                string errorText;
                if (message.Header == null)
                {
                    errorText = "Failed to find a Bundle Entry containing a Resource of type MessageHeader";
                }
                else if (message.MessageType == null)
                {
                    errorText = "Message type was missing from MessageHeader";
                }
                else
                {
                    errorText = $"Unsupported message type: {message.MessageType}";
                }
                throw new MessageParseException(errorText, message);
            }
            return(message);
        }
Ejemplo n.º 2
0
        public void CreateCodingUpdateFromJSON()
        {
            CodingUpdateMessage message = BaseMessage.Parse <CodingUpdateMessage>(FixtureStream("fixtures/json/CodingUpdateMessage.json"));

            Assert.Equal("http://nchs.cdc.gov/vrdr_coding_update", message.MessageType);
            Assert.Equal("destination", message.MessageDestination);
            Assert.Equal((uint)1, message.CertificateNumber);
            Assert.Equal((uint)2018, message.DeathYear);
            Assert.Equal("42", message.StateAuxiliaryIdentifier);
            Assert.Equal("2018MA000001", message.NCHSIdentifier);
            var ethnicity = message.Ethnicity;

            Assert.Equal(2, ethnicity.Count);
            Assert.True(ethnicity.ContainsKey(CodingResponseMessage.HispanicOrigin.DETHNICE));
            Assert.Equal("123", ethnicity.GetValueOrDefault(CodingResponseMessage.HispanicOrigin.DETHNICE, "foo"));
            Assert.True(ethnicity.ContainsKey(CodingResponseMessage.HispanicOrigin.DETHNIC5C));
            Assert.Equal("456", ethnicity.GetValueOrDefault(CodingResponseMessage.HispanicOrigin.DETHNIC5C, "foo"));
            var race = message.Race;

            Assert.Equal(3, race.Count);
            Assert.True(race.ContainsKey(CodingResponseMessage.RaceCode.RACE1E));
            Assert.Equal("foo", race.GetValueOrDefault(CodingResponseMessage.RaceCode.RACE1E, "yyz"));
            Assert.True(race.ContainsKey(CodingResponseMessage.RaceCode.RACE17C));
            Assert.Equal("bar", race.GetValueOrDefault(CodingResponseMessage.RaceCode.RACE17C, "yyz"));
            Assert.True(race.ContainsKey(CodingResponseMessage.RaceCode.RACEBRG));
            Assert.Equal("baz", race.GetValueOrDefault(CodingResponseMessage.RaceCode.RACEBRG, "yyz"));
            Assert.Equal("A04.7", message.UnderlyingCauseOfDeath);
            var recordAxisCodes = message.CauseOfDeathRecordAxis;

            Assert.Equal(4, recordAxisCodes.Count);
            Assert.Equal("A04.7", recordAxisCodes[0]);
            Assert.Equal("A41.9", recordAxisCodes[1]);
            Assert.Equal("J18.9", recordAxisCodes[2]);
            Assert.Equal("J96.0", recordAxisCodes[3]);
            var entityAxisEntries = message.CauseOfDeathEntityAxis;

            Assert.Equal(2, (int)entityAxisEntries.Count);
            Assert.Equal("1", entityAxisEntries[0].LineNumber);
            Assert.Equal(2, (int)entityAxisEntries[0].AssignedCodes.Count);
            Assert.Equal("code1_1", entityAxisEntries[0].AssignedCodes[0]);
            Assert.Equal("code1_2", entityAxisEntries[0].AssignedCodes[1]);
            Assert.Equal("2", entityAxisEntries[1].LineNumber);
            Assert.Equal(1, (int)entityAxisEntries[1].AssignedCodes.Count);
            Assert.Equal("code2_1", entityAxisEntries[1].AssignedCodes[0]);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Parse an XML or JSON serialization of a FHIR Bundle and construct the appropriate subclass of
        /// BaseMessage. Clients can use the typeof operator to determine the type of message object returned.
        /// </summary>
        /// <param name="source">the XML or JSON serialization of a FHIR Bundle</param>
        /// <param name="permissive">if the parser should be permissive when parsing the given string</param>
        /// <returns>The deserialized message object</returns>
        public static BaseMessage Parse(string source, bool permissive = false)
        {
            Bundle bundle = null;

            if (!String.IsNullOrEmpty(source) && source.TrimStart().StartsWith("<"))
            {
                bundle = ParseXML(source, permissive);
            }
            else if (!String.IsNullOrEmpty(source) && source.TrimStart().StartsWith("{"))
            {
                bundle = ParseJSON(source, permissive);
            }
            else
            {
                throw new System.ArgumentException("The given input does not appear to be a valid XML or JSON FHIR message.");
            }

            BaseMessage message = new BaseMessage(bundle, true, false);

            switch (message.MessageType)
            {
            case "http://nchs.cdc.gov/vrdr_submission":
                message = new DeathRecordSubmission(bundle, message);
                break;

            case "http://nchs.cdc.gov/vrdr_submission_update":
                message = new DeathRecordUpdate(bundle, message);
                break;

            case "http://nchs.cdc.gov/vrdr_acknowledgement":
                message = new AckMessage(bundle);
                break;

            case "http://nchs.cdc.gov/vrdr_submission_void":
                message = new VoidMessage(bundle);
                break;

            case "http://nchs.cdc.gov/vrdr_coding":
                message = new CodingResponseMessage(bundle);
                break;

            case "http://nchs.cdc.gov/vrdr_coding_update":
                message = new CodingUpdateMessage(bundle);
                break;

            case "http://nchs.cdc.gov/vrdr_extraction_error":
                message = new ExtractionErrorMessage(bundle, message);
                break;

            default:
                string errorText;
                if (message.Header == null)
                {
                    errorText = "Failed to find a Bundle Entry containing a Resource of type MessageHeader";
                }
                else if (message.MessageType == null)
                {
                    errorText = "Message type was missing from MessageHeader";
                }
                else
                {
                    errorText = $"Unsupported message type: {message.MessageType}";
                }
                throw new MessageParseException(errorText, message);
            }
            return(message);
        }
Ejemplo n.º 4
0
        public void CreateCodingUpdate()
        {
            CodingUpdateMessage message = new CodingUpdateMessage("destination", "http://nchs.cdc.gov/vrdr_submission");

            Assert.Equal("http://nchs.cdc.gov/vrdr_coding_update", message.MessageType);
            Assert.Equal("destination", message.MessageDestination);

            Assert.Null(message.CertificateNumber);
            message.CertificateNumber = 10;
            Assert.Equal((uint)10, message.CertificateNumber);

            Assert.Null(message.StateAuxiliaryIdentifier);
            message.StateAuxiliaryIdentifier = "id101010";
            Assert.Equal("id101010", message.StateAuxiliaryIdentifier);

            Assert.Null(message.DeathYear);
            message.DeathYear = 2019;
            Assert.Equal((uint)2019, message.DeathYear);

            Assert.Null(message.DeathJurisdictionID);
            message.DeathJurisdictionID = "NH";
            Assert.Equal("NH", message.DeathJurisdictionID);
            Assert.Equal("2019NH000010", message.NCHSIdentifier);

            Assert.Empty(message.Ethnicity);
            var ethnicity = new Dictionary <CodingResponseMessage.HispanicOrigin, string>();

            ethnicity.Add(CodingResponseMessage.HispanicOrigin.DETHNICE, "123");
            ethnicity.Add(CodingResponseMessage.HispanicOrigin.DETHNIC5C, "456");
            message.Ethnicity = ethnicity;
            ethnicity         = message.Ethnicity;
            Assert.Equal(2, ethnicity.Count);
            Assert.True(ethnicity.ContainsKey(CodingResponseMessage.HispanicOrigin.DETHNICE));
            Assert.Equal("123", ethnicity.GetValueOrDefault(CodingResponseMessage.HispanicOrigin.DETHNICE, "foo"));
            Assert.True(ethnicity.ContainsKey(CodingResponseMessage.HispanicOrigin.DETHNIC5C));
            Assert.Equal("456", ethnicity.GetValueOrDefault(CodingResponseMessage.HispanicOrigin.DETHNIC5C, "foo"));

            Assert.Empty(message.Race);
            var race = new Dictionary <CodingResponseMessage.RaceCode, string>();

            race.Add(CodingResponseMessage.RaceCode.RACE1E, "foo");
            race.Add(CodingResponseMessage.RaceCode.RACE17C, "bar");
            race.Add(CodingResponseMessage.RaceCode.RACEBRG, "baz");
            message.Race = race;
            race         = message.Race;
            Assert.Equal(3, race.Count);
            Assert.True(race.ContainsKey(CodingResponseMessage.RaceCode.RACE1E));
            Assert.Equal("foo", race.GetValueOrDefault(CodingResponseMessage.RaceCode.RACE1E, "yyz"));
            Assert.True(race.ContainsKey(CodingResponseMessage.RaceCode.RACE17C));
            Assert.Equal("bar", race.GetValueOrDefault(CodingResponseMessage.RaceCode.RACE17C, "yyz"));
            Assert.True(race.ContainsKey(CodingResponseMessage.RaceCode.RACEBRG));
            Assert.Equal("baz", race.GetValueOrDefault(CodingResponseMessage.RaceCode.RACEBRG, "yyz"));

            Assert.Null(message.UnderlyingCauseOfDeath);
            message.UnderlyingCauseOfDeath = "A04.7";
            Assert.Equal("A04.7", message.UnderlyingCauseOfDeath);

            Assert.Empty(message.CauseOfDeathRecordAxis);
            var recordAxisCodes = new List <string>();

            recordAxisCodes.Add("A04.7");
            recordAxisCodes.Add("A41.9");
            recordAxisCodes.Add("J18.9");
            recordAxisCodes.Add("J96.0");
            message.CauseOfDeathRecordAxis = recordAxisCodes;
            recordAxisCodes = message.CauseOfDeathRecordAxis;
            Assert.Equal(4, recordAxisCodes.Count);
            Assert.Equal("A04.7", recordAxisCodes[0]);
            Assert.Equal("A41.9", recordAxisCodes[1]);
            Assert.Equal("J18.9", recordAxisCodes[2]);
            Assert.Equal("J96.0", recordAxisCodes[3]);

            Assert.Empty(message.CauseOfDeathEntityAxis);
            var entityAxisEntries = new List <CauseOfDeathEntityAxisEntry>();
            var entry1            = new CauseOfDeathEntityAxisEntry("1");

            entry1.AssignedCodes.Add("code1_1");
            entry1.AssignedCodes.Add("code1_2");
            entityAxisEntries.Add(entry1);
            var entry2 = new CauseOfDeathEntityAxisEntry("2");

            entry2.AssignedCodes.Add("code2_1");
            entityAxisEntries.Add(entry2);
            message.CauseOfDeathEntityAxis = entityAxisEntries;
            entityAxisEntries = message.CauseOfDeathEntityAxis;
            Assert.Equal(2, (int)entityAxisEntries.Count);
            Assert.Equal("1", entityAxisEntries[0].LineNumber);
            Assert.Equal(2, (int)entityAxisEntries[0].AssignedCodes.Count);
            Assert.Equal("code1_1", entityAxisEntries[0].AssignedCodes[0]);
            Assert.Equal("code1_2", entityAxisEntries[0].AssignedCodes[1]);
            Assert.Equal("2", entityAxisEntries[1].LineNumber);
            Assert.Equal(1, (int)entityAxisEntries[1].AssignedCodes.Count);
            Assert.Equal("code2_1", entityAxisEntries[1].AssignedCodes[0]);
        }