Exemplo 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);
        }
Exemplo 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);
        }
Exemplo n.º 3
0
 public void ApproveRequest(string therapistNRIC, short permission)
 {
     if (AccountBLL.IsPatient())
     {
         patientDAL.UpdateRequestApprove(AccountBLL.GetNRIC(), therapistNRIC, permission);
         logPermissionBLL.LogEvent(AccountBLL.GetNRIC(), "Approve Therapist Permissions", "Action on: " + therapistNRIC + ".");
     }
 }
Exemplo 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 + ".");
     }
 }
Exemplo n.º 5
0
 public void RevokePermissions(string therapistNRIC)
 {
     if (AccountBLL.IsPatient())
     {
         patientDAL.UpdateRequestRevoke(AccountBLL.GetNRIC(), therapistNRIC);
         logPermissionBLL.LogEvent(AccountBLL.GetNRIC(), "Revoke Therapist Permissions", "Action on: " + therapistNRIC + ".");
     }
 }
Exemplo n.º 6
0
 public void UpdateRecordDisable(long recordID)
 {
     if (AccountBLL.IsPatient())
     {
         recordDAL.UpdateRecordDisable(recordID, AccountBLL.GetNRIC());
         logRecordBLL.LogEvent(AccountBLL.GetNRIC(), "Update Record Status Disable", "Record ID: " + recordID + ".");
     }
 }
Exemplo n.º 7
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 + ".");
     }
 }
Exemplo n.º 8
0
        public List <Entity.Therapist> GetTherapists(string term)
        {
            if (AccountBLL.IsTherapist())
            {
                return(therapistDAL.RetrieveTherapists(term, AccountBLL.GetNRIC()));
            }

            return(null);
        }
Exemplo n.º 9
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 + ".");
                }
            }
        }
Exemplo n.º 10
0
        private bool HasNote(long noteID)
        {
            if (AccountBLL.IsTherapist())
            {
                return(therapistDAL.DoesNoteExist(noteID, AccountBLL.GetNRIC()));
            }

            return(false);
        }
Exemplo n.º 11
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 + ".");
     }
 }
Exemplo n.º 12
0
        public Entity.Therapist GetTherapistPermission(string therapistNRIC)
        {
            if (AccountBLL.IsPatient())
            {
                Entity.Therapist result = patientDAL.RetrieveTherapistPermission(therapistNRIC, AccountBLL.GetNRIC());
                logPermissionBLL.LogEvent(AccountBLL.GetNRIC(), "View Therapist Permissions", "Action on: " + therapistNRIC + ".");
                return(result);
            }

            return(null);
        }
Exemplo n.º 13
0
        public List <Entity.Therapist> GetDisallowedTherapists(int recordID, string term)
        {
            if (AccountBLL.IsPatient())
            {
                List <Entity.Therapist> result = patientDAL.RetrievePermissionsDisallow(recordID, term, AccountBLL.GetNRIC());
                logPermissionBLL.LogEvent(AccountBLL.GetNRIC(), "View Disallowed Therapists", "Term: \"" + term + "\", Record ID: " + recordID + ".");
                return(result);
            }

            return(null);
        }
Exemplo n.º 14
0
        public List <Entity.Therapist> GetCurrentTherapistsFineGrain(string term, long recordID)
        {
            if (AccountBLL.IsPatient())
            {
                List <Entity.Therapist> result = patientDAL.RetrieveCurrentTherapistsFineGrain(term, recordID, AccountBLL.GetNRIC());
                logPermissionBLL.LogEvent(AccountBLL.GetNRIC(), "View Record Fine Grain Permissions", "Term: \"" + term + "\", Record ID: " + recordID + ".");
                return(result);
            }

            return(null);
        }
Exemplo n.º 15
0
 public void UpdateRecordTherapistDisallow(long recordID, string therapistNRIC)
 {
     if (AccountBLL.IsPatient())
     {
         if (recordDAL.RetrieveRecordOwner(AccountBLL.GetNRIC(), recordID))
         {
             recordDAL.InsertRecordPermissionDisallow(recordID, therapistNRIC);
             logRecordBLL.LogEvent(AccountBLL.GetNRIC(), "Update Record Fine Grain Permission Disallow", "Action on: " + therapistNRIC + ", Record ID: " + recordID + ".");
         }
     }
 }
Exemplo n.º 16
0
 public void UpdateRecordTherapistDefault(long recordID, string therapistNRIC)
 {
     if (AccountBLL.IsPatient())
     {
         if (recordDAL.RetrieveRecordOwner(AccountBLL.GetNRIC(), recordID))
         {
             recordDAL.DeleteRecordPermission(recordID, therapistNRIC);
             logRecordBLL.LogEvent(AccountBLL.GetNRIC(), "Update Record Status Default", "Record ID: " + recordID + ".");
         }
     }
 }
Exemplo n.º 17
0
        public List <Record> GetRecords()
        {
            if (AccountBLL.IsPatient())
            {
                List <Record> result = recordDAL.RetrieveRecords(AccountBLL.GetNRIC());
                logRecordBLL.LogEvent(AccountBLL.GetNRIC(), "View Records", "Self.");
                return(result);
            }

            return(null);
        }
Exemplo n.º 18
0
        public List <Entity.Therapist> GetCurrentTherapists(string term)
        {
            if (AccountBLL.IsPatient())
            {
                List <Entity.Therapist> result = patientDAL.RetrieveCurrentTherapists(term, AccountBLL.GetNRIC());
                logAccountBLL.LogEvent(AccountBLL.GetNRIC(), "View Current Therapists", "Term: \"" + term + "\".");
                return(result);
            }

            return(null);
        }
Exemplo n.º 19
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);
        }
        public List <PatientDiagnosis> GetPatientDiagnoses(string id)
        {
            if (AccountBLL.IsResearcher())
            {
                List <PatientDiagnosis> result = dataDAL.RetrievePatientDiagnoses(id);
                logAccountBLL.LogEvent(AccountBLL.GetNRIC(), "View Patient Diagnoses", "View Patient Diagnoses");
                return(result);
            }

            return(null);
        }
Exemplo n.º 21
0
        public List <PatientDiagnosis> GetDiagnoses()
        {
            if (AccountBLL.IsPatient())
            {
                List <PatientDiagnosis> result = patientDAL.RetrievePatientDiagnoses(AccountBLL.GetNRIC());
                logAccountBLL.LogEvent(AccountBLL.GetNRIC(), "View Diagnoses", "Self.");

                return(result);
            }

            return(null);
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
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);
                }
            }
        }
        public List <Record> GetRecords(List <long> recordIDs)
        {
            if (AccountBLL.IsResearcher())
            {
                IEnumerable <Tuple <string, long> > recordIDsParameterized = from recordID in recordIDs
                                                                             select(new Tuple <string, long>("@" + recordID.ToString().Replace(" ", string.Empty), recordID));

                List <Record> result = dataDAL.RetrieveRecords(recordIDsParameterized);

                logRecordBLL.LogEvent(AccountBLL.GetNRIC(), "View Records", "Record IDs: " + string.Join(", ", recordIDs) + ".");
                return(result);
            }

            return(null);
        }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
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 + ".");
            }
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
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);
        }