class TipoUsoMdtoON extends BaseBusiness {

	public void remover(String siglaAfaTipoUsoMdto) throws BaseException {
		AfaTipoUsoMdto elemento = getAfaTipoUsoMdtoDAO().obterPorChavePrimaria(siglaAfaTipoUsoMdto);
		
		if(elemento != null){
			getTipoUsoMdtoRN().preDeleteTipoUsoMdto(elemento);
			
			//@PreRemove
			if (elemento.getAfaMedicamentos() != null && elemento.getAfaMedicamentos().size() > 0) {
				throw new BaseRuntimeException(BaseRuntimeExceptionCode.OFG_00005);
			}
		
			try {
				getAfaTipoUsoMdtoDAO().remover(elemento);
				getAfaTipoUsoMdtoDAO().flush();
			} catch (BaseRuntimeException e) {
				if ( ApplicationBusinessExceptionCode.OFG_00005.toString().equals(e.getCode().toString()) ) {
					throw new BaseException(e.getCode(), elemento.getDescricao(), "Medicamentos");
				} else {
					throw e;
				}
			}
		
			getTipoUsoMdtoRN().posDeleteTipoUsoMdto(elemento);
			
		}
		else{
			throw new ApplicationBusinessException (FarmaciaExceptionCode.REGISTRO_NULO_EXCLUSAO);
		}
	}

}