class AllMedorgWindow(QFrame):
	def __init__(self):
		QFrame.__init__(self)
		self.ui = Ui_all_medorg_form()
	
		self.ui.setupUi(self)
		self.drawTable()
		QObject.connect(self.ui.add_medorg_btn, SIGNAL("clicked()"), self.showNewMedorgForm)
		QObject.connect(self.ui.del_medorg_btn, SIGNAL("clicked()"), self.delMedorg)
	
	def drawTable(self):
		self.mos = query_session.query(M_organisation).all()
		self.ui.medorg_table.clear()
		self.ui.medorg_table.setRowCount(1)
		self.ui.medorg_table.setColumnCount(2)
		self.ui.medorg_table.setHorizontalHeaderLabels([QString.fromUtf8('Номер'), QString.fromUtf8('Название')])
		
		for mo in self.mos:
			data = []
			data.append(str(mo.id))
			data.append(mo.name)
			for i in range(0,2):	
				tableitem = QTableWidgetItem()
				tableitem.setText(data[i])
				tableitem.font = QFont("Arial", 10)
				tableitem.font.setBold(True)
				tableitem.textcolor = QColor("black")
				self.ui.medorg_table.setItem(self.ui.medorg_table.rowCount() - 1,i,tableitem)
			self.ui.medorg_table.setRowCount(self.ui.medorg_table.rowCount()+1)
		self.ui.medorg_table.resizeColumnsToContents()

				
	def showNewMedorgForm(self):
		self.new_medorg_form = NewMedorgForm(self)
		QObject.connect(self.new_medorg_form, SIGNAL("medorgAdded()"), self.drawTable)
		self.new_medorg_form.setWindowModality(2)
		self.new_medorg_form.show()
		
		
	def delMedorg(self):
		row = self.ui.medorg_table.currentRow()
		id_for_delete = int(self.ui.medorg_table.item(row, 0).text())
		medorg_for_delete = query_session.query(M_organisation).filter_by(id=id_for_delete).one()
		s = Session()
		s.delete(medorg_for_delete)
		s.commit()
		s.close
		self.drawTable()
示例#2
0
class SaleWindow(QFrame):
	def initForm(self):
		QFrame.__init__(self)
		self.ui = Ui_sale_form()
		self.ui.setupUi(self)
		self.s = Session()
		QObject.connect(self.ui.tableWidget, SIGNAL("cellDoubleClicked(int, int)"), self.showAddDrugForm)
		QObject.connect(self.ui.reciever_btn, SIGNAL("clicked()"), self.setReciever)
		QObject.connect(self.ui.reciever_combo, SIGNAL("currentIndexChanged(int)"), self.changeReciever)
		QObject.connect(self.ui.save_close_btn, SIGNAL("clicked()"), self.acceptSale)
		QObject.connect(self.ui.save_btn, SIGNAL("clicked()"), self.saveSale)
		QObject.connect(self.ui.financing_combo, SIGNAL("currentIndexChanged(int)"), self.setFinancing)
		QObject.connect(self.ui.close_btn, SIGNAL("clicked()"), self.closeme)
		
		self.setWindowTitle(QString.fromUtf8('Создание расходной накладной'))
		self.drawFinancingCombo()
		
		self.ui.m_org_combo = QComboBox(self)
		self.ui.gridLayout.addWidget(self.ui.m_org_combo, 4, 2, 1, 1)
		self.ui.m_org_combo.setVisible(False)
		
		QObject.connect(self.ui.m_org_combo, SIGNAL("currentIndexChanged(int)"), self.newMedorg)
	def initNewSale(self):
		self.sale = Sale()
#financing
		self.sale.financing = self.financing
		self.sale.create_date = date.today()
		
	def __init__(self,sale = None):
		self.initForm()
		if sale == None:
			self.initNewSale()
		else:
			self.sale = sale
		self.drawTable()
		self.drawControls()
			
	
	def drawControls(self):
		self.ui.financing_combo.setCurrentIndex(self.ui.financing_combo.findText(self.sale.financing.name))
		self.ui.reciever_label.setText(QString.fromUtf8(repr(self.sale.getReciever())))
		if self.sale.m_organisation == None:
			self.ui.reciever_btn.setVisible(True)
			self.ui.m_org_combo.setVisible(False)
		else:
			self.ui.reciever_btn.setVisible(False)
			self.ui.m_org_combo.setVisible(True)
			self.ui.m_org_combo.setCurrentIndex(2)
			self.drawMedorgCombo()
			self.ui.m_org_combo.setCurrentIndex(self.ui.m_org_combo.findText(self.sale.m_organisation.name))

		self.ui.bill_number_date.setText(QString.fromUtf8(repr(self.sale)))
		self.ui.financing_combo.setDisabled(self.sale.accepted)
		self.ui.reciever_btn.setDisabled(self.sale.accepted)
		self.ui.m_org_combo.setDisabled(self.sale.accepted)
		self.ui.reciever_combo.setDisabled(self.sale.accepted)
		self.ui.save_close_btn.setDisabled(self.sale.accepted)
		self.ui.save_btn.setDisabled(self.sale.accepted)
		
	def drawTable(self):
		self.ui.tableWidget.clear()
		self.ui.tableWidget.setColumnCount(7)
		self.ui.tableWidget.setRowCount(1)
		self.ui.tableWidget.setHorizontalHeaderLabels([QString.fromUtf8('ИД'), QString.fromUtf8('Название препарата'), QString.fromUtf8('Производитель'), QString.fromUtf8('Серийный номер'), QString.fromUtf8('Годен до'), QString.fromUtf8('Цена'),QString.fromUtf8('Количество')])
		self.summ = 0
		for m in self.sale.maps:
			data = []
			data.append(str(m.drug.id))
			data.append(QString.fromUtf8(m.drug.name()))
			data.append(QString.fromUtf8(m.drug.manufacter.name))
			data.append(str(m.drug.serial))
			data.append(m.drug.best_before.strftime("%d.%m.%Y"))
			data.append(str(m.drug.price))
			data.append(str(m.count))
		
			self.summ = self.summ + m.count*m.drug.price
			for i in range(0,7):	
				tableitem = QTableWidgetItem()
				tableitem.setText(data[i])
				tableitem.font = QFont("Arial", 10)
				tableitem.font.setBold(True)
				tableitem.textcolor = QColor("black")
				tableitem.setBackgroundColor(QColor('White'))
				self.ui.tableWidget.setItem(self.ui.tableWidget.rowCount() - 1,i,tableitem)
			self.ui.tableWidget.setRowCount(self.ui.tableWidget.rowCount()+1)
		self.ui.label_3.setText(QString.fromUtf8("Всего лс на сумму " + str(self.summ) + "р."))
		self.ui.tableWidget.resizeColumnsToContents()
		
	def drawFinancingCombo(self):
		fin = query_session.query(Financing).all()
		self.ui.financing_combo.clear()
		
		for item in fin:
			self.ui.financing_combo.addItem(item.name)
		self.setFinancing(0)
		
	def setFinancing(self,num):
		financing = query_session.query(Financing).filter_by(name=unicode(self.ui.financing_combo.itemText(num))).one()
		self.financing = financing
		print self.financing

	def changeReciever(self, res):
		if (res == 0):
			self.ui.reciever_btn.setText(QString.fromUtf8('Рецепт'))
			self.ui.reciever_btn.setVisible(True)
			self.ui.m_org_combo.setVisible(False)
		elif (res == 1):
			#self.ui.reciever_btn.setText(QString.fromUtf8('Мед. организация'))
			self.ui.m_org_combo.setVisible(True)
			self.ui.reciever_btn.setVisible(False)
			self.drawMedorgCombo()

	def showNewRecipeForm(self):
		self.new_recipe_form = NewRecipeForm(self)
		self.new_recipe_form.setWindowModality(2)
		self.new_recipe_form.show()
		self.ui.reciever_combo.setDisabled(True)

	def showAddDrugForm(self, row, col):
		if row == self.ui.tableWidget.rowCount() - 1:
			self.add_drug_form = AddDrugForm(self)
			self.add_drug_form.setWindowModality(2)
			QObject.connect(self.add_drug_form.count_form, SIGNAL("drugAdded()"), self.drawTable)
			self.add_drug_form.show()
			
			
	def acceptSale(self):
		self.sale.accepted = True
		self.saveSale()
	
	def saveSale(self):
		self.s.add(self.sale)
		self.s.commit()
		self.s.close()
		self.closeme()
		
	def closeme(self):
		self.parent().close()
		
	def setReciever(self):
		if self.ui.reciever_combo.currentIndex() == 0:
			self.showNewRecipeForm()
	
	
	def drawMedorgCombo(self):
		combo = self.ui.m_org_combo
		items = query_session.query(M_organisation).all()
		combo.clear()		
		for item in items:
			combo.addItem(QString.fromUtf8(repr(item)))
		
		combo.addItem(QString.fromUtf8('Добавить'))
		combo.setCurrentIndex(0)
		
	def newMedorg(self,num):
		if (num >= self.ui.m_org_combo.count() - 1) and (self.ui.m_org_combo.count() > 1):
			self.new_medorg_form = NewMedorgForm()
			self.new_medorg_form.setWindowModality(2)
			QObject.connect(self.new_medorg_form, SIGNAL("medorgAdded()"), self.drawMedorgCombo)
			self.new_medorg_form.show()
		else:
			self.sale.m_organisation = query_session.query(M_organisation).filter_by(name=str(self.ui.m_org_combo.currentText().toUtf8())).one()
class NewRecipeForm(QFrame):
	def __init__(self,parent):
		QFrame.__init__(self)
		self.ui = Ui_new_recipe_form()
		self.ui.setupUi(self)
		self.parent = parent
		
		self.recipe = Recipe()
		self.setWindowTitle(QString.fromUtf8('Новый рецепт'))
		self.ui.recipe_num.setText(QString.fromUtf8('Рецепт №'+str(self.recipe.id)))
		
		
		
		
		self.drawPatientCombo()
		self.drawMedorgCombo()
		self.drawDoctorCombo()
		self.drawIllCombo()
		
		QObject.connect(self.ui.ok_btn, SIGNAL("clicked()"), self.addRecipe)
		
		QObject.connect(self.ui.patient_combo, SIGNAL("currentIndexChanged(int)"), self.newPatient)
		QObject.connect(self.ui.m_org_combo, SIGNAL("currentIndexChanged(int)"), self.newMedorg)
		QObject.connect(self.ui.doctor_combo, SIGNAL("currentIndexChanged(int)"), self.newDoctor)
		#QObject.connect(self.ui.ill_combo, SIGNAL("currentIndexChanged(int)"), self.newIll)
		
	
	def addRecipe(self):
		firstname, lastname = parseStr(str(self.ui.patient_combo.currentText().toUtf8()),' ')
		patient = query_session.query(Patient).filter_by(first_name=firstname).filter_by(last_name=lastname).one()
		m_organisation = query_session.query(M_organisation).filter_by(name=str(self.ui.m_org_combo.currentText().toUtf8())).one()
		
		firstname, lastname = parseStr(str(self.ui.doctor_combo.currentText().toUtf8()),' ')
		doctor = query_session.query(Doctor).filter_by(first_name=firstname).filter_by(last_name=lastname).one()
		ill = query_session.query(Ill).filter_by(name=str(self.ui.ill_combo.currentText().toUtf8())).one()
		self.recipe.sale = self.parent.sale
		
		self.recipe.patient = patient
		self.recipe.m_organisation = m_organisation
		self.recipe.doctor = doctor
		self.recipe.ill = ill
		self.parent.s.add(self.recipe)
		self.parent.ui.reciever_label.setText(QString.fromUtf8('Рецепт №%i для %s' % (self.recipe.id,repr(self.recipe.patient))))
		self.parent.sale.m_organisation = None
		#self.parent.s.commit()
		#self.parent.s.close()
		#self.emit(SIGNAL("recipeAdded()"))
		self.close()


	def drawCombo(self,combo,items):
		combo.clear()		
		for item in items:
			combo.addItem(QString.fromUtf8(repr(item)))
		
		combo.addItem(QString.fromUtf8('Добавить'))
		combo.setCurrentIndex(0)
		
	
	def drawPatientCombo(self):
		self.patients = query_session.query(Patient).all()
		self.drawCombo(self.ui.patient_combo, self.patients)
		
	def drawMedorgCombo(self):
		self.m_organisations = query_session.query(M_organisation).all()
		self.drawCombo(self.ui.m_org_combo, self.m_organisations)
		
	def drawDoctorCombo(self):
		self.doctors = query_session.query(Doctor).all()
		self.drawCombo(self.ui.doctor_combo, self.doctors)
		
	def drawIllCombo(self):
		self.ills = query_session.query(Ill).all()
		self.drawCombo(self.ui.ill_combo, self.ills)
		
		
	def newPatient(self,num):
		if (num >= self.ui.patient_combo.count() - 1):
			self.new_patient_form = NewPatientForm()
			self.new_patient_form.setWindowModality(2)
			QObject.connect(self.new_patient_form, SIGNAL("patientAdded()"), self.drawPatientCombo)
			self.new_patient_form.show()
			
	def newMedorg(self,num):
		if (num >= self.ui.m_org_combo.count() - 1):
			self.new_medorg_form = NewMedorgForm()
			self.new_medorg_form.setWindowModality(2)
			QObject.connect(self.new_medorg_form, SIGNAL("medorgAdded()"), self.drawMedorgCombo)
			self.new_medorg_form.show()
			
	def newDoctor(self,num):
		if (num >= self.ui.doctor_combo.count() - 1):
			self.new_doctor_form = NewDoctorForm()
			self.new_doctor_form.setWindowModality(2)
			QObject.connect(self.new_doctor_form, SIGNAL("doctorAdded()"), self.drawDoctorCombo)
			self.new_doctor_form.show()
	
#	def newIll(self,num):
#		if (num >= self.ui.ill_combo.count() - 1):
#			self.new_ill_form = NewIllForm()
#			self.new_ill_form .setWindowModality(2)
#			QObject.connect(self.new_ill_form , SIGNAL("illAdded()"), self.drawIllCombo)
#			self.new_doctor_form.show()