Exemple #1
0
def validate(id):
    order = Order.query.get(id)
    data_xls = pd.read_excel(order.file_url)
    for index, row in data_xls.iterrows():
        # one patient have samples that have results
        # check patient number first if exist in db per row
        patient = Patient()
        patient_count = Patient.query.filter_by(code=row[0]).count()
        if patient_count > 0:
            sample_count = Sample.query.filter_by(code=row[7]).count()
            if sample_count > 0:
                # add new resltuts
                print(row[0] + ' ' + str(index))
            else:
                sample = Sample()
                sample.origin_id = 1
                sample.bio_code = patient.bio_code
                sample.volume = row[16]
                sample_nature = SampleNature.query.filter_by(
                    name=row[8]).first()
                sample.sample_nature_id = sample_nature.id

                print(row[14])
                sample_type = SampleType.query.filter_by(name=row[9]).first()
                sample.sample_type_id = sample_type.id

                support = Support.query.filter_by(name=row[13]).first()
                sample.support_id = support.id

                jonc_type = JoncType.query.filter_by(name=row[14]).first()
                if jonc_type is not None:
                    sample.jonc_type_id = jonc_type.id

                mesure = Mesure.query.filter_by(name=row[17]).first()
                sample.mesure_id = mesure.id

                sample.code = row[7]
                sample.date = str(row[10])
                sample.technique = row[11]
                sample.site = row[12]
                sample.status = 0

                patient.samples.append(sample)
                order.patients.append(patient)
                db.session.commit()
                generateCode(sample, index + 1)

        else:
            # add new patient and samples and result of sample
            patient.code = row[0]
            patient.origin_id = 1
            patient.bio_code = get_bio_code('HU')
            patient.age = row[1]
            patient.sexe = row[2]
            patient.birthday = str(row[3])
            patient.city = row[4]
            patient.job = row[5]
            patient.clinical_data = row[6]
            # samples implementation
            for r in range(int(row[15])):
                sample = Sample()
                sample.origin_id = 1
                sample.bio_code = patient.bio_code
                sample.volume = row[16]
                sample_nature = SampleNature.query.filter_by(
                    name=row[8]).first()
                sample.sample_nature = sample_nature

                sample_type = SampleType.query.filter_by(name=row[9]).first()
                sample.sample_type = sample_type

                support = Support.query.filter_by(name=row[13]).first()
                sample.support = support

                jonc_type = JoncType.query.filter_by(name=row[14]).first()
                sample.jonc_type = jonc_type

                mesure = Mesure.query.filter_by(name=row[17]).first()
                sample.mesure_id = mesure.id

                sample.code = row[7]
                sample.date = str(row[10])
                sample.technique = row[11]
                sample.site = row[12]
                sample.status = 0
                sample.number = int(row[15])

                patient.samples.append(sample)
                generateCode(sample, r + 1)

                print(str(sample.bio_code))
            order.patients.append(patient)
            db.session.commit()
        order.status = 1
        db.session.commit()
        # and check sample id if already in db
    flash(_('Traitement effectué avec succes!'))
    return redirect(url_for('order.detail', id=order.id))
Exemple #2
0
def do_import(id):
    order = Order.query.get(id)
    if request.method == 'POST':
        file = request.files['file']
        filename = documents.save(file)

        data_xls = pd.read_excel(file)

        for index, row in data_xls.iterrows():
            # one patient have samples that have results
            # check patient number first if exist in db per row
            patient = Patient()
            patient_count = Patient.query.filter_by(code=row[0]).count()
            if patient_count > 0:
                sample_count = Sample.query.filter_by(code=row[7]).count()
                if sample_count > 0:
                    # add new resltuts
                    print(row[0] + ' ' + str(index))
                else:
                    sample = Sample()
                    sample.bio_code = patient.bio_code
                    sample.volume = row[16]
                    sample_nature = SampleNature.query.filter_by(
                        name=row[8]).first()
                    sample.sample_nature_id = sample_nature.id

                    sample_type = SampleType.query.filter_by(
                        name=row[9]).first()
                    sample.sample_type_id = sample_type.id

                    support = Support.query.filter_by(name=row[13]).first()
                    sample.support_id = support.id

                    jonc_type = JoncType.query.filter_by(name=row[14]).first()
                    sample.jonc_type_id = jonc_type.id

                    mesure = Mesure.query.filter_by(name=row[17]).first()
                    sample.mesure_id = mesure.id

                    sample.code = row[7]
                    sample.date = str(row[10])
                    sample.technique = row[11]
                    sample.site = row[12]
                    sample.status = 0

                    patient.samples.append(sample)
                    order.patients.append(patient)
                    db.session.commit()
                    generateCode(sample, r + 1)

            else:
                # add new patient and samples and result of sample
                print(row[4] + ' ' + str(index))
                patient.code = row[0]
                patient.origin_id = 1
                patient.bio_code = get_bio_code('HU')
                patient.age = row[1]
                patient.sexe = row[2]
                patient.birthday = str(row[3])
                patient.city = row[4]
                patient.job = row[5]
                patient.clinical_data = row[6]
                # samples implementation
                for r in range(int(row[15])):
                    sample = Sample()
                    sample.bio_code = patient.bio_code
                    sample.volume = row[16]
                    sample_nature = SampleNature.query.filter_by(
                        name=row[8]).first()
                    sample.sample_nature_id = sample_nature.id

                    sample_type = SampleType.query.filter_by(
                        name=row[9]).first()
                    sample.sample_type_id = sample_type.id

                    support = Support.query.filter_by(name=row[13]).first()
                    sample.support_id = support.id

                    jonc_type = JoncType.query.filter_by(name=row[14]).first()
                    sample.jonc_type_id = jonc_type.id

                    mesure = Mesure.query.filter_by(name=row[17]).first()
                    sample.mesure_id = mesure.id

                    sample.code = row[7]
                    sample.date = str(row[10])
                    sample.technique = row[11]
                    sample.site = row[12]
                    sample.status = 0

                    patient.samples.append(sample)
                    generateCode(sample, r + 1)

                    print(str(sample.bio_code))
                order.patients.append(patient)
                db.session.commit()
        # and check sample id if already in db

        url = documents.url(filename)
        document = Document(name=filename, url=url)
        order.documents.append(document)
        db.session.add(document)
        db.session.commit()
        flash(_('Fichier importé avec succes!'))
        return redirect(url_for('order.detail', id=order.id))
    return render_template('order/import.html', order=order)