def to_representation(self, instance):
        config = instance.resort.incident_template

        incident_json = get_incident_data(instance.incident_pk)

        ret = super(IncidentListSerializer, self).to_representation(instance)
        incident_status = ret['incident_status']
        ret.update(incident_json)
        data = get_extra_incident_info(config, incident_json,
                                       instance.incident_pk, 'list',
                                       self.context['data_key'])
        ret.update(data)

        ret.update(
            get_patient_info(instance.incident_pk, self.context['data_key']))

        try:
            ret['incident_status'] = incident_status_option(incident_status)
        except:
            ret['incident_status'] = ""

        if instance.resort.use_sequential_incident_id == 1 and instance.assigned_to.user_connected == 1:
            ret['incident_pk'] = instance.incident_sequence
        else:
            ret['incident_pk'] = instance.incident_pk

        notes = IncidentNotes.objects.filter(
            incident=instance).order_by('-note_date')
        ret['notes'] = IncidentNotesSerializer(notes,
                                               fields=('note_id', 'note_date',
                                                       'note', 'user'),
                                               many=True).data

        return replace_null(ret)
Exemplo n.º 2
0
    def to_representation(self, instance):
        final_representation = {}
        ret = super(UserResortSerializer, self).to_representation(instance)
        final_representation.update(ret['user'])
        final_representation.update({"resort": ret['resort']})

        try:
            devices = Devices.objects.filter(device_user=instance.user,
                                             device_state=0)
            devices_data = DeviceSerializer(devices,
                                            fields=('device_id', 'device_type',
                                                    'device_os'),
                                            many=True)
            final_representation['devices'] = devices_data.data
        except:
            final_representation['devices'] = []

        try:
            from apps.custom_user.utils import userrole_option
            final_representation['role_id'] = userrole_option(int(ret['role']))
        except:
            final_representation['role_id'] = ""

        try:
            final_representation['user_status'] = construct_options(
                USER_STATUS, ret['user_status'])
        except:
            final_representation['user_status'] = ""

        return replace_null(final_representation)
Exemplo n.º 3
0
    def to_representation(self, instance):
        ret = super(UserSerializer, self).to_representation(instance)

        try:
            ret['user_connected'] = construct_options(UserConnected,
                                                      ret['user_connected'])
        except:
            pass

        return replace_null(ret)
Exemplo n.º 4
0
    def to_representation(self, instance):
        ret = super(DeviceSerializer, self).to_representation(instance)

        device_state = ret.get('device_state')
        try:
            if device_state is not None:
                ret['device_state'] = construct_options(DeviceState, device_state)
        except:
            pass

        return replace_null(ret)
    def to_representation(self, instance):
        ret = super(LocationSerializer, self).to_representation(instance)
        location_status = ret.get('location_status')

        if location_status is not None:
            try:
                ret['location_status'] = construct_options(LOCATION_STATUS, location_status)
            except:
                pass

        return replace_null(ret)
    def to_representation(self, instance):
        domain = instance.domain_id.domain
        ret = super(ResortSerializer, self).to_representation(instance)

        dispatch_field_choice = ret.get('dispatch_field_choice')
        if dispatch_field_choice is not None:
            ret['dispatch_field_choice'] = ast.literal_eval(dispatch_field_choice)

        map_kml = ret.get('map_kml')
        image = ret.get('resort_logo')
        # default_unit_distance = ret.get('default_unit_distance')
        map_type = ret.get('map_type')
        print_on_device = ret.get('print_on_device')
        # default_unit_temp = ret.get('default_unit_temp')
        # default_unit_length = ret.get('default_unit_length')
        # default_unit_weight = ret.get('default_unit_weight')
        report_form = ret.get('report_form')
        unit_format = ret.get('unit_format')
        default_unit_paper = ret.get('default_unit_paper')
        domain_id = ret.get('domain_id')
        datetime_format = ret.get('datetime_format')
        try:
            # if default_unit_distance is not None:
            #     ret['default_unit_distance'] = construct_options(DistanceUnit, default_unit_distance)
            if map_type is not None:
                ret['map_type'] = construct_options(MapType, map_type)
            if print_on_device is not None:
                ret['print_on_device'] = construct_options(Choice, print_on_device)
            # if default_unit_temp is not None:
            #     ret['default_unit_temp'] = construct_options(TemperatureUnit, default_unit_temp)
            # if default_unit_length is not None:
            #     ret['default_unit_length'] = construct_options(LengthUnit, default_unit_length)
            # if default_unit_distance is not None:
            #     ret['default_unit_distance'] = construct_options(DistanceUnit, default_unit_distance)
            # if default_unit_weight is not None:
            #     ret['default_unit_weight'] = construct_options(WeightUnit, default_unit_weight)
            # if map_kml is not None and map_kml:
            #     ret['map_kml'] = settings.SCHEME + domain + '/static' + ret['map_kml'].split('static')[1]
            # if image is not None and image:
            #     ret['resort_logo'] = settings.SCHEME + domain + '/static' + ret['resort_logo'].split('static')[1]
            # if report_form is not None and report_form:
            #     ret['report_form'] = settings.SCHEME + domain + '/static' + ret['report_form'].split('static')[1]
            if unit_format is not None:
                ret['unit_format'] = construct_options(UnitType, unit_format)
            if default_unit_paper is not None:
                ret['default_unit_paper'] = construct_options(PaperSize, default_unit_paper)
            if datetime_format is not None:
                ret['datetime_format'] = construct_options(DATETIME_FORMAT, datetime_format)
            if domain_id is not None:
                ret['domain_id'] = domain
        except:
            pass
        return replace_null(ret)
Exemplo n.º 7
0
    def to_representation(self, instance):
        # Add assignment if its found
        assignment = StockAssignment.objects.filter(controlled_substance_stock=instance)

        if assignment:
            assignment_data = StockAssignmentSerializer(assignment[0], fields=('controlled_substance_stock_assignment_id',
                                                                            'dt_added', 'dt_used', 'user',
                                                                            'incident_id')).data
        else:
            assignment_data = {}


        ret = super(StockReportSerializer, self).to_representation(instance)
        ret['assignment'] = assignment_data
        return replace_null(ret)
Exemplo n.º 8
0
    def to_representation(self, instance):
        ret = super(StockAssignmentSerializer, self).to_representation(instance)
        controlled_substance_stock_assignment_status = ret.get('controlled_substance_stock_assignment_status')

        if controlled_substance_stock_assignment_status is not None:
            try:
                ret['controlled_substance_stock_assignment_status'] = construct_options(STOCK_ASSIGNMENT_STATUS,
                                                                                        controlled_substance_stock_assignment_status)
            except:
                pass

        try:
            if 'incident_id' in ret:
                ret['incident_pk'] = instance.incident_id.incident_sequence if instance.incident_id.resort.use_sequential_incident_id else instance.incident_id.incident_pk
        except:
            pass

        return replace_null(ret)
    def to_representation(self, instance):
        config = instance.resort.incident_template

        incident_json = get_incident_data(instance.incident_pk)

        ret = super(IncidentStatusReportSerializer,
                    self).to_representation(instance)

        data = get_extra_incident_info_status_report(config, incident_json)
        ret.update(data)

        try:
            ret['incident_status'] = incident_status_option_for_status_report(
                ret['incident_status'])
        except:
            ret['incident_status'] = ""

        if instance.resort.use_sequential_incident_id == 1 and instance.assigned_to.user_connected == 1:
            ret['incident_pk'] = instance.incident_sequence
        else:
            ret['incident_pk'] = instance.incident_pk

        return replace_null(ret)
    def to_representation(self, instance):
        ret = super(IncidentNotesSerializer, self).to_representation(instance)
        ret = replace_null(ret)
        return_data = {
            "field_52ca448dg94ja3": ret['note'],
            "field_52ca448dg94ja4": ret['note_date']
        }

        try:
            return_data.update({
                "field_52ca448dg94ja5": {
                    "key": str(ret['user']),
                    "value": instance.user.name
                }
            })
        except:
            pass

        try:
            return_data.update({"note_id": ret['note_id']})
        except:
            pass

        return return_data
 def to_representation(self, instance):
     ret = super(StatusHistorySerializer, self).to_representation(instance)
     return replace_null(ret)
 def to_representation(self, instance):
     from apps.custom_user.utils import userrole_option
     ret = super(UserResortListSerializer, self).to_representation(instance)
     ret['role'] = userrole_option(int(ret['role']))
     return replace_null(ret)
Exemplo n.º 13
0
 def to_representation(self, instance):
     ret = super(AssetSerializer, self).to_representation(instance)
     return replace_null(ret)
 def to_representation(self, instance):
     ret = super(RoutingCompanySerializer, self).to_representation(instance)
     return replace_null(ret)
Exemplo n.º 15
0
 def to_representation(self, instance):
     ret = super(ControlledSubstancesSerializer, self).to_representation(instance)
     return replace_null(ret)
 def to_representation(self, instance):
     ret = super(AreaSerializer, self).to_representation(instance)
     if 'location_count' in self.context:
         ret['location_count'] = ResortLocation.objects.filter(resort=self.context['resort'], area=instance,
                                                               location_status=LIVE).count()
     return replace_null(ret)
 def to_representation(self, instance):
     ret = super(IncidentTemplateExceptionsSerializer,
                 self).to_representation(instance)
     return replace_null(ret)
def migrate_encrypted_patient_info(apps, schema_editor):
    from apps.incidents.utils import dictfetchall
    from helper_functions import create_client

    Resort = apps.get_model("resorts", "Resort")

    client = create_client()
    response = client.generate_data_key(KeyId=settings.GLOBAL_KMS_KEY_ID, KeySpec='AES_256')
    cursor = connection.cursor()

    cursor.execute("""SELECT
  incident_patient_id,
  pgp_pub_decrypt(name, keys.privkey)     AS name,
  pgp_pub_decrypt(address, keys.privkey)  AS address,
  pgp_pub_decrypt(suburb, keys.privkey)   AS suburb,
  pgp_pub_decrypt(state, keys.privkey)    AS state,
  pgp_pub_decrypt(postcode, keys.privkey) AS postcode,
  pgp_pub_decrypt(phone, keys.privkey)    AS phone,
  pgp_pub_decrypt(email, keys.privkey)    AS email,
  pgp_pub_decrypt(dob, keys.privkey) AS dob
FROM incidents_patients
CROSS JOIN (SELECT dearmor(%s) As privkey) As keys;""", [settings.GPG_PRIVATE_KEY, ])

    data = dictfetchall(cursor)

    for each_data in data:
        each_data = replace_null(each_data)
        cursor.execute("""UPDATE incidents_patients SET
                            name = pgp_sym_encrypt(v.name, keys.datakey, 'compress-algo=1, cipher-algo=aes256'),
                         address = pgp_sym_encrypt(v.address, keys.datakey, 'compress-algo=1, cipher-algo=aes256'),
                         suburb = pgp_sym_encrypt(v.suburb, keys.datakey, 'compress-algo=1, cipher-algo=aes256'),
                         state = pgp_sym_encrypt(v.state,keys.datakey, 'compress-algo=1, cipher-algo=aes256'),
                         postcode = pgp_sym_encrypt(v.postcode, keys.datakey, 'compress-algo=1, cipher-algo=aes256'),
                         phone = pgp_sym_encrypt(v.phone,keys.datakey, 'compress-algo=1, cipher-algo=aes256'),
                         email = pgp_sym_encrypt(v.email, keys.datakey, 'compress-algo=1, cipher-algo=aes256'),
                         dob = pgp_sym_encrypt(v.dob, keys.datakey, 'compress-algo=1, cipher-algo=aes256')
                        FROM (
                          VALUES (
                           %s,
                           %s,
                           %s,
                           %s,
                           %s,
                           %s,
                           %s,
                           %s
                          )
                            ) AS v (
                           name,
                           address,
                           suburb,
                           state,
                           postcode,
                           phone,
                           email,
                           dob
                          )
CROSS JOIN ( SELECT %s::TEXT AS datakey) AS keys
WHERE incidents_patients.incident_patient_id = %s;""", [each_data['name'], each_data['address'],
                                                        each_data['suburb'], each_data['state'], each_data['postcode'],
                                                        each_data['phone'], each_data['email'],
                                                        each_data['dob'], base64.b64encode(response['Plaintext']),
                                                        each_data['incident_patient_id']])

    resorts = Resort.objects.all().update(enc_data_key=base64.b64encode(response['CiphertextBlob']))
    cursor.close()