예제 #1
0
/**
 * Define the current patient using its \e uuid. Return true if the current patient
 * was correctly set. If the \e uuid is empty, the current patient will be unset in
 * all patient models.
 */
bool PatientCore::setCurrentPatientUuid(const QString &uuid)
{
    // Take the Core:IPatient internal PatientModel
    PatientModel *patientModel = d->_patientModelWrapper->patientModel();
    if (uuid.isEmpty())
        LOG("Unsetting the current patient.");
    else
        LOG("Changing the current patient. Actual current patient: " + patientModel->index(patientModel->currentPatient().row(), Core::IPatient::Uid).data().toString());

    // Start changing the current patient
    if (!patientModel->beginChangeCurrentPatient()) {
        LOG_ERROR("Unable to change the current patient. Start process wrong.");
        return false;
    }

    // if uuid is empty -> remove any current patient
    if (uuid.isEmpty()) {
        patientModel->setFilter("", "", "%", PatientModel::FilterOnUuid);
        if (!patientModel->setCurrentPatient(QModelIndex())) {
            LOG_ERROR("Unable to unset the current patient");
            return false;
        }
        patientModel->endChangeCurrentPatient();
    } else {
        // Update the filter to the correct uuid
        patientModel->setFilter("", "", uuid, PatientModel::FilterOnUuid);
        if (patientModel->numberOfFilteredPatients() != 1) {
            LOG_ERROR(QString("No patient found; Number of uuids: %1")
                      .arg(patientModel->numberOfFilteredPatients()));
            return false;
        }

        // Define the new current patient
        patientModel->setCurrentPatient(patientModel->index(0,0));
    }

    // Finish the current patient modification process
    patientModel->endChangeCurrentPatient();

    if (uuid.isEmpty())
        LOG("Unsetted any current patient");
    else
        LOG("Current patient changed to: " + patient()->uuid());

    return true;
}
예제 #2
0
/**
 * Validate the wizard page. \n
 * Also check for identity duplicates
 */
bool IdentityPage::validatePage()
{
    setFocus();
    if (!m_Identity->isIdentityValid()) {
        LOG_ERROR("Unable to validate page. Invalid identity.");
        return false;
    }

    // check duplicates
    if (patientBase()->isPatientExists(m_Identity->currentUsualName(),
                                       m_Identity->currentOtherNames(),
                                       m_Identity->currentFirstName(),
                                       m_Identity->currentGender(),
                                       m_Identity->currentDateOfBirth())) {
        Utils::warningMessageBox(tr("Patient already exists"),
                                 tr("A patient with the same names, gender and date of birth "
                                    "already exists. You can not create duplicates."));
        return false;
    } else {
        // nearly duplicates (same names only)
        PatientModel *model = new PatientModel(this);
        model->setFilter(m_Identity->currentUsualName(), m_Identity->currentFirstName(), "", PatientModel::FilterOnFullName);
        if (model->rowCount() > 0) {
            QStringList names;
            int count = qMin(10, model->rowCount());
            for(int i=0; i < count; ++i)
                names << QString("%1 (%2; %3)")
                         .arg(model->data(model->index(i, Core::IPatient::FullName)).toString())
                         .arg(model->data(model->index(i, Core::IPatient::DateOfBirth)).toString())
                         .arg(model->data(model->index(i, Core::IPatient::Age)).toString());
            QString fullName = QString("%1 %2 %3<br />&nbsp;&nbsp;%4: %5<br />&nbsp;&nbsp;%6: %7")
                    .arg(m_Identity->currentUsualName())
                    .arg(m_Identity->currentOtherNames())
                    .arg(m_Identity->currentFirstName())
                    .arg(tkTr(Trans::Constants::GENDER))
                    .arg(m_Identity->currentGender())
                    .arg(tkTr(Trans::Constants::DATE_OF_BIRTH))
                    .arg(m_Identity->currentDateOfBirth().toString(QLocale().dateFormat(QLocale::LongFormat))).simplified();
            QString msg = QString("%1.<br />"
                                  "<br />%2<br /><ul><li>%3</li></ul><br />%4")
                    .arg(tr("You are about to create the following  patient: %1")
                         .arg("<br /><br />&nbsp;&nbsp;<b>"+fullName+"</b>"))
                    .arg(tr("Patients with the same names exist in the database."))
                    .arg(names.join("</li><li>"))
                    .arg(tr("Do you really want to create this patient?"))
                    ;
            bool yes = Utils::yesNoMessageBox(tr("Patients of the same name exist"), msg);
            if (!yes)
                return false;
        }
        delete model;
    }

    // submit the new patient data to the model
    bool ok = true;
    connect(m_Model, SIGNAL(patientCreated(QString)), patient(), SIGNAL(patientCreated(QString)), Qt::UniqueConnection);
    if (m_Identity->submit()) {
        // Submit the model to the database
        m_Model->submit();
        LOG("Patient successfully created");
    } else {
        LOG_ERROR("Unable to create patient. IdentityPage::validatePage()");
        ok = false;
    }
    return ok;
}