 
 commit;
 
-begin
-   devv5.vocabulary_pack.DeleteAmbiguousMAPSTO;
-end;
-
-commit;
-
---6 Working with replacement mappings
-
+--get duplicates for some reason 
+delete from concept_relationship_stage a where exists (select 1 from  (
+  select concept_code_1,concept_code_2,relationship_id, max (rowid) as rid from concept_relationship_stage group by concept_code_1,concept_code_2,relationship_id having count ( 1) >1 ) x 
+  where  a.concept_code_1= x.concept_code_1 and a.concept_code_2= x.concept_code_2 and a.relationship_id =x.relationship_id and x.rid = a.rowid)
+;  
+--6 Working with replacement mappings;
 BEGIN
    DEVV5.VOCABULARY_PACK.CheckReplacementMappings;
 END;
+/
 COMMIT;
 
 --7 Deprecate 'Maps to' mappings to deprecated and upgraded concepts
 BEGIN
    DEVV5.VOCABULARY_PACK.DeprecateWrongMAPSTO;
 END;
+/
 COMMIT;
 
 --8 Add mapping from deprecated to fresh concepts
 BEGIN
    DEVV5.VOCABULARY_PACK.AddFreshMAPSTO;
 END;
+/
 COMMIT;
 
 --9 Delete ambiguous 'Maps to' mappings
 BEGIN
    DEVV5.VOCABULARY_PACK.DeleteAmbiguousMAPSTO;
 END;
+/
 COMMIT;

* 3. Write all concept classes, whether existing or not from all possible combinations *
***************************************************************************************/

drop table complete_concept_stage cascade constraints purge;
create table complete_concept_stage nologging as
select 'XXX'||xxx_seq.nextval as concept_code, -- make sure xxx_seq is defined.
  c.*

      when others then null;
  end;
end;
/
-- generate OMOP codes for new concepts
insert into xxx_replace
select concept_code as xxx_code, 'OMOP'||omop_seq.nextval as omop_code
