Esempio n. 1
0
	def _save_as_new(self):

		# save the data as a new instance
		vaccine = gmVaccination.create_vaccine (
			pk_drug_product = self._PRW_drug_product.GetData(),
			product_name = self._PRW_drug_product.GetValue().strip(),
			indications = self.__indications,
			is_live = self._CHBOX_live.GetValue()
		)
		val = self._PRW_age_min.GetValue().strip()
		if val != '':
			vaccine['min_age'] = gmDateTime.str2interval(val)
		val = self._PRW_age_max.GetValue().strip()
		if val != '':
			vaccine['max_age'] = gmDateTime.str2interval(val)
		val = self._TCTRL_comment.GetValue().strip()
		if val != '':
			vaccine['comment'] = val
		vaccine.save()

		drug = vaccine.product
		drug['is_fake_product'] = self._CHBOX_fake.GetValue()
		val = self._PRW_atc.GetData()
		if val is not None:
			if val != 'J07':
				drug['atc'] = val.strip()
		drug.save()

		# must be done very late or else the property access
		# will refresh the display such that later field
		# access will return empty values
		self.data = vaccine

		return True
Esempio n. 2
0
	def _save_as_new(self):

		# save the data as a new instance
		vaccine = gmVaccination.create_vaccine (
			pk_drug_product = self._PRW_drug_product.GetData(),
			product_name = self._PRW_drug_product.GetValue().strip(),
			indications = self.__indications,
			is_live = self._CHBOX_live.GetValue()
		)
		val = self._PRW_age_min.GetValue().strip()
		if val != '':
			vaccine['min_age'] = gmDateTime.str2interval(val)
		val = self._PRW_age_max.GetValue().strip()
		if val != '':
			vaccine['max_age'] = gmDateTime.str2interval(val)
		val = self._TCTRL_comment.GetValue().strip()
		if val != '':
			vaccine['comment'] = val
		vaccine.save()

		drug = vaccine.product
		drug['is_fake_product'] = self._CHBOX_fake.GetValue()
		val = self._PRW_atc.GetData()
		if val is not None:
			if val != 'J07':
				drug['atc'] = val.strip()
		drug.save()

		# must be done very late or else the property access
		# will refresh the display such that later field
		# access will return empty values
		self.data = vaccine

		return True
Esempio n. 3
0
	def _save_as_update(self):

		if len(self.__indications) == 0:
			gmGuiHelpers.gm_show_info (
				aTitle = _('Saving vaccine'),
				aMessage = _('You must select at least one indication.')
			)
			return False

		drug = self.data.brand
		drug['brand'] = self._PRW_brand.GetValue().strip()
		drug['is_fake_brand'] = self._CHBOX_fake.GetValue()
		val = self._PRW_atc.GetData()
		if val is not None:
			if val != u'J07':
				drug['atc'] = val.strip()
		drug.save()

		# the validator already asked for changes so just do it
		self.data.set_indications(pk_indications = [ i['id'] for i in self.__indications ])

#		self.data['is_live'] = self._CHBOX_live.GetValue()
		val = self._PRW_age_min.GetValue().strip()
		if val != u'':
			self.data['min_age'] = gmDateTime.str2interval(val)
		if val != u'':
			self.data['max_age'] = gmDateTime.str2interval(val)
		val = self._TCTRL_comment.GetValue().strip()
		if val != u'':
			self.data['comment'] = val

		self.data.save()
		return True
Esempio n. 4
0
	def _save_as_new(self):

		if len(self.__indications) == 0:
			gmGuiHelpers.gm_show_info (
				aTitle = _('Saving vaccine'),
				aMessage = _('You must select at least one indication.')
			)
			return False

		# save the data as a new instance
		data = gmVaccination.create_vaccine (
			pk_brand = self._PRW_brand.GetData(),
			brand_name = self._PRW_brand.GetValue(),
			pk_indications = [ i['id'] for i in self.__indications ]
		)

#		data['is_live'] = self._CHBOX_live.GetValue()
		val = self._PRW_age_min.GetValue().strip()
		if val != u'':
			data['min_age'] = gmDateTime.str2interval(val)
		val = self._PRW_age_max.GetValue().strip()
		if val != u'':
			data['max_age'] = gmDateTime.str2interval(val)
		val = self._TCTRL_comment.GetValue().strip()
		if val != u'':
			data['comment'] = val

		data.save()

		drug = data.brand
		drug['is_fake_brand'] = self._CHBOX_fake.GetValue()
		val = self._PRW_atc.GetData()
		if val is not None:
			if val != u'J07':
				drug['atc'] = val.strip()
		drug.save()

		# must be done very late or else the property access
		# will refresh the display such that later field
		# access will return empty values
		self.data = data

		return True
Esempio n. 5
0
	def _update_candidates_in_picklist(self, val):
		intv = gmDateTime.str2interval(str_interval = val)
		if intv is None:
			self._current_match_candidates = []
		else:
			self._current_match_candidates = [{
				'data': intv,
				'field_label': gmDateTime.format_interval(intv, gmDateTime.acc_minutes),
				'list_label': gmDateTime.format_interval(intv, gmDateTime.acc_minutes)
			}]
		self._picklist.SetItems(self._current_match_candidates)
Esempio n. 6
0
	def _update_candidates_in_picklist(self, val):
		intv = gmDateTime.str2interval(str_interval = val)
		if intv is None:
			self._current_match_candidates = []
		else:
			self._current_match_candidates = [{
				'data': intv,
				'field_label': gmDateTime.format_interval(intv, gmDateTime.acc_minutes),
				'list_label': gmDateTime.format_interval(intv, gmDateTime.acc_minutes)
			}]
		self._picklist.SetItems(self._current_match_candidates)
Esempio n. 7
0
	def _save_as_update(self):

		drug = self.data.product
		drug['product'] = self._PRW_drug_product.GetValue().strip()
		drug['is_fake_product'] = self._CHBOX_fake.GetValue()
		val = self._PRW_atc.GetData()
		if val is not None:
			if val != 'J07':
				drug['atc'] = val.strip()
		drug.save()

		self.data['is_live'] = self._CHBOX_live.GetValue()
		val = self._PRW_age_min.GetValue().strip()
		if val != '':
			self.data['min_age'] = gmDateTime.str2interval(val)
		if val != '':
			self.data['max_age'] = gmDateTime.str2interval(val)
		val = self._TCTRL_comment.GetValue().strip()
		if val != '':
			self.data['comment'] = val
		self.data.save()

		return True
Esempio n. 8
0
	def _save_as_update(self):

		drug = self.data.product
		drug['product'] = self._PRW_drug_product.GetValue().strip()
		drug['is_fake_product'] = self._CHBOX_fake.GetValue()
		val = self._PRW_atc.GetData()
		if val is not None:
			if val != 'J07':
				drug['atc'] = val.strip()
		drug.save()

		self.data['is_live'] = self._CHBOX_live.GetValue()
		val = self._PRW_age_min.GetValue().strip()
		if val != '':
			self.data['min_age'] = gmDateTime.str2interval(val)
		if val != '':
			self.data['max_age'] = gmDateTime.str2interval(val)
		val = self._TCTRL_comment.GetValue().strip()
		if val != '':
			self.data['comment'] = val
		self.data.save()

		return True
Esempio n. 9
0
	def _valid_for_save(self):

		if self._PRW_condition.GetValue().strip() == '':
			self._PRW_condition.display_as_valid(False)
			self._PRW_condition.SetFocus()
			return False
		self._PRW_condition.display_as_valid(True)
		self._PRW_condition.Refresh()

		# FIXME: sanity check age/year diagnosed
		age_noted = self._PRW_age_noted.GetValue().strip()
		if age_noted != '':
			if gmDateTime.str2interval(str_interval = age_noted) is None:
				self._PRW_age_noted.display_as_valid(False)
				self._PRW_age_noted.SetFocus()
				return False
		self._PRW_age_noted.display_as_valid(True)
		return True
Esempio n. 10
0
	def _valid_for_save(self):

		if self._PRW_condition.GetValue().strip() == '':
			self._PRW_condition.display_as_valid(False)
			self._PRW_condition.SetFocus()
			return False
		self._PRW_condition.display_as_valid(True)
		self._PRW_condition.Refresh()

		# FIXME: sanity check age/year diagnosed
		age_noted = self._PRW_age_noted.GetValue().strip()
		if age_noted != '':
			if gmDateTime.str2interval(str_interval = age_noted) is None:
				self._PRW_age_noted.display_as_valid(False)
				self._PRW_age_noted.SetFocus()
				return False
		self._PRW_age_noted.display_as_valid(True)
		return True
Esempio n. 11
0
	def _on_leave_age_noted(self, *args, **kwargs):

		if not self._PRW_age_noted.IsModified():
			return True

		age_str = self._PRW_age_noted.GetValue().strip()

		if age_str == '':
			return True

		issue_age = gmDateTime.str2interval(str_interval = age_str)

		if issue_age is None:
			self.StatusText = _('Cannot parse [%s] into valid interval.') % age_str
			self._PRW_age_noted.display_as_valid(False)
			return True

		pat = gmPerson.gmCurrentPatient()
		if pat['dob'] is not None:
			max_issue_age = pydt.datetime.now(tz=pat['dob'].tzinfo) - pat['dob']
			if issue_age >= max_issue_age:
				self.StatusText = _('Health issue cannot have been noted at age %s. Patient is only %s old.') % (issue_age, pat.get_medical_age())
				self._PRW_age_noted.display_as_valid(False)
				return True

		self._PRW_age_noted.display_as_valid(True)
		self._PRW_age_noted.SetText(value = age_str, data = issue_age)

		if pat['dob'] is not None:
			fts = gmDateTime.cFuzzyTimestamp (
				timestamp = pat['dob'] + issue_age,
				accuracy = gmDateTime.acc_months
			)
			self._PRW_year_noted.SetText(value = str(fts), data = fts)

		return True
Esempio n. 12
0
	def _on_leave_age_noted(self, *args, **kwargs):

		if not self._PRW_age_noted.IsModified():
			return True

		age_str = self._PRW_age_noted.GetValue().strip()

		if age_str == '':
			return True

		issue_age = gmDateTime.str2interval(str_interval = age_str)

		if issue_age is None:
			self.status_message = _('Cannot parse [%s] into valid interval.') % age_str
			self._PRW_age_noted.display_as_valid(False)
			return True

		pat = gmPerson.gmCurrentPatient()
		if pat['dob'] is not None:
			max_issue_age = pydt.datetime.now(tz=pat['dob'].tzinfo) - pat['dob']
			if issue_age >= max_issue_age:
				self.status_message = _('Health issue cannot have been noted at age %s. Patient is only %s old.') % (issue_age, pat.get_medical_age())
				self._PRW_age_noted.display_as_valid(False)
				return True

		self._PRW_age_noted.display_as_valid(True)
		self._PRW_age_noted.SetText(value = age_str, data = issue_age)

		if pat['dob'] is not None:
			fts = gmDateTime.cFuzzyTimestamp (
				timestamp = pat['dob'] + issue_age,
				accuracy = gmDateTime.acc_months
			)
			self._PRW_year_noted.SetText(value = str(fts), data = fts)

		return True
Esempio n. 13
0
	def _valid_for_save(self):

		has_errors = False

		if self._PRW_drug_product.GetValue().strip() == '':
			has_errors = True
			self._PRW_drug_product.display_as_valid(False)
		else:
			self._PRW_drug_product.display_as_valid(True)

		atc = self._PRW_atc.GetValue().strip()
		if (atc == '') or (atc.startswith('J07')):
			self._PRW_atc.display_as_valid(True)
		else:
			if self._PRW_atc.GetData() is None:
				self._PRW_atc.display_as_valid(True)
			else:
				has_errors = True
				self._PRW_atc.display_as_valid(False)

		val = self._PRW_age_min.GetValue().strip()
		if val == '':
			self._PRW_age_min.display_as_valid(True)
		else:
			if gmDateTime.str2interval(val) is None:
				has_errors = True
				self._PRW_age_min.display_as_valid(False)
			else:
				self._PRW_age_min.display_as_valid(True)

		val = self._PRW_age_max.GetValue().strip()
		if val == '':
			self._PRW_age_max.display_as_valid(True)
		else:
			if gmDateTime.str2interval(val) is None:
				has_errors = True
				self._PRW_age_max.display_as_valid(False)
			else:
				self._PRW_age_max.display_as_valid(True)

		# complex conditions
		# are we editing ?
		if self.mode == 'edit':
			change_of_product = self.data['pk_drug_product'] != self._PRW_drug_product.GetData()
			if change_of_product and self.data.is_in_use:
				do_it = gmGuiHelpers.gm_show_question (
					aTitle = _('Saving vaccine'),
					aMessage = _(
						'This vaccine is already in use:\n'
						'\n'
						' "%s"\n'
						'\n'
						'Are you absolutely positively sure that\n'
						'you really want to edit this vaccine ?\n'
						'\n'
						'This will change the vaccine name and/or target\n'
						'conditions in each patient this vaccine was\n'
						'used in to document a vaccination with.\n'
					) % self._PRW_drug_product.GetValue().strip()
				)
				if not do_it:
					has_errors = True
		else:
			if self._PRW_drug_product.GetData() is None:
				# need to ask for indications ?
				if self._PRW_drug_product.GetValue().strip() != '':
					self.__indications = gmSubstanceMgmtWidgets.manage_substance_doses(vaccine_indications_only = True)
					if self.__indications is None:
						has_errors = True
			else:
				# existing drug product selected
				pass

		return (has_errors is False)
Esempio n. 14
0
	def _valid_for_save(self):

		has_errors = False

		if self._PRW_brand.GetValue().strip() == u'':
			has_errors = True
			self._PRW_brand.display_as_valid(False)
		else:
			self._PRW_brand.display_as_valid(True)

		if self._PRW_atc.GetValue().strip() in [u'', u'J07']:
			self._PRW_atc.display_as_valid(True)
		else:
			if self._PRW_atc.GetData() is None:
				self._PRW_atc.display_as_valid(True)
			else:
				has_errors = True
				self._PRW_atc.display_as_valid(False)

		val = self._PRW_age_min.GetValue().strip()
		if val == u'':
			self._PRW_age_min.display_as_valid(True)
		else:
			if gmDateTime.str2interval(val) is None:
				has_errors = True
				self._PRW_age_min.display_as_valid(False)
			else:
				self._PRW_age_min.display_as_valid(True)

		val = self._PRW_age_max.GetValue().strip()
		if val == u'':
			self._PRW_age_max.display_as_valid(True)
		else:
			if gmDateTime.str2interval(val) is None:
				has_errors = True
				self._PRW_age_max.display_as_valid(False)
			else:
				self._PRW_age_max.display_as_valid(True)

		# are we editing ?
		ask_user = (self.mode == 'edit')
		# is this vaccine in use ?
		ask_user = (ask_user and self.data.is_in_use)
		# a change ...
		ask_user = ask_user and (
			# ... of brand ...
			(self.data['pk_brand'] != self._PRW_route.GetData())
				or
			# ... or indications ?
			(set(self.data['pk_indications']) != set([ i['id'] for i in self.__indications ]))
		)

		if ask_user:
			do_it = gmGuiHelpers.gm_show_question (
				aTitle = _('Saving vaccine'),
				aMessage = _(
					u'This vaccine is already in use:\n'
					u'\n'
					u' "%s"\n'
					u' (%s)\n'
					u'\n'
					u'Are you absolutely positively sure that\n'
					u'you really want to edit this vaccine ?\n'
					'\n'
					u'This will change the vaccine name and/or target\n'
					u'conditions in each patient this vaccine was\n'
					u'used in to document a vaccination with.\n'
				) % (
					self._PRW_brand.GetValue().strip(),
					u', '.join(self.data['l10n_indications'])
				)
			)
			if not do_it:
				has_errors = True

		return (has_errors is False)
Esempio n. 15
0
	def _valid_for_save(self):

		has_errors = False

		if self._PRW_drug_product.GetValue().strip() == '':
			has_errors = True
			self._PRW_drug_product.display_as_valid(False)
		else:
			self._PRW_drug_product.display_as_valid(True)

		atc = self._PRW_atc.GetValue().strip()
		if (atc == '') or (atc.startswith('J07')):
			self._PRW_atc.display_as_valid(True)
		else:
			if self._PRW_atc.GetData() is None:
				self._PRW_atc.display_as_valid(True)
			else:
				has_errors = True
				self._PRW_atc.display_as_valid(False)

		val = self._PRW_age_min.GetValue().strip()
		if val == '':
			self._PRW_age_min.display_as_valid(True)
		else:
			if gmDateTime.str2interval(val) is None:
				has_errors = True
				self._PRW_age_min.display_as_valid(False)
			else:
				self._PRW_age_min.display_as_valid(True)

		val = self._PRW_age_max.GetValue().strip()
		if val == '':
			self._PRW_age_max.display_as_valid(True)
		else:
			if gmDateTime.str2interval(val) is None:
				has_errors = True
				self._PRW_age_max.display_as_valid(False)
			else:
				self._PRW_age_max.display_as_valid(True)

		# complex conditions
		# are we editing ?
		if self.mode == 'edit':
			change_of_product = self.data['pk_drug_product'] != self._PRW_drug_product.GetData()
			if change_of_product and self.data.is_in_use:
				do_it = gmGuiHelpers.gm_show_question (
					aTitle = _('Saving vaccine'),
					aMessage = _(
						'This vaccine is already in use:\n'
						'\n'
						' "%s"\n'
						'\n'
						'Are you absolutely positively sure that\n'
						'you really want to edit this vaccine ?\n'
						'\n'
						'This will change the vaccine name and/or target\n'
						'conditions in each patient this vaccine was\n'
						'used in to document a vaccination with.\n'
					) % self._PRW_drug_product.GetValue().strip()
				)
				if not do_it:
					has_errors = True
		else:
			if self._PRW_drug_product.GetData() is None:
				# need to ask for indications ?
				if self._PRW_drug_product.GetValue().strip() != '':
					self.__indications = gmSubstanceMgmtWidgets.manage_substance_doses(vaccine_indications_only = True)
					if self.__indications is None:
						has_errors = True
			else:
				# existing drug product selected
				pass

		return (has_errors is False)