Esempio n. 1
0
        public List <Record> GetRecords(string patientNRIC, long noteID)
        {
            if (AccountBLL.IsTherapist())
            {
                List <Record>  records = recordDAL.RetrieveRecords(noteID, patientNRIC, AccountBLL.GetNRIC());
                Entity.Patient patient = new TherapistBLL().GetPatient(patientNRIC);

                List <Record> result = new List <Record>();
                foreach (Record record in records)
                {
                    if (!patient.hasPermissionsApproved(record))
                    {
                        Record newRecord = new Record();
                        newRecord.id     = record.id;
                        newRecord.title  = record.title;
                        newRecord.type   = record.type;
                        newRecord.status = record.status;
                        newRecord.recordPermissionStatus = record.recordPermissionStatus;
                        result.Add(newRecord);
                    }
                    else
                    {
                        record.permited = true;
                        result.Add(record);
                    }
                }

                logRecordBLL.LogEvent(AccountBLL.GetNRIC(), "View Records of Note", "Action on: " + patientNRIC + " , Note ID: " + noteID + ".");
                return(result);
            }

            return(null);
        }
Esempio n. 2
0
        public bool AddNote(Note note)
        {
            if (AccountBLL.IsTherapist())
            {
                note.therapist.nric = AccountBLL.GetNRIC();
                note.creator.nric   = AccountBLL.GetNRIC();

                // check if every record is valid
                RecordBLL recordBLL = new RecordBLL();

                foreach (Record record in note.records)
                {
                    Entity.Patient patient = GetPatientPermissions(record.patientNRIC);

                    if (patient.approvedTime == null || !recordBLL.VerifyRecord(record))
                    {
                        return(false);
                    }
                }

                therapistDAL.InsertNote(note);
                foreach (Record record in note.records)
                {
                    therapistDAL.InsertNoteRecord(note, record);
                }

                logAccountBLL.LogEvent(AccountBLL.GetNRIC(), "Add Note", "Note ID: " + note.id + ".");
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
 public void RescindPermissions(string patientNRIC)
 {
     if (AccountBLL.IsTherapist() && !patientNRIC.Equals(AccountBLL.GetNRIC()))
     {
         therapistDAL.UpdateRecordTypeRescind(patientNRIC, AccountBLL.GetNRIC());
         logPermissionBLL.LogEvent(AccountBLL.GetNRIC(), "Delete Request for Permissions", "Action on: " + patientNRIC + ".");
     }
 }
Esempio n. 4
0
 public void UpdateRequest(string patientNRIC, short permission)
 {
     if (AccountBLL.IsTherapist() && !patientNRIC.Equals(AccountBLL.GetNRIC()))
     {
         therapistDAL.UpdateRecordTypeRequest(patientNRIC, AccountBLL.GetNRIC(), permission);
         logPermissionBLL.LogEvent(AccountBLL.GetNRIC(), "Update Request for Permissions", "Action on: " + patientNRIC + ", Permissions: " + permission + ".");
     }
 }
Esempio n. 5
0
        public List <Entity.Therapist> GetTherapists(string term)
        {
            if (AccountBLL.IsTherapist())
            {
                return(therapistDAL.RetrieveTherapists(term, AccountBLL.GetNRIC()));
            }

            return(null);
        }
Esempio n. 6
0
        private bool HasNote(long noteID)
        {
            if (AccountBLL.IsTherapist())
            {
                return(therapistDAL.DoesNoteExist(noteID, AccountBLL.GetNRIC()));
            }

            return(false);
        }
Esempio n. 7
0
        //public void DeleteRecords(string nric)
        //{
        //    if (AccountBLL.IsAdministrator())
        //    {
        //        List<Record> records = recordDAL.RetrieveAssociatedRecords(nric);

        //        foreach (Record record in records)
        //        {
        //            // delete all record diagnosis first
        //            recordDAL.DeleteRecordDiagnosis(record.id);

        //            // delete all permissions
        //            recordDAL.DeleteRecordPermission(record.id);

        //            // delete record
        //            recordDAL.DeleteRecord(record.id);
        //        }
        //    }
        //}

        public bool VerifyRecord(Record record)
        {
            if (AccountBLL.IsTherapist() && recordDAL.RetrieveRecordExists(record.id, record.patientNRIC))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 8
0
        public void AddRecord(Record record)
        {
            if (AccountBLL.IsPatient() && record.patientNRIC.Equals(AccountBLL.GetNRIC()))
            {
                if (record.type.isContent)
                {
                    recordDAL.InsertContent(record, AccountBLL.GetNRIC());
                    logRecordBLL.LogEvent(AccountBLL.GetNRIC(), "Insert Record", "Action on: " + record.patientNRIC + ", Record ID: " + record.id + ".");
                }
                else if (!record.type.isContent)
                {
                    record.fileChecksum = record.GetMD5HashFromFile();

                    if (record.IsFileSafe())
                    {
                        recordDAL.InsertFile(record, AccountBLL.GetNRIC());
                    }
                    else
                    {
                        throw new Exception();
                    }

                    logRecordBLL.LogEvent(AccountBLL.GetNRIC(), "Insert Record", "Action on: " + record.patientNRIC + ", Record ID: " + record.id + ".");
                }
            }
            else if (AccountBLL.IsTherapist())
            {
                Entity.Patient patient = new TherapistBLL().GetPatientPermissions(record.patientNRIC);

                if (patient.permissionApproved == 0 || ((patient.permissionApproved & record.type.permissionFlag) == 0) ||
                    AccountBLL.GetNRIC().Equals(record.patientNRIC))
                {
                    return;
                }

                if (record.type.isContent)
                {
                    recordDAL.InsertContent(record, AccountBLL.GetNRIC());
                    logRecordBLL.LogEvent(AccountBLL.GetNRIC(), "Insert Record", "Action on: " + record.patientNRIC + ", Record ID: " + record.id + ".");
                }
                else if (!record.type.isContent)
                {
                    record.fileChecksum = record.GetMD5HashFromFile();

                    if (record.IsFileSafe())
                    {
                        recordDAL.InsertFile(record, AccountBLL.GetNRIC());
                    }
                    else
                    {
                        throw new Exception();
                    }

                    logRecordBLL.LogEvent(AccountBLL.GetNRIC(), "Insert Record", "Action on: " + record.patientNRIC + ", Record ID: " + record.id + ".");
                }
            }
        }
Esempio n. 9
0
 public void AddPatientDiagnosis(string patientNRIC, string code)
 {
     if (AccountBLL.IsTherapist() &&
         !patientNRIC.Equals(AccountBLL.GetNRIC()) &&
         therapistDAL.RetrievePatientPermission(patientNRIC, AccountBLL.GetNRIC()).approvedTime != null)
     {
         therapistDAL.InsertPatientDiagnosis(patientNRIC, AccountBLL.GetNRIC(), code);
         logAccountBLL.LogEvent(AccountBLL.GetNRIC(), "Add Patient Diagnosis", "Action on: " + patientNRIC + ", Diagnosis Code: " + code + ".");
     }
 }
Esempio n. 10
0
        public Entity.Patient GetPatientPermissions(string patientNRIC)
        {
            if (AccountBLL.IsTherapist() && !patientNRIC.Equals(AccountBLL.GetNRIC()))
            {
                Entity.Patient result = therapistDAL.RetrievePatientPermission(patientNRIC, AccountBLL.GetNRIC());
                logAccountBLL.LogEvent(AccountBLL.GetNRIC(), "View Patients Permission", "Action on: " + patientNRIC + ".");
                return(result);
            }

            return(null);
        }
Esempio n. 11
0
        public List <PatientDiagnosis> GetPatientDiagnoses(string patientNRIC, long id)
        {
            if (AccountBLL.IsTherapist() && !patientNRIC.Equals(AccountBLL.GetNRIC()) &&
                therapistDAL.RetrievePatientPermission(patientNRIC, AccountBLL.GetNRIC()).approvedTime != null)
            {
                List <PatientDiagnosis> result = therapistDAL.RetrievePatientDiagnoses(patientNRIC, AccountBLL.GetNRIC());
                logAccountBLL.LogEvent(AccountBLL.GetNRIC(), "View Patient Diagnoses", "Action on: " + patientNRIC + ".");
                return(result);
            }

            return(null);
        }
Esempio n. 12
0
        public void AddRecordDiagnosis(string patientNRIC, long recordID, string code)
        {
            if (AccountBLL.IsTherapist())
            {
                Record         record  = recordDAL.RetrieveRecord(recordID, AccountBLL.GetNRIC());
                Entity.Patient patient = new TherapistBLL().GetPatient(record.patientNRIC);

                if (record.patientNRIC.Equals(patientNRIC) && patient.hasPermissionsApproved(record))
                {
                    logRecordBLL.LogEvent(AccountBLL.GetNRIC(), "Insert Record Diagnoses", "Action on: " + patientNRIC + ", Record ID: " + recordID + ", Diagnosis Code: " + code + ".");

                    recordDAL.InsertRecordDiagnosis(AccountBLL.GetNRIC(), recordID, code);
                }
            }
        }
Esempio n. 13
0
        public Note GetNote(long noteID)
        {
            if (AccountBLL.IsTherapist())
            {
                Note note = therapistDAL.RetrieveNote(noteID, AccountBLL.GetNRIC());

                if (note.patient.approvedTime != null)
                {
                    note.patient = therapistDAL.RetrievePatientInformation(note.patient.nric, AccountBLL.GetNRIC());
                }

                logAccountBLL.LogEvent(AccountBLL.GetNRIC(), "View Note", "Note ID: " + noteID + ".");
                return(note);
            }

            return(null);
        }
Esempio n. 14
0
        public bool AcceptEmergencyPatient(string tokenID)
        {
            if (AccountBLL.IsTherapist())
            {
                string patientNRIC = therapistDAL.RetrieveEmergencyPatient(tokenID, AccountBLL.GetNRIC());

                if (string.IsNullOrEmpty(patientNRIC) || string.Equals(patientNRIC, AccountBLL.GetNRIC()))
                {
                    return(false);
                }

                therapistDAL.AcceptEmergencyTherapist(patientNRIC, AccountBLL.GetNRIC());

                return(true);
            }

            return(false);
        }
Esempio n. 15
0
        public List <RecordDiagnosis> GetRecordDiagnoses(long recordID)
        {
            if (AccountBLL.IsPatient())
            {
                return(recordDAL.RetrieveRecordDiagnoses(recordID, AccountBLL.GetNRIC()));
            }
            else if (AccountBLL.IsTherapist())
            {
                Record         record  = recordDAL.RetrieveRecord(recordID, AccountBLL.GetNRIC());
                Entity.Patient patient = new TherapistBLL().GetPatient(record.patientNRIC);

                if (patient.hasPermissionsApproved(record))
                {
                    List <RecordDiagnosis> result = recordDAL.RetrieveRecordDiagnoses(recordID, record.patientNRIC, AccountBLL.GetNRIC());
                    logRecordBLL.LogEvent(AccountBLL.GetNRIC(), "View Record Diagnoses", "Record ID: " + recordID + ".");
                    return(result);
                }
            }

            return(null);
        }
Esempio n. 16
0
        public List <Entity.Patient> GetCurrentPatients(string term)
        {
            if (AccountBLL.IsTherapist())
            {
                List <Entity.Patient> patients = therapistDAL.RetrieveCurrentPatients(term, AccountBLL.GetNRIC());

                foreach (Entity.Patient patient in patients)
                {
                    if (patient.approvedTime == null)
                    {
                        patient.firstName = string.Empty;
                        patient.lastName  = string.Empty;
                    }
                }

                logAccountBLL.LogEvent(AccountBLL.GetNRIC(), "View Current Patients", "Term: \"" + term + "\".");
                return(patients);
            }

            return(null);
        }
Esempio n. 17
0
        public void SendNote(long noteID, HashSet <string> therapistsNRIC)
        {
            if (AccountBLL.IsTherapist() && HasNote(noteID))
            {
                Note note = therapistDAL.RetrieveNote(noteID, AccountBLL.GetNRIC());
                note.records = new RecordBLL().GetRecords(note.patient.nric, note.id);

                foreach (string therapistNRIC in therapistsNRIC)
                {
                    note.therapist.nric = therapistNRIC;

                    therapistDAL.InsertNote(note);
                    foreach (Record record in note.records)
                    {
                        therapistDAL.InsertNoteRecord(note, record);
                    }
                }

                logAccountBLL.LogEvent(AccountBLL.GetNRIC(), "Send Note", "Sent to: " + therapistsNRIC + ", Note ID: " + note.id + ".");
            }
        }
Esempio n. 18
0
        public List <Diagnosis> GetDiagnoses(string term, string patientNRIC, List <RecordDiagnosis> recordDiagnoses)
        {
            if (AccountBLL.IsTherapist() &&
                !patientNRIC.Equals(AccountBLL.GetNRIC()) &&
                therapistDAL.RetrievePatientPermission(patientNRIC, AccountBLL.GetNRIC()).approvedTime != null)
            {
                List <Diagnosis> patientDiagnoses = therapistDAL.RetrievePatientCurrentDiagnoses(patientNRIC, AccountBLL.GetNRIC(), term);
                List <Diagnosis> result           = new List <Diagnosis>();

                foreach (Diagnosis diagnosis in patientDiagnoses)
                {
                    if (!recordDiagnoses.Any(x => x.diagnosis.code.Equals(diagnosis.code)))
                    {
                        result.Add(diagnosis);
                    }
                }
                return(result);
            }

            return(null);
        }
Esempio n. 19
0
        public List <Note> GetNotes(string term)
        {
            if (AccountBLL.IsTherapist())
            {
                List <Note> notes = therapistDAL.RetrieveNotes(term, AccountBLL.GetNRIC());

                foreach (Note note in notes)
                {
                    if (note.patient.approvedTime == null)
                    {
                        note.patient.firstName = string.Empty;
                        note.patient.lastName  = string.Empty;
                    }
                }

                logAccountBLL.LogEvent(AccountBLL.GetNRIC(), "View Notes", "Term: \"" + term + "\".");
                return(notes);
            }

            return(null);
        }
Esempio n. 20
0
        public Record GetRecord(long recordID)
        {
            if (AccountBLL.IsPatient())
            {
                return(recordDAL.RetrieveRecord(AccountBLL.GetNRIC(), recordID));
            }
            else if (AccountBLL.IsTherapist())
            {
                Record         record  = recordDAL.RetrieveRecord(recordID, AccountBLL.GetNRIC());
                Entity.Patient patient = new TherapistBLL().GetPatient(record.patientNRIC);

                if (patient.hasPermissionsApproved(record))
                {
                    record.permited = true;

                    logRecordBLL.LogEvent(AccountBLL.GetNRIC(), "View Record", "Record ID: " + recordID + ".");

                    return(record);
                }
            }

            return(null);
        }
Esempio n. 21
0
        public List <Entity.Patient> GetUnrequestedPatients(string term)
        {
            if (AccountBLL.IsTherapist())
            {
                List <Entity.Patient> accountsAllPatients     = therapistDAL.RetrieveAllPatients(term);
                List <Entity.Patient> accountsCurrentPatients = therapistDAL.RetrieveCurrentPatientsDelimited(AccountBLL.GetNRIC());

                // remove current user
                accountsAllPatients.RemoveAll(x => x.nric.Equals(AccountBLL.GetNRIC(), StringComparison.InvariantCultureIgnoreCase));

                foreach (Entity.Patient patients in accountsAllPatients)
                {
                    if (!accountsCurrentPatients.Any(x => x.nric.Equals(patients.nric)))
                    {
                        patients.acceptNewRequest = true;
                    }
                }

                logAccountBLL.LogEvent(AccountBLL.GetNRIC(), "View Unrequested Patients", "Term: \"" + term + "\".");
                return(accountsAllPatients);
            }

            return(null);
        }