public HttpResponseMessage Create(Hl7.Fhir.Model.Observation fhirObservation)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            Observation observation = ObservationMapper.MapResource(fhirObservation);

            observation = (Observation)ControllerUtils.AddMetadata(observation, ControllerUtils.CREATE);

            db.Observations.Add(observation);
            db.SaveChanges();

            message.Content          = new StringContent("Observation created!", Encoding.UTF8, "text/html");
            message.StatusCode       = HttpStatusCode.Created;
            message.Headers.Location = new Uri(Url.Link("SpecificObservation", new { id = observation.ObservationId }));

            return(message);
        }
Exemple #2
0
        public HttpResponseMessage Create(Hl7.Fhir.Model.Device fhirDevice)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            Device device = DeviceMapper.MapResource(fhirDevice);

            device = (Device)ControllerUtils.AddMetadata(device, ControllerUtils.CREATE);

            db.Devices.Add(device);
            db.SaveChanges();

            message.Content          = new StringContent("Device created!", Encoding.UTF8, "text/html");
            message.StatusCode       = HttpStatusCode.Created;
            message.Headers.Location = new Uri(Url.Link("SpecificDevice", new { id = device.DeviceId }));

            return(message);
        }
        public HttpResponseMessage Delete(int observationId)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            Observation observation = db.Observations.Find(observationId);

            if (observation == null)
            {
                message.StatusCode = HttpStatusCode.NotFound;
                message.Content    = new StringContent("Observation with id " + observationId + " not found!", Encoding.UTF8, "text/html");
                return(message);
            }
            observation = (Observation)ControllerUtils.AddMetadata(observation, ControllerUtils.DELETE);

            db.Observations.Remove(observation);
            db.SaveChanges();

            message.StatusCode = HttpStatusCode.NoContent;
            return(message);
        }
Exemple #4
0
        public HttpResponseMessage Delete(int deviceId)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            Device device = db.Devices.Find(deviceId);

            if (device == null)
            {
                message.StatusCode = HttpStatusCode.NotFound;
                message.Content    = new StringContent("Device with id " + deviceId + " not found!", Encoding.UTF8, "text/html");
                return(message);
            }
            device = (Device)ControllerUtils.AddMetadata(device, ControllerUtils.DELETE);

            db.Devices.Remove(device);
            db.SaveChanges();

            message.StatusCode = HttpStatusCode.NoContent;
            return(message);
        }
        public HttpResponseMessage Read(int observationId, string _format = "application/xml+FHIR", bool _summary = false)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            Observation observation = db.Observations.Find(observationId);

            if (observation == null)
            {
                message.StatusCode = HttpStatusCode.NotFound;
                message.Content    = new StringContent("observation with id " + observationId + " not found!", Encoding.UTF8, "text/html");
                return(message);
            }

            Hl7.Fhir.Model.Observation fhirObservation = ObservationMapper.MapModel(observation);
            string fixedFormat = ControllerUtils.FixMimeString(_format);

            string payload = ControllerUtils.Serialize(fhirObservation, fixedFormat, _summary);

            message.Content = new StringContent(payload, Encoding.UTF8, fixedFormat);
            return(message);
        }
Exemple #6
0
        public HttpResponseMessage Read(int deviceId, string _format = "application/xml+FHIR", bool _summary = false)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            Device device = db.Devices.Find(deviceId);

            if (device == null)
            {
                message.StatusCode = HttpStatusCode.NotFound;
                message.Content    = new StringContent("Device with id " + deviceId + " not found!", Encoding.UTF8, "text/html");
                return(message);
            }

            Hl7.Fhir.Model.Device fhirDevice = DeviceMapper.MapModel(device);
            string fixedFormat = ControllerUtils.FixMimeString(_format);

            string payload = ControllerUtils.Serialize(fhirDevice, fixedFormat, _summary);

            message.Content = new StringContent(payload, Encoding.UTF8, fixedFormat);
            return(message);
        }
        public HttpResponseMessage Update(Hl7.Fhir.Model.Observation fhirObservation, int observationId)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            if (observationId != int.Parse(fhirObservation.Id))
            {
                message.StatusCode = HttpStatusCode.BadRequest;
                message.Content    = new StringContent("Mismatch of observation ID! Provided " + observationId + " in URL but found " + fhirObservation.Id + "in payload!", Encoding.UTF8, "text/html");
                return(message);
            }

            Observation observation = ObservationMapper.MapResource(fhirObservation);

            observation = (Observation)ControllerUtils.AddMetadata(observation, ControllerUtils.UPDATE);

            db.Entry(observation).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ObservationExists(observationId))
                {
                    message.StatusCode = HttpStatusCode.NotFound;
                    message.Content    = new StringContent("observation with id " + observationId + " not found!", Encoding.UTF8, "text/html");
                    return(message);
                }
                else
                {
                    throw;
                }
            }

            message.StatusCode = HttpStatusCode.OK;
            return(message);
        }
Exemple #8
0
        public HttpResponseMessage Update(Hl7.Fhir.Model.Device fhirDevice, int deviceId)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            if (deviceId != int.Parse(fhirDevice.Id))
            {
                message.StatusCode = HttpStatusCode.BadRequest;
                message.Content    = new StringContent("Mismatch of Device ID! Provided " + deviceId + " in URL but found " + fhirDevice.Id + "in payload!", Encoding.UTF8, "text/html");
                return(message);
            }

            Device device = DeviceMapper.MapResource(fhirDevice);

            device = (Device)ControllerUtils.AddMetadata(device, ControllerUtils.UPDATE);

            db.Entry(device).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DeviceExists(deviceId))
                {
                    message.StatusCode = HttpStatusCode.NotFound;
                    message.Content    = new StringContent("Device with id " + deviceId + " not found!", Encoding.UTF8, "text/html");
                    return(message);
                }
                else
                {
                    throw;
                }
            }

            message.StatusCode = HttpStatusCode.OK;
            return(message);
        }