public async Task <IHttpActionResult> PuttUserNarrativeEntry(int id, tUserNarrativeEntry tUserNarrativeEntry)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tUserNarrativeEntry.ID)
            {
                return(BadRequest());
            }

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

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tUserNarrativeEntryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
        public async Task <IHttpActionResult> GetSubDataByCategory(int itemId, string category)
        {
            Models.UserData.UserDataWithNote _retval = new Models.UserData.UserDataWithNote();
            switch (category)
            {
            case "Immunizations":
                #region Immunizations
                tUserImmunizationsDate _userImmunizationDate = await db.tUserImmunizationsDates.FindAsync(itemId);

                _retval = new Models.UserData.UserDataWithNote()
                {
                    ID       = _userImmunizationDate.ID,
                    ParentId = _userImmunizationDate.UserImmunizationID,
                    Date     = _userImmunizationDate.DateTime
                };
                #endregion
                break;

            case "Narratives":
                #region Narrative Entry
                tUserNarrativeEntry _userNarrativeEntry = await db.tUserNarrativeEntries.FindAsync(itemId);

                _retval = new Models.UserData.UserDataWithNote()
                {
                    ID       = _userNarrativeEntry.ID,
                    ParentId = _userNarrativeEntry.NarrativeID,
                    SeqNum   = _userNarrativeEntry.SectionSeqNum,
                    Text     = _userNarrativeEntry.SectionText,
                    Title    = _userNarrativeEntry.SectionTitle
                };
                #endregion
                break;

            case "Test Results":
                #region Test Results Component
                tUserTestResultComponent _userTestResultComponent = await db.tUserTestResultComponents.FindAsync(itemId);

                _retval = new Models.UserData.UserDataWithNote()
                {
                    ID              = _userTestResultComponent.ID,
                    ParentId        = _userTestResultComponent.TestResultID,
                    UOMID           = _userTestResultComponent.UOMID != null ? _userTestResultComponent.UOMID.Value : 0,
                    Name            = _userTestResultComponent.Name,
                    ComponentsValue = _userTestResultComponent.Value,
                    LowValue        = _userTestResultComponent.LowValue,
                    HighValue       = _userTestResultComponent.HighValue,
                    RefRange        = _userTestResultComponent.RefRange,
                    Comments        = _userTestResultComponent.Comments
                };
                #endregion
                break;

            default:
                break;
            }
            return(Ok(_retval));
        }
        public async Task <IHttpActionResult> GettUserNarrativeEntry(int id)
        {
            tUserNarrativeEntry tUserNarrativeEntry = await db.tUserNarrativeEntries.FindAsync(id);

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

            return(Ok(tUserNarrativeEntry));
        }
        public async Task <IHttpActionResult> PosttUserNarrativeEntry(tUserNarrativeEntry tUserNarrativeEntry)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.tUserNarrativeEntries.Add(tUserNarrativeEntry);
            await db.SaveChangesAsync();

            return(Ok(tUserNarrativeEntry));
        }
        public async Task <IHttpActionResult> SoftDeleteUserNarrativeEntry(int id, int status)
        {
            tUserNarrativeEntry tUserNarrativeEntry = await db.tUserNarrativeEntries.FindAsync(id);

            if (tUserNarrativeEntry == null)
            {
                return(NotFound());
            }
            tUserNarrativeEntry.SystemStatusID = status;
            await db.SaveChangesAsync();

            return(Ok(tUserNarrativeEntry));
        }
        public async Task <IHttpActionResult> DeletetUserNarrativeEntry(int id)
        {
            tUserNarrativeEntry tUserNarrativeEntry = await db.tUserNarrativeEntries.FindAsync(id);

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

            db.tUserNarrativeEntries.Remove(tUserNarrativeEntry);
            await db.SaveChangesAsync();

            return(Ok(tUserNarrativeEntry));
        }
Пример #7
0
        public IHttpActionResult Post(Narratives value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (value.source == null || value.access_token == null)
            {
                return(BadRequest());
            }

            using (var dbContextTransaction = db.Database.BeginTransaction())
            {
                try
                {
                    tSourceService sourceServiceObj = db.tSourceServices
                                                      .SingleOrDefault(x => x.ServiceName == value.source && x.SourceID == 5);

                    if (sourceServiceObj == null)
                    {
                        sourceServiceObj             = new tSourceService();
                        sourceServiceObj.ServiceName = value.source;
                        sourceServiceObj.TypeID      = 1; //Medical
                        sourceServiceObj.SourceID    = 5; //HumanAPI

                        db.tSourceServices.Add(sourceServiceObj);
                    }

                    tUserSourceService userSourceServiceObj = null;

                    //Get credentials
                    tCredential credentialObj =
                        db.tCredentials.SingleOrDefault(x => x.SourceID == 5 &&
                                                        x.AccessToken == value.access_token &&
                                                        x.SystemStatusID == 1);
                    if (credentialObj == null)
                    {
                        throw new NoUserCredentialsException("Unable to find any matching HAPI user credentials");
                    }
                    else
                    {
                        userSourceServiceObj = db.tUserSourceServices.SingleOrDefault(
                            x => x.SourceServiceID == sourceServiceObj.ID &&
                            x.CredentialID == credentialObj.ID &&
                            x.SystemStatusID == 1);

                        if (userSourceServiceObj == null)
                        {
                            userSourceServiceObj = new tUserSourceService();
                            userSourceServiceObj.SourceServiceID     = sourceServiceObj.ID;
                            userSourceServiceObj.UserID              = credentialObj.UserID;
                            userSourceServiceObj.CredentialID        = credentialObj.ID;
                            userSourceServiceObj.ConnectedOnDateTime = DateTime.Now;
                            userSourceServiceObj.LastSyncDateTime    = DateTime.Now;
                            userSourceServiceObj.LatestDateTime      = value.updatedAt;
                            userSourceServiceObj.StatusID            = 3; //connected
                            userSourceServiceObj.SystemStatusID      = 1; //valid
                            userSourceServiceObj.tCredential         = credentialObj;

                            db.tUserSourceServices.Add(userSourceServiceObj);
                        }
                        else
                        {
                            //update LatestDateTime to the most recent datetime
                            if (userSourceServiceObj.LatestDateTime == null ||
                                userSourceServiceObj.LatestDateTime < value.updatedAt)
                            {
                                userSourceServiceObj.LatestDateTime = value.updatedAt;
                            }
                        }
                    }

                    tSourceOrganization userSourceOrganization = null;
                    if (value.organization != null)
                    {
                        //Get source org
                        userSourceOrganization =
                            db.tSourceOrganizations.SingleOrDefault(x => x.SourceObjectID == value.organization.id);
                        if (userSourceOrganization == null)
                        {
                            //create org
                            tOrganization userOrganization = new tOrganization();
                            userOrganization.Name = value.organization.name;

                            //create new source org entry
                            userSourceOrganization = new tSourceOrganization();
                            userSourceOrganization.SourceObjectID  = value.organization.id;
                            userSourceOrganization.tOrganization   = userOrganization;
                            userSourceOrganization.OrganizationID  = userOrganization.ID;
                            userSourceOrganization.SourceServiceID = sourceServiceObj.ID;

                            db.tSourceOrganizations.Add(userSourceOrganization);
                        }
                    }

                    tProvider userProvider = new tProvider();
                    if (value.author != null)
                    {
                        userProvider.Name = value.author;
                        if (userSourceOrganization != null)
                        {
                            userProvider.tOrganization  = userSourceOrganization.tOrganization;
                            userProvider.OrganizationID = userSourceOrganization.OrganizationID;
                        }

                        db.tProviders.Add(userProvider);
                    }

                    tUserNarrative userNarrative = null;
                    userNarrative = db.tUserNarratives
                                    .SingleOrDefault(x => x.SourceObjectID == value.Id);

                    if (userNarrative == null)
                    {
                        //insert
                        userNarrative = new tUserNarrative();
                        userNarrative.SourceObjectID = value.Id;
                        userNarrative.UserID         = credentialObj.UserID;
                        if (userSourceOrganization != null)
                        {
                            userNarrative.tSourceOrganization  = userSourceOrganization;
                            userNarrative.SourceOrganizationID = userSourceOrganization.ID;
                        }
                        userNarrative.tUserSourceService  = userSourceServiceObj;
                        userNarrative.UserSourceServiceID = userSourceServiceObj.ID;

                        if (value.author != null)
                        {
                            userNarrative.tProvider  = userProvider;
                            userNarrative.ProviderID = userProvider.ID;
                        }

                        userNarrative.StartDateTime  = value.dateTime;
                        userNarrative.SystemStatusID = 1;

                        int seqNum = 0;
                        foreach (entries narrativeEntry in value.entries)
                        {
                            tUserNarrativeEntry userNarrativeEntry = new tUserNarrativeEntry();
                            userNarrativeEntry.SectionSeqNum  = seqNum++;
                            userNarrativeEntry.SectionText    = narrativeEntry.text;
                            userNarrativeEntry.SectionTitle   = narrativeEntry.title;
                            userNarrativeEntry.NarrativeID    = userNarrative.ID;
                            userNarrativeEntry.SystemStatusID = 1;
                            userNarrative.tUserNarrativeEntries.Add(userNarrativeEntry);
                        }

                        db.tUserNarratives.Add(userNarrative);
                    }
                    else
                    {
                        //update
                        if (userSourceOrganization != null)
                        {
                            userNarrative.tSourceOrganization  = userSourceOrganization;
                            userNarrative.SourceOrganizationID = userSourceOrganization.ID;
                        }
                        userNarrative.tUserSourceService  = userSourceServiceObj;
                        userNarrative.UserSourceServiceID = userSourceServiceObj.ID;

                        if (value.author != null)
                        {
                            userNarrative.tProvider  = userProvider;
                            userNarrative.ProviderID = userProvider.ID;
                        }

                        userNarrative.StartDateTime = value.dateTime;

                        List <tUserNarrativeEntry> existingEntries = db.tUserNarrativeEntries
                                                                     .Where(x => x.NarrativeID == userNarrative.ID).ToList();
                        existingEntries.ForEach(e => e.SystemStatusID = 4);

                        int seqNum = 0;
                        foreach (entries narrativeEntry in value.entries)
                        {
                            tUserNarrativeEntry userNarrativeEntry = new tUserNarrativeEntry();
                            userNarrativeEntry.SectionSeqNum  = seqNum++;
                            userNarrativeEntry.SectionText    = narrativeEntry.text;
                            userNarrativeEntry.SectionTitle   = narrativeEntry.title;
                            userNarrativeEntry.NarrativeID    = userNarrative.ID;
                            userNarrativeEntry.SystemStatusID = 1;
                            userNarrative.tUserNarrativeEntries.Add(userNarrativeEntry);
                        }

                        userNarrative.LastUpdatedDateTime = DateTime.Now;
                    }

                    db.SaveChanges();

                    dbContextTransaction.Commit();

                    return(Ok(userNarrative));
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();

                    //Insert Error Log
                    tUserDataErrLog userErrorLog = new tUserDataErrLog();

                    userErrorLog.ErrTypeID   = (int)ErrorLogging.enumErrorType.Application;
                    userErrorLog.ErrSourceID = (int)AuditLogging.enumApplication.SFCBAL;
                    userErrorLog.Code        = ex.HResult.ToString();
                    userErrorLog.Description = ex.Message;
                    userErrorLog.Trace       = ex.StackTrace;

                    dbErr.tUserDataErrLogs.Add(userErrorLog);
                    dbErr.SaveChanges();

                    string ErrMsg = "An error occured and we have logged the error. Please try again later.";

                    Exception Err = new Exception(ErrMsg, ex);

                    return(InternalServerError(Err));
                }
            }
        }