예제 #1
0
        public async Task <ActionResult> Get([Required][FromRoute] string id)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    PersonProfileResponse response = await _personsRepository.GetPersonProfileAsync(id);

                    if (response.statusCode == HttpStatusCode.OK)
                    {
                        IEnumerable <PersonProfileContainer> personProfileContainers = new List <PersonProfileContainer> {
                            new PersonProfileContainer {
                                data = response.data
                            }
                        };
                        return(Ok(personProfileContainers.First()));
                    }
                    else
                    {
                        return(StatusCode((int)HttpStatusCode.PartialContent, "No target with type value of Patient"));
                    }
                }
                catch (Exception)
                {
                    return(StatusCode(StatusCodes.Status500InternalServerError, "Internal Server Error"));
                }
            }//ends If ModelState.IsValid

            return(BadRequest());
        } //ends Get
        public async Task <PersonProfileResponse> FindByIdAsync(int id)
        {
            try
            {
                var customer = await _customerRepository.FindByIdAsync(id);

                var aux = new PersonProfileResponse(customer);
                if (customer == null)
                {
                    aux = new PersonProfileResponse(false, "No se encontro al customer porque no existe", customer);
                }
                return(aux);
            }
            catch (Exception ex)
            {
                return(new PersonProfileResponse($"An error ocurred while deleting the customer: {ex.Message}"));
            }
        }
예제 #3
0
        public async Task <PersonProfileResponse> GetPersonProfileAsync(string person_id)
        {
            PersonProfileResponse response = new PersonProfileResponse();

            //PHASE 1
            Person person = await GetPersonWithConfirmedIdentity(person_id);

            if (person == null)
            {
                response.statusCode = HttpStatusCode.BadRequest;
                return(response);
            }

            response.statusCode = HttpStatusCode.Accepted; //The request has been accepted for processing, but the processing has not been completed

            //PHASE 2

            List <string> patientReferences = GetReferences(person, "Patient");

            if (patientReferences.Count == 0)
            {
                response.statusCode = HttpStatusCode.PartialContent;
                return(response);
            }
            string patientReference = patientReferences[0];
            // response.statusCode = HttpStatusCode.Accepted; //The request has been accepted for processing, but the processing has not been completed

            //PHASE 3
            //Since there is always only one patient associated with a person, So in patientReferences array at index 0, we have that one patientReference

            List <Appointment> appointments = await GetInFutureAppointmentsForPatientAsync(patientReference);

            if (appointments == null)                                     //appointments will be null only when ResponseCode is other than 200
            {
                response.statusCode = HttpStatusCode.InternalServerError; //500
                return(response);
            }

            // response.statusCode = HttpStatusCode.Accepted; //The request has been accepted for processing, but the processing has not been completed

            List <FutureAppointment> futureAppointments = GetFutureAppointmentsFromAppointmentsWhereActorIsPractitionerRole(appointments);

            //PHASE 4

            List <Related_Person> related_People = await GetRelatedPeopleAsync(person);

            //PHASE 5
            PatientResponse getPatientResponse = await GetPatientAsync(patientReference);

            if (getPatientResponse.statusCode != HttpStatusCode.OK)
            {
                response.statusCode = HttpStatusCode.InternalServerError;
                return(response);
            }

            // response.statusCode = HttpStatusCode.Accepted; //The request has been accepted for processing, but the processing has not been completed

            List <string> practitionerRoleReferences = GetPractitionerRoleReferencesFromPatient(getPatientResponse.patient);

            List <_Provider> providers = null;

            if (practitionerRoleReferences.Count > 0)
            {
                providers = await GetPractitionerRolesAsync(practitionerRoleReferences);
            }

            //PHASE 5a
            //Extraction externalIds from the retrieved patient resource
            List <ExternalId> externalIds = GetExternalIdsFromPatient(getPatientResponse.patient);

            //PHASE 6
            //Collecting data into a single object
            response.data = new PersonProfile
            {
                personId       = person_id,
                patientSelfId  = getPatientResponse.patient.Id,
                externalIds    = (externalIds?.Count > 0 ? externalIds : null),
                relatedPersons = (related_People?.Count > 0 ? related_People : null),
                appointments   = (futureAppointments?.Count > 0 ? futureAppointments : null),
                providers      = (providers?.Count > 0 ? providers : null)
            };

            //Setting Response Code
            response.statusCode = HttpStatusCode.OK;

            return(response);
        }//ends GetPersonProfileAsync