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

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> SoftDeleteUserEncounter(int id, int status)
        {
            tUserEncounter tUserEncounter = await db.tUserEncounters.FindAsync(id);

            if (tUserEncounter == null)
            {
                return(NotFound());
            }
            if (tUserEncounter.FollowUpInstructionID != null)
            {
                tUserInstruction _followIns = await db.tUserInstructions.FindAsync(tUserEncounter.FollowUpInstructionID);

                _followIns.SystemStatusID = status;
            }
            if (tUserEncounter.PatientInstructionID != null)
            {
                tUserInstruction _patientIns = await db.tUserInstructions.FindAsync(tUserEncounter.PatientInstructionID);

                _patientIns.SystemStatusID = status;
            }
            tUserEncounter.SystemStatusID = status;
            await db.SaveChangesAsync();

            return(Ok(tUserEncounter));
        }
        public async Task <IHttpActionResult> GettUserInstruction(int id)
        {
            tUserInstruction tUserInstruction = await db.tUserInstructions.FindAsync(id);

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

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

            db.tUserInstructions.Add(tUserInstruction);
            await db.SaveChangesAsync();

            return(Ok(tUserInstruction));
        }
        public async Task <IHttpActionResult> SoftDeleteUserInstruction(int id, int status)
        {
            tUserInstruction tUserInstruction = await db.tUserInstructions.FindAsync(id);

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

            return(Ok(tUserInstruction));
        }
        public async Task <IHttpActionResult> DeletetUserInstruction(int id)
        {
            tUserInstruction tUserInstruction = await db.tUserInstructions.FindAsync(id);

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

            db.tUserInstructions.Remove(tUserInstruction);
            await db.SaveChangesAsync();

            return(Ok(tUserInstruction));
        }
Exemple #7
0
        public IHttpActionResult Post(Instructions 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;
                    //Get source org via sourceserviceid [hack]
                    userSourceOrganization =
                        db.tSourceOrganizations.SingleOrDefault(x => x.SourceServiceID == sourceServiceObj.ID);

                    tUserInstruction userInstruction = null;
                    userInstruction = db.tUserInstructions
                                      .SingleOrDefault(x => x.SourceObjectID == value.Id);

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

                        userInstruction.Name = value.name;
                        userInstruction.Text = value.text;

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

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

                        userInstruction.Name = value.name;
                        userInstruction.Text = value.text;

                        userInstruction.StartDateTime       = value.dateTime;
                        userInstruction.LastUpdatedDateTime = DateTime.Now;
                    }

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

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

                                tXrefUserInstructionsCode userXrefInsCodes = null;
                                userXrefInsCodes = db.tXrefUserInstructionsCodes
                                                   .SingleOrDefault(x => x.CodeID == instructionCode.ID &&
                                                                    x.UserInstructionID == userInstruction.ID);

                                if (userXrefInsCodes == null)
                                {
                                    userXrefInsCodes = new tXrefUserInstructionsCode();
                                    userXrefInsCodes.tUserInstruction  = userInstruction;
                                    userXrefInsCodes.tCode             = instructionCode;
                                    userXrefInsCodes.CodeID            = instructionCode.ID;
                                    userXrefInsCodes.UserInstructionID = userInstruction.ID;

                                    userInstruction.tXrefUserInstructionsCodes.Add(userXrefInsCodes);
                                }
                            }
                        }
                    }

                    db.SaveChanges();

                    dbContextTransaction.Commit();

                    return(Ok(userInstruction));
                }
                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));
                }
            }
        }
Exemple #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));
        }