Creating copy of one2many field with additional attributes

86 views
Skip to first unread message

Khurram Shahzad

unread,
Jan 22, 2017, 4:45:08 AM1/22/17
to try...@googlegroups.com
Dear all,

At our hospital, doctors prescribe medication for admitted patients which is stored as:

patient-id, medicine-name

This is stored in a model patient-medication.

Our nursing department wants to have a form for 'Ordering medicine', when the open this form they want an already populated list containing:

patient-id, medicine-name, qty_to_order

These lines should be populated using the patient-medication table and 'qty_to_order' field is provided to user for entering how much quantity is to be ordered. They should also be able to add/remove rows from the list.

For this, I have written following code:

 medications = fields.One2Many('gnuhealth.inpatient.medication', 'name','Medications',[('admission_no.state','=','hospitalized')])

 But, I am unable to add 'qty_to_order' field and make it editable

Thanking you in anticipation.

--
 
Regards,
Khurram.

Cédric Krier

unread,
Jan 22, 2017, 5:10:06 AM1/22/17
to try...@googlegroups.com
With such design, you have to extend the model
'gnuhealth.inpatient.medication' to add the field qty_to_order. I do not
know if it makes sense at all.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Khurram Shahzad

unread,
Jan 22, 2017, 12:55:07 PM1/22/17
to try...@googlegroups.com
Dear Cedric,
Even after adding the field qty_to_order (just for the sake or ordering), I am unable to add the value of 'qty_to_order' without updating the original patient-medication record.

I just want to have a grid which has copy (in-memory copy) of patient-medication records (already in db) so that user can set the qty_to_order and submit it. Against this submission, at back-end an internal shipment request will be submitted to the Warehouse.

--
 
Regards,
Khurram.

Cédric Krier

unread,
Jan 23, 2017, 3:10:06 PM1/23/17
to try...@googlegroups.com
On 2017-01-22 20:03, Khurram Shahzad wrote:
> Even after adding the field qty_to_order (just for the sake or ordering), I
> am unable to add the value of 'qty_to_order' without updating the original
> patient-medication record.

Of course if you use a One2Many, what is displayed is the records of the
target model.
But I'm not sure to understand the schema here.
Is 'patient-medication' a different model than
'gnuhealth.inpatient.medication' ?

> I just want to have a grid which has copy (in-memory copy) of
> patient-medication records (already in db) so that user can set the
> qty_to_order and submit it. Against this submission, at back-end an
> internal shipment request will be submitted to the Warehouse.

Then you must use a different target for the One2Many and define a
default value method for this field which must return a list of
dictionary values.

Khurram Shahzad

unread,
Jan 24, 2017, 4:20:06 AM1/24/17
to try...@googlegroups.com

Dear Cedric,
On Tue, Jan 24, 2017 at 1:06 AM, Cédric Krier <cedric...@b2ck.com> wrote:
On 2017-01-22 20:03, Khurram Shahzad wrote:
> Even after adding the field qty_to_order (just for the sake or ordering), I
> am unable to add the value of 'qty_to_order' without updating the original
> patient-medication record.

Of course if you use a One2Many, what is displayed is the records of the
target model.
But I'm not sure to understand the schema here.
Is 'patient-medication' a different model than
'gnuhealth.inpatient.medication' ?

It is 'gnuhealth.inpatient.medication'!
 

> I just want to have a grid which has copy (in-memory copy) of
> patient-medication records (already in db) so that user can set the
> qty_to_order and submit it. Against this submission, at back-end an
> internal shipment request will be submitted to the Warehouse.

Then you must use a different target for the One2Many and define a
default value method for this field which must return a list of
dictionary values.


I am sorry, I could not understand! If I use a model different than 'gnuhealth.inpatient.medication', how can I read values from db stored in 'gnuhealth_inpatient_medication' table? Similarly, I think I will lose 'add_remove' feature which allow easy selection from already prescribed inpatient medication.
--
 
Regards,
Khurram.

Cédric Krier

unread,
Jan 24, 2017, 4:45:06 AM1/24/17
to try...@googlegroups.com
On 2017-01-24 08:40, Khurram Shahzad wrote:
> > > I just want to have a grid which has copy (in-memory copy) of
> > > patient-medication records (already in db) so that user can set the
> > > qty_to_order and submit it. Against this submission, at back-end an
> > > internal shipment request will be submitted to the Warehouse.
> >
> > Then you must use a different target for the One2Many and define a
> > default value method for this field which must return a list of
> > dictionary values.
> >
> >
> I am sorry, I could not understand! If I use a model different than
> 'gnuhealth.inpatient.medication', how can I read values from db stored in
> 'gnuhealth_inpatient_medication' table?

Using the ORM.

> Similarly, I think I will lose
> 'add_remove' feature which allow easy selection from already prescribed
> inpatient medication.

Yes, you can not have both: using the 'gnuhealth_inpatient_medication'
for relation and not store on it.

But for me, it is still unclear what is exactly the process/work-flow.
And more over what are those models, what should they represent etc.
So I can not help you more than just telling how database schema will
behave.
Reply all
Reply to author
Forward
0 new messages