Esempio n. 1
0
        public string Convert(string content, FhirMimeType fhirMimeType)
        {
            var baseFromObject = FromSerializer.Parse(content);
            var baseToObject   = _converter.Convert <Base, Base>(baseFromObject.Resource);

            return(ToSerializer.Serialize(baseToObject, fhirMimeType));
        }
        private ValueSet ConvertValueSetFromR4ToR3(string path)
        {
            string data;

            using (TextReader reader = new StreamReader(path))
                data = reader.ReadToEnd();

            R4Model.ValueSet valueSet = null;
            if (SerializationUtil.ProbeIsXml(data))
            {
                valueSet = _r4XmlParser.Parse <R4Model.ValueSet>(data);
            }
            else if (SerializationUtil.ProbeIsJson(data))
            {
                valueSet = _r4JsonParser.Parse <R4Model.ValueSet>(data);
            }
            else
            {
                Assert.True(false, $"File '{path}' does not contain valid Xml or Json");
            }

            if (valueSet == null)
            {
                return(null);
            }

            FhirConverter converter = new FhirConverter(FhirVersion.R3, FhirVersion.R4);

            return(converter.Convert <ValueSet, R4Model.ValueSet>(valueSet));
        }
Esempio n. 3
0
        public void Can_ConvertElement_R3_Instant_To_R4_Instant()
        {
            var value            = DateTimeOffset.UtcNow;
            var r3TypeInstance   = new Instant(value);
            var r3ToR4Conversion = new FhirConverter(FhirVersion.R4, FhirVersion.R3);
            var r4TypeInstance   = r3ToR4Conversion.Convert <Instant, Instant>(r3TypeInstance);

            Assert.NotNull(r4TypeInstance);
            Assert.Equal(value, r4TypeInstance.Value);
        }
        public void CreateGenereltBlodTrykk()
        {
            string path = Path.Combine(".", "TestData", "Generelt blodtrykk", "questionnaire-Blodtrykk-R4.xml");
            string xml;

            using (TextReader reader = new StreamReader(path))
                xml = reader.ReadToEnd();
            R4Model.Questionnaire r4Questionnaire = _r4XmlParser.Parse <R4Model.Questionnaire>(xml);

            FhirConverter converter     = new FhirConverter(FhirVersion.R3, FhirVersion.R4);
            Questionnaire questionnaire = converter.Convert <Questionnaire, R4Model.Questionnaire>(r4Questionnaire);

            questionnaire.SerializeResourceToDiskAsXml("questionnaire-Blodtrykk-R3.xml", FhirVersion.R3);
            questionnaire.SerializeResourceToDiskAsJson("questionnaire-Blodtrykk-R3.json", FhirVersion.R3);
        }
Esempio n. 5
0
        //[InlineData(@"TestData\account.profile-r4.json")]
        //[InlineData(@"TestData\activitydefinition.profile-r4.json")]
        //[InlineData(@"TestData\adverseevent.profile-r4.json")]
        //[InlineData(@"TestData\allergyintolerance.profile-r4.json")]
        //[InlineData(@"TestData\appointment.profile-r4.json")]
        //[InlineData(@"TestData\appointmentresponse.profile-r4.json")]
        //[InlineData(@"TestData\consent.profile-r4.json")]
        public async Task CanConvert_Questionnaire_FromR4ToR3_RoundTrip(string path)
        {
            var converterFromR4ToR3 = new FhirConverter(to: FhirVersion.R3, from: FhirVersion.R4);
            var converterFromR3ToR4 = new FhirConverter(to: FhirVersion.R4, from: FhirVersion.R3);

            var r4Serializer = new SerializationWrapper(FhirVersion.R4);
            var r4Resource   = r4Serializer.Parse(await File.ReadAllTextAsync(path));

            var r3Resource          = converterFromR4ToR3.Convert <Resource, Resource>(r4Resource.Resource);
            var r4ResourceRoundTrip = converterFromR3ToR4.Convert <Resource, Resource>(r3Resource);

            var r4ResourceContent          = r4Serializer.Serialize(r4Resource);
            var r4ResourceRoundTripContent = r4Serializer.Serialize(r4ResourceRoundTrip);

            Assert.Equal(r4ResourceContent, r4ResourceRoundTripContent);
        }
        public void CanR4ResourceConvertToR3()
        {
            // questionnaire-Bloodpressure-R4.xml
            string path = Path.Combine(".", "TestData", "questionnaire-Bloodpressure-R4.xml");
            string xml;

            using (TextReader reader = new StreamReader(path))
                xml = reader.ReadToEnd();
            R4Model.Questionnaire r4Questionnaire = _r4XmlParser.Parse <R4Model.Questionnaire>(xml);

            FhirConverter converter     = new FhirConverter(FhirVersion.R3, FhirVersion.R4);
            Questionnaire questionnaire = converter.Convert <Questionnaire, R4Model.Questionnaire>(r4Questionnaire);

            // ValueSet-blood-pressure-v2-cuffsize-R4.xml
            ValueSet valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "ValueSet-blood-pressure-v2-cuffsize-R4.xml"));

            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            // ValueSet-blood-pressure-v2-diastolicendpoint-R4.xml
            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "ValueSet-blood-pressure-v2-diastolicendpoint-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            // ValueSet-blood-pressure-v2-locationofmeasurement-R4.xml
            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "ValueSet-blood-pressure-v2-locationofmeasurement-R4.xml"));
            using (TextReader reader = new StreamReader(path))
                xml = reader.ReadToEnd();
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            // ValueSet-blood-pressure-v2-method-R4.xml
            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "ValueSet-blood-pressure-v2-method-R4.xml"));
            using (TextReader reader = new StreamReader(path))
                xml = reader.ReadToEnd();
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            FixContainedValueSetReferences(questionnaire.Contained.FindAll(r => r.ResourceType(FhirVersion.R3) == ResourceTypeWrapper.ValueSet), questionnaire.Item);

            questionnaire.SerializeResourceToDiskAsXml("questionnaire-Bloodpressure-R3.xml", FhirVersion.R3);
            questionnaire.SerializeResourceToDiskAsJson("questionnaire-Bloodpressure-R3.json", FhirVersion.R3);
        }
        public void CreateCovid19PandemiRegister()
        {
            string path = Path.Combine(".", "TestData", "covid-19-pandemiregister", "questionnaire-Rapport-R4.xml");
            string xml;

            using (TextReader reader = new StreamReader(path))
                xml = reader.ReadToEnd();
            R4Model.Questionnaire r4Questionnaire = _r4XmlParser.Parse <R4Model.Questionnaire>(xml);

            FhirConverter converter     = new FhirConverter(FhirVersion.R3, FhirVersion.R4);
            Questionnaire questionnaire = converter.Convert <Questionnaire, R4Model.Questionnaire>(r4Questionnaire);

            ValueSet valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-_testname_en_-R4.xml"));

            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-agens_at0043-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-agens-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-analysenavn_at0024-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-analysenavn-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-bildediagnostiskdiagnose-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-eksponeringssituasjon_at0045-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-eksponeringssituasjon-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-erdetnoentilstandertilstede_-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-innenlands_utenlands-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-innleggelsefra-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-iverksatt__at0005-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-iverksatt_-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-legemiddelibruk__at0024-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-legemiddelibruk_-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-legemiddelklasseibruk_-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-legemiddelklasse-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-legemiddelnavn_at0021-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-legemiddelnavn-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-navnpaaktiviteten_at0004-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-navnpaaktiviteten-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-navnpatilstand_at0004-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-navnpatilstand-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-reise_-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-tilstede__at0005-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-tilstede_-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-tilstedeværelse_at0046-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            valueSet = ConvertValueSetFromR4ToR3(Path.Combine(".", "TestData", "covid-19-pandemiregister", "ValueSet-report-v1-tilstedeværelse-R4.xml"));
            valueSet = RemoveDesignation(valueSet);
            questionnaire.Contained.Add(valueSet);

            FixContainedValueSetReferences(questionnaire.Contained.FindAll(r => r.ResourceType(FhirVersion.R3) == ResourceTypeWrapper.ValueSet), questionnaire.Item);

            questionnaire.SerializeResourceToDiskAsXml($"questionnaire-Covid19-Pandemiregister.xml", FhirVersion.R3);
            questionnaire.SerializeResourceToDiskAsJson("questionnaire-Covid19-Pandemiregister.json", FhirVersion.R3);
        }