patient.move
							parent
							
								
									aa2448888d
								
							
						
					
					
						commit
						b977b8ad48
					
				| 
						 | 
					@ -0,0 +1,13 @@
 | 
				
			||||||
 | 
					<action>
 | 
				
			||||||
 | 
					    <field name="string">Patient Moves</field>
 | 
				
			||||||
 | 
					    <field name="view_cls">multi_view</field>
 | 
				
			||||||
 | 
					    <field name="model">clinic.patient.move</field>
 | 
				
			||||||
 | 
					    <field name="tabs">[
 | 
				
			||||||
 | 
					        ["All",[]],
 | 
				
			||||||
 | 
					        ["New",[["state","=","new"]]],
 | 
				
			||||||
 | 
					        ["Move",[["state","=","move"]]],
 | 
				
			||||||
 | 
					        ["Dispose",[["state","=","dispose"]]]
 | 
				
			||||||
 | 
					        ]</field>
 | 
				
			||||||
 | 
					    <field name="modes">list,form</field>
 | 
				
			||||||
 | 
					    <field name="menu">clinic_menu</field>
 | 
				
			||||||
 | 
					</action>
 | 
				
			||||||
| 
						 | 
					@ -12,6 +12,7 @@
 | 
				
			||||||
    </item>
 | 
					    </item>
 | 
				
			||||||
    <item string="Patients" perm="clinic_patient">
 | 
					    <item string="Patients" perm="clinic_patient">
 | 
				
			||||||
        <item string="Patients" action="clinic_patient"/>
 | 
					        <item string="Patients" action="clinic_patient"/>
 | 
				
			||||||
 | 
					        <item string="Patient Moves" action="clinic_patient_move"/>
 | 
				
			||||||
        <item string="Dialyzers" action="clinic_dialyzer"/>
 | 
					        <item string="Dialyzers" action="clinic_dialyzer"/>
 | 
				
			||||||
        <divider/>
 | 
					        <divider/>
 | 
				
			||||||
        <header string="SETTINGS"/>
 | 
					        <header string="SETTINGS"/>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,8 @@
 | 
				
			||||||
    <head>
 | 
					    <head>
 | 
				
			||||||
        <field name="type_id"/>
 | 
					        <field name="type_id"/>
 | 
				
			||||||
        <button string="Options" dropdown="1">
 | 
					        <button string="Options" dropdown="1">
 | 
				
			||||||
            <item string="Share" action="clinic_share_location"/>
 | 
					            <item string="Share" action="clinic_share_location" states="admit"/>
 | 
				
			||||||
 | 
					            <item string="Dispose" method="dispose" confirm="Are you sure?" states="admit"/>
 | 
				
			||||||
        </button>
 | 
					        </button>
 | 
				
			||||||
    </head>
 | 
					    </head>
 | 
				
			||||||
    <field name="number"/>
 | 
					    <field name="number"/>
 | 
				
			||||||
| 
						 | 
					@ -113,16 +114,16 @@
 | 
				
			||||||
        <tab string="Accounting" perm="clinic_patient_account">
 | 
					        <tab string="Accounting" perm="clinic_patient_account">
 | 
				
			||||||
            <field name="partner_id" domain='[["is_patient","=","true"]]'/>
 | 
					            <field name="partner_id" domain='[["is_patient","=","true"]]'/>
 | 
				
			||||||
        </tab>
 | 
					        </tab>
 | 
				
			||||||
        <tab string="Dispose Info">
 | 
					        <tab string="Disposing">
 | 
				
			||||||
            <group>
 | 
					            <group>
 | 
				
			||||||
                <field name="dispose"/>
 | 
					                <!--<field name="dispose"/>-->
 | 
				
			||||||
                <field name="resign_date" attrs='{"required":[["dispose","=","true"]]}'/>
 | 
					                <field name="resign_date" attrs='{"required":[["dispose","=","true"]]}'/>
 | 
				
			||||||
                <field name="note" attrs='{"required":[["dispose","=","true"]]}'/> 
 | 
					                <field name="note" attrs='{"required":[["dispose","=","true"]]}'/> 
 | 
				
			||||||
                <field name="state" invisible="1"/>
 | 
					                <field name="state" invisible="1"/>
 | 
				
			||||||
                <field name="hn_no" invisible="1"/>
 | 
					                <field name="hn_no" invisible="1"/>
 | 
				
			||||||
            </group>
 | 
					            </group>
 | 
				
			||||||
        </tab>
 | 
					        </tab>
 | 
				
			||||||
        <tab string="Log">
 | 
					        <tab string="Other info">
 | 
				
			||||||
            <group>
 | 
					            <group>
 | 
				
			||||||
                <field name="c_time"/>
 | 
					                <field name="c_time"/>
 | 
				
			||||||
                <field name="w_time"/>
 | 
					                <field name="w_time"/>
 | 
				
			||||||
| 
						 | 
					@ -173,4 +174,7 @@
 | 
				
			||||||
        <field name="documents"/>
 | 
					        <field name="documents"/>
 | 
				
			||||||
        <field name="comments"/>
 | 
					        <field name="comments"/>
 | 
				
			||||||
    </related>
 | 
					    </related>
 | 
				
			||||||
 | 
					    <foot>
 | 
				
			||||||
 | 
					        <button string="Active" method="do_active" type="success" attrs='{"invisible":[["state","!=","dispose"]]}'/>
 | 
				
			||||||
 | 
					    </foot>
 | 
				
			||||||
</form>
 | 
					</form>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					<form model="clinic.patient.move">
 | 
				
			||||||
 | 
					    <field name="date"/>
 | 
				
			||||||
 | 
					    <field name="state"/>
 | 
				
			||||||
 | 
					    <field name="patient_id" onchange="onchange_patient"/>
 | 
				
			||||||
 | 
					    <field name="patient_type_id"/>
 | 
				
			||||||
 | 
					    <field name="location_from_id"/>
 | 
				
			||||||
 | 
					    <field name="location_to_id"/>
 | 
				
			||||||
 | 
					</form>
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					<list model="clinic.patient.move">
 | 
				
			||||||
 | 
					    <field name="date"/>
 | 
				
			||||||
 | 
					    <field name="patient_id"/>
 | 
				
			||||||
 | 
					    <field name="patient_type_id"/>
 | 
				
			||||||
 | 
					    <field name="location_from_id"/>
 | 
				
			||||||
 | 
					    <field name="location_to_id"/>
 | 
				
			||||||
 | 
					    <field name="state"/>
 | 
				
			||||||
 | 
					</list>
 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,7 @@ import time
 | 
				
			||||||
from netforce.model import Model, fields, get_model
 | 
					from netforce.model import Model, fields, get_model
 | 
				
			||||||
from netforce.access import get_active_company, get_active_user, set_active_user
 | 
					from netforce.access import get_active_company, get_active_user, set_active_user
 | 
				
			||||||
from netforce.database import get_connection
 | 
					from netforce.database import get_connection
 | 
				
			||||||
 | 
					from netforce.utils import print_color
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from . import utils
 | 
					from . import utils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,6 +11,7 @@ class Patient(Model):
 | 
				
			||||||
    _name="clinic.patient"
 | 
					    _name="clinic.patient"
 | 
				
			||||||
    _string="Patient"
 | 
					    _string="Patient"
 | 
				
			||||||
    _audit_log=True
 | 
					    _audit_log=True
 | 
				
			||||||
 | 
					    _key=["number","name","branch_id"]
 | 
				
			||||||
    _multi_company=True
 | 
					    _multi_company=True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _get_age(self,ids,context):
 | 
					    def _get_age(self,ids,context):
 | 
				
			||||||
| 
						 | 
					@ -271,7 +273,7 @@ class Patient(Model):
 | 
				
			||||||
        'dispose': False,
 | 
					        'dispose': False,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    _sql_constraints=("clinic_patient_key_uniq","unique(name_check)","name should be unique"),
 | 
					    #_sql_constraints=("clinic_patient_key_uniq","unique(name_check)","name should be unique"),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def check_idcard(self,card_type,idcard=''):
 | 
					    def check_idcard(self,card_type,idcard=''):
 | 
				
			||||||
        res=True
 | 
					        res=True
 | 
				
			||||||
| 
						 | 
					@ -288,14 +290,11 @@ class Patient(Model):
 | 
				
			||||||
        elif len(idcard)!=13:
 | 
					        elif len(idcard)!=13:
 | 
				
			||||||
            res=False
 | 
					            res=False
 | 
				
			||||||
        if not res:
 | 
					        if not res:
 | 
				
			||||||
            raise Exception("Wrong ID Card!")
 | 
					            raise Exception("Wrong ID Card! %s/%s"%(len(idcard), 13))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def create(self, vals,**kw):
 | 
					
 | 
				
			||||||
        if 'card_no' in vals.keys():
 | 
					    def create_contact(self, ids, context={}):
 | 
				
			||||||
            self.check_idcard(vals.get("card_type",""),vals['card_no'])
 | 
					        obj=self.browse(ids)[0]
 | 
				
			||||||
        obj_id=super().create(vals,**kw)
 | 
					 | 
				
			||||||
        self.function_store([obj_id])
 | 
					 | 
				
			||||||
        obj=self.browse(obj_id)
 | 
					 | 
				
			||||||
        partner_id=obj.partner_id
 | 
					        partner_id=obj.partner_id
 | 
				
			||||||
        if not partner_id:
 | 
					        if not partner_id:
 | 
				
			||||||
            partner_name='%s %s'%(obj.first_name or "",obj.last_name or "") # XXX
 | 
					            partner_name='%s %s'%(obj.first_name or "",obj.last_name or "") # XXX
 | 
				
			||||||
| 
						 | 
					@ -327,7 +326,40 @@ class Patient(Model):
 | 
				
			||||||
            obj.write({
 | 
					            obj.write({
 | 
				
			||||||
                'partner_id': partner_id,
 | 
					                'partner_id': partner_id,
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
        return obj_id
 | 
					            print_color('contact created: %s'%partner_name,"green")
 | 
				
			||||||
 | 
					        return 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def create_patient_move(self, ids, context={}):
 | 
				
			||||||
 | 
					        obj=self.browse(ids)[0]
 | 
				
			||||||
 | 
					        cond=[
 | 
				
			||||||
 | 
					            ['date','=', time.strftime("%Y-%m-%d")],
 | 
				
			||||||
 | 
					            ['patient_id','=',obj.id],
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					        #XXX
 | 
				
			||||||
 | 
					        move_ids=get_model("clinic.patient.move").search(cond)
 | 
				
			||||||
 | 
					        if move_ids:
 | 
				
			||||||
 | 
					            get_model("clinic.patient.move").delete(move_ids)
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					        vals={
 | 
				
			||||||
 | 
					            'patient_id': obj.id,
 | 
				
			||||||
 | 
					            'patient_type_id': obj.type_id.id,
 | 
				
			||||||
 | 
					            'location_from_id': obj.department_id.id,
 | 
				
			||||||
 | 
					            'location_to_id': obj.department_id.id,
 | 
				
			||||||
 | 
					            "state": context.get('state') or "new",
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        get_model('clinic.patient.move').create(vals)
 | 
				
			||||||
 | 
					        print_color('patient_move created: %s'%vals,"green")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def create(self, vals,**kw):
 | 
				
			||||||
 | 
					        if 'card_no' in vals.keys():
 | 
				
			||||||
 | 
					            self.check_idcard(vals.get("card_type",""),vals['card_no'])
 | 
				
			||||||
 | 
					        new_id=super().create(vals,**kw)
 | 
				
			||||||
 | 
					        self.function_store([new_id])
 | 
				
			||||||
 | 
					        obj=self.browse(new_id)
 | 
				
			||||||
 | 
					        self.create_contact([new_id])
 | 
				
			||||||
 | 
					        self.create_patient_move([new_id])
 | 
				
			||||||
 | 
					        #return to wizard patient.move
 | 
				
			||||||
 | 
					        return new_id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def delete(self,ids,context={}):
 | 
					    def delete(self,ids,context={}):
 | 
				
			||||||
        partner_ids=[]
 | 
					        partner_ids=[]
 | 
				
			||||||
| 
						 | 
					@ -359,8 +391,8 @@ class Patient(Model):
 | 
				
			||||||
            vals['cw_time']=time.strftime("%Y-%m-%d %H:%M:%S")
 | 
					            vals['cw_time']=time.strftime("%Y-%m-%d %H:%M:%S")
 | 
				
			||||||
            vals['cw_uid']=get_active_user()
 | 
					            vals['cw_uid']=get_active_user()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #update type patient for pending hd case
 | 
				
			||||||
        if 'type_id' in vals.keys():
 | 
					        if 'type_id' in vals.keys():
 | 
				
			||||||
            #update patient in hd case which state is condition below
 | 
					 | 
				
			||||||
            for obj in self.browse(ids):
 | 
					            for obj in self.browse(ids):
 | 
				
			||||||
                for hdcase in get_model('clinic.hd.case').search_browse([['patient_id','in',ids],['state','in',['draft','waiting_treatment']]]):
 | 
					                for hdcase in get_model('clinic.hd.case').search_browse([['patient_id','in',ids],['state','in',['draft','waiting_treatment']]]):
 | 
				
			||||||
                    hdcase.write({
 | 
					                    hdcase.write({
 | 
				
			||||||
| 
						 | 
					@ -376,6 +408,8 @@ class Patient(Model):
 | 
				
			||||||
                vals['state']='admit'
 | 
					                vals['state']='admit'
 | 
				
			||||||
                vals['rm_remain_visit']=False
 | 
					                vals['rm_remain_visit']=False
 | 
				
			||||||
                vals['resign_date']=None
 | 
					                vals['resign_date']=None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #XXX reset resign date 
 | 
				
			||||||
        ctx={}
 | 
					        ctx={}
 | 
				
			||||||
        if 'active' in vals.keys():
 | 
					        if 'active' in vals.keys():
 | 
				
			||||||
            if not vals['active']:
 | 
					            if not vals['active']:
 | 
				
			||||||
| 
						 | 
					@ -460,10 +494,12 @@ class Patient(Model):
 | 
				
			||||||
                    del vals['addresses']
 | 
					                    del vals['addresses']
 | 
				
			||||||
                else:
 | 
					                else:
 | 
				
			||||||
                    obj.simple_address()
 | 
					                    obj.simple_address()
 | 
				
			||||||
 | 
					            # clear pending visit
 | 
				
			||||||
            if obj.rm_remain_visit or vals.get('rm_remain_visit'):
 | 
					            if obj.rm_remain_visit or vals.get('rm_remain_visit'):
 | 
				
			||||||
                visit_ids=get_model('clinic.visit').search([['patient_id','=',obj.id],['state','in',('draft','pending')]])
 | 
					                visit_ids=get_model('clinic.visit').search([['patient_id','=',obj.id],['state','in',('draft','pending')]])
 | 
				
			||||||
                get_model('clinic.visit').delete(visit_ids)
 | 
					                get_model('clinic.visit').delete(visit_ids)
 | 
				
			||||||
                print('remove visit auto %s'%visit_ids)
 | 
					                print('remove visit auto %s'%visit_ids)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        super().write(ids,vals,**kw)
 | 
					        super().write(ids,vals,**kw)
 | 
				
			||||||
        self.function_store(ids,context=ctx)
 | 
					        self.function_store(ids,context=ctx)
 | 
				
			||||||
        # update name of partner
 | 
					        # update name of partner
 | 
				
			||||||
| 
						 | 
					@ -574,4 +610,25 @@ class Patient(Model):
 | 
				
			||||||
            #data['doctor_id']=None
 | 
					            #data['doctor_id']=None
 | 
				
			||||||
        return data
 | 
					        return data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def dispose(self, ids, context={}):
 | 
				
			||||||
 | 
					        obj=self.browse(ids)[0]
 | 
				
			||||||
 | 
					        obj.write({
 | 
				
			||||||
 | 
					            'dispose': True,
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					        context['state']='dispose'
 | 
				
			||||||
 | 
					        obj.create_patient_move(context)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    def do_active(self, ids, context={}):
 | 
				
			||||||
 | 
					        obj=self.browse(ids)[0]
 | 
				
			||||||
 | 
					        obj.write({
 | 
				
			||||||
 | 
					            'active': True,
 | 
				
			||||||
 | 
					            'dispose': False,
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					        context['state']='new'
 | 
				
			||||||
 | 
					        obj.create_patient_move(context)
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        print('do_active')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Patient.register()
 | 
					Patient.register()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,17 +1,43 @@
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from netforce.model import Model, fields
 | 
					from netforce.model import Model, fields, get_model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PatientMove(Model):
 | 
					class PatientMove(Model):
 | 
				
			||||||
    _name="clinic.patient.move"
 | 
					    _name="clinic.patient.move"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    _fields={
 | 
					    _fields={
 | 
				
			||||||
        'patient_id': fields.Many2One('clinic.patient','Patient'),
 | 
					        'create_date': fields.DateTime("Create Date", required=True),
 | 
				
			||||||
        'date': fields.DateTime("Date"),
 | 
					        'date': fields.Date("Date", search=True, required=True),
 | 
				
			||||||
        'location_id': fields.Many2One("clinic.department","Department"),
 | 
					        'patient_id': fields.Many2One('clinic.patient','Patient', search=True, required=True),
 | 
				
			||||||
 | 
					        'patient_type_id': fields.Many2One('clinic.patient.type','Patient Type', search=True, required=True),
 | 
				
			||||||
 | 
					        'location_from_id': fields.Many2One("clinic.department","From Department", search=True, required=True),
 | 
				
			||||||
 | 
					        'location_to_id': fields.Many2One("clinic.department","To Department", search=True, required=True),
 | 
				
			||||||
 | 
					        "state": fields.Selection([['new','New'],["move","Move"],['dispose','Dispose']],'State'),
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    _defaults={
 | 
					    _defaults={
 | 
				
			||||||
        'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
 | 
					        'create_date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
 | 
				
			||||||
 | 
					        'date': lambda *a: time.strftime("%Y-%m-%d"),
 | 
				
			||||||
 | 
					        "state": "new",
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
PatientMove()
 | 
					    _order="date desc"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    _constraints=["check_location_status"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def check_location_status(self, ids, context={}):
 | 
				
			||||||
 | 
					        for obj in self.browse(ids):
 | 
				
			||||||
 | 
					            if obj.state=='move' and obj.location_from_id.id == obj.location_to_id.id:
 | 
				
			||||||
 | 
					                raise Exception("Can not move patient the same location!!")
 | 
				
			||||||
 | 
					            elif obj.state in ('new','dispose') and obj.location_from_id.id != obj.location_to_id.id:
 | 
				
			||||||
 | 
					                raise Exception("New/Dispose patient should be the same location!!")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def onchange_patient(self, context={}):
 | 
				
			||||||
 | 
					        data=context['data']
 | 
				
			||||||
 | 
					        patient_id=data['patient_id']
 | 
				
			||||||
 | 
					        patient=get_model("clinic.patient").browse(patient_id)
 | 
				
			||||||
 | 
					        data['patient_type_id']=patient.type_id.id
 | 
				
			||||||
 | 
					        data['location_from_id']=patient.branch_id.id
 | 
				
			||||||
 | 
					        return data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					PatientMove.register()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,7 @@ class Staff(Model):
 | 
				
			||||||
    _name="clinic.staff"
 | 
					    _name="clinic.staff"
 | 
				
			||||||
    _string="Staff"
 | 
					    _string="Staff"
 | 
				
			||||||
    _audit_log=True
 | 
					    _audit_log=True
 | 
				
			||||||
 | 
					    _key=["number","name","branch_id"]
 | 
				
			||||||
    _multi_company=True
 | 
					    _multi_company=True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _get_age(self,ids,context={}):
 | 
					    def _get_age(self,ids,context={}):
 | 
				
			||||||
| 
						 | 
					@ -251,7 +252,7 @@ class Staff(Model):
 | 
				
			||||||
        'location': _get_default_location,
 | 
					        'location': _get_default_location,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    _sql_constraints=("clinic_staff_key_uniq","unique(name_check)","name should be unique"),
 | 
					    #_sql_constraints=("clinic_staff_key_uniq","unique(name_check)","name should be unique"),
 | 
				
			||||||
    _order="date desc,number desc"
 | 
					    _order="date desc,number desc"
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    def create_contact(self,code,name):
 | 
					    def create_contact(self,code,name):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue