public void addGroupOwnership(StepsovcCase stepsovcCase) {
    Beneficiary beneficiary =
        allBeneficiaries.findBeneficiaryByCode(stepsovcCase.getBeneficiary_code());

    if (beneficiary != null) {
      commcareGateway.addGroupOwnership(
          populateBeneficiaryCase(stepsovcCase, beneficiary), stepsovcCase.getFacility_code());
    }
  }
  public void addUserOwnership(StepsovcCase stepsovcCase) {
    Beneficiary beneficiary =
        allBeneficiaries.findBeneficiaryByCode(stepsovcCase.getBeneficiary_code());
    Caregiver caregiver = allCaregivers.findCaregiverByCode(stepsovcCase.getCaregiver_code());

    if (beneficiary != null && caregiver != null) {
      commcareGateway.addUserOwnership(
          populateBeneficiaryCase(stepsovcCase, beneficiary), caregiver.getCgId());
    }
  }
  private CaseOwnershipInformation populateBeneficiaryCase(
      StepsovcCase stepsovcCase, Beneficiary beneficiary) {
    stepsovcCase.setCaregiver_code(beneficiary.getCaregiverCode());
    stepsovcCase.setCase_id(beneficiary.getCaseId());

    Caregiver caregiver = allCaregivers.findCaregiverByCode(beneficiary.getCaregiverCode());
    stepsovcCase.setCaregiver_name(caregiver.getFirstName());
    stepsovcCase.setUser_id(caregiver.getCgId());
    stepsovcCase.setOwner_id(caregiver.getCgId());

    return new BeneficiaryMapper().createOwnershipInfo(stepsovcCase);
  }
  public void createBeneficiary(StepsovcCase stepsovcCase) {
    logger.info("Handling beneficiary registration for " + stepsovcCase.getBeneficiary_name());

    Beneficiary oldBeneficiary =
        allBeneficiaries.findBeneficiaryByCode(stepsovcCase.getBeneficiary_code());
    if (oldBeneficiary == null) allBeneficiaries.add(new BeneficiaryMapper().map(stepsovcCase));
    else {
      logger.error(
          "Updating as Beneficiary already present in database, "
              + stepsovcCase.getBeneficiary_code());
      allBeneficiaries.remove(oldBeneficiary);
      allBeneficiaries.add(new BeneficiaryMapper().map(stepsovcCase));
    }
  }