Example #1
0
        private ResourceEntry clone(ResourceEntry e)
        {
            ErrorList err  = new ErrorList();
            var       json = FhirSerializer.SerializeBundleEntryToJson(e);

            return((ResourceEntry)FhirParser.ParseBundleEntryFromJson(json, err));
        }
Example #2
0
        private BsonDocument entryToBsonDocument(BundleEntry entry)
        {
            try
            {
                var docJson = FhirSerializer.SerializeBundleEntryToJson(entry);
                var doc     = BsonDocument.Parse(docJson);

                doc[BSON_RECORDID_MEMBER]   = entry.Links.SelfLink.ToString();
                doc[BSON_ENTRY_TYPE_MEMBER] = getEntryTypeFromInstance(entry);
                doc[BSON_COLLECTION_MEMBER] = new ResourceIdentity(entry.Id).Collection;

                if (entry is ResourceEntry)
                {
                    doc[BSON_VERSIONDATE_MEMBER] = convertDateTimeOffsetToDateTime(((ResourceEntry)entry).LastUpdated);
                    //                doc[BSON_VERSIONDATE_MEMBER_ISO] = Util.FormatIsoDateTime(((ContentEntry)entry).LastUpdated.Value.ToUniversalTime());
                }
                if (entry is DeletedEntry)
                {
                    doc[BSON_VERSIONDATE_MEMBER] = convertDateTimeOffsetToDateTime(((DeletedEntry)entry).When);
                    //                doc[BSON_VERSIONDATE_MEMBER_ISO] = Util.FormatIsoDateTime(((DeletedEntry)entry).When.Value.ToUniversalTime());
                }

                return(doc);
            }
            catch
            {
                throw; // sorry. dit gedaan, omdat we de fout anders niet vinden in de serializer.
            }
        }
Example #3
0
        private static BsonDocument BundleEntryToBson(BundleEntry entry)
        {
            string       json     = FhirSerializer.SerializeBundleEntryToJson(entry);
            BsonDocument document = BsonDocument.Parse(json);

            AddMetaData(document, entry);
            return(document);
        }
Example #4
0
        public void ParseBundleResourceEntryJson()
        {
            var input  = testResourceEntryAsJson;
            var result = FhirParser.ParseBundleEntry(FhirParser.JsonReaderFromString(input));

            Assert.IsTrue(result is ResourceEntry <Patient>);
            Assert.IsNotNull(result);
            Assert.AreEqual(input, FhirSerializer.SerializeBundleEntryToJson(result));
        }
        public void SerializeBinaryEntryJson()
        {
            var re     = createTestBinaryEntry();
            var actual = FhirSerializer.SerializeBundleEntryToJson(re);

            File.WriteAllText("c:\\temp\\bentryE.json", testBinaryEntryAsJson);
            File.WriteAllText("c:\\temp\\bentryA.json", actual);

            Assert.AreEqual(testBinaryEntryAsJson, actual);
        }
        private static void checkSerDeser(BundleEntry be)
        {
            var errs = new ErrorList();

            FhirParser.ParseBundleEntryFromJson(FhirSerializer.SerializeBundleEntryToJson(be), errs);
            Assert.IsTrue(errs.Count == 0);

            FhirParser.ParseBundleEntryFromXml(FhirSerializer.SerializeBundleEntryToXml(be), errs);
            Assert.IsTrue(errs.Count == 0);
        }
Example #7
0
        public void ParseBundleDeletedEntryJson()
        {
            var input  = testDeletedEntryAsJson;
            var result = FhirParser.ParseBundleEntry(FhirParser.JsonReaderFromString(input));

            Assert.IsTrue(result is DeletedEntry);

            Assert.IsNotNull(result);
            Assert.AreEqual(input, FhirSerializer.SerializeBundleEntryToJson(result));
        }
Example #8
0
        public void SerializeResourceEntryJson()
        {
            var re     = createTestResourceEntry();
            var actual = FhirSerializer.SerializeBundleEntryToJson(re);

            File.WriteAllText(TempFileLocation + "rentryE.json", testResourceEntryAsJson);
            File.WriteAllText(TempFileLocation + "rentryA.json", actual);

            Assert.AreEqual(testResourceEntryAsJson, actual);
        }
        public void ParseBundleBinaryEntryJson()
        {
            ErrorList errors = new ErrorList();

            var input  = testBinaryEntryAsJson;
            var result = FhirParser.ParseBundleEntry(Util.JsonReaderFromString(input), errors);

            Assert.IsTrue(result is ResourceEntry <Binary>);

            Assert.IsNotNull(result);
            Assert.AreEqual(0, errors.Count, errors.Count > 0 ? errors.ToString() : null);

            Assert.AreEqual(input, FhirSerializer.SerializeBundleEntryToJson(result));
        }
Example #10
0
        public void Read()
        {
            FhirClient client = new FhirClient(testEndpoint);

            var loc = client.Read <Location>("1");

            Assert.IsNotNull(loc);
            Assert.AreEqual("Den Burg", loc.Resource.Address.City);

            string version = new ResourceLocation(loc.SelfLink).VersionId;

            Assert.AreEqual("1", version);

            string id = new ResourceLocation(loc.Id).Id;

            Assert.AreEqual("1", id);

            try
            {
                var random = client.Read <Location>("45qq54");
                Assert.Fail();
            }
            catch (FhirOperationException)
            {
                Assert.IsTrue(client.LastResponseDetails.Result == HttpStatusCode.NotFound);
            }

            var loc2 = client.VRead <Location>("1", version);

            Assert.IsNotNull(loc2);
            Assert.AreEqual(FhirSerializer.SerializeBundleEntryToJson(loc),
                            FhirSerializer.SerializeBundleEntryToJson(loc2));

            var loc3 = client.Fetch <Location>(loc.SelfLink);

            Assert.IsNotNull(loc3);
            Assert.AreEqual(FhirSerializer.SerializeBundleEntryToJson(loc),
                            FhirSerializer.SerializeBundleEntryToJson(loc3));
        }