public async Task <ActionResult <Patient> > CreatePatient(PatientResource patientResource)
        {
            var patient = _mapper.Map <PatientResource, Patient>(patientResource);
            await _patientService.CreatePatient(patient);

            return(Ok(patient));
        }
예제 #2
0
        public async Task <IActionResult> PutPatient([FromRoute] int id, [FromBody] PatientResource patientResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var patient = mapper.Map <PatientResource, Patient>(patientResource);

            repository.UpdatePatient(patient);

            try
            {
                await unitOfWork.CompleteAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PatientExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #3
0
 public void TestInitialize()
 {
     PatientResource = new PatientResource();
     LoginResource   = new LoginResource();
     Helpers.SetBaseAddress();
     Helpers.Wipe();
 }
예제 #4
0
        public ActionResult Search(PatientResource patient)
        {
            if (ModelState.IsValid)
            {
                //TODO: SubscribeUser(model.Email);
            }

            return(View("Index", patient));
        }
예제 #5
0
        public async Task <IActionResult> AddPatient(PatientResource patientResource)
        {
            var mapPatient = _mapper.Map <Patient>(patientResource);

            mapPatient.IsAudit     = false;
            mapPatient.CreatedDate = DateTime.Now;
            mapPatient.EditedDate  = mapPatient.CreatedDate;
            // var newPatient = await _context.Patients.AddAsync(mapPatient);
            _patientRepo.Add(mapPatient);
            // await _context.SaveChangesAsync();
            await _unitOfWork.CompleteAsync();

            return(CreatedAtAction("GetPatients", new { id = mapPatient.PatientId }, mapPatient));
        }
예제 #6
0
        public async Task AssignPatientResource(int patientId, int resourceId)
        {
            PatientResource patientResource = new PatientResource()
            {
                PatientID  = patientId,
                ResourceID = resourceId
            };
            var    data  = JsonSerializer.Serialize(patientResource);
            string route = "patientresources";

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            var stringContent = new StringContent(data, Encoding.UTF8, "application/json");
            await client.PostAsync($"{baseURL}/{route}", stringContent);
        }
        public async Task <ActionResult <Patient> > UpdatePatient(Guid id, [FromBody] PatientResource savePatient)
        {
            var patientToBeUpdate = await _patientService.GetPatientById(id);

            if (patientToBeUpdate == null)
            {
                return(NotFound());
            }

            var patientResuource = _mapper.Map <PatientResource, Patient>(savePatient);

            await _patientService.UpdatePatient(patientToBeUpdate, patientResuource);

            var updatedPatient = await _patientService.GetPatientById(id);

            return(Ok(updatedPatient));
        }
예제 #8
0
        public IActionResult Search(PatientResource patient)
        {
            var pan = new Patient();
            //The fhir server end point address
            string ServiceRootUrl = "http://sqlonfhir-stu3.azurewebsites.net/fhir";
            //Create a client to send to the server at a given endpoint.
            var FhirClient = new FhirClient(ServiceRootUrl);

            // increase timeouts since the server might be powered down
            FhirClient.Timeout = (60 * 1000);
            try
            {
                ////Attempt to send the resource to the server endpoint
                //Bundle ReturnedSearchBundle = FhirClient.Search<Patient>(new string[] { "family=Nguyen" });

                //foreach (var Entry in ReturnedSearchBundle.Entry)
                //{

                //    Console.WriteLine("ID: " + Entry.Resource.Id);
                //    Console.WriteLine("Quốc gia: " + Entry.Resource.Language);
                //}
                //Console.WriteLine();
            }
            catch (FhirOperationException FhirOpExec)
            {
                ////Process any Fhir Errors returned as OperationOutcome resource
                //Console.WriteLine();
                //Console.WriteLine("An error message: " + FhirOpExec.Message);
                //Console.WriteLine();
            }
            catch (Exception GeneralException)
            {
                //Console.WriteLine();
                //Console.WriteLine("An error message: " + GeneralException.Message);
                //Console.WriteLine();
            }
            //Console.WriteLine("Press any key to end.");
            //Console.ReadKey();
            return(View());
        }
예제 #9
0
        public IActionResult Add(PatientResource patient)
        {
            string id        = patient.Id;
            string MessageID = Guid.NewGuid().ToString();

            var pan = new Patient();

            pan.Name.Add(new HumanName().WithGiven(patient.givenName).AndFamily(patient.familyName));
            pan.Identifier.Add(new Identifier("http://acme.org/MRNs", id));
            pan.Id         = MessageID;
            patient.Active = true;

            pan.Active = patient.Active;
            if (patient.Gender == "Male")
            {
                pan.Gender = AdministrativeGender.Male;
            }
            else if (patient.Gender == "Female")
            {
                pan.Gender = AdministrativeGender.Female;
            }
            else if (patient.Gender == "Other")
            {
                pan.Gender = AdministrativeGender.Other;
            }
            else if (patient.Gender == "Unknown")
            {
                pan.Gender = AdministrativeGender.Unknown;
            }
            pan.BirthDate = patient.birthDay;
            pan.Address.Add(new Address()
            {
                Text     = patient.Line,
                District = patient.District,
                City     = patient.City
            });
            pan.Telecom.Add(new ContactPoint()
            {
                System = ContactPoint.ContactPointSystem.Phone,
                Value  = patient.phoneNumber
            });
            pan.MaritalStatus = new CodeableConcept("http://acme.org/MRNs", patient.maritalStatus);
            pan.Language      = patient.Language;
            pan.Contact.Add(new Patient.ContactComponent()
            {
                Name    = new HumanName().WithGiven(patient.middleNameContact).WithGiven(patient.givenNameContact).AndFamily(patient.familyNameContact),
                Address = new Address()
                {
                    Text     = patient.LineContact,
                    District = patient.CityContact,
                    City     = patient.DistrictContact
                },
                Gender = AdministrativeGender.Female,
            });
            var client  = new FhirClient("http://sqlonfhir-stu3.azurewebsites.net/fhir/");
            var outcome = client.Create <Patient>(pan);

            //var outcome = client.Update<Patient>(pat);
            // Print the ID of the newly created resource

            Console.WriteLine(outcome.Id);
            Console.ReadLine();
            return(View());
        }
예제 #10
0
 public PatientController()
 {
     _patientResource = new PatientResource();
 }
예제 #11
0
        public async Task <IActionResult> UpdatePatient(int id, [FromBody] PatientResource patientResource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != patientResource.PatientId)
            {
                return(Unauthorized());
            }

            var currPatient = await _context.Patients.Where(p => p.PatientId == id)
                              .AsNoTracking()
                              .Include(e => e.EmergencyContacts)
                              .FirstOrDefaultAsync();


            // var tempPatient = await _context.Patients.Where(p => p.PatientId == id)
            //     .AsNoTracking()
            //     .FirstOrDefaultAsync();

            var tempPatient = new Patient
            {
                PatientName      = currPatient.PatientName,
                MRN              = currPatient.MRN,
                Gender           = currPatient.Gender,
                DOB              = currPatient.DOB,
                IdentificationId = currPatient.IdentificationId,
                IdentificationNo = currPatient.IdentificationNo,
                Version          = currPatient.Version,
                ZipCode          = currPatient.ZipCode,
                IsAudit          = true,
                CreatedDate      = currPatient.CreatedDate,
                EditedDate       = DateTime.Now
                                   // EmergencyContacts.ContactNo = currPatient.EmergencyContacts.ContactNo,
            };

            var tempEcListInsert = new List <EmergencyContact>();
            var tempEcListUpdate = new List <EmergencyContact>();

            foreach (var a in patientResource.EmergencyContactsResource)
            {
                var currEc = currPatient.EmergencyContacts.Where(e => e.EmergencyContactId == a.EmergencyContactId)
                             .FirstOrDefault();

                tempEcListUpdate.Add(new EmergencyContact()
                {
                    EmergencyContactId = currEc.EmergencyContactId,
                    ContactNo          = a.ContactNo,
                    RelationshipId     = a.RelationshipId,
                    IdentificationId   = a.IdentificationId,
                    IdentificationNo   = a.IdentificationNo,
                    CreatedDate        = currEc.CreatedDate,
                    EditedDate         = DateTime.Now,
                    Version            = currEc.Version + 1
                });

                tempEcListInsert.Add(new EmergencyContact()
                {
                    // EmergencyContactId = currEc.EmergencyContactId,
                    ContactNo        = currEc.ContactNo,
                    RelationshipId   = currEc.RelationshipId,
                    IdentificationId = currEc.IdentificationId,
                    IdentificationNo = currEc.IdentificationNo,
                    CreatedDate      = currEc.CreatedDate,
                    EditedDate       = currEc.EditedDate,
                    Version          = currEc.Version,
                    IsAudit          = true
                });
            }

            tempPatient.EmergencyContacts = tempEcListInsert;

            var mapPatient = _mapper.Map <PatientResource, Patient>(patientResource, currPatient);

            mapPatient.Version    = currPatient.Version + 1;
            mapPatient.IsAudit    = false;
            mapPatient.EditedDate = DateTime.Now;

            mapPatient.EmergencyContacts = tempEcListUpdate;

            //insert existing record (from db)
            // await _context.Patients.AddAsync(tempPatient);
            _patientRepo.Add(tempPatient);

            //update edited patient record
            _context.Update(mapPatient);

            // if (await _context.SaveChangesAsync() > 0)
            if (await _unitOfWork.CompleteAsync() > 0)
            {
                //var result = _mapper.Map<Patient, PatientResource>(patient, patientResource);
                return(Ok());
            }

            throw new Exception($"Updating patient {id} failed on save");
        }