Пример #1
0
        public HttpResponseMessage Create(Hl7.Fhir.Model.Patient fhirPatient)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            Patient patient = PatientMapper.MapResource(fhirPatient);

            patient = (Patient)ControllerUtils.AddMetadata(patient, ControllerUtils.CREATE);

            db.Patients.Add(patient);
            db.SaveChanges();

            message.Content          = new StringContent("Patient created!", Encoding.UTF8, "text/html");
            message.StatusCode       = HttpStatusCode.Created;
            message.Headers.Location = new Uri(Url.Link("SpecificPatient", new { id = patient.PatientId }));

            return(message);
        }
Пример #2
0
        public HttpResponseMessage Delete(int patientId)
        {
            HttpResponseMessage message = new HttpResponseMessage();

            Patient patient = db.Patients.Find(patientId);

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

            db.Patients.Remove(patient);
            db.SaveChanges();

            message.StatusCode = HttpStatusCode.OK;
            return(message);
        }
Пример #3
0
        public HttpResponseMessage Update(Hl7.Fhir.Model.Patient fhirPatient, int patientId)
        {
            HttpResponseMessage message = new HttpResponseMessage();

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

            Patient patient = PatientMapper.MapResource(fhirPatient);

            patient = (Patient)ControllerUtils.AddMetadata(patient, ControllerUtils.UPDATE);

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

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

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