Make the combination of patient ID and accession number unique.

This commit is contained in:
sunwen
2023-08-28 16:25:40 +08:00
parent abf576444c
commit 89ccd96278

View File

@@ -21,11 +21,11 @@
namespace namespace
{ {
const int ENDLINE_SPACE = 3; const int ENDLINE_SPACE = 3;
int queryValue(QSqlTableModel* model, int colID, const QVariant& var) int queryValue(QSqlTableModel* model, int aColIDIndex, const QVariant& aPatId, int aColAccessionNumberIndex, const QVariant& aAccessionNumber)
{ {
for (int i = 0; i < model->rowCount(); ++i) for (int i = 0; i < model->rowCount(); ++i)
{ {
if (model->data(model->index(i, colID)) == var) return i; if (model->data(model->index(i, aColIDIndex)) == aPatId && model->data(model->index(i, aColAccessionNumberIndex)) == aAccessionNumber) return i;
} }
return -1; return -1;
} }
@@ -189,10 +189,10 @@ bool EditPatientDialog::updateReferenceData()
bool isAdd = currentPatientUID.isEmpty(); bool isAdd = currentPatientUID.isEmpty();
if (isAdd) if (isAdd)
{ {
int ref_rowid = queryValue(model, 1, inf->ID); int ref_rowid = queryValue(model, 1, inf->ID, 2, inf->AccessionNumber);
if (ref_rowid >= 0) if (ref_rowid >= 0)
{ {
lbl_error->setText("The ID is already existed!"); lbl_error->setText("The ID and Accession number is already existed!");
lbl_error->setVisible(true); lbl_error->setVisible(true);
return false; return false;
} }
@@ -203,7 +203,7 @@ bool EditPatientDialog::updateReferenceData()
else else
{ {
inf->PatientUID = currentPatientUID; inf->PatientUID = currentPatientUID;
selectedRow = queryValue(model, 1, inf->ID); selectedRow = queryValue(model, 1, inf->ID, 2, inf->AccessionNumber);
inf->AddDate = AddDate; inf->AddDate = AddDate;
} }
inf->Sex = btnSex->text() == tr("Female") ? "F" : (tr("Male") == btnSex->text() ? "M" : "O"); inf->Sex = btnSex->text() == tr("Female") ? "F" : (tr("Male") == btnSex->text() ? "M" : "O");