optimize and refactor below code 
function generateUW(journey) {

  const fullUW = [];

  const uwQuestions = journey.personalDetails.declarations.uw || [];


  fullUW.push({
    questionid: 'HDFCPart4Section.Build.HeightQ',
    questionans: getHeightCode(journey.personalDetails.heightFeet, journey.personalDetails.heightInches)
  })

  fullUW.push({
    questionid: 'HDFCPart4Section.Build.WeightQ',
    questionans: getWeightCode(journey.personalDetails.weight)
  })

  if (journey.personalDetails.identyMark) {
    fullUW.push({
      questionid: "HDFCPart2Section.IdentificationMark",
      questionans: journey.personalDetails.identyMark
    })
  }

  if (journey.personalDetails.country) {
    fullUW.push({
      questionid: "HDFCPart2Section.NRICountryOfResidence",
      questionans: journey.personalDetails.country
    })
  }

  if (journey.personalDetails.occupation) {
    fullUW.push({
      questionid: "HDFCPart2Section.OccupationSection.OccupationDetails",
      questionans: journey.personalDetails.occupation === 'salaried' ? 'OCCT_SALR' : 'OCCT_SEBS'
    })
  }


  if (journey.personalDetails.declarations.designation) {
    fullUW.push({
      questionid: "HDFCPart2Section.OccupationSection.OccupationMainSection.Occupation",
      questionans: journey.personalDetails.declarations.designation
    })
  }

  // TODO: Need to make it dynamic
  fullUW.push(
    {
      questionid: "HDFCSMQSection.HDFCSMQOccupation.OccDetailsSection.OccDetailsHighRisk",
      questionans: "OHRD_NOT"
    })

  fullUW.push({
    questionid: "HDFCPart2Section.OccupationSection.OccupationMainSection.OccDetailsHighRisk",
    questionans: "OHRD_NOT"
  })

  if (journey.personalDetails.income) {
    fullUW.push({
      questionid: "HDFCPart2Section.OccupationSection.OccupationMainSection.OccAnnualIncome",
      questionans: journey.personalDetails.income
    })
  }

  if (journey.personalDetails.declarations.employerName) {
    fullUW.push({
      questionid: "HDFCPart2Section.OccupationSection.OccupationMainSection.OccPresentEmployer",
      questionans: journey.personalDetails.declarations.employerName
    })
  }

  if (journey.personalDetails.declarations.employerAddress) {
    fullUW.push({
      questionid: "HDFCPart2Section.OccupationSection.OccupationMainSection.OccOfficeAddress",
      questionans: journey.personalDetails.declarations.employerAddress
    })
  }

  if (journey.personalDetails.declarations.employerCity) {
    fullUW.push({
      questionid: "HDFCPart2Section.OccupationSection.OccupationMainSection.OccWorkPlaceCity",
      questionans: journey.personalDetails.declarations.employerCity
    })
  }

  if (journey.personalDetails.declarations.country) {
    fullUW.push({
      questionid: "HDFCPart2Section.OccupationSection.OccupationMainSection.OccCountry",
      questionans: COUNTRIES_TEBT_MAP[journey.personalDetails.declarations.country]
    })
  }

  if (journey.personalDetails.declarations.industryType) {
    fullUW.push({
      questionid: "HDFCPart2Section.OccupationSection.OccupationMainSection.OccIndustryPOS",
      questionans: INDUSTRY_TYPE_TEBT_MAP[journey.personalDetails.declarations.industryType] || (journey.personalDetails.occupation === 'Agriculture' ? INDUSTRY_TYPE_TEBT_MAP.Agriculture : INDUSTRY_TYPE_TEBT_MAP.Other)
    })
  }

  if (journey.personalDetails.eduction) {
    fullUW.push({
      questionid: "HDFCPart2Section.OccupationSection.OccupationStudentSection.OccStuStandard",
      questionans: journey.personalDetails.eduction
    })
  }

  if (journey.personalDetails.course) {
    fullUW.push({
      questionid: "HDFCPart2Section.OccupationSection.OccupationStudentSection.OccStudentCourse",
      questionans: journey.personalDetails.course
    })
  }

  if (journey.personalDetails.instituteName) {
    fullUW.push({
      questionid: "HDFCPart2Section.OccupationSection.OccupationStudentSection.OccStudentSchoolDetails",
      questionans: journey.personalDetails.instituteName
    })
  }

  if (journey.personalDetails.parentLifeCover) {
    fullUW.push({
      questionid: "HDFCPart2Section.OccupationSection.OccupationStudentSection.ParentsTotalLifeCover",
      questionans: journey.personalDetails.parentLifeCover
    })
  }

  for (const uwQuestion of uwQuestions) {
    const questionID = uwQuestion.questionID;
    const subQuestions = uwQuestion.subQuestion;
    const questionValue = uwQuestion.value;
    fullUW.push({
      questionid: questionID,
      questionans: questionValue
    },)

    if (subQuestions) {
      if (!['N', 'SAD_NOT'].includes(questionValue)) {
        for (const subQuestion of subQuestions) {

          if (Array.isArray(subQuestion)) {

            for (const subSubQuestion of subQuestion) {
              const subQuestionID = subSubQuestion.questionID;
              const subQuestionValue = subSubQuestion.value;
              fullUW.push({
                questionid: subQuestionID,
                questionans: subQuestionValue
              },)
            }

          } else {
            const subQuestionID = subQuestion.questionID;
            const subQuestionValue = subQuestion.value;
            fullUW.push({
              questionid: subQuestionID,
              questionans: subQuestionValue
            },)
          }
        }
      }



    }
  }

  // console.log('fullUW', JSON.stringify(fullUW))

  return fullUW;
}