private void updatePeripherals(
      DeviceConfig deviceConfig, List<MedicalTestType> medicalTestTypeList)
      throws NoSuchPeripheralConfigException, SystemException {

    debug("getting peripherals for deviceConfigId: " + deviceConfig.getDeviceConfigId());
    List<PeripheralConfig> peripherals =
        PeripheralConfigLocalServiceUtil.findByDeviceConfigId(deviceConfig.getDeviceConfigId());
    debug("found " + (peripherals == null ? 0 : peripherals.size()) + " peripherals");
    for (PeripheralConfig peripheral : peripherals) {
      debug("Deleting PeripheralConfig: " + peripheral);
      PeripheralConfigLocalServiceUtil.deletePeripheralConfig(peripheral);
    }
    for (MedicalTestType mtt : medicalTestTypeList) {
      debug("Creating PeripheralConfig for MedicalTestType: " + mtt.getNameCurrentValue());
      PeripheralConfig pc = createPeripheral(mtt.getMedicalTestTypeId());
      pc.setDeviceConfigId(deviceConfig.getDeviceConfigId());
      pc.setMedicalTestTypeId(mtt.getMedicalTestTypeId());
      // flag values for Primum to fill
      pc.setModel(mtt.getNameCurrentValue());
      pc.setPeripheralMAC(PrimumConstantsLocalServiceUtil.getDefaultPeripheralMAC());
      pc.setPeripheralPIN(PrimumConstantsLocalServiceUtil.getDefaultPeripheralPIN());
      pc = PeripheralConfigLocalServiceUtil.addPeripheralConfig(pc);
      debug("PeripheralConfig saved!");
    }
    debug("Peripherals updated!!");
  }
  private PeripheralConfig createPeripheral(long medicalTestTypeId) throws SystemException {

    debug("Creating a new peripheral");
    PeripheralConfig pc =
        PeripheralConfigLocalServiceUtil.createPeripheralConfig(
            CounterLocalServiceUtil.increment());
    pc.setNew(true);
    return pc;
  }