def keep_one(subject_id=None, reference=None, qnr_ids=None): if qnr_ids is not None: items = session.query(QuestionnaireResponse).filter( QuestionnaireResponse.id.in_(qnr_ids)).order_by( QuestionnaireResponse.id) else: items = session.query(QuestionnaireResponse).filter( QuestionnaireResponse.subject_id == subject_id).filter( QuestionnaireResponse.document[( "questionnaire", "reference")].astext == reference).order_by( QuestionnaireResponse.id) keeper = None for i in items: if keeper is None: keeper = i print("Keep {}".format(keeper)) continue # Confirm results are the same if keeper.document != i.document: report = StringIO() dict_match(keeper.document, i.document, report) print(report.getvalue()) print("ERROR different docs; skipping QNRs {} and {}".format( keeper.id, i.id), file=sys.stderr) continue print(" deleting {}".format(i)) # direct delete of obj breaks due to fk w/ encounter session.execute( sa.text("DELETE FROM questionnaire_responses WHERE ID = :ID"). params(ID=i.id))
def keep_one(subject_id=None, reference=None, qnr_ids=None): if qnr_ids is not None: items = session.query(QuestionnaireResponse).filter( QuestionnaireResponse.id.in_(qnr_ids) ).order_by(QuestionnaireResponse.id) else: items = session.query(QuestionnaireResponse).filter( QuestionnaireResponse.subject_id == subject_id).filter( QuestionnaireResponse.document[ ("questionnaire", "reference") ].astext == reference).order_by(QuestionnaireResponse.id) keeper = None for i in items: if keeper is None: keeper = i print("Keep {}".format(keeper)) continue # Confirm results are the same if keeper.document != i.document: report = BytesIO() dict_match(keeper.document, i.document, report) print(report.getvalue()) print("ERROR different docs; skipping QNRs {} and {}".format( keeper.id, i.id), file=sys.stderr) continue print(" deleting {}".format(i)) # direct delete of obj breaks due to fk w/ encounter session.execute(sa.text( "DELETE FROM questionnaire_responses WHERE ID = :ID").params( ID=i.id))
def test_dict_match_not_match(): d1 = {'one': 1, 'two': True, 'three': {'nested zero': 0}} d2 = {'one': 1, 'two': False, 'three': {'nested zero': 0}} assert not dict_match(d1, d2, io.StringIO())