-- =====================================================
-- SIMPUS Database Schema - Odontogram Module Rollback
-- Version: 000019
-- Description: Rollback odontogram tables and types
-- =====================================================

-- Drop views
DROP VIEW IF EXISTS odontogram_complete;

-- Drop functions
DROP FUNCTION IF EXISTS get_next_dental_procedure_number(
    p_puskesmas_id UUID, 
    p_procedure_date DATE, 
    p_procedure_type VARCHAR(20)
);

-- Drop tables in reverse order
DROP TABLE IF EXISTS dental_procedure_sequences;
DROP TABLE IF EXISTS tooth_restorations;
DROP TABLE IF EXISTS tooth_conditions;
DROP TABLE IF EXISTS teeth;
DROP TABLE IF EXISTS odontograms;

-- Drop custom types
DROP TYPE IF EXISTS restoration_status;
DROP TYPE IF EXISTS restoration_type;
DROP TYPE IF EXISTS restoration_material;
DROP TYPE IF EXISTS dental_condition_code;
DROP TYPE IF EXISTS tooth_surface;
DROP TYPE IF EXISTS torus_type;
DROP TYPE IF EXISTS occlusion_type;