def to_client_json(self, model):
        result = model.asdict()
        # Participants that withdrew more than 48 hours ago should have fields other than
        # WITHDRAWN_PARTICIPANT_FIELDS cleared.
        if (model.withdrawalStatus == WithdrawalStatus.NO_USE
                and model.withdrawalTime <
                clock.CLOCK.now() - WITHDRAWN_PARTICIPANT_VISIBILITY_TIME):
            result = {k: result.get(k) for k in WITHDRAWN_PARTICIPANT_FIELDS}

        result['participantId'] = to_client_participant_id(model.participantId)
        biobank_id = result.get('biobankId')
        if biobank_id:
            result['biobankId'] = to_client_biobank_id(biobank_id)
        date_of_birth = result.get('dateOfBirth')
        if date_of_birth:
            result['ageRange'] = get_bucketed_age(date_of_birth,
                                                  clock.CLOCK.now())
        else:
            result['ageRange'] = UNSET
        format_json_hpo(result, self.hpo_dao, 'hpoId')
        _initialize_field_type_sets()
        for fieldname in _DATE_FIELDS:
            format_json_date(result, fieldname)
        for fieldname in _CODE_FIELDS:
            format_json_code(result, self.code_dao, fieldname)
        for fieldname in _ENUM_FIELDS:
            format_json_enum(result, fieldname)
        if (model.withdrawalStatus == WithdrawalStatus.NO_USE
                or model.suspensionStatus == SuspensionStatus.NO_CONTACT):
            result['recontactMethod'] = 'NO_CONTACT'
        # Strip None values.
        result = {k: v for k, v in result.iteritems() if v is not None}

        return result
 def to_client_json(self, model):
     client_json = {
         'participantId': to_client_participant_id(model.participantId),
         'hpoId': model.hpoId,
         'awardee': model.hpoId,
         'organization': model.organizationId,
         'siteId': model.siteId,
         'biobankId': to_client_biobank_id(model.biobankId),
         'lastModified': model.lastModified.isoformat(),
         'signUpTime': model.signUpTime.isoformat(),
         'providerLink': json.loads(model.providerLink),
         'withdrawalStatus': model.withdrawalStatus,
         'withdrawalTime': model.withdrawalTime,
         'suspensionStatus': model.suspensionStatus,
         'suspensionTime': model.suspensionTime
     }
     format_json_hpo(client_json, self.hpo_dao, 'hpoId'),
     format_json_org(client_json, self.organization_dao, 'organization'),
     format_json_site(client_json, self.site_dao, 'site'),
     format_json_enum(client_json, 'withdrawalStatus')
     format_json_enum(client_json, 'suspensionStatus')
     format_json_date(client_json, 'withdrawalTime')
     format_json_date(client_json, 'suspensionTime')
     client_json['awardee'] = client_json['hpoId']
     if 'siteId' in client_json:
         del client_json['siteId']
     return client_json
Example #3
0
    def __dict_to_mayo_xml__(self, order):
        root = etree.fromstring(self.payload_template)
        # A super lame way to do this, sorry ? :-)
        root[0][0].text = order['order']['collected']
        root[0][1].text = str(self.account)
        root[0][2].text = order['order']['number']
        root[0][3][0].text = order['order']['patient']['medical_record_number']
        root[0][3][1].text = order['order']['patient']['first_name']
        root[0][3][2].text = order['order']['patient']['last_name']
        root[0][3][3].text = order['order']['patient']['middle_name']
        root[0][3][4].text = order['order']['patient']['birth_date']
        root[0][3][5].text = order['order']['patient']['gender']
        root[0][3][6].text = order['order']['patient']['address1']
        root[0][3][7].text = order['order']['patient']['address2']
        root[0][3][8].text = order['order']['patient']['city']
        root[0][3][9].text = order['order']['patient']['state']
        root[0][3][10].text = order['order']['patient']['postal_code']
        root[0][3][11].text = order['order']['patient']['phone']
        root[0][3][12].text = order['order']['patient']['account_number']
        root[0][3][13].text = format_json_enum(order['order']['patient'],
                                               'race')
        root[0][3][14].text = order['order']['patient']['ethnic_group']
        root[0][4][0].text = order['order']['physician']['name']
        root[0][4][1].text = order['order']['physician']['phone']
        root[0][4][2].text = order['order']['physician']['npi']
        root[0][5].text = order['order']['report_notes']
        root[0][6][0][0].text = order['order']['tests']['test']['code']
        root[0][6][0][1].text = order['order']['tests']['test']['name']
        root[0][6][0][2].text = order['order']['tests']['test']['comments']
        root[0][7].text = order['order']['comments']

        request = etree.tostring(root)
        return request
 def to_client_json(self, model):
   client_json = {
       'participantId': to_client_participant_id(model.participantId),
       'biobankId': to_client_biobank_id(model.biobankId),
       'lastModified': model.lastModified.isoformat(),
       'signUpTime': model.signUpTime.isoformat(),
       'providerLink': json.loads(model.providerLink),
       'withdrawalStatus': model.withdrawalStatus,
       'withdrawalTime': model.withdrawalTime,
       'suspensionStatus': model.suspensionStatus,
       'suspensionTime': model.suspensionTime
   }
   format_json_enum(client_json, 'withdrawalStatus')
   format_json_enum(client_json, 'suspensionStatus')
   format_json_date(client_json, 'withdrawalTime')
   format_json_date(client_json, 'suspensionTime')
   return client_json
    def to_client_json(self, model, for_update=False):
        if for_update:
            result = dict()
            reduced_model = model['orders']['order']
            result['biobankStatus'] = reduced_model['status']
            result['barcode'] = reduced_model['reference_number']
            result['received'] = reduced_model['received']
            result['biobankOrderId'] = reduced_model['number']
            result['biobankTrackingId'] = reduced_model['patient'][
                'medical_record_number']
        else:
            result = model.asdict()
            result['orderStatus'] = format_json_enum(result, 'orderStatus')
            result['shipmentStatus'] = format_json_enum(
                result, 'shipmentStatus')
            format_json_code(result, self.code_dao, 'stateId')
            result['state'] = result['state'][-2:]  # Get the abbreviation
            del result['id']  # PK for model

        result = {k: v for k, v in result.items() if v is not None}
        if 'participantId' in result:
            result['participantId'] = to_client_participant_id(
                result['participantId'])
        return result
Example #6
0
    def to_client_json(self, model):
        result = model.asdict()
        # Participants that withdrew more than 48 hours ago should have fields other than
        # WITHDRAWN_PARTICIPANT_FIELDS cleared.
        if (model.withdrawalStatus == WithdrawalStatus.NO_USE and
            (model.withdrawalTime is None or model.withdrawalTime <
             clock.CLOCK.now() - WITHDRAWN_PARTICIPANT_VISIBILITY_TIME)):
            result = {k: result.get(k) for k in WITHDRAWN_PARTICIPANT_FIELDS}

        elif model.withdrawalStatus != WithdrawalStatus.NO_USE and \
          model.suspensionStatus == SuspensionStatus.NO_CONTACT:
            for i in SUSPENDED_PARTICIPANT_FIELDS:
                result[i] = UNSET

        result['participantId'] = to_client_participant_id(model.participantId)
        biobank_id = result.get('biobankId')
        if biobank_id:
            result['biobankId'] = to_client_biobank_id(biobank_id)
        date_of_birth = result.get('dateOfBirth')
        if date_of_birth:
            result['ageRange'] = get_bucketed_age(date_of_birth,
                                                  clock.CLOCK.now())
        else:
            result['ageRange'] = UNSET

        if result.get('primaryLanguage') is None:
            result['primaryLanguage'] = UNSET

        if 'organizationId' in result:
            result['organization'] = result['organizationId']
            del result['organizationId']
            format_json_org(result, self.organization_dao, 'organization')

        if result.get('genderIdentityId'):
            del result[
                'genderIdentityId']  # deprecated in favor of genderIdentity

        # Note: leaving for future use if we go back to using a relationship to PatientStatus table.
        # def format_patient_status_record(status_obj):
        #   status_dict = self.patient_status_dao.to_client_json(status_obj)
        #   return {
        #     'organization': status_dict['organization'],
        #     'status': status_dict['patient_status'],
        #   }
        # result['patientStatus'] = map(format_patient_status_record, model.patientStatus)
        result['patientStatus'] = model.patientStatus

        format_json_hpo(result, self.hpo_dao, 'hpoId')
        result['awardee'] = result['hpoId']
        _initialize_field_type_sets()
        for fieldname in _DATE_FIELDS:
            format_json_date(result, fieldname)
        for fieldname in _CODE_FIELDS:
            format_json_code(result, self.code_dao, fieldname)
        for fieldname in _ENUM_FIELDS:
            format_json_enum(result, fieldname)
        for fieldname in _SITE_FIELDS:
            format_json_site(result, self.site_dao, fieldname)
        if (model.withdrawalStatus == WithdrawalStatus.NO_USE
                or model.suspensionStatus == SuspensionStatus.NO_CONTACT):
            result['recontactMethod'] = 'NO_CONTACT'
        # Strip None values.
        result = {k: v for k, v in result.iteritems() if v is not None}

        return result