Esempio n. 1
0
class ExamSchema(ma.ModelSchema):
    class Meta:
        model = Exam
        jit = toastedmarshmallow.Jit

    booking_id = fields.Int()
    deleted_date = fields.Str()
    event_id = fields.Str()
    exam_id = fields.Int(dump_only=True)
    exam_method = fields.Str()
    exam_name = fields.Str()
    exam_received = fields.Int()
    exam_received_date = fields.DateTime(allow_none=True)
    exam_type_id = fields.Int()
    examinee_name = fields.Str()
    expiry_date = fields.DateTime()
    notes = fields.Str(allow_none=True)
    number_of_students = fields.Int()
    office_id = fields.Int()
    session_number = fields.Int()
    exam_returned_date = fields.Str(allow_none=True)
    exam_returned_tracking_number = fields.String(allow_none=True)
    exam_written_ind = fields.Int()
    offsite_location = fields.String()

    booking = fields.Nested(BookingSchema())
    exam_type = fields.Nested(ExamTypeSchema())
    office = fields.Nested(OfficeSchema(exclude=("csrs", )))
Esempio n. 2
0
class CsrSelf(Resource):

    csr_schema = CSRSchema()
    citizen_schema = CitizenSchema(many=True)
    exam_schema = ExamSchema(many=True)
    exam_type_schema = ExamTypeSchema()

    @oidc.accept_token(require_token=True)
    def get(self):
        try:
            csr = CSR.find_by_username(g.oidc_token_info['username'])

            if not csr:
                return {'Message': 'User Not Found'}, 404

            db.session.add(csr)
            active_sr_state = SRState.get_state_by_name("Active")
            today = datetime.now()

            active_citizens = Citizen.query \
                .join(Citizen.service_reqs) \
                .filter_by(sr_state_id=active_sr_state.sr_state_id) \
                .join(ServiceReq.periods) \
                .filter_by(csr_id=csr.csr_id) \
                .filter(Period.time_end.is_(None))

            individual_exams = Exam.query \
                .filter_by(office_id=csr.office_id) \
                .filter(Exam.exam_returned_date.is_(None),
                        Exam.expiry_date <= today,
                        Exam.deleted_date.is_(None)) \
                .join(ExamType, Exam.exam_type_id == ExamType.exam_type_id) \
                .filter(ExamType.group_exam_ind == 0).count()

            group_exams = Exam.query \
                .filter_by(office_id=csr.office_id) \
                .filter(Exam.deleted_date.is_(None)) \
                .join(ExamType, Exam.exam_type_id == ExamType.exam_type_id) \
                .filter(ExamType.group_exam_ind == 1) \
                .join(Booking, Exam.booking_id == Booking.booking_id) \
                .filter(Booking.invigilator_id.is_(None))\
                .filter(Booking.sbc_staff_invigilated == 0).count()

            result = self.csr_schema.dump(csr)
            active_citizens = self.citizen_schema.dump(active_citizens)

            return {
                'csr': result.data,
                'individual_exams': individual_exams,
                'group_exams': group_exams,
                'active_citizens': active_citizens.data,
                'errors': result.errors
            }

        except exc.SQLAlchemyError as e:
            print(e)
            return {'message': 'API is down'}, 500
Esempio n. 3
0
class ExamSchema(ma.SQLAlchemySchema):

    class Meta:
        model = Exam
        include_relationships = True
        load_instance = True
        jit = toastedmarshmallow.Jit

    booking_id = fields.Int(allow_none=True)
    deleted_date = fields.Str(allow_none=True)
    event_id = fields.Str(allow_none=True)
    exam_destroyed_date = fields.Str(allow_none=True)
    exam_id = fields.Int(dump_only=True)
    exam_method = fields.Str()
    exam_name = fields.Str()
    exam_received = fields.Int()
    exam_received_date = fields.DateTime(allow_none=True)
    exam_type_id = fields.Int()
    examinee_name = fields.Str(allow_none=True)
    examinee_phone = fields.Str(allow_none=True)
    examinee_email = fields.Str(allow_none=True)
    expiry_date = fields.DateTime(allow_none=True)
    notes = fields.Str(allow_none=True)
    number_of_students = fields.Int(allow_none=True)
    office_id = fields.Int()
    invigilator_id = fields.Int(allow_none=True)
    session_number = fields.Int(allow_none=True)
    exam_returned_ind = fields.Int()
    exam_returned_date = fields.Str(allow_none=True)
    exam_returned_tracking_number = fields.Str(allow_none=True)
    exam_written_ind = fields.Int()
    upload_received_ind = fields.Int(allow_none=True)
    offsite_location = fields.Str(allow_none=True)
    sbc_managed_ind = fields.Int(allow_none=True)
    receipt = fields.Str(allow_none=True)
    receipt_number = fields.Str()
    fees = fields.Str()
    payee_ind = fields.Int(allow_none=True)
    receipt_sent_ind = fields.Int(allow_none=True)
    payee_name = fields.Str(allow_none=True)
    payee_email = fields.Str(allow_none=True)
    payee_phone = fields.Str(allow_none=True)
    bcmp_job_id = fields.Str(allow_none=True)
    is_pesticide = fields.Int(allow_none=True)
    candidates_list = fields.Nested(CandidateSchema)

    booking = fields.Nested(BookingSchema())
    exam_type = fields.Nested(ExamTypeSchema())
    invigilator = fields.Nested(InvigilatorSchema())
    office = fields.Nested(OfficeSchema(only=('appointments_enabled_ind', 'exams_enabled_ind', 'office_id',
                                              'office_name', 'office_number', 'timezone')))
Esempio n. 4
0
class ExamTypeList(Resource):

    exam_type_schema = ExamTypeSchema(many=True)

    @oidc.accept_token(require_token=True)
    def get(self):

        try:
            exam_types = ExamType.query.all()
            result = self.exam_type_schema.dump(exam_types)
            return {'exam_types': result.data, 'errors': result.errors}, 200

        except exc.SQLAlchemyError as error:
            logging.error(error, exc_info=True)
            return {'message': 'API is down'}, 500
class ExamTypeList(Resource):

    exam_type_schema = ExamTypeSchema(many=True)

    @oidc.accept_token(require_token=True)
    @has_any_role(roles=[Role.internal_user.value])
    def get(self):

        try:
            exam_types = ExamType.query.order_by(asc(ExamType.exam_type_name))
            result = self.exam_type_schema.dump(exam_types)
            return {'exam_types': result.data, 'errors': result.errors}, 200

        except exc.SQLAlchemyError as error:
            logging.error(error, exc_info=True)
            return {'message': 'API is down'}, 500
class ExamTypeList(Resource):

    exam_type_schema = ExamTypeSchema(many=True)

    @jwt.has_one_of_roles([Role.internal_user.value])
    def get(self):

        try:
            exam_types = ExamType.query.order_by(asc(ExamType.exam_type_name))
            result = self.exam_type_schema.dump(exam_types)
            return {
                'exam_types': result,
                'errors': self.exam_type_schema.validate(exam_types)
            }, 200

        except exc.SQLAlchemyError as error:
            logging.error(error, exc_info=True)
            return {'message': 'API is down'}, 500
Esempio n. 7
0
class CsrSelf(Resource):

    csr_schema = CSRSchema()
    citizen_schema = CitizenSchema(many=True)
    exam_schema = ExamSchema(many=True)
    exam_type_schema = ExamTypeSchema()
    timezone = pytz.timezone("US/Pacific")
    back_office_display = application.config['BACK_OFFICE_DISPLAY']
    recurring_feature_flag = application.config['RECURRING_FEATURE_FLAG']

    @oidc.accept_token(require_token=True)
    @api_call_with_retry
    def get(self):
        try:
            csr = CSR.find_by_username(g.oidc_token_info['username'])

            if not csr:
                return {'Message': 'User Not Found'}, 404

            db.session.add(csr)
            active_sr_state = SRState.get_state_by_name("Active")
            today = datetime.now()
            start_date = self.timezone.localize(today)

            active_citizens = Citizen.query \
                .join(Citizen.service_reqs) \
                .filter_by(sr_state_id=active_sr_state.sr_state_id) \
                .join(ServiceReq.periods) \
                .filter_by(csr_id=csr.csr_id) \
                .filter(Period.time_end.is_(None))

            individual_exams = Exam.query \
                .filter_by(office_id=csr.office_id) \
                .filter(Exam.exam_returned_date.is_(None),
                        Exam.expiry_date <= today,
                        Exam.deleted_date.is_(None)) \
                .join(ExamType, Exam.exam_type_id == ExamType.exam_type_id) \
                .filter(ExamType.group_exam_ind == 0).count()

            individual_exams_past_schedule = Exam.query \
                .join(Booking, Exam.booking_id == Booking.booking_id)\
                .filter(Booking.start_time < start_date)\
                .filter_by(office_id=csr.office_id) \
                .join(ExamType, Exam.exam_type_id == ExamType.exam_type_id) \
                .filter(ExamType.group_exam_ind == 0).count()

            group_exams = Exam.query \
                .filter_by(office_id=csr.office_id) \
                .filter(Exam.deleted_date.is_(None)) \
                .join(ExamType, Exam.exam_type_id == ExamType.exam_type_id) \
                .filter(ExamType.group_exam_ind == 1) \
                .join(Booking, Exam.booking_id == Booking.booking_id) \
                .filter(Booking.sbc_staff_invigilated == 0).count()
                #.filter(Booking.invigilator_id.is_(None))\ TODO: Update this plz

            group_attention = Exam.query \
                .filter_by(office_id=csr.office_id)\
                .filter(Exam.deleted_date.is_(None))\
                .filter(Exam.exam_returned_date.is_(None))\
                .join(ExamType, Exam.exam_type_id == ExamType.exam_type_id)\
                .filter(ExamType.group_exam_ind == 1)\
                .join(Booking, Exam.booking_id == Booking.booking_id)\
                .filter(Booking.start_time < start_date).count()

            if group_attention > 0 and individual_exams > 0:
                group_attention += individual_exams

            result = self.csr_schema.dump(csr)
            active_citizens = self.citizen_schema.dump(active_citizens)

            return {'csr': result.data,
                    'individual_exams': individual_exams,
                    'individual_exams_past_schedule': individual_exams_past_schedule,
                    'group_exams': group_exams,
                    'group_individual_attention': group_attention,
                    'active_citizens': active_citizens.data,
                    'back_office_display': self.back_office_display,
                    'recurring_feature_flag': self.recurring_feature_flag,
                    'errors': result.errors}

        except exc.SQLAlchemyError as e:
            print(e)
            return {'message': 'API is down'}, 500
Esempio n. 8
0
class CsrSelf(Resource):

    csr_schema = CSRSchema()
    citizen_schema = CitizenSchema(many=True)
    exam_schema = ExamSchema(many=True)
    exam_type_schema = ExamTypeSchema()
    timezone = pytz.timezone("US/Pacific")
    back_office_display = application.config['BACK_OFFICE_DISPLAY']
    recurring_feature_flag = application.config['RECURRING_FEATURE_FLAG']

    @oidc.accept_token(require_token=True)
    @api_call_with_retry
    def get(self):
        try:
            csr = CSR.find_by_username(g.oidc_token_info['username'])

            if not csr:
                return {'Message': 'User Not Found'}, 404

            db.session.add(csr)
            active_sr_state = SRState.get_state_by_name("Active")
            today = datetime.now()
            start_date = self.timezone.localize(today)

            active_citizens = Citizen.query \
                .join(Citizen.service_reqs) \
                .filter_by(sr_state_id=active_sr_state.sr_state_id) \
                .join(ServiceReq.periods) \
                .filter_by(csr_id=csr.csr_id) \
                .filter(Period.time_end.is_(None))

            #   Get a list of all current exams for the office.
            office_exams = Exam.query \
                .filter(Exam.office_id == csr.office_id, \
                        Exam.exam_returned_date.is_(None), \
                        Exam.deleted_date.is_(None)) \
                .join(ExamType, Exam.exam_type_id == ExamType.exam_type_id) \
                .outerjoin(Booking, Exam.booking_id == Booking.booking_id) \
                .outerjoin(Booking.booking_invigilators, Booking.booking_id == Booking.booking_invigilators.c.invigilator_id) \
                .all()

            #   Default condition ... attention is not needed for any exam.
            attention_needed = False

            #   Check for attention needed, individual exam.
            individual = []
            for exam in office_exams:

                if exam.exam_type.group_exam_ind == 0:
                    if exam.booking is not None:
                        attention_needed = attention_needed or exam.booking.start_time < start_date
                    if exam.expiry_date is not None:
                        attention_needed = attention_needed or exam.expiry_date < start_date
                    if exam.exam_returned_date is not None:
                        attention_needed = False
                    if attention_needed:
                        individual.append(exam)


            #   Only do further checks if attention not already needed.
            group = []
            if not attention_needed:
                for exam in office_exams:
                    if exam.exam_type.group_exam_ind == 1:
                        attention_needed = attention_needed or exam.booking.start_time < start_date
                        if exam.expiry_date is not None:
                            attention_needed = attention_needed or exam.expiry_date < start_date
                        if exam.booking is not None and exam.number_of_students is not None:
                            attention_needed = attention_needed or exam.booking.start_time < start_date
                            attention_needed = attention_needed or (len(exam.booking.invigilators) < 1
                                                                    and exam.number_of_students < 25)
                            attention_needed = attention_needed or (len(exam.booking.invigilators) < 2
                                                                    and exam.number_of_students > 24)
                        if exam.exam_returned_date is not None:
                            attention_needed = False
                        if attention_needed:
                            group.append(exam)

            result = self.csr_schema.dump(csr)
            active_citizens = self.citizen_schema.dump(active_citizens)

            return {'csr': result.data,
                    'attention_needed': attention_needed,
                    'active_citizens': active_citizens.data,
                    'back_office_display': self.back_office_display,
                    'recurring_feature_flag': self.recurring_feature_flag,
                    'errors': result.errors}

        except exc.SQLAlchemyError as e:
            print(e)
            return {'message': 'API is down'}, 500
Esempio n. 9
0
class CsrSelf(Resource):

    csr_schema = CSRSchema()
    citizen_schema = CitizenSchema(many=True)
    exam_schema = ExamSchema(many=True)
    exam_type_schema = ExamTypeSchema()
    timezone = pytz.timezone("US/Pacific")
    back_office_display = application.config['BACK_OFFICE_DISPLAY']
    recurring_feature_flag = application.config['RECURRING_FEATURE_FLAG']

    @api_call_with_retry
    @jwt.has_one_of_roles([Role.internal_user.value])
    def get(self):
        try:
            # print('====> ATTENTION NEEDED')
            csr = CSR.find_by_username(g.jwt_oidc_token_info['username'])

            if not csr:
                return {'Message': 'User Not Found'}, 404

            db.session.add(csr)
            active_sr_state = SRState.get_state_by_name("Active")
            today = datetime.now()
            start_date = self.timezone.localize(today).date()
            # print('====> ATTENTION NEEDED==>start_Date',start_date)

            active_citizens = Citizen.query \
                .join(Citizen.service_reqs) \
                .filter_by(sr_state_id=active_sr_state.sr_state_id) \
                .join(ServiceReq.periods) \
                .filter_by(csr_id=csr.csr_id) \
                .filter(Period.time_end.is_(None))

            #   Get a list of all current exams for the office.
            office_exams = Exam.query \
                .filter(Exam.office_id == csr.office_id, \
                        Exam.exam_returned_date.is_(None), \
                        Exam.deleted_date.is_(None)) \
                .join(ExamType, Exam.exam_type_id == ExamType.exam_type_id) \
                .outerjoin(Booking, Exam.booking_id == Booking.booking_id) \
                .outerjoin(Booking.booking_invigilators, Booking.booking_id == Booking.booking_invigilators.c.invigilator_id) \
                .all()

            #   Default condition ... attention is not needed for any exam.
            attention_needed = False

            #   Check for attention needed, individual exam.
            individual = []
            for exam in office_exams:

                if exam.exam_type.group_exam_ind == 0:
                    # print('====> INDIVIDUAL EXAM CHECKS',exam.exam_name)
                    if exam.booking is not None:
                        # print('====> EXAM BOOKING IS NOT NONE')
                        # print('====> EXAM.BOOKING==>start_Date', start_date)
                        # print('====> EXAM.BOOKING==>exam.booking.start_time', exam.booking.start_time)
                        attention_needed = attention_needed or exam.booking.start_time.date(
                        ) < start_date
                        # print('====> ATTENTION NEEDED',attention_needed)
                    if exam.expiry_date is not None:
                        # print('====> EXPIRY IS NOT NONE')
                        # print('====> EXAM.BOOKING==>start_Date', start_date)
                        # print('====> EXAM.BOOKING==>exam.expiry_date', exam.expiry_date)
                        attention_needed = attention_needed or exam.expiry_date.date(
                        ) < start_date
                        # print('====> ATTENTION NEEDED', attention_needed)
                    if exam.is_pesticide and exam.exam_received_date is None:
                        # print('====> PESTICIDE AND NOT RECEIVED')
                        attention_needed = True
                        # print('====> ATTENTION NEEDED', attention_needed)
                    if exam.exam_returned_date is not None:
                        # print('====> exam.exam_returned_date')
                        attention_needed = False
                        # print('====> ATTENTION NEEDED', attention_needed)
                    if attention_needed:
                        individual.append(exam)

            #   Only do further checks if attention not already needed.
            group = []
            if not attention_needed:
                for exam in office_exams:
                    if exam.exam_type.group_exam_ind == 1:
                        # print('====> GROUP EXAM CHECKS',exam.exam_name)
                        if exam.booking is not None:
                            # print('====> ATTENTION NEEDED==>start_Date', start_date)
                            # print('====> EXAM.BOOKING==>exam.booking.start_time', exam.booking.start_time)
                            attention_needed = attention_needed or exam.booking.start_time.date(
                            ) < start_date
                            # print('====> ATTENTION NEEDED', attention_needed)
                        if exam.expiry_date is not None:
                            # print('====> EXPIRY IS NOT NONE')
                            # print('====> EXAM.BOOKING==>start_Date', start_date)
                            # print('====> EXAM.BOOKING==>exam.expiry_date', exam.expiry_date)
                            attention_needed = attention_needed or exam.expiry_date.date(
                            ) < start_date
                            # print('====> ATTENTION NEEDED', attention_needed)
                        if exam.booking is not None and exam.number_of_students is not None:
                            # print('====> exam.number_of_students IS NOT NONE')
                            # print('====> EXAM.BOOKING==>exam.number_of_students', exam.number_of_students)
                            # print('====> EXAM.BOOKING==>len(exam.booking.invigilators', len(exam.booking.invigilators))
                            attention_needed = attention_needed or (
                                len(exam.booking.invigilators) < 1
                                and exam.number_of_students < 25)
                            attention_needed = attention_needed or (
                                len(exam.booking.invigilators) < 2
                                and exam.number_of_students > 24)
                            # print('====> ATTENTION NEEDED', attention_needed)
                        if exam.is_pesticide and exam.exam_received_date is None:
                            # print('====> PESTICIDE AND NOT RECEIVED')
                            attention_needed = True
                            # print('====> ATTENTION NEEDED', attention_needed)
                        if exam.exam_returned_date is not None:
                            attention_needed = False
                            # print('====> ATTENTION NEEDED', attention_needed)
                        if attention_needed:
                            group.append(exam)

            result = self.csr_schema.dump(csr)
            active_citizens = self.citizen_schema.dump(active_citizens)

            return {
                'csr': result,
                'attention_needed': attention_needed,
                'active_citizens': active_citizens,
                'back_office_display': self.back_office_display,
                'recurring_feature_flag': self.recurring_feature_flag,
                'errors': self.csr_schema.validate(csr)
            }

        except exc.SQLAlchemyError as e:
            print(e)
            return {'message': 'API is down'}, 500