コード例 #1
0
        public async Task <IHttpActionResult> PuttUserTestResult(int id, tUserTestResult tUserTestResult)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        public async Task <IHttpActionResult> GettUserTestResult(int id)
        {
            tUserTestResult tUserTestResult = await db.tUserTestResults.FindAsync(id);

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

            return(Ok(tUserTestResult));
        }
コード例 #3
0
        public async Task <IHttpActionResult> SoftDeletetUserTestResult(int id, int status)
        {
            tUserTestResult tUserTestResult = await db.tUserTestResults.FindAsync(id);

            if (tUserTestResult == null)
            {
                return(NotFound());
            }
            tUserTestResult.SystemStatusID      = status;
            tUserTestResult.LastUpdatedDateTime = DateTime.Now;
            await db.SaveChangesAsync();

            return(Ok(tUserTestResult));
        }
コード例 #4
0
        public async Task <IHttpActionResult> DeletetUserTestResult(int id)
        {
            tUserTestResult tUserTestResult = await db.tUserTestResults.FindAsync(id);

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

            db.tUserTestResults.Remove(tUserTestResult);
            await db.SaveChangesAsync();

            return(Ok(tUserTestResult));
        }
コード例 #5
0
        public async Task <IHttpActionResult> PosttUserTestResult(tUserTestResult tUserTestResult)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                db.tUserTestResults.Add(tUserTestResult);
                await db.SaveChangesAsync();

                // return CreatedAtRoute("DefaultApi", new { id = tUserTestResult.ID }, tUserTestResult);
                return(Ok(tUserTestResult));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #6
0
        public IHttpActionResult Post(BloodOxygen value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (value.source == null || value.humanId == 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      = 2; //Wellness
                        sourceServiceObj.SourceID    = 5; //HumanAPI

                        db.tSourceServices.Add(sourceServiceObj);
                    }

                    tUserSourceService userSourceServiceObj = null;

                    //Get credentials
                    tCredential credentialObj =
                        db.tCredentials.SingleOrDefault(x => x.SourceID == 5 && x.SourceUserID == value.humanId &&
                                                        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;
                            }
                        }
                    }

                    tUserTestResult userTestResult = null;
                    userTestResult = db.tUserTestResults
                                     .SingleOrDefault(x => x.SourceObjectID == value.id);

                    if (userTestResult == null)
                    {
                        //insert
                        userTestResult = new tUserTestResult();
                        userTestResult.SourceObjectID      = value.id;
                        userTestResult.UserID              = credentialObj.UserID;
                        userTestResult.tUserSourceService  = userSourceServiceObj;
                        userTestResult.UserSourceServiceID = userSourceServiceObj.ID;
                        userTestResult.Name           = "Blood Oxygen";
                        userTestResult.StatusID       = 3; //captured
                        userTestResult.SystemStatusID = 1;

                        //Dates
                        DateTimeOffset dtoStart;
                        if (RESTfulBAL.Models.DynamoDB.Utilities.ConvertToDateTimeOffset(value.timestamp,
                                                                                         value.tzOffset,
                                                                                         out dtoStart))
                        {
                            userTestResult.ResultDateTime = dtoStart;
                        }
                        else
                        {
                            userTestResult.ResultDateTime = value.timestamp;
                        }

                        tUserTestResultComponent userTestResultComponent = new tUserTestResultComponent();
                        userTestResultComponent.SystemStatusID = 1;
                        userTestResultComponent.Name           = "Blood Oxygen";
                        userTestResultComponent.Value          = value.value.ToString();

                        //UOM
                        if (value.unit != null)
                        {
                            tUnitsOfMeasure uom = null;
                            uom = db.tUnitsOfMeasures.SingleOrDefault(x => x.UnitOfMeasure == value.unit);
                            if (uom == null)
                            {
                                uom = new tUnitsOfMeasure();
                                uom.UnitOfMeasure = value.unit;

                                db.tUnitsOfMeasures.Add(uom);
                            }

                            userTestResultComponent.tUnitsOfMeasure = uom;
                            userTestResultComponent.UOMID           = uom.ID;
                        }
                        userTestResult.tUserTestResultComponents.Add(userTestResultComponent);

                        tXrefUserTestResultComponentsCode xRefComponentCode = new tXrefUserTestResultComponentsCode();
                        xRefComponentCode.UserTestResultComponentID = userTestResultComponent.ID;
                        xRefComponentCode.CodeID = 6720;
                        userTestResultComponent.tXrefUserTestResultComponentsCodes.Add(xRefComponentCode);

                        userTestResult.tUserSourceService = userSourceServiceObj;

                        db.tUserTestResults.Add(userTestResult);
                    }
                    else
                    {
                        //update

                        //Dates
                        DateTimeOffset dtoStart;
                        if (RESTfulBAL.Models.DynamoDB.Utilities.ConvertToDateTimeOffset(value.timestamp,
                                                                                         value.tzOffset,
                                                                                         out dtoStart))
                        {
                            userTestResult.ResultDateTime = dtoStart;
                        }
                        else
                        {
                            userTestResult.ResultDateTime = value.timestamp;
                        }


                        tUserTestResultComponent userTestResultComponent = db.tUserTestResultComponents
                                                                           .SingleOrDefault(x => x.TestResultID == userTestResult.ID);
                        if (userTestResultComponent != null)
                        {
                            userTestResultComponent.Value = value.value.ToString();

                            //UOM
                            if (value.unit != null)
                            {
                                tUnitsOfMeasure uom = null;
                                uom = db.tUnitsOfMeasures.SingleOrDefault(x => x.UnitOfMeasure == value.unit);
                                if (uom == null)
                                {
                                    uom = new tUnitsOfMeasure();
                                    uom.UnitOfMeasure = value.unit;

                                    db.tUnitsOfMeasures.Add(uom);
                                }

                                if (!uom.UnitOfMeasure.Equals(value.unit))
                                {
                                    userTestResultComponent.tUnitsOfMeasure = uom;
                                    userTestResultComponent.UOMID           = uom.ID;
                                }
                            }

                            userTestResult.tUserTestResultComponents.Add(userTestResultComponent);
                        }

                        userTestResult.LastUpdatedDateTime = DateTime.Now;
                        userTestResult.tUserSourceService  = userSourceServiceObj;
                    }

                    db.SaveChanges();

                    dbContextTransaction.Commit();

                    return(Ok(userTestResult));
                }
                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));
                }
            }
        }
コード例 #7
0
        public IHttpActionResult Post(TestResults 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 userOrderingProvider = new tProvider();
                    if (value.orderedBy != null)
                    {
                        userOrderingProvider.Name = value.orderedBy;
                        if (userSourceOrganization != null)
                        {
                            userOrderingProvider.tOrganization  = userSourceOrganization.tOrganization;
                            userOrderingProvider.OrganizationID = userSourceOrganization.OrganizationID;
                        }

                        db.tProviders.Add(userOrderingProvider);
                    }

                    tTestResultStatus testResultStatus = null;
                    if (value.status != null)
                    {
                        testResultStatus =
                            db.tTestResultStatuses.SingleOrDefault(x => x.Status == value.status);
                        if (testResultStatus == null)
                        {
                            testResultStatus        = new tTestResultStatus();
                            testResultStatus.Status = value.status;

                            db.tTestResultStatuses.Add(testResultStatus);
                        }
                    }

                    tUserTestResult userTestResult = null;
                    userTestResult = db.tUserTestResults
                                     .SingleOrDefault(x => x.SourceObjectID == value.Id);

                    if (userTestResult == null)
                    {
                        //insert
                        userTestResult = new tUserTestResult();
                        userTestResult.SourceObjectID = value.Id;
                        userTestResult.UserID         = credentialObj.UserID;
                        if (userSourceOrganization != null)
                        {
                            userTestResult.tSourceOrganization  = userSourceOrganization;
                            userTestResult.SourceOrganizationID = userSourceOrganization.ID;
                        }
                        userTestResult.tUserSourceService  = userSourceServiceObj;
                        userTestResult.UserSourceServiceID = userSourceServiceObj.ID;
                        userTestResult.Name = value.name;
                        if (value.orderedBy != null)
                        {
                            userTestResult.tProvider          = userOrderingProvider;
                            userTestResult.OrderingProviderID = userOrderingProvider.ID;
                        }
                        if (testResultStatus != null)
                        {
                            userTestResult.tTestResultStatus = testResultStatus;
                            userTestResult.StatusID          = testResultStatus.ID;
                        }
                        userTestResult.Comments       = value.comments;
                        userTestResult.Narrative      = value.narrative;
                        userTestResult.Impression     = value.impression;
                        userTestResult.Transcriptions = value.transcriptions;
                        userTestResult.ResultDateTime = value.resultDateTime;
                        userTestResult.SystemStatusID = 1;


                        db.tUserTestResults.Add(userTestResult);
                    }
                    else
                    {
                        //update
                        if (userSourceOrganization != null)
                        {
                            userTestResult.tSourceOrganization  = userSourceOrganization;
                            userTestResult.SourceOrganizationID = userSourceOrganization.ID;
                        }
                        userTestResult.tUserSourceService  = userSourceServiceObj;
                        userTestResult.UserSourceServiceID = userSourceServiceObj.ID;
                        userTestResult.Name = value.name;
                        if (value.orderedBy != null)
                        {
                            userTestResult.tProvider          = userOrderingProvider;
                            userTestResult.OrderingProviderID = userOrderingProvider.ID;
                        }
                        if (testResultStatus != null)
                        {
                            userTestResult.tTestResultStatus = testResultStatus;
                            userTestResult.StatusID          = testResultStatus.ID;
                        }
                        userTestResult.Comments            = value.comments;
                        userTestResult.Narrative           = value.narrative;
                        userTestResult.Impression          = value.impression;
                        userTestResult.Transcriptions      = value.transcriptions;
                        userTestResult.ResultDateTime      = value.resultDateTime;
                        userTestResult.LastUpdatedDateTime = DateTime.Now;

                        userTestResult.tTestResultStatus = testResultStatus;
                    }

                    if (value.codes != null)
                    {
                        foreach (Codes code in value.codes)
                        {
                            if (code.code != null && code.codeSystem != null)
                            {
                                tCode testResultCode = null;
                                testResultCode =
                                    db.tCodes.SingleOrDefault(
                                        x => x.Code == code.code && x.CodeSystem == code.codeSystem);
                                if (testResultCode == null)
                                {
                                    testResultCode                = new tCode();
                                    testResultCode.Code           = code.code;
                                    testResultCode.CodeSystem     = code.codeSystem;
                                    testResultCode.CodeSystemName = code.codeSystemName;
                                    testResultCode.Name           = code.name;

                                    db.tCodes.Add(testResultCode);
                                    db.SaveChanges();
                                }

                                tXrefUserTestResultsCode userXrefTestCodes = null;
                                userXrefTestCodes =
                                    db.tXrefUserTestResultsCodes.SingleOrDefault(
                                        x => x.CodeID == testResultCode.ID && x.UserTestResultID == userTestResult.ID);
                                if (userXrefTestCodes == null)
                                {
                                    userXrefTestCodes = new tXrefUserTestResultsCode();
                                    userXrefTestCodes.tUserTestResult  = userTestResult;
                                    userXrefTestCodes.tCode            = testResultCode;
                                    userXrefTestCodes.CodeID           = testResultCode.ID;
                                    userXrefTestCodes.UserTestResultID = userTestResult.ID;

                                    db.tXrefUserTestResultsCodes.Add(userXrefTestCodes);
                                }
                            }
                        }
                    }
                    db.SaveChanges();

                    //components & component codes
                    if (value.components != null)
                    {
                        foreach (Components component in value.components)
                        {
                            tUserTestResultComponent userTestResultComponent = null;
                            userTestResultComponent =
                                db.tUserTestResultComponents.SingleOrDefault(x => x.TestResultID == userTestResult.ID &&
                                                                             x.Name == component.name);
                            if (userTestResultComponent == null)
                            {
                                userTestResultComponent = new tUserTestResultComponent();
                                userTestResultComponent.tUserTestResult = userTestResult;
                                userTestResultComponent.TestResultID    = userTestResult.ID;
                                userTestResultComponent.SystemStatusID  = 1;
                            }

                            userTestResultComponent.Name = component.name;
                            if (component.value == null)
                            {
                                userTestResultComponent.Value = "No Data";
                            }
                            else
                            {
                                if (component.unit == null && component.value.Split(' ').Length == 2)
                                {
                                    StringParser sParse = FindUOM(component.value);
                                    if (sParse.matchCount == 1)
                                    {
                                        userTestResultComponent.Value = sParse.newValue;
                                        userTestResultComponent.UOMID = sParse.uomID;
                                        component.unit = sParse.newUnit;
                                    }
                                    else
                                    {
                                        userTestResultComponent.Value = component.value;
                                    }
                                }
                                else
                                {
                                    userTestResultComponent.Value = component.value;
                                }
                            }
                            userTestResultComponent.LowValue  = component.low;
                            userTestResultComponent.HighValue = component.high;
                            userTestResultComponent.RefRange  = component.refRange;
                            userTestResultComponent.Comments  = component.componentComments;

                            //UOM
                            if (component.unit != null)
                            {
                                tUnitsOfMeasure uom = null;
                                uom = db.tUnitsOfMeasures.SingleOrDefault(x => x.UnitOfMeasure == component.unit);
                                if (uom == null)
                                {
                                    uom = new tUnitsOfMeasure();
                                    uom.UnitOfMeasure = component.unit;

                                    db.tUnitsOfMeasures.Add(uom);
                                    db.SaveChanges();
                                }

                                userTestResultComponent.tUnitsOfMeasure = uom;
                                userTestResultComponent.UOMID           = uom.ID;
                            }
                            if (userTestResultComponent.ObjectID == null)
                            {
                                db.tUserTestResultComponents.Add(userTestResultComponent);
                            }

                            //component codes
                            foreach (Codes code in component.codes)
                            {
                                if (code.code != null && code.codeSystem != null)
                                {
                                    tCode componentCode = null;
                                    componentCode =
                                        db.tCodes.SingleOrDefault(
                                            x => x.Code == code.code && x.CodeSystem == code.codeSystem);
                                    if (componentCode == null)
                                    {
                                        componentCode                = new tCode();
                                        componentCode.Code           = code.code;
                                        componentCode.CodeSystem     = code.codeSystem;
                                        componentCode.CodeSystemName = code.codeSystemName;
                                        componentCode.Name           = code.name;

                                        db.tCodes.Add(componentCode);
                                        db.SaveChanges();
                                    }

                                    tXrefUserTestResultComponentsCode userXrefComponentCodes = null;
                                    userXrefComponentCodes =
                                        db.tXrefUserTestResultComponentsCodes.SingleOrDefault(
                                            x =>
                                            x.CodeID == componentCode.ID &&
                                            x.UserTestResultComponentID == userTestResultComponent.ID);
                                    if (userXrefComponentCodes == null)
                                    {
                                        userXrefComponentCodes = new tXrefUserTestResultComponentsCode();
                                        userXrefComponentCodes.tUserTestResultComponent = userTestResultComponent;
                                        userXrefComponentCodes.tCode  = componentCode;
                                        userXrefComponentCodes.CodeID = componentCode.ID;
                                        userXrefComponentCodes.UserTestResultComponentID = userTestResultComponent.ID;

                                        db.tXrefUserTestResultComponentsCodes.Add(userXrefComponentCodes);
                                    }
                                }
                            }
                        }
                    }

                    //Recipients
                    if (value.recipients != null)
                    {
                        foreach (Recipients recip in value.recipients)
                        {
                            tProvider userProviderRecipients = null;
                            userProviderRecipients =
                                db.tProviders.SingleOrDefault(x => x.SourceProviderID == recip.objectID);
                            if (userProviderRecipients == null)
                            {
                                userProviderRecipients = new tProvider();
                                userProviderRecipients.SourceProviderID = recip.objectID;
                                userProviderRecipients.Name             = recip.name;
                                if (userSourceOrganization != null)
                                {
                                    userProviderRecipients.OrganizationID = userSourceOrganization.OrganizationID;
                                }

                                db.tProviders.Add(userProviderRecipients);
                            }

                            tXrefUserTestResultRecipientsProvider userXrefProviderRecip =
                                new tXrefUserTestResultRecipientsProvider();
                            userXrefProviderRecip.tProvider        = userProviderRecipients;
                            userXrefProviderRecip.tUserTestResult  = userTestResult;
                            userXrefProviderRecip.IsPCP            = recip.isPCP;
                            userXrefProviderRecip.ProviderID       = userProviderRecipients.ID;
                            userXrefProviderRecip.UserTestResultID = userTestResult.ID;

                            db.tXrefUserTestResultRecipientsProviders.Add(userXrefProviderRecip);
                        }
                    }

                    db.SaveChanges();

                    dbContextTransaction.Commit();

                    return(Ok(userTestResult));
                }
                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));
                }
            }
        }
コード例 #8
0
        public async Task <IHttpActionResult> GetUserDataWithNotes(int categoryid, string category)
        {
            Models.UserData.UserDataWithNote _retval = new Models.UserData.UserDataWithNote();
            tUserDerivedNote _tUserDerivedNote       = null;

            switch (category)
            {
            case "Allergies":
                #region Allergies
                tUserAllergy _userAllergy = await db.tUserAllergies.FindAsync(categoryid);

                _tUserDerivedNote = db.tUserDerivedNotes.FirstOrDefault(a => a.fkObjectID == _userAllergy.ObjectID);
                _retval           = new Models.UserData.UserDataWithNote()
                {
                    ID            = _tUserDerivedNote != null ? _tUserDerivedNote.ID : -1,
                    ParentId      = _userAllergy.ID,
                    EndDateTime   = _userAllergy.EndDateTime,
                    StartDateTime = _userAllergy.StartDateTime,
                    AllergenID    = _userAllergy.AllergenID,
                    ReactionID    = _userAllergy.ReactionID,
                    SeverityID    = _userAllergy.SeverityID,
                    StatusID      = _userAllergy.StatusID,
                    Note          = _tUserDerivedNote != null ? _tUserDerivedNote.Note : string.Empty
                };
                #endregion
                break;

            case "Care Plans":
                #region Care Plans
                tUserCarePlan _userCarePlan = await db.tUserCarePlans.FindAsync(categoryid);

                _tUserDerivedNote = db.tUserDerivedNotes.FirstOrDefault(a => a.fkObjectID == _userCarePlan.ObjectID);
                _retval           = new Models.UserData.UserDataWithNote()
                {
                    ID                  = _tUserDerivedNote != null ? _tUserDerivedNote.ID : -1,
                    ParentId            = _userCarePlan.ID,
                    EndDateTime         = _userCarePlan.EndDateTime,
                    StartDateTime       = _userCarePlan.StartDateTime,
                    CarePlanTypeID      = _userCarePlan.TypeID,
                    CarePlanSpecialtyID = _userCarePlan.SpecialtyID,
                    CarePlanName        = _userCarePlan.Name,
                    CarePlanText        = _userCarePlan.Text,
                    Note                = _tUserDerivedNote != null ? _tUserDerivedNote.Note : string.Empty
                };
                #endregion
                break;

            case "Encounters":
                #region Encounters
                tUserEncounter _userEncounters = await db.tUserEncounters.FindAsync(categoryid);

                tUserInstruction _FollowUpIns = await db.tUserInstructions.FindAsync(_userEncounters.FollowUpInstructionID);

                tUserInstruction _PatientIns = await db.tUserInstructions.FindAsync(_userEncounters.PatientInstructionID);

                _tUserDerivedNote = db.tUserDerivedNotes.FirstOrDefault(a => a.fkObjectID == _userEncounters.ObjectID);
                _retval           = new Models.UserData.UserDataWithNote()
                {
                    ID                  = _tUserDerivedNote != null ? _tUserDerivedNote.ID : -1,
                    ParentId            = _userEncounters.ID,
                    EncounterDateTime   = _userEncounters.EncounterDateTime,
                    ProviderID          = _userEncounters.ProviderID,
                    VisitTypeID         = _userEncounters.VisitTypeID,
                    Note                = _tUserDerivedNote != null ? _tUserDerivedNote.Note : string.Empty,
                    FollowUpInstruction = _FollowUpIns,
                    PatientInstruction  = _PatientIns
                };
                #endregion
                break;

            case "Functional Statuses":
                #region Functional Statuses
                tUserFunctionalStatus _userFunctionalStatus = await db.tUserFunctionalStatuses.FindAsync(categoryid);

                _tUserDerivedNote = db.tUserDerivedNotes.FirstOrDefault(a => a.fkObjectID == _userFunctionalStatus.ObjectID);
                _retval           = new Models.UserData.UserDataWithNote()
                {
                    ID            = _tUserDerivedNote != null ? _tUserDerivedNote.ID : -1,
                    ParentId      = _userFunctionalStatus.ID,
                    EndDateTime   = _userFunctionalStatus.EndDateTime,
                    StartDateTime = _userFunctionalStatus.StartDateTime,
                    Name          = _userFunctionalStatus.Name,
                    Note          = _tUserDerivedNote != null ? _tUserDerivedNote.Note : string.Empty
                };
                #endregion
                break;

            case "Immunizations":
                #region Immunizations
                tUserImmunization _userImmunization = await db.tUserImmunizations.FindAsync(categoryid);

                _tUserDerivedNote = db.tUserDerivedNotes.FirstOrDefault(a => a.fkObjectID == _userImmunization.ObjectID);
                _retval           = new Models.UserData.UserDataWithNote()
                {
                    ID       = _tUserDerivedNote != null ? _tUserDerivedNote.ID : -1,
                    ParentId = _userImmunization.ID,
                    Name     = _userImmunization.Name,
                    Note     = _tUserDerivedNote != null ? _tUserDerivedNote.Note : string.Empty
                };
                #endregion
                break;

            case "Instructions":
                #region Instruction
                tUserInstruction _userInstruction = await db.tUserInstructions.FindAsync(categoryid);

                _tUserDerivedNote = db.tUserDerivedNotes.FirstOrDefault(a => a.fkObjectID == _userInstruction.ObjectID);
                _retval           = new Models.UserData.UserDataWithNote()
                {
                    ID                = _tUserDerivedNote != null ? _tUserDerivedNote.ID : -1,
                    ParentId          = _userInstruction.ID,
                    Name              = _userInstruction.Name,
                    Text              = _userInstruction.Text,
                    StartDateTime     = _userInstruction.StartDateTime,
                    EndDateTime       = _userInstruction.EndDateTime,
                    InstructionTypeID = _userInstruction.InstructionTypeID,
                    Note              = _tUserDerivedNote != null ? _tUserDerivedNote.Note : string.Empty
                };
                #endregion
                break;

            case "Narratives":
                #region Narratives
                tUserNarrative _userNarrative = await db.tUserNarratives.FindAsync(categoryid);

                _tUserDerivedNote = db.tUserDerivedNotes.FirstOrDefault(a => a.fkObjectID == _userNarrative.ObjectID);
                _retval           = new Models.UserData.UserDataWithNote()
                {
                    ID            = _tUserDerivedNote != null ? _tUserDerivedNote.ID : -1,
                    ParentId      = _userNarrative.ID,
                    ProviderID    = _userNarrative.ProviderID,
                    StartDateTime = _userNarrative.StartDateTime,
                    EndDateTime   = _userNarrative.EndDateTime,
                    Note          = _tUserDerivedNote != null ? _tUserDerivedNote.Note : string.Empty
                };
                #endregion
                break;

            case "Prescriptions":
                #region Prescriptions
                tUserPrescription _userPrescription = await db.tUserPrescriptions.FindAsync(categoryid);

                _tUserDerivedNote = db.tUserDerivedNotes.FirstOrDefault(a => a.fkObjectID == _userPrescription.ObjectID);
                _retval           = new Models.UserData.UserDataWithNote()
                {
                    ID                 = _tUserDerivedNote != null ? _tUserDerivedNote.ID : -1,
                    ParentId           = _userPrescription.ID,
                    ProviderID         = _userPrescription.ProviderID,
                    MedFormID          = _userPrescription.MedFormID,
                    FrequencyUOMID     = _userPrescription.FrequencyUOMID,
                    StrengthUOMID      = _userPrescription.StrengthUOMID,
                    RouteID            = _userPrescription.RouteID,
                    PharmacyID         = _userPrescription.PharmacyID,
                    Name               = _userPrescription.Name,
                    Instructions       = _userPrescription.Instructions,
                    ProductName        = _userPrescription.ProductName,
                    BrandName          = _userPrescription.BrandName,
                    DosageText         = _userPrescription.DosageText,
                    DosageValue        = _userPrescription.DosageValue,
                    FrequencyValue     = _userPrescription.FrequencyValue,
                    StrengthValue      = _userPrescription.StrengthValue,
                    RefillsRemaining   = _userPrescription.RefillsRemaining,
                    RefillsTotal       = _userPrescription.RefillsTotal,
                    ExpirationDateTime = _userPrescription.ExpirationDateTime,
                    StartDateTime      = _userPrescription.StartDateTime,
                    EndDateTime        = _userPrescription.EndDateTime,
                    Note               = _tUserDerivedNote != null ? _tUserDerivedNote.Note : string.Empty
                };
                #endregion
                break;

            case "Problems":
                #region Problems
                tUserProblem _userProblem = await db.tUserProblems.FindAsync(categoryid);

                _tUserDerivedNote = db.tUserDerivedNotes.FirstOrDefault(a => a.fkObjectID == _userProblem.ObjectID);
                _retval           = new Models.UserData.UserDataWithNote()
                {
                    ID            = _tUserDerivedNote != null ? _tUserDerivedNote.ID : -1,
                    Name          = _userProblem.Name,
                    ParentId      = _userProblem.ID,
                    StartDateTime = _userProblem.StartDateTime,
                    EndDateTime   = _userProblem.EndDateTime,
                    Note          = _tUserDerivedNote != null ? _tUserDerivedNote.Note : string.Empty
                };
                #endregion
                break;

            case "Procedures":
                #region Procedures
                tUserProcedure _userProcedure = await db.tUserProcedures.FindAsync(categoryid);

                _tUserDerivedNote = db.tUserDerivedNotes.FirstOrDefault(a => a.fkObjectID == _userProcedure.ObjectID);
                _retval           = new Models.UserData.UserDataWithNote()
                {
                    ID       = _tUserDerivedNote != null ? _tUserDerivedNote.ID : -1,
                    Name     = _userProcedure.Name,
                    ParentId = _userProcedure.ID,
                    PerformingOrganizationID = _userProcedure.PerformingOrganizationID,
                    DeviceID      = _userProcedure.DeviceID,
                    SpecimenID    = _userProcedure.SpecimenID,
                    StartDateTime = _userProcedure.StartDateTime,
                    EndDateTime   = _userProcedure.EndDateTime,
                    Note          = _tUserDerivedNote != null ? _tUserDerivedNote.Note : string.Empty
                };
                #endregion
                break;

            case "Test Results":
                #region Test Results
                tUserTestResult _userTestResult = await db.tUserTestResults.FindAsync(categoryid);

                _tUserDerivedNote = db.tUserDerivedNotes.FirstOrDefault(a => a.fkObjectID == _userTestResult.ObjectID);
                _retval           = new Models.UserData.UserDataWithNote()
                {
                    ID             = _tUserDerivedNote != null ? _tUserDerivedNote.ID : -1,
                    Name           = _userTestResult.Name,
                    Comments       = _userTestResult.Comments,
                    Narrative      = _userTestResult.Narrative,
                    Impression     = _userTestResult.Impression,
                    Transcriptions = _userTestResult.Transcriptions,
                    ParentId       = _userTestResult.ID,
                    ProviderID     = _userTestResult.OrderingProviderID,
                    StatusID       = _userTestResult.StatusID,
                    ResultDateTime = _userTestResult.ResultDateTime,
                    Note           = _tUserDerivedNote != null ? _tUserDerivedNote.Note : string.Empty
                };
                #endregion
                break;

            case "Vitals":
                #region Test Results
                tUserVital _userVital = await db.tUserVitals.FindAsync(categoryid);

                _tUserDerivedNote = db.tUserDerivedNotes.FirstOrDefault(a => a.fkObjectID == _userVital.ObjectID);
                _retval           = new Models.UserData.UserDataWithNote()
                {
                    ID             = _tUserDerivedNote != null ? _tUserDerivedNote.ID : -1,
                    Name           = _userVital.Name,
                    Value          = _userVital.Value,
                    ParentId       = _userVital.ID,
                    ProviderID     = _userVital.ProviderID,
                    UOMID          = _userVital.UOMID,
                    ResultDateTime = _userVital.ResultDateTime,
                    Note           = _tUserDerivedNote != null ? _tUserDerivedNote.Note : string.Empty
                };
                #endregion
                break;

            default:
                break;
            }
            return(Ok(_retval));
        }