cycle time start & stop

conv_bal
watcha.h 2014-11-30 20:05:14 +07:00
parent 03a84b98a0
commit 7054fcc183
12 changed files with 275 additions and 107 deletions

View File

@ -4,9 +4,12 @@
</button> </button>
</head> </head>
<field name="name"/> <field name="name"/>
<field name="duration"/>
<field name="sequence"/> <field name="sequence"/>
<field name="time_start"/>
<field name="time_stop"/>
<field name="color"/> <field name="color"/>
<field name="duration"/>
<field name="note"/>
<related> <related>
<field name="cycle_items"/> <field name="cycle_items"/>
<field name="visits"/> <field name="visits"/>

View File

@ -1,5 +1,7 @@
<list model="clinic.cycle"> <list model="clinic.cycle">
<field name="name"/> <field name="name"/>
<field name="time_start"/>
<field name="time_stop"/>
<field name="duration"/> <field name="duration"/>
<field name="sequence"/> <field name="sequence"/>
<!--<field name="color"/>--> <!--<field name="color"/>-->

View File

@ -1,46 +1,41 @@
<form model="clinic.gen.visit"> <form model="clinic.gen.visit">
<group form_layout="stacked"> <group form_layout="stacked">
<field name="date_from" onchange="onchange_time" span="3"/> <field name="date_from" span="2"/>
<field name="date_to" onchange="onchange_dateto" span="3"/> <field name="time_start" span="1"/>
<!--<field name="duration" span="3"/>--> <field name="date_to" span="2"/>
<field name="cycle_id" onchange="onchange_time" span="3"/> <field name="time_stop" span="1"/>
<field name="patient_categ_id" span="3"/> <field name="cycle_id" onchange="onchange_cycle" span="2"/>
<field name="doctor_id" span="3"/> <field name="patient_categ_id" span="2"/>
<field name="nurse_categ_id" span="3"/> <field name="patient_type" span="2"/>
<field name="department_id" span="3"/> <field name="doctor_id" span="2"/>
<field name="patient_type" span="3"/> <field name="department_id" span="2"/>
</group> <field name="nurse_categ_id" span="2"/>
<separator string="Select Days"/> <separator string="Select Days"/>
<group form_layout="stacked"> <field name="monday" span="2"/>
<field name="monday" span="3"/> <field name="tuesday" span="2"/>
<field name="tuesday" span="3"/> <field name="wednesday" span="2"/>
<field name="wednesday" span="3"/> <field name="thursday" span="2"/>
<field name="thursday" span="3"/> <field name="friday" span="2"/>
<field name="friday" span="3"/> <field name="sathurday" span="2"/>
<field name="sathurday" span="3"/> <field name="sunday" span="2"/>
<field name="sunday" span="3"/> <separator string="Manual"/>
</group> <tabs>
<separator string="Manual"/> <tab string="Patients">
<tabs> <field name="patient_lines" nolabel="1">
<tab string="Patients">
<group form_layout="stacked">
<field name="patient_lines" nolabel="1" span="6">
<list> <list>
<field name="patient_id"/> <field name="patient_id"/>
</list> </list>
</field> </field>
</group> </tab>
</tab> <tab string="Nurses">
<tab string="Nurses"> <field name="nurse_lines" nolabel="1">
<group form_layout="stacked">
<field name="nurse_lines" nolabel="1" span="6">
<list> <list>
<field name="nurse_id"/> <field name="nurse_id"/>
</list> </list>
</field> </field>
</group> </tab>
</tab> </tabs>
</tabs> </group>
<foot> <foot>
<button string="Generate" type="success" icon="arrow-right" method="gen_visit"/> <button string="Generate" type="success" icon="arrow-right" method="gen_visit"/>
<button string="Remove" type="danger" icon="remove" method="clear_visit"/> <button string="Remove" type="danger" icon="remove" method="clear_visit"/>

View File

@ -86,10 +86,17 @@
</field> </field>
</tab> </tab>
<tab string="Note"> <tab string="Note">
<field name="note" nolabel="1"/> <group form_layout="stacked">
<field name="active"/> <field name="active" span="2"/>
<field name="resign_date" readonly="1"/> <field name="rm_remain_visit" span="2" attrs='{"invisible":[["active","=","true"]]}'/>
<field name="rm_remain_visit" attrs='{"invisible":[["active","=","true"]]}'/> <field name="resign_date" span="2" readonly="1"/>
<newline/>
<field name="note" nolabel="1"/>
</group>
</tab>
<tab string="Other">
<field name="cycle_id"/>
<field name="fee_partner_id"/>
</tab> </tab>
</tabs> </tabs>
<related> <related>

View File

@ -1,10 +1,9 @@
<form title="Social Security"> <form title="Social Security">
<group span="6" columns="1"> <group form_layout="stacked">
<field name="file"/> <field name="file" span="3"/>
</group> <field name="hcode" span="3"/>
<group span="6" columns="1">
</group> </group>
<foot replace="1"> <foot replace="1">
<button string="Import" method="import_uc" type="primary" icon="arrow-right"/> <button string="Import" method="import_sc" type="primary" icon="arrow-right"/>
</foot> </foot>
</form> </form>

View File

@ -1,3 +1,5 @@
from datetime import datetime
from netforce.model import Model, fields from netforce.model import Model, fields
from netforce.access import get_active_company from netforce.access import get_active_company
@ -6,16 +8,45 @@ class Cycle(Model):
_string="Cycle" _string="Cycle"
_key=["name"] _key=["name"]
def _get_duration(self,ids,context={}):
res={}
fmt="%Y-%m-%d %H:%M"
date=datetime.now().strftime(fmt)[0:10]
for obj in self.browse(ids):
tstart=obj.time_start
tstop=obj.time_stop
if not tstart:
tstart='00:00'
if not tstop:
tstop='00:00'
# recheck
tstart=tstart.replace(".",":")
tstop=tstop.replace(".",":")
if len(tstart.split(":"))!=2:
tstart="00:00"
if len(tstop.split(":"))!=2:
tstop="00:00"
dstart='%s %s'%(date,tstart)
dstop='%s %s'%(date,tstop)
diff=datetime.strptime(dstop,fmt)-datetime.strptime(dstart,fmt)
total_time=round(diff.seconds/3600,2)
res[obj.id]=total_time
return res
_fields={ _fields={
"name": fields.Char("Name",required=True,search=True), "name": fields.Char("Name",required=True,search=True),
'duration': fields.Integer("Duration (hrs)"), 'duration': fields.Integer("Duration(Hour)",function="_get_duration"),
'sequence': fields.Integer("Sequence"), 'sequence': fields.Integer("Sequence"),
'time_start': fields.Char("Start Time"),
'time_stop': fields.Char("End Time"),
'company_id': fields.Many2One("company", "Company"), 'company_id': fields.Many2One("company", "Company"),
'hd_cases': fields.One2Many("clinic.hd.case","cycle_id", "HD Cases"), 'hd_cases': fields.One2Many("clinic.hd.case","cycle_id", "HD Cases"),
'visits': fields.One2Many("clinic.visit","cycle_id", "Visits"), 'visits': fields.One2Many("clinic.visit","cycle_id", "Visits"),
'cycle_items': fields.One2Many("clinic.cycle.item","cycle_id", "Cycle Items"), 'cycle_items': fields.One2Many("clinic.cycle.item","cycle_id", "Cycle Items"),
'var_k': fields.Float("K"), 'var_k': fields.Float("K"),
'color': fields.Char("Color"), 'color': fields.Char("Color"),
'note': fields.Text("Note"),
} }
_defaults={ _defaults={

View File

@ -10,17 +10,11 @@ class GenVisit(Model):
_name="clinic.gen.visit" _name="clinic.gen.visit"
_transient=True _transient=True
def _get_duration(self,ids,context={}):
res={}
for obj in self.browse(ids):
duration=datetime.strptime(obj.date_to,FMT_DATETIME)-datetime.strptime(obj.date_from,FMT_DATETIME)
res[obj.id]=duration.days
return res
_fields={ _fields={
'date_from': fields.DateTime("From", required=True), 'date_from': fields.Date("From", required=True),
'date_to': fields.DateTime("To", required=True), 'date_to': fields.Date("To", required=True),
'time_start': fields.Char("Time start"),
'time_stop': fields.Char("Time Stop"),
'cycle_id': fields.Many2One("clinic.cycle","Cycle", required=True), 'cycle_id': fields.Many2One("clinic.cycle","Cycle", required=True),
'patient_lines': fields.One2Many("clinic.gen.visit.line","gen_id","Patient Lines"), 'patient_lines': fields.One2Many("clinic.gen.visit.line","gen_id","Patient Lines"),
'nurse_lines': fields.One2Many("clinic.gen.visit.line","gen_id","Nurse Lines"), 'nurse_lines': fields.One2Many("clinic.gen.visit.line","gen_id","Nurse Lines"),
@ -33,7 +27,6 @@ class GenVisit(Model):
'sunday': fields.Boolean("Sunday"), 'sunday': fields.Boolean("Sunday"),
'doctor_id': fields.Many2One("clinic.staff","Doctor",domain=[['type','=','doctor']]), 'doctor_id': fields.Many2One("clinic.staff","Doctor",domain=[['type','=','doctor']]),
'department_id': fields.Many2One("clinic.department","Department"), 'department_id': fields.Many2One("clinic.department","Department"),
'duration': fields.Integer("Duration (hrs)", function="_get_duration"),
"patient_type": fields.Selection([("sc","Social Security"),("uc","UC."),("others","Others")],"Patient Type"), "patient_type": fields.Selection([("sc","Social Security"),("uc","UC."),("others","Others")],"Patient Type"),
'patient_categ_id': fields.Many2One("clinic.patient.categ", "Patient Category"), 'patient_categ_id': fields.Many2One("clinic.patient.categ", "Patient Category"),
'nurse_categ_id': fields.Many2One("clinic.staff.categ", "Nurse Category", domain=[['type','=','nurse']]), 'nurse_categ_id': fields.Many2One("clinic.staff.categ", "Nurse Category", domain=[['type','=','nurse']]),
@ -64,12 +57,32 @@ class GenVisit(Model):
cycle_id=cycle_ids[0] cycle_id=cycle_ids[0]
return cycle_id or None return cycle_id or None
def _get_start(self,context={}):
cycle_ids=get_model('clinic.cycle').search([],order="sequence")
time_start="00:00"
if cycle_ids:
cycle_id=cycle_ids[0]
cycle=get_model('clinic.cycle').browse(cycle_id)
time_start=cycle.time_start
return time_start
def _get_stop(self,context={}):
cycle_ids=get_model('clinic.cycle').search([],order="sequence")
time_stop="00:00"
if cycle_ids:
cycle_id=cycle_ids[0]
cycle=get_model('clinic.cycle').browse(cycle_id)
time_stop=cycle.time_stop
return time_stop
_defaults={ _defaults={
'patient_lines': _get_patient_lines, 'patient_lines': _get_patient_lines,
'date_from': lambda *a: datetime.now().strftime(FMT_DATETIME), 'date_from': lambda *a: datetime.now().strftime(FMT_DATE),
'date_to': lambda *a: (datetime.now()+timedelta(days=7)).strftime(FMT_DATETIME), 'date_to': lambda *a: (datetime.now()+timedelta(days=7)).strftime(FMT_DATE),
'time_start': _get_start,
'time_stop': _get_stop,
'nurse_id': _get_nurse, 'nurse_id': _get_nurse,
'duration': 1, 'duration': 2,
'cycle_id': _get_cycle, 'cycle_id': _get_cycle,
#'monday': True, # dynamic select weekday, use default_get #'monday': True, # dynamic select weekday, use default_get
} }
@ -89,24 +102,13 @@ class GenVisit(Model):
vals[wds[wd]]=True vals[wds[wd]]=True
return vals return vals
def onchange_time(self,context={}): def onchange_cycle(self,context={}):
data=context['data'] data=context['data']
cycle_id=data['cycle_id'] cycle_id=data['cycle_id']
duration=1
if cycle_id: if cycle_id:
cycle=get_model('clinic.cycle').browse(cycle_id) cycle=get_model('clinic.cycle').browse(cycle_id)
duration=cycle.duration or 0 data['time_start']=cycle.time_start
seconds=duration*3600 data['time_stop']=cycle.time_stop
date_from=data['date_from']
date_to=(datetime.strptime(date_from,FMT_DATETIME)+timedelta(seconds=seconds)).strftime(FMT_DATETIME)
data['date_to']='%s %s'%(data['date_to'][0:10],date_to[11:])
duration=(datetime.strptime(data['date_to'],FMT_DATETIME)-datetime.strptime(data['date_from'],FMT_DATETIME)).seconds/3600
data['duration']=duration
return data
def onchange_dateto(self,context={}):
data=context['data']
data['duration']=(datetime.strptime(data['date_to'],FMT_DATETIME)-datetime.strptime(data['date_from'],FMT_DATETIME)).seconds/3600
return data return data
def gen_visit(self,ids,context): def gen_visit(self,ids,context):
@ -125,8 +127,8 @@ class GenVisit(Model):
if not days: if not days:
raise Exception("Please select Day") raise Exception("Please select Day")
visit_vals=[] visit_vals=[]
date_from=datetime.strptime(obj.date_from,FMT_DATETIME) date_from=datetime.strptime(obj.date_from,FMT_DATE)
date_to=datetime.strptime(obj.date_to,FMT_DATETIME) date_to=datetime.strptime(obj.date_to,FMT_DATE)
patients=[p.patient_id.id for p in obj.patient_lines if p.patient_id] patients=[p.patient_id.id for p in obj.patient_lines if p.patient_id]
if not patients and obj.patient_type: if not patients and obj.patient_type:
patients=get_model("clinic.patient").search([['type','=',obj.patient_type]]) patients=get_model("clinic.patient").search([['type','=',obj.patient_type]])
@ -158,6 +160,10 @@ class GenVisit(Model):
'level_id': nurse.level_id.id, 'level_id': nurse.level_id.id,
}) })
schedules={} schedules={}
cycle=obj.cycle_id
cstart='%s:00'%cycle.time_start
cstop='%s:00'%cycle.time_stop
for patient_id in patients: for patient_id in patients:
patient=get_model("clinic.patient").browse(patient_id) patient=get_model("clinic.patient").browse(patient_id)
ntoday=1 ntoday=1
@ -175,13 +181,13 @@ class GenVisit(Model):
tmp=start_date tmp=start_date
while count < day_total: while count < day_total:
tmp=start_date+timedelta(days=count) tmp=start_date+timedelta(days=count)
ttime_start="%s %s" % (tmp.strftime(FMT_DATE),date_from.strftime(FMT_DATETIME)[11:]) ttime_start="%s %s" % (tmp.strftime(FMT_DATE),cstart)
ttime_stop="%s %s" % (tmp.strftime(FMT_DATE),date_to.strftime(FMT_DATETIME)[11:]) ttime_stop="%s %s" % (tmp.strftime(FMT_DATE),cstop)
vals={ vals={
'patient_id': patient_id, 'patient_id': patient_id,
'doctor_id': obj.doctor_id.id or patient.doctor_id.id, 'doctor_id': obj.doctor_id.id or patient.doctor_id.id,
'department_id': obj.department_id.id, 'department_id': obj.department_id.id,
'cycle_id': obj.cycle_id.id, 'cycle_id': cycle.id,
'time_start': ttime_start, 'time_start': ttime_start,
'time_stop': ttime_stop, 'time_stop': ttime_stop,
'state': 'draft', 'state': 'draft',
@ -205,10 +211,14 @@ class GenVisit(Model):
'time_stop': ttime_stop, 'time_stop': ttime_stop,
'state':'draft', 'state':'draft',
} }
start_date=tmp start_date=tmp
user_id=get_active_user()
staff_ids=get_model("clinic.staff").search([['type','=','type'],['user_id','=',user_id]])
confirm_id=None
if staff_ids:
confirm_id=staff_ids[0]
for vals in visit_vals: for vals in visit_vals:
vals['nurse_id']=confirm_id
visit_obj.create(vals) visit_obj.create(vals)
print("create schedule") print("create schedule")
@ -263,8 +273,8 @@ class GenVisit(Model):
] ]
days=[day for day in days if day] days=[day for day in days if day]
visit_ids=[] visit_ids=[]
date_from=datetime.strptime(obj.date_from,FMT_DATETIME) date_from=datetime.strptime(obj.date_from,FMT_DATE)
date_to=datetime.strptime(obj.date_to,FMT_DATETIME) date_to=datetime.strptime(obj.date_to,FMT_DATE)
# FIXME add more 1 week for make sure # FIXME add more 1 week for make sure
date_to2=(date_to+timedelta(days=7)).strftime(FMT_DATETIME) date_to2=(date_to+timedelta(days=7)).strftime(FMT_DATETIME)
visit_obj=get_model("clinic.visit") visit_obj=get_model("clinic.visit")
@ -282,12 +292,16 @@ class GenVisit(Model):
dom=[] dom=[]
dom.append(['time_start','>=','%s %s'%(obj.date_from[0:10],' 00:00:00')]) dom.append(['time_start','>=','%s %s'%(obj.date_from[0:10],' 00:00:00')])
dom.append(['time_stop','<=','%s %s'%(date_to2[0:10],' 23:59:59')]) dom.append(['time_stop','<=','%s %s'%(date_to2[0:10],' 23:59:59')])
dom.append(['cycle_id','=',obj.cycle_id.id])
dom.append(['state','=','draft']) dom.append(['state','=','draft'])
vids=visit_obj.search(dom) vids=visit_obj.search(dom)
visit_obj.delete(vids) visit_obj.delete(vids)
schedule_obj=get_model("clinic.schedule") schedule_obj=get_model("clinic.schedule")
schedule_ids=schedule_obj.search(dom) schedules=schedule_obj.search_browse(dom)
schedule_ids=[]
for sch in schedules:
for line in sch.lines:
if obj.cycle_id.id==line.cycle_id.id:
schedule_ids.append(sch.id)
schedule_obj.delete(schedule_ids) schedule_obj.delete(schedule_ids)
return { return {
'next': { 'next': {

View File

@ -15,7 +15,7 @@ class HDCase(Model):
_name_field="number" _name_field="number"
_multi_company=True _multi_company=True
def get_hrs(self,ids,context={}): def _get_duration(self,ids,context={}):
res={} res={}
fmt="%Y-%m-%d %H:%M:%S" fmt="%Y-%m-%d %H:%M:%S"
for obj in self.browse(ids): for obj in self.browse(ids):
@ -24,7 +24,7 @@ class HDCase(Model):
res[obj.id]=total_time res[obj.id]=total_time
return res return res
def get_pay_amount(self,ids,context={}): def _get_pay_amount(self,ids,context={}):
res={} res={}
for obj in self.browse(ids): for obj in self.browse(ids):
res[obj.id]=obj.amount res[obj.id]=obj.amount
@ -101,7 +101,7 @@ class HDCase(Model):
"payments": fields.One2Many("account.payment","related_id","Payments"), "payments": fields.One2Many("account.payment","related_id","Payments"),
"payment_lines": fields.One2Many("clinic.payment","hd_case_id","Payment Lines"), "payment_lines": fields.One2Many("clinic.payment","hd_case_id","Payment Lines"),
'visit_id': fields.Many2One("clinic.visit", "Visit"), 'visit_id': fields.Many2One("clinic.visit", "Visit"),
'duration': fields.Integer("Duration(Hours)",function="get_hrs"), 'duration': fields.Integer("Duration(Hours)",function="_get_duration"),
"total": fields.Float("Total",function="_get_total",readonly=True,function_multi=True), "total": fields.Float("Total",function="_get_total",readonly=True,function_multi=True),
"fee_amount": fields.Float("Fee",function="_get_total",readonly=True,function_multi=True), "fee_amount": fields.Float("Fee",function="_get_total",readonly=True,function_multi=True),
"mdc_amount": fields.Float("Medicine",function="_get_total",readonly=True,function_multi=True), "mdc_amount": fields.Float("Medicine",function="_get_total",readonly=True,function_multi=True),
@ -112,7 +112,7 @@ class HDCase(Model):
'complication': fields.Text("Complication"), 'complication': fields.Text("Complication"),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"), "cycle_id": fields.Many2One("clinic.cycle","Cycle"),
'cycle_item_id': fields.Many2One("clinic.cycle.item","Nurse Schedule"), # on_delete="cascade" -> will rm visit from cycle item 'cycle_item_id': fields.Many2One("clinic.cycle.item","Nurse Schedule"), # on_delete="cascade" -> will rm visit from cycle item
'pay_amount': fields.Float("Amount",function="get_pay_amount"), 'pay_amount': fields.Float("Amount",function="_get_pay_amount"),
'pay_date': fields.Date("Pay Date"), 'pay_date': fields.Date("Pay Date"),
'pay_account_id': fields.Many2One("account.account","Account"), 'pay_account_id': fields.Many2One("account.account","Account"),
'payment_id': fields.Many2One("account.payment","Payment"), # for print 'payment_id': fields.Many2One("account.payment","Payment"), # for print
@ -187,13 +187,15 @@ class HDCase(Model):
def onchange_patient(self,context={}): def onchange_patient(self,context={}):
data=context['data'] data=context['data']
patient_id=data['patient_id'] patient_id=data['patient_id']
hd_cases=self.search_browse([['patient_id','=',patient_id]]) if patient_id:
if hd_cases: patient=get_model('clinic.patient').browse(patient_id)
hd_case=hd_cases[-1] department=patient.department_id
data['department_id']=hd_case.department_id.id cycle=patient.cycle_id
else: partner=patient.fee_partner_id
data['department_id']=None data['department_id']=department.id
#XXX data['patient_type']=patient.type
data['cycle_id']=cycle.id
data['fee_partner_id']=partner.id
data['dialyzers']=[] data['dialyzers']=[]
return data return data

View File

@ -9,6 +9,8 @@ from netforce.utils import get_file_path
from netforce.utils import get_data_path from netforce.utils import get_data_path
from netforce.database import get_connection from netforce.database import get_connection
from pprint import pprint
class ImportPayment(Model): class ImportPayment(Model):
_name="clinic.import.payment" _name="clinic.import.payment"
_transient=True _transient=True
@ -121,6 +123,49 @@ class ImportPayment(Model):
lines=self.read_excel(fpath) lines=self.read_excel(fpath)
if not lines: if not lines:
raise Exception("Wrong File") raise Exception("Wrong File")
for line in lines:
hcode=line.get('hcode18','0')
if not hcode:
hcode='0'
hcode=int(hcode)
hcode=str(hcode)
if obj.hcode==hcode:
invno=line.get("invno","")
name=line.get("name14")
hn=line.get('hn',"")
hct=line.get("HCT","")
amount=line.get("amount23",0)
dttran=line.get("dttran","")
#==== product =====
prod_code=line.get("code31","")
prod_name=line.get('eponame',"")
prod_qty=line.get("qty",0)
prod_unit=line.get("unit32","")
prod_ids=get_model("product").search([['code','=',prod_code]])
if not prod_ids:
print('create')
vals={
'code': prod_code,
'name': prod_name,
'type': 'stock',
}
unit_ids=get_model("uom").search([['name','=',prod_unit]])
if not unit_ids:
prod_unit_id=get_model("uom").create({
'name': prod_unit,
'type': 'unit',
})
else:
prod_unit_id=unit_ids[0]
vals['uom_id']=prod_unit_id
prod_id=get_model("product").create(vals)
print("create product ", prod_id, prod_name)
# ================
print(dttran, invno, hcode, hn, name, hct, amount)
return
data_sc=get_model("clinic.data.sc") data_sc=get_model("clinic.data.sc")
sc_ids=data_sc.search([]) sc_ids=data_sc.search([])
data_sc.delete(sc_ids) data_sc.delete(sc_ids)
@ -191,12 +236,6 @@ class ImportPayment(Model):
'result': msg, 'result': msg,
}) })
def import_mg(self,ids,context={}):
obj=self.browse(ids)[0]
fname=obj.file
fpath=get_file_path(fname)
print("fpath ", fpath)
def clear_sc(self,ids,context={}): def clear_sc(self,ids,context={}):
sc_ids=get_model("clinic.data.sc").search([]) sc_ids=get_model("clinic.data.sc").search([])
get_model("clinic.data.sc").delete(sc_ids) get_model("clinic.data.sc").delete(sc_ids)
@ -254,5 +293,4 @@ class ImportPayment(Model):
'flash': 'Paid', 'flash': 'Paid',
} }
ImportPayment.register() ImportPayment.register()

View File

@ -3,11 +3,8 @@ 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
PATIENT_TYPE={ from . import utils
"sc":"Social Security",
"uc":"UC",
"others": "Others",
}
class Patient(Model): class Patient(Model):
_name="clinic.patient" _name="clinic.patient"
@ -27,6 +24,28 @@ class Patient(Model):
res[obj.id]=age res[obj.id]=age
return res # -> {1: 30, 2: 45,.....} return res # -> {1: 30, 2: 45,.....}
def _get_last_cycle(self,ids,context={}):
res={}
for obj in self.browse(ids):
cycle_id=None
for vs in obj.visits:
cycle=vs.cycle_id
cycle_id=cycle.id
res[obj.id]=cycle_id
return res
def _get_fee_partner(self,ids,context={}):
res={}
for obj in self.browse(ids):
pt_type=utils.PATIENT_TYPE.get(obj.type)
categ_ids=get_model("partner.categ").search([['name','=',pt_type]])
partner_ids=get_model("partner").search([['categ_id','in',categ_ids]])
partner_id=None
if partner_ids:
partner_id=partner_ids[0]
res[obj.id]=partner_id
return res
_fields={ _fields={
"type": fields.Selection([("sc","Social Security"),("uc","UC"),("others","Others")],"Type",required=True), "type": fields.Selection([("sc","Social Security"),("uc","UC"),("others","Others")],"Type",required=True),
"number": fields.Char("Number",required=True,search=True), "number": fields.Char("Number",required=True,search=True),
@ -84,6 +103,8 @@ class Patient(Model):
'rm_remain_visit': fields.Boolean("Auto Remove Remaining Visit"), 'rm_remain_visit': fields.Boolean("Auto Remove Remaining Visit"),
'branch_id': fields.Many2One("clinic.branch","Branch"), 'branch_id': fields.Many2One("clinic.branch","Branch"),
'department_id': fields.Many2One("clinic.department","Department"), 'department_id': fields.Many2One("clinic.department","Department"),
'cycle_id': fields.Many2One("clinic.cycle","Last Cycle",function="_get_last_cycle"),
'fee_partner_id': fields.Many2One("partner","Contact Fee",function="_get_fee_partner"),
} }
def _get_number(self,context={}): def _get_number(self,context={}):

View File

@ -55,6 +55,56 @@ class ClinicSetting(Model):
return data return data
def make_visit(self,ids,context={}): def make_visit(self,ids,context={}):
obj=self.browse(ids)[0]
fname=obj.file
fpath=get_file_path(fname)
lines=self.read_excel(fpath)
if not lines:
raise Exception("Wrong File")
for line in lines:
hcode=line.get('hcode18','0')
if not hcode:
hcode='0'
hcode=int(hcode)
hcode=str(hcode)
if obj.hcode==hcode:
invno=line.get("invno","")
name=line.get("name14")
hn=line.get('hn',"")
hct=line.get("HCT","")
amount=line.get("amount23",0)
dttran=line.get("dttran","")
#==== product =====
prod_code=line.get("code31","")
prod_name=line.get('eponame',"")
prod_qty=line.get("qty",0)
prod_unit=line.get("unit32","")
prod_ids=get_model("product").search([['code','=',prod_code]])
if not prod_ids:
print('create')
vals={
'code': prod_code,
'name': prod_name,
'type': 'stock',
}
unit_ids=get_model("uom").search([['name','=',prod_unit]])
if not unit_ids:
prod_unit_id=get_model("uom").create({
'name': prod_unit,
'type': 'unit',
})
else:
prod_unit_id=unit_ids[0]
vals['uom_id']=prod_unit_id
prod_id=get_model("product").create(vals)
print("create product ", prod_id, prod_name)
# ================
print(dttran, invno, hcode, hn, name, hct, amount)
return
def _make_visit(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
fname=obj.file fname=obj.file
fpath=get_file_path(fname) fpath=get_file_path(fname)

View File

@ -7,6 +7,12 @@ improval
- uc - uc
excel excel
- social security - social security
- step
1. create visit
2. confirm visit -> hd case
3. match payment
- show wrong match
- show how to solve
====== ======
bug: bug:
มีปัญหาการสร้าง address ของ contact จากผู้ป่วยโดยอัตโนมัติ เพราะมันไม่ได้ถูกเก็บไว้ที่ form มีปัญหาการสร้าง address ของ contact จากผู้ป่วยโดยอัตโนมัติ เพราะมันไม่ได้ถูกเก็บไว้ที่ form