public async void GivenDeviceWithPatientReferenceUnsupportedCharacters_WhenResolveResourceIdentitiesAsync_ThenNotSupportedExceptionThrown_Test()
        {
            var fhirClient      = Utilities.CreateMockFhirClient();
            var resourceService = Substitute.For <ResourceManagementService>();
            var device          = new Model.Device
            {
                Id      = "1",
                Patient = new Model.ResourceReference("Not a reference in the form of: /ResourceName/Identifier"),
            };

            var mg = Substitute.For <IMeasurementGroup>();

            mg.DeviceId.Returns("deviceId");

            resourceService.GetResourceByIdentityAsync <Model.Device>(Arg.Any <FhirClient>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(Task.FromResult(device));

            using (var idSrv = new R4DeviceAndPatientLookupIdentityService(fhirClient, resourceService))
            {
                var ex = await Assert.ThrowsAsync <FhirResourceNotFoundException>(async() => await idSrv.ResolveResourceIdentitiesAsync(mg));

                Assert.Equal(ResourceType.Patient, ex.FhirResourceType);
            }

            await resourceService.Received(1).GetResourceByIdentityAsync <Model.Device>(fhirClient, "deviceId", null);
        }
        public async void GivenValidDeviceIdentifier_WhenResolveResourceIdentitiesAsync_ThenDeviceAndPatientIdReturnedAndCreateNotInvoked_Test()
        {
            var fhirClient      = Substitute.For <IFhirClient>();
            var resourceService = Substitute.For <ResourceManagementService>();
            var device          = new Model.Device
            {
                Id      = "1",
                Patient = new Model.ResourceReference("Patient/123"),
            };

            var mg = Substitute.For <IMeasurementGroup>();

            mg.DeviceId.Returns("deviceId");

            resourceService.GetResourceByIdentityAsync <Model.Device>(Arg.Any <IFhirClient>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(Task.FromResult(device));

            using (var idSrv = new R4DeviceAndPatientCreateIdentityService(fhirClient, resourceService))
            {
                var ids = await idSrv.ResolveResourceIdentitiesAsync(mg);

                Assert.Equal("1", ids[ResourceType.Device]);
                Assert.Equal("123", ids[ResourceType.Patient]);
            }

            await resourceService.Received(1).GetResourceByIdentityAsync <Model.Device>(fhirClient, "deviceId", null);

            await resourceService.DidNotReceiveWithAnyArgs().EnsureResourceByIdentityAsync <Model.Device>(null, null, null, null);

            await resourceService.DidNotReceiveWithAnyArgs().EnsureResourceByIdentityAsync <Model.Patient>(null, null, null, null);
        }
        public async void GivenValidDeviceIdentifierWhenDefaultSystemSet_WhenResolveResourceIdentitiesAsync_ThenDeviceAndPatientIdReturned_Test()
        {
            var fhirClient      = Substitute.For <IFhirClient>();
            var resourceService = Substitute.For <ResourceManagementService>();
            var device          = new Model.Device
            {
                Id      = "1",
                Patient = new Model.ResourceReference("Patient/123"),
            };

            var mg = Substitute.For <IMeasurementGroup>();

            mg.DeviceId.Returns("deviceId");

            var options = new ResourceIdentityOptions
            {
                DefaultDeviceIdentifierSystem = "mySystem",
            };

            resourceService.GetResourceByIdentityAsync <Model.Device>(Arg.Any <IFhirClient>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(Task.FromResult(device));

            using (var idSrv = new R4DeviceAndPatientLookupIdentityService(fhirClient, resourceService))
            {
                idSrv.Initialize(options);
                var ids = await idSrv.ResolveResourceIdentitiesAsync(mg);

                Assert.Equal("1", ids[ResourceType.Device]);
                Assert.Equal("123", ids[ResourceType.Patient]);
            }

            await resourceService.Received(1).GetResourceByIdentityAsync <Model.Device>(fhirClient, "deviceId", "mySystem");
        }
Esempio n. 4
0
        public async void GivenNoEncounterIdentifier_WhenResolveResourceIdentitiesAsync_ThenResourceIdentityNotDefinedExceptionThrown_Test()
        {
            var fhirClient      = Substitute.For <IFhirClient>();
            var resourceService = Substitute.For <ResourceManagementService>();
            var device          = new Model.Device
            {
                Id      = "1",
                Patient = new Model.ResourceReference("Patient/123"),
            };

            var mg = Substitute.For <IMeasurementGroup>();

            mg.DeviceId.Returns("deviceId");
            mg.EncounterId.Returns((string)null);

            resourceService.GetResourceByIdentityAsync <Model.Device>(Arg.Any <IFhirClient>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(Task.FromResult(device));

            using (var idSrv = new R4DeviceAndPatientWithEncounterLookupIdentityService(fhirClient, resourceService))
            {
                var ex = await Assert.ThrowsAsync <ResourceIdentityNotDefinedException>(async() => await idSrv.ResolveResourceIdentitiesAsync(mg));

                Assert.Equal(ResourceType.Encounter, ex.FhirResourceType);
            }

            await resourceService.Received(1).GetResourceByIdentityAsync <Model.Device>(fhirClient, "deviceId", null);

            await resourceService.DidNotReceiveWithAnyArgs().GetResourceByIdentityAsync <Model.Encounter>(null, null, null);
        }
Esempio n. 5
0
        public void GivenDeviceWithInvalidPatientReference_GetId_ThenNullIsReturned_Test()
        {
            var device = new Model.Device
            {
                Id      = "1",
                Patient = new Model.ResourceReference("Not a reference in the form of: ResourceName/Identifier"),
            };

            var patientReference = device.Patient?.GetId <Model.Patient>();

            Assert.Null(patientReference);
        }
Esempio n. 6
0
        public void GivenDeviceWithPatientReferenceQueryParam_GetId_ThenNullIsReturned_Test()
        {
            var device = new Model.Device
            {
                Id      = "1",
                Patient = new Model.ResourceReference("Patient/123?_id=123"),
            };

            var patientReference = device.Patient?.GetId <Model.Patient>();

            Assert.Null(patientReference);
        }
Esempio n. 7
0
        public void GivenDeviceWithValidPatientReference_GetId_ThenReferenceIdentifierIsReturned_Test()
        {
            var device = new Model.Device
            {
                Id      = "1",
                Patient = new Model.ResourceReference("Patient/123"),
            };

            var patientIdentifier = device.Patient?.GetId <Model.Patient>();

            Assert.Equal("123", patientIdentifier);
        }
Esempio n. 8
0
        public async Task <HttpResponseMessage> Post()
        {
            HttpResponseMessage response = null;
            string raw = await Request.Content.ReadAsStringAsync();

            JObject obj = JObject.Parse(raw);

            Hl7.Fhir.Model.Device dev = new Hl7.Fhir.Model.Device();
            dev.Id = Guid.NewGuid().ToString();
            //stub in IOT Hub
            registryManager = RegistryManager.CreateFromConnectionString(connectionString);
            Device device = await AddDeviceAsync(dev.Id);

            if (device != null)
            {
                dev.Type            = new model.CodeableConcept("http://snomed.info/sct", "448703006", "Pulse oximeter (physical object)");
                dev.ManufactureDate = "2016-12-11";
                dev.ExpirationDate  = "2021-12-11";
                dev.Identifier      = new List <model.Identifier>();
                dev.Identifier.Add(new model.Identifier("http://fhiriothub/key", device.Authentication.SymmetricKey.PrimaryKey));
                dev.Patient      = new model.ResourceReference("Patient/" + obj.GetValue("id"));
                dev.Manufacturer = "Acme Medical Devices, Inc.";
                dev.LotNumber    = "29328-992";
                dev.Model        = "SuperDeluxePulseOx";
                if (_client.SaveResource(dev))
                {
                    string respval = "{\"devid\":\"" + dev.Id + "\"}";
                    response         = this.Request.CreateResponse(HttpStatusCode.OK);
                    response.Content = new StringContent(respval, Encoding.UTF8, "application/json");
                }
                else
                {
                    response         = this.Request.CreateResponse(HttpStatusCode.InternalServerError);
                    response.Content = new StringContent("{\"message\":\"Error creating device\"", Encoding.UTF8, "application/json");
                }
            }
            else
            {
                response         = this.Request.CreateResponse(HttpStatusCode.InternalServerError);
                response.Content = new StringContent("{\"message\":\"Error registering device with IOT hub\"", Encoding.UTF8, "application/json");
            }


            return(response);
        }
        public async void GivenDeviceNotFoundExceptionWithDeviceSystemSet_WhenResolveResourceIdentitiesAsync_ThenDeviceAndPatientCreateInvokedWithDeviceSystemAndIdsReturned_Test()
        {
            var fhirClient      = Substitute.For <IFhirClient>();
            var resourceService = Substitute.For <ResourceManagementService>();

            var device = new Model.Device
            {
                Id      = "1",
                Patient = new Model.ResourceReference("Patient/123"),
            };

            var patient = new Model.Patient
            {
                Id = "123",
            };

            resourceService.EnsureResourceByIdentityAsync <Model.Device>(null, null, null, null).ReturnsForAnyArgs(Task.FromResult(device));
            resourceService.EnsureResourceByIdentityAsync <Model.Patient>(null, null, null, null).ReturnsForAnyArgs(Task.FromResult(patient));

            var mg = Substitute.For <IMeasurementGroup>();

            mg.DeviceId.Returns("deviceId");
            mg.PatientId.Returns("patientId");

            resourceService.GetResourceByIdentityAsync <Model.Device>(Arg.Any <IFhirClient>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(Task.FromException <Model.Device>(new FhirResourceNotFoundException(ResourceType.Device)));

            using (var idSrv = new R4DeviceAndPatientCreateIdentityService(fhirClient, resourceService))
            {
                idSrv.Initialize(new ResourceIdentityOptions {
                    DefaultDeviceIdentifierSystem = "mySystem"
                });
                var ids = await idSrv.ResolveResourceIdentitiesAsync(mg);

                Assert.Equal("1", ids[ResourceType.Device]);
                Assert.Equal("123", ids[ResourceType.Patient]);
            }

            await resourceService.Received(1).GetResourceByIdentityAsync <Model.Device>(fhirClient, "deviceId", "mySystem");

            await resourceService.Received(1).EnsureResourceByIdentityAsync <Model.Device>(fhirClient, "deviceId", "mySystem", Arg.Any <Action <Model.Device, Model.Identifier> >());

            await resourceService.Received(1).EnsureResourceByIdentityAsync <Model.Patient>(fhirClient, "patientId", null, Arg.Any <Action <Model.Patient, Model.Identifier> >());
        }
        public async void GivenIdNotFoundExceptionWithNoPatientId_WhenResolveResourceIdentitiesAsync_ThenResourceIdentityNotDefinedExceptionThrown_Test(string value)
        {
            var fhirClient      = Substitute.For <IFhirClient>();
            var resourceService = Substitute.For <ResourceManagementService>();

            var device = new Model.Device
            {
                Id      = "1",
                Patient = new Model.ResourceReference("Patient/123"),
            };

            var patient = new Model.Patient
            {
                Id = "123",
            };

            var createService = Substitute.For <ResourceManagementService>();

            resourceService.EnsureResourceByIdentityAsync <Model.Device>(null, null, null, null).ReturnsForAnyArgs(Task.FromResult(device));
            resourceService.EnsureResourceByIdentityAsync <Model.Patient>(null, null, null, null).ReturnsForAnyArgs(Task.FromResult(patient));

            var mg = Substitute.For <IMeasurementGroup>();

            mg.DeviceId.Returns("deviceId");
            mg.PatientId.Returns(value);

            resourceService.GetResourceByIdentityAsync <Model.Device>(Arg.Any <IFhirClient>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(Task.FromException <Model.Device>(new FhirResourceNotFoundException(ResourceType.Patient)));

            using (var idSrv = new R4DeviceAndPatientCreateIdentityService(fhirClient, resourceService))
            {
                var ex = await Assert.ThrowsAsync <ResourceIdentityNotDefinedException>(() => idSrv.ResolveResourceIdentitiesAsync(mg));

                Assert.Equal(ResourceType.Patient, ex.FhirResourceType);
            }

            await resourceService.Received(1).GetResourceByIdentityAsync <Model.Device>(fhirClient, "deviceId", null);

            await resourceService.DidNotReceiveWithAnyArgs().EnsureResourceByIdentityAsync <Model.Device>(null, null, null, null);

            await resourceService.DidNotReceiveWithAnyArgs().EnsureResourceByIdentityAsync <Model.Patient>(null, null, null, null);
        }
Esempio n. 11
0
        public async void GivenValidEncounterIdentifier_WhenResolveResourceIdentitiesAsync_ThenEncounterIdReturned_Test()
        {
            var fhirClient      = Substitute.For <IFhirClient>();
            var resourceService = Substitute.For <ResourceManagementService>();
            var device          = new Model.Device
            {
                Id      = "1",
                Patient = new Model.ResourceReference("Patient/123"),
            };

            var encounter = new Model.Encounter
            {
                Id = "abc",
            };

            var mg = Substitute.For <IMeasurementGroup>();

            mg.DeviceId.Returns("deviceId");
            mg.EncounterId.Returns("eId");

            resourceService.GetResourceByIdentityAsync <Model.Device>(Arg.Any <IFhirClient>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(Task.FromResult(device));

            resourceService.GetResourceByIdentityAsync <Model.Encounter>(Arg.Any <IFhirClient>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(Task.FromResult(encounter));

            using (var idSrv = new R4DeviceAndPatientWithEncounterLookupIdentityService(fhirClient, resourceService))
            {
                var ids = await idSrv.ResolveResourceIdentitiesAsync(mg);

                Assert.Equal("1", ids[ResourceType.Device]);
                Assert.Equal("123", ids[ResourceType.Patient]);
                Assert.Equal("abc", ids[ResourceType.Encounter]);
            }

            await resourceService.Received(1).GetResourceByIdentityAsync <Model.Device>(fhirClient, "deviceId", null);

            await resourceService.Received(1).GetResourceByIdentityAsync <Model.Encounter>(fhirClient, "eId", null);
        }
        public async void GivenMismatchedDeviceAndPatientIdReference_WhenResolveResourceIdentitiesAsync_ThenPatientDeviceMismatchExceptionThrown_Test()
        {
            var fhirClient      = Substitute.For <IFhirClient>();
            var resourceService = Substitute.For <ResourceManagementService>();

            var device = new Model.Device
            {
                Id      = "1",
                Patient = new Model.ResourceReference("Patient/abc"),
            };

            var patient = new Model.Patient
            {
                Id = "123",
            };

            resourceService.EnsureResourceByIdentityAsync <Model.Device>(null, null, null, null).ReturnsForAnyArgs(Task.FromResult(device));
            resourceService.EnsureResourceByIdentityAsync <Model.Patient>(null, null, null, null).ReturnsForAnyArgs(Task.FromResult(patient));

            var mg = Substitute.For <IMeasurementGroup>();

            mg.DeviceId.Returns("deviceId");
            mg.PatientId.Returns("patientId");

            resourceService.GetResourceByIdentityAsync <Model.Device>(Arg.Any <IFhirClient>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(Task.FromException <Model.Device>(new FhirResourceNotFoundException(ResourceType.Patient)));

            using (var idSrv = new R4DeviceAndPatientCreateIdentityService(fhirClient, resourceService))
            {
                await Assert.ThrowsAsync <PatientDeviceMismatchException>(() => idSrv.ResolveResourceIdentitiesAsync(mg));
            }

            await resourceService.Received(1).GetResourceByIdentityAsync <Model.Device>(fhirClient, "deviceId", null);

            await resourceService.Received(1).EnsureResourceByIdentityAsync <Model.Device>(fhirClient, "deviceId", null, Arg.Any <Action <Model.Device, Model.Identifier> >());

            await resourceService.Received(1).EnsureResourceByIdentityAsync <Model.Patient>(fhirClient, "patientId", null, Arg.Any <Action <Model.Patient, Model.Identifier> >());
        }
        public async void GivenDeviceWithNotPatientReference_WhenResolveResourceIdentitiesAsync_ThenFhirResourceNotFoundExceptionThrown_Test()
        {
            var fhirClient      = Substitute.For <IFhirClient>();
            var resourceService = Substitute.For <ResourceManagementService>();

            Model.Device device = new Model.Device();

            var mg = Substitute.For <IMeasurementGroup>();

            mg.DeviceId.Returns("deviceId");

            resourceService.GetResourceByIdentityAsync <Model.Device>(Arg.Any <IFhirClient>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(Task.FromResult(device));

            using (var idSrv = new R4DeviceAndPatientLookupIdentityService(fhirClient, resourceService))
            {
                var ex = await Assert.ThrowsAsync <FhirResourceNotFoundException>(async() => await idSrv.ResolveResourceIdentitiesAsync(mg));

                Assert.Equal(ResourceType.Patient, ex.FhirResourceType);
            }

            await resourceService.Received(1).GetResourceByIdentityAsync <Model.Device>(fhirClient, "deviceId", null);
        }
Esempio n. 14
0
        public FhirModel.Device GetResource()
        {
            var ManufactureDate = new DateTimeOffset(2017, 10, 17, 6, 00, 00, new TimeSpan(8, 0, 0));

            var Resource = new FhirModel.Device();

            Resource.Id = GetResourceId();
            IPyroFhirServerCodeSystem.SetProtectedMetaTag(Resource);
            Resource.Meta.LastUpdated = MasterLastUpdated;
            Resource.Identifier       = new List <FhirModel.Identifier>()
            {
                IPyroHealthCodeSystem.GetIdentifier(CodeSystems.PyroHealth.Codes.PyroFhirServer)
            };
            Resource.Status      = FhirModel.Device.FHIRDeviceStatus.Active;
            Resource.Type        = new FhirModel.CodeableConcept();
            Resource.Type.Coding = new List <FhirModel.Coding>()
            {
                new FhirModel.Coding("http://snomed.info/sct", "129465004", "Medical record")
            };
            Resource.Manufacturer    = "Pyro Health";
            Resource.ManufactureDate = ManufactureDate.ToString();
            Resource.Version         = $"V{IGlobalProperties.ApplicationVersionInfo}";
            if (string.IsNullOrWhiteSpace(IGlobalProperties.ThisServersManagingOrganizationResource))
            {
                Resource.Owner = new FhirModel.ResourceReference($"{FhirModel.ResourceType.Organization.GetLiteral()}/{IPyroHealthOrg.GetResourceId()}");
            }
            else
            {
                Resource.Owner = new FhirModel.ResourceReference(IGlobalProperties.ThisServersManagingOrganizationResource);
            }
            Resource.Url  = IGlobalProperties.ServiceBaseURL;
            Resource.Note = new List <FhirModel.Annotation>();
            var Annotation = new FhirModel.Annotation();

            Annotation.Text = "This device is a Medical Record FHIR server.";
            return(Resource);
        }
Esempio n. 15
0
        /// <summary>
        /// Parse Device
        /// </summary>
        public static Hl7.Fhir.Model.Device ParseDevice(IFhirReader reader, ErrorList errors, Hl7.Fhir.Model.Device existingInstance = null)
        {
            Hl7.Fhir.Model.Device result = existingInstance != null ? existingInstance : new Hl7.Fhir.Model.Device();
            string currentElementName    = reader.CurrentElementName;

            reader.EnterElement();

            while (reader.HasMoreElements())
            {
                var atName = reader.CurrentElementName;
                // Parse element extension
                if (atName == "extension")
                {
                    result.Extension = new List <Hl7.Fhir.Model.Extension>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "extension"))
                    {
                        result.Extension.Add(ExtensionParser.ParseExtension(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element language
                else if (atName == "language")
                {
                    result.LanguageElement = CodeParser.ParseCode(reader, errors);
                }

                // Parse element text
                else if (atName == "text")
                {
                    result.Text = NarrativeParser.ParseNarrative(reader, errors);
                }

                // Parse element contained
                else if (atName == "contained")
                {
                    result.Contained = new List <Hl7.Fhir.Model.Resource>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "contained"))
                    {
                        result.Contained.Add(ParserUtils.ParseContainedResource(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element _id
                else if (atName == "_id")
                {
                    result.LocalIdElement = Id.Parse(reader.ReadPrimitiveContents(typeof(Id)));
                }

                // Parse element type
                else if (atName == "type")
                {
                    result.Type = CodeableConceptParser.ParseCodeableConcept(reader, errors);
                }

                // Parse element manufacturer
                else if (atName == "manufacturer")
                {
                    result.ManufacturerElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element model
                else if (atName == "model")
                {
                    result.ModelElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element version
                else if (atName == "version")
                {
                    result.VersionElement = FhirStringParser.ParseFhirString(reader, errors);
                }

                // Parse element expiry
                else if (atName == "expiry")
                {
                    result.ExpiryElement = DateParser.ParseDate(reader, errors);
                }

                // Parse element identity
                else if (atName == "identity")
                {
                    result.Identity = DeviceParser.ParseDeviceIdentityComponent(reader, errors);
                }

                // Parse element owner
                else if (atName == "owner")
                {
                    result.Owner = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element assignedId
                else if (atName == "assignedId")
                {
                    result.AssignedId = new List <Hl7.Fhir.Model.Identifier>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "assignedId"))
                    {
                        result.AssignedId.Add(IdentifierParser.ParseIdentifier(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element location
                else if (atName == "location")
                {
                    result.Location = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element patient
                else if (atName == "patient")
                {
                    result.Patient = ResourceReferenceParser.ParseResourceReference(reader, errors);
                }

                // Parse element contact
                else if (atName == "contact")
                {
                    result.Contact = new List <Hl7.Fhir.Model.Contact>();
                    reader.EnterArray();

                    while (ParserUtils.IsAtArrayElement(reader, "contact"))
                    {
                        result.Contact.Add(ContactParser.ParseContact(reader, errors));
                    }

                    reader.LeaveArray();
                }

                // Parse element url
                else if (atName == "url")
                {
                    result.UrlElement = FhirUriParser.ParseFhirUri(reader, errors);
                }

                else
                {
                    errors.Add(String.Format("Encountered unknown element {0} while parsing {1}", reader.CurrentElementName, currentElementName), reader);
                    reader.SkipSubElementsFor(currentElementName);
                    result = null;
                }
            }

            reader.LeaveElement();
            return(result);
        }
Esempio n. 16
0
        protected static string GetPatientIdFromDevice(Model.Device device)
        {
            EnsureArg.IsNotNull(device, nameof(device));

            return(device.Patient?.GetId <Model.Patient>() ?? throw new FhirResourceNotFoundException(ResourceType.Patient));
        }
Esempio n. 17
0
        public static void SerializeDevice(Hl7.Fhir.Model.Device value, IFhirWriter writer, bool summary)
        {
            writer.WriteStartRootObject("Device");
            writer.WriteStartComplexContent();

            // Serialize element _id
            if (value.LocalIdElement != null)
            {
                writer.WritePrimitiveContents("_id", value.LocalIdElement, XmlSerializationHint.Attribute);
            }

            // Serialize element extension
            if (value.Extension != null && !summary && value.Extension.Count > 0)
            {
                writer.WriteStartArrayElement("extension");
                foreach (var item in value.Extension)
                {
                    writer.WriteStartArrayMember("extension");
                    ExtensionSerializer.SerializeExtension(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element language
            if (value.LanguageElement != null && !summary)
            {
                writer.WriteStartElement("language");
                CodeSerializer.SerializeCode(value.LanguageElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element text
            if (value.Text != null && !summary)
            {
                writer.WriteStartElement("text");
                NarrativeSerializer.SerializeNarrative(value.Text, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element contained
            if (value.Contained != null && !summary && value.Contained.Count > 0)
            {
                writer.WriteStartArrayElement("contained");
                foreach (var item in value.Contained)
                {
                    writer.WriteStartArrayMember("contained");
                    FhirSerializer.SerializeResource(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element type
            if (value.Type != null && !summary)
            {
                writer.WriteStartElement("type");
                CodeableConceptSerializer.SerializeCodeableConcept(value.Type, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element manufacturer
            if (value.ManufacturerElement != null && !summary)
            {
                writer.WriteStartElement("manufacturer");
                FhirStringSerializer.SerializeFhirString(value.ManufacturerElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element model
            if (value.ModelElement != null && !summary)
            {
                writer.WriteStartElement("model");
                FhirStringSerializer.SerializeFhirString(value.ModelElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element version
            if (value.VersionElement != null && !summary)
            {
                writer.WriteStartElement("version");
                FhirStringSerializer.SerializeFhirString(value.VersionElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element expiry
            if (value.ExpiryElement != null && !summary)
            {
                writer.WriteStartElement("expiry");
                DateSerializer.SerializeDate(value.ExpiryElement, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element identity
            if (value.Identity != null && !summary)
            {
                writer.WriteStartElement("identity");
                DeviceSerializer.SerializeDeviceIdentityComponent(value.Identity, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element owner
            if (value.Owner != null && !summary)
            {
                writer.WriteStartElement("owner");
                ResourceReferenceSerializer.SerializeResourceReference(value.Owner, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element assignedId
            if (value.AssignedId != null && !summary && value.AssignedId.Count > 0)
            {
                writer.WriteStartArrayElement("assignedId");
                foreach (var item in value.AssignedId)
                {
                    writer.WriteStartArrayMember("assignedId");
                    IdentifierSerializer.SerializeIdentifier(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element location
            if (value.Location != null && !summary)
            {
                writer.WriteStartElement("location");
                ResourceReferenceSerializer.SerializeResourceReference(value.Location, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element patient
            if (value.Patient != null && !summary)
            {
                writer.WriteStartElement("patient");
                ResourceReferenceSerializer.SerializeResourceReference(value.Patient, writer, summary);
                writer.WriteEndElement();
            }

            // Serialize element contact
            if (value.Contact != null && !summary && value.Contact.Count > 0)
            {
                writer.WriteStartArrayElement("contact");
                foreach (var item in value.Contact)
                {
                    writer.WriteStartArrayMember("contact");
                    ContactSerializer.SerializeContact(item, writer, summary);
                    writer.WriteEndArrayMember();
                }
                writer.WriteEndArrayElement();
            }

            // Serialize element url
            if (value.UrlElement != null && !summary)
            {
                writer.WriteStartElement("url");
                FhirUriSerializer.SerializeFhirUri(value.UrlElement, writer, summary);
                writer.WriteEndElement();
            }


            writer.WriteEndComplexContent();
            writer.WriteEndRootObject();
        }
Esempio n. 18
0
        // Select a device
        private void btnDeviceSelect_Click(object sender, EventArgs e)
        {
            deviceSelectStatus.Text = "Selecting...";
            var endpoint = new Uri("http://fhirtest.uhn.ca/baseDstu2");
            var client = new FhirClient(endpoint);

            var query = new string[] { "_id=" + selectDeviceSearch.Text.Trim() };
            Bundle result = client.Search<Device>(query);

            CurrentDevice = ((Device)result.Entry.FirstOrDefault().Resource);

            deviceID.Text = CurrentDevice.Id;
            deviceManufacturer.Text = CurrentDevice.Manufacturer;
            deviceModel.Text = CurrentDevice.Model;
            deviceSelectStatus.Text = "Done!";
        }
Esempio n. 19
0
        // Create a device
        private void btnDeviceCreate_Click(object sender, EventArgs e)
        {
            createDeviceStatus.Text = "Creating...";

            var endpoint = new Uri("http://fhirtest.uhn.ca/baseDstu2");
            var client = new FhirClient(endpoint);

            var dev = new Device() { Manufacturer = createDeviceManufacturer.Text, Model =  createDeviceModel.Text};
            client.Create(dev);

            createDeviceStatus.Text = "Done!";
        }
 protected static string GetPatientIdFromDevice(Model.Device device)
 {
     return(device.Patient?.GetId <Model.Patient>() ?? throw new FhirResourceNotFoundException(ResourceType.Patient));
 }