Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######## Modelo 1 ########
- cut_text = fields.Text("Cut Text")
- cut_image = fields.Binary("Cut Image")
- @classmethod
- def convert_cut_image(cls, data):
- if data and Image:
- image = Image.open(BytesIO(data))
- image.thumbnail((200, 200), Image.LANCZOS)
- data = BytesIO()
- image.save(data, image.format)
- data = fields.Binary.cast(data.getvalue())
- return data
- @classmethod
- def create(cls, vlist):
- vlist = [x.copy() for x in vlist]
- for values in vlist:
- if 'cut_image' in values:
- values['cut_image'] = cls.convert_cut_image(values['cut_image'])
- return super(AnatomyOrgan, cls).create(vlist)
- ######## Modelo 2 En el modelo 2 se encuentra igual que en el modelo 1 ########
- cut_text = fields.Text("Cut Text")
- cut_image = fields.Binary("Cut Image")
- @classmethod
- def convert_cut_image(cls, data):
- if data and Image:
- image = Image.open(BytesIO(data))
- image.thumbnail((200, 200), Image.LANCZOS)
- data = BytesIO()
- image.save(data, image.format)
- data = fields.Binary.cast(data.getvalue())
- return data
- @classmethod
- def create(cls, vlist):
- vlist = [x.copy() for x in vlist]
- for values in vlist:
- if 'cut_image' in values:
- values['cut_image'] = cls.convert_cut_image(values['cut_image'])
- return super(AnatomyOrgan, cls).create(vlist)
- ######## Asistente ########
- def _create_study(self):
- Study = Pool().get('study.study')
- to_create_container = []
- for c in self.start.containers:
- samples = []
- for s in c.samples:
- criteria = []
- for criterion in s.organ.criteria:
- options = [
- {
- 'name': option.name,
- 'type_measure': option.type_measure,
- 'pre_sub': option.pre_sub,
- 'pos_sub': option.pos_sub,
- 'sub_options': [
- {
- 'name': subOption.name,
- 'result': subOption.result
- }
- for subOption in option.sub_options
- if option.sub_options
- ],
- 'result': option.result,
- 'for_diagnostic': option.for_diagnostic
- }
- for option in criterion.options
- if criterion.options
- ]
- result = choice(options)['result'] \
- if criterion.utility == 'ts'else ""
- criteria.append(
- {
- 'sequence': criterion.sequence,
- 'name': criterion.name,
- 'type_critearea': criterion.type_critearea,
- 'utility': criterion.utility,
- 'type_measure': criterion.type_measure,
- 'singular': criterion.singular,
- 'plural': criterion.plural,
- 'post_measure': criterion.post_measure,
- 'pre_option': criterion.pre_option,
- 'post_option': criterion.post_option,
- 'options': options,
- 'unit_measure': criterion.unit_measure and criterion.unit_measure.id,
- 'text_option': result,
- 'result': result,
- 'for_diagnostic': criterion.for_diagnostic
- }
- )
- slides = [
- {
- 'name': self.incremental_slide(len(
- to_create_container) + 1,
- len(samples) + 1, j + 1,
- slide.name)
- }
- for j, slide in enumerate(s.organ.slides)
- if s.organ.slides
- ]
- if s.type_sample == 'complete' and s.organ.divisions:
- for division in s.organ.divisions:
- to_create_container.append(
- {
- 'name': self.incremental_container(
- len(to_create_container) + 1),
- 'desc': division.name,
- 'samples': [
- {
- 'name': self.incremental_sample(
- len(to_create_container) + 1,
- 1, division.name),
- 'system': s.system.id,
- 'organ': s.organ.id,
- 'criteria': criteria,
- 'slides': [
- {
- 'name': self.incremental_slide(len(
- to_create_container) + 1,
- len(samples) + 1, j + 1,
- slide.name)
- }
- for j, slide in enumerate(s.organ.slides)
- if s.organ.slides
- ],
- ######## asi se guarda el campo del modelo 2 llamado desde el modelo 1 ########
- 'cut_text': s.organ.cut_text,
- 'cut_image': self.convert_cut_image(s.organ.cut_image),
- }
- ]
- }
- )
- else:
- ######## asi se guarda el campo del modelo 2 llamado desde el modelo 1 ########
- samples.append(
- {
- 'system': s.system.id,
- 'organ': s.organ.id,
- 'criteria': criteria,
- 'slides': slides,
- 'cut_text': s.organ.cut_text,
- 'cut_image': self.convert_cut_image(s.organ.cut_image),
- })
- if not samples:
- continue
- for i, sample in enumerate(samples):
- sample['name'] = self.incremental_sample(
- len(to_create_container) + 1, i + 1)
- to_create_container.append(
- {
- 'name': self.incremental_container(
- len(to_create_container) + 1),
- 'desc': c.desc,
- 'samples': samples
- })
- study = Study()
- study.patient = self.start.patient.id
- study.institution_request = self.start.institution_requested.id
- study.pathologist = self.start.pathologist.id
- study.date = self.start.date
- study.containers = to_create_container
- study.save()
- return study
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement