diff --git a/netforce_clinic/layouts/clinic_setting.xml b/netforce_clinic/layouts/clinic_setting.xml
index ba56b29..b3d635f 100644
--- a/netforce_clinic/layouts/clinic_setting.xml
+++ b/netforce_clinic/layouts/clinic_setting.xml
@@ -80,5 +80,6 @@
+
diff --git a/netforce_clinic/migrations/__init__.py b/netforce_clinic/migrations/__init__.py
index 7232eae..3055632 100644
--- a/netforce_clinic/migrations/__init__.py
+++ b/netforce_clinic/migrations/__init__.py
@@ -1,2 +1,3 @@
from . import clinic_setting
-from . import import_data
+#from . import import_pks
+from . import import_uc
diff --git a/netforce_clinic/migrations/import_data.py b/netforce_clinic/migrations/import_pks.py
similarity index 71%
rename from netforce_clinic/migrations/import_data.py
rename to netforce_clinic/migrations/import_pks.py
index 922e9ab..6eaacb3 100644
--- a/netforce_clinic/migrations/import_data.py
+++ b/netforce_clinic/migrations/import_pks.py
@@ -5,7 +5,7 @@ from netforce.access import get_active_user, set_active_user, set_active_company
from . import utils
class Migration(migration.Migration):
- _name="import.clinic.hd.case"
+ _name="import.pks"
_version="2.10"
def import_visit(self,lines):
@@ -62,6 +62,9 @@ class Migration(migration.Migration):
visits.update({
visit_id: {
'hct': line.get('hct'),
+ 'epoadm29':line.get("epoadm29"), # SRV
+ 'amount23':line.get("amount23"), # FEE
+ 'allow37':line.get("allow37"), # EPO
}
})
else:
@@ -77,12 +80,38 @@ class Migration(migration.Migration):
visit_ids=visits.keys()
for visit in get_model('clinic.visit').browse(visit_ids):
if visit!='confirmed':
- visit.confirm()
- hd_case=visit.hd_cases[0]
+ hd_case_id=visit.confirm()['next']['active_id']
+ hd_case=get_model("clinic.hd.case").browse(hd_case_id)
# lines
- hd_case.write({
+ vals={
'hct': visits[visit.id]['hct'] or 0,
- })
+ 'lines': [],
+ }
+ for st_prod in st.products:
+ if st_prod.patient_type_id.id==3:
+ prod=st_prod.product_id
+ price=st_prod.price
+ qty=st_prod.qty
+ categ=st_prod.product_categ_id
+ if categ.code=='FEE':
+ amt=visits[visit.id]['amount23'] or 0
+ elif categ.code=='SRV':
+ amt=visits[visit.id]['epoadm29'] or 0
+ elif categ.code=='EPO':
+ amt=visits[visit.id]['allow37'] or 0
+ else:
+ amt=0
+ vals['lines'].append(('create',{
+ 'product_id': prod.id,
+ 'uom_id': st_prod.uom_id.id,
+ 'product_categ_id': categ.id,
+ 'description': st_prod.description,
+ 'price': price,
+ 'qty': qty,
+ 'reimbursable': st_prod.reimbursable,
+ 'amount': amt,
+ }))
+ hd_case.write(vals)
hd_case_ids.append(hd_case.id)
st.write({
'auto_gen': False,
@@ -109,6 +138,7 @@ class Migration(migration.Migration):
print('hd case ', len(hd_case_ids))
hd_case_ids=self.hdc_done(hd_case_ids)
print('Done ', len(hd_case_ids))
+ set_active_company(1)
return True
Migration.register()
diff --git a/netforce_clinic/migrations/import_uc.py b/netforce_clinic/migrations/import_uc.py
new file mode 100644
index 0000000..787a820
--- /dev/null
+++ b/netforce_clinic/migrations/import_uc.py
@@ -0,0 +1,141 @@
+from netforce.model import get_model
+from netforce import migration
+from netforce.utils import get_file_path
+from netforce.access import get_active_user, set_active_user, set_active_company, get_active_company
+from . import utils
+
+class Migration(migration.Migration):
+ _name="import.uc"
+ _version="2.11"
+
+ def import_visit(self,lines):
+ visits={}
+ cycles=[(c['id'],'%s:00'%c['time_start'],'%s:00'%c['time_stop']) for c in get_model("clinic.cycle").search_read([[]],['time_start','time_stop'])]
+ patients=get_model("clinic.patient").search_browse([])
+ for line in lines:
+ dttran=line.get("dttran")
+ hn=line.get("hn")
+ if hn:
+ hn=''.join(x for x in hn if x.isdigit)
+
+ pid=None
+ for pt in patients:
+ if pt['hn_num']==hn:
+ pid=pt.id
+ break
+ if not pid:
+ print('continue ', pid)
+ continue
+ if dttran:
+ date,time=dttran.split("T")
+ if not time:
+ continue
+ cycle_id=None
+ patient=get_model("clinic.patient").browse(pid)
+ doctor=patient.doctor_id
+ department=patient.department_id
+ vals={
+ 'patient_id': patient.id,
+ 'doctor_id': doctor.id,
+ 'department_id': department.id,
+ 'state': 'pending',
+ }
+ for cycle in cycles:
+ time_start=cycle[1]
+ time_stop=cycle[2]
+ if time >= time_start:
+ cycle_id=cycle[0]
+ vals['cycle_id']=cycle_id
+ vals['time_start']='%s %s'%(date,time_start)
+ vals['time_stop']='%s %s'%(date,time_stop)
+ if not cycle_id:
+ raise Exception("not found cycle on this time %s %s %s"%(dttran, time_start,time_stop))
+ visit_ids=get_model("clinic.visit").search([['visit_date','=',date],['patient_id','=',pid]])
+ visit_id=None
+ if not visit_ids:
+ vals['visit_date']=date
+ visit_id=get_model('clinic.visit').create(vals)
+ else:
+ visit_id=visit_ids[0]
+ if visit_id:
+ visits.update({
+ visit_id: {
+ 'hct': line.get('hct'),
+ }
+ })
+
+ pass
+ return visits
+
+ def confirm_visit(self,visits):
+ st=get_model("clinic.setting").browse(1)
+ st.write({
+ 'auto_gen': True,
+ })
+ hd_case_ids=[]
+ visit_ids=visits.keys()
+ for visit in get_model('clinic.visit').browse(visit_ids):
+ if visit!='confirmed':
+ hd_case_id=visit.confirm()['next']['active_id']
+ hd_case=get_model("clinic.hd.case").browse(hd_case_id)
+ # lines
+ vals={
+ 'hct': visits[visit.id]['hct'] or 0,
+ 'lines': [],
+ }
+ for st_prod in st.products:
+ if st_prod.patient_type_id.id==3:
+ prod=st_prod.product_id
+ price=st_prod.price
+ qty=st_prod.qty
+ categ=st_prod.product_categ_id
+ if categ.code=='FEE':
+ amt=visits[visit.id]['amount23'] or 0
+ elif categ.code=='SRV':
+ amt=visits[visit.id]['epoadm29'] or 0
+ elif categ.code=='EPO':
+ amt=visits[visit.id]['allow37'] or 0
+ else:
+ amt=0
+ vals['lines'].append(('create',{
+ 'product_id': prod.id,
+ 'uom_id': st_prod.uom_id.id,
+ 'product_categ_id': categ.id,
+ 'description': st_prod.description,
+ 'price': price,
+ 'qty': qty,
+ 'reimbursable': st_prod.reimbursable,
+ 'amount': amt,
+ }))
+ hd_case.write(vals)
+ hd_case_ids.append(hd_case.id)
+ st.write({
+ 'auto_gen': False,
+ })
+ return hd_case_ids
+
+
+ def hdc_done(self,hd_case_ids):
+ done_ids=[]
+ for hd_case in get_model("clinic.hd.case").browse(hd_case_ids):
+ if hd_case.state=='waiting_treatment':
+ hd_case.complete()
+ done_ids.append(hd_case.id)
+ return done_ids
+
+ def migrate(self):
+ #fname='22283_EURSTM_201406.xml'
+ fname='22283_UOCDSTM_20140902.xml'
+ fpath=get_file_path(fname)
+ node='HDBills'
+ lines=utils.read_xml(fpath,node=node)
+ set_active_company(1)
+ visits=self.import_visit(lines)
+ print("visit ", len(visits))
+ #hd_case_ids=self.confirm_visit(visits)
+ #print('hd case ', len(hd_case_ids))
+ #hd_case_ids=self.hdc_done(hd_case_ids)
+ #print('Done ', len(hd_case_ids))
+ return True
+
+Migration.register()
diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py
index 8067f7d..aa37c75 100644
--- a/netforce_clinic/models/hd_case.py
+++ b/netforce_clinic/models/hd_case.py
@@ -361,6 +361,7 @@ class HDCase(Model):
context['inv_type']='invoice'
lines1=[] #yes
lines2=[] #no
+
for line in obj.lines:
if line.state!='draft':
continue
@@ -403,6 +404,7 @@ class HDCase(Model):
account_mdc_id=partner.account_mdc_id.id
account_fee_id=partner.account_fee_id.id
account_service_id=partner.account_service_id.id
+ print('>>>> ', partner.id, account_service_id, account_mdc_id, account_fee_id, ' <<<')
vals={
"type": "out",
"inv_type": "invoice",
@@ -531,6 +533,9 @@ class HDCase(Model):
def post_invoices(self,ids,context={}):
obj=self.browse(ids[0])
for inv in obj.invoices:
+ #XXX
+ if inv.amount_total<1:
+ continue
inv.post()
print("Post!")
@@ -890,8 +895,7 @@ class HDCase(Model):
# fee
st=get_model("clinic.setting").browse(1)
if st.auto_gen:
- return
-
+ return vals
if not vals.get('lines'):
vals['lines']=[]
for st_prod in st.products:
@@ -946,7 +950,13 @@ class HDCase(Model):
obj=self.browse(ids)[0]
vals['req_fee']=0
if 'lines' in vals.keys():
- for mode, line_ids, line_vals in vals['lines']:
+ #for mode, line_ids, line_vals in vals['lines']:
+ for line in vals['lines']:
+ mode=line[0]
+ if mode=='create':
+ line_vals=line[1]
+ else:
+ line_vals=line[2]
if line_vals['reimbursable']=='no':
vals['req_fee']=1 # to show button pay
else:
diff --git a/netforce_clinic/models/hd_case_expense.py b/netforce_clinic/models/hd_case_expense.py
index fd4cda8..e795aaa 100644
--- a/netforce_clinic/models/hd_case_expense.py
+++ b/netforce_clinic/models/hd_case_expense.py
@@ -37,6 +37,7 @@ class HDCaseExpense(Model):
'pt_conflict': fields.Boolean("Patient Conclict",function="_get_patient_conflict"),
'company_id': fields.Many2One("company","Company"),
'match_id': fields.Many2One("clinic.report.payment.matching","Match"),
+ 'invno': fields.Char("Invoice No"),
}
_defaults={
diff --git a/netforce_clinic/models/report_payment_matching.py b/netforce_clinic/models/report_payment_matching.py
index 025e0dc..47232b6 100644
--- a/netforce_clinic/models/report_payment_matching.py
+++ b/netforce_clinic/models/report_payment_matching.py
@@ -5,6 +5,14 @@ from netforce.model import Model,fields,get_model
from netforce.access import get_active_company
from . import utils
+STATES={
+ 'draft': 'Draft',
+ 'waiting_matching':'Waiting Matching',
+ 'match':'Match',
+ 'unmatch':'Unmatch',
+ 'approved':'Approved',
+}
+
class ReportPaymentMatching(Model):
_name="clinic.report.payment.matching"
_string="Report Payment Mathching"
@@ -42,14 +50,27 @@ class ReportPaymentMatching(Model):
}
def match_invoice(self,ids,context={}):
+ if not ids:
+ print("no ids")
+ return
obj=self.browse(ids)[0]
if not obj.file:
raise Exception("File not found!")
-
- for exp in get_model("clinic.hd.case.expense").search_browse([]):
- exp.write({
- 'match_id': obj.id,
- })
+ dom=[]
+ dom.append(['state','=','waiting_matching'])
+ for exp in get_model("clinic.hd.case.expense").search_browse(dom):
+ ptype=exp.patient_id.type_id
+ if ptype.id==obj.type_id.id:
+ exp.write({
+ 'match_id': obj.id,
+ })
+ else:
+ exp.write({
+ 'match_id': None,
+ })
+ # TODO
+ # udpate check state , write ref (invno)
+
return {
'next': {
'name': 'clinic_report_payment_matching',
@@ -61,21 +82,33 @@ class ReportPaymentMatching(Model):
def get_report_data(self,ids,context={}):
year, month=time.strftime("%Y-%m").split("-")
- obj_id=None
- if ids:
- obj=self.browse(ids)[0]
- obj_id=obj.id
lines=[]
- for exp in get_model("clinic.hd.case.expense").search_browse([]):
- if exp.match_id.id!=obj_id:
- continue
+ if not ids:
+ return
+ obj=self.browse(ids)[0]
+ dom=[]
+ dom.append(['state','=','waiting_matching'])
+ dom.append(['match_id','=',obj.id])
+ for exp in get_model("clinic.hd.case.expense").search_browse(dom):
patient=exp.patient_id
+ match='No'
+ exp_color=""
+ if exp.state=='match':
+ match='Yes'
+ else:
+ exp_color='#C0C0C0'
lines.append({
- 'name': patient.name,
- 'fee': 'Yes',
- 'medicine': 'Yes',
- 'service': 'Yes',
- 'state': 'Match',
+ 'exp_id': exp.id,
+ 'patient_name': patient.name,
+ 'patient_id': patient.id,
+ 'hn': patient.hn,
+ 'fee_amt': exp.fee_amt or 0,
+ 'mdc_amt': exp.mdc_amt or 0,
+ 'srv_amt': exp.srv_amt or 0,
+ #'state': STATES[exp.state],
+ 'match': match,
+ 'invno': exp.invno,
+ 'exp_color': exp_color,
})
data={
diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py
index 4348a6d..b3728c4 100644
--- a/netforce_clinic/models/setting.py
+++ b/netforce_clinic/models/setting.py
@@ -71,5 +71,50 @@ class ClinicSetting(Model):
amt=qty*price
line['amount']=amt
return data
+
+ def update_date(self,ids,context={}):
+ pass
+ #for hd_case in get_model("clinic.hd.case").search_browse([]):
+ #if hd_case.state!='waiting_treatment':
+ #continue
+ #for line in hd_case.lines:
+ #categ=line.product_categ_id
+ #if categ:
+ #if categ.code=='SRV':
+ #line.delete()
+
+ #for vs in get_model("clinic.visit").search_browse([]):
+ #if vs.state=='pending':
+ #vs.confirm()
+ #print(vs.number)
+
+ #obj=self.browse(ids)[0]
+ #for hd_case in get_model("clinic.hd.case").search_browse([]):
+ #number='/'
+ #if hd_case.number=='/':
+ #number=get_model("clinic.hd.case")._get_number()
+ #if hd_case.state=='waiting_treatment':
+ #hd_case.complete()
+
+ #date,time=hd_case.time_start.split(" ")
+ #hd_case.write({
+ #'date': date,
+ #'number': number,
+ #})
+ #for inv in hd_case.invoices:
+ #inv.write({
+ #'date': date,
+ #'due_date': date,
+ #})
+ #for pick in hd_case.pickings:
+ #pick.write({
+ #'date': date,
+ #})
+ #for exp in get_model('clinic.hd.case.expense').search_browse([]):
+ #exp.write({
+ #'date': exp.hd_case_id.date,
+ #})
+
+ #print('done')
ClinicSetting.register()
diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py
index c5196a2..afec25a 100644
--- a/netforce_clinic/models/visit.py
+++ b/netforce_clinic/models/visit.py
@@ -394,6 +394,7 @@ class Visit(Model):
vals['sequence']='%s-%s'%(vals['time_start'][0:10],cycle.sequence) #date-sequence
vals['visit_date']=vals['time_start'][0:10]
new_id=super().create(vals,**kw)
+ print('create visit ', new_id)
return new_id
def cancel(self,ids,context={}):
diff --git a/netforce_clinic/templates/report_payment_matching.hbs b/netforce_clinic/templates/report_payment_matching.hbs
index b75f8ea..8f82fab 100644
--- a/netforce_clinic/templates/report_payment_matching.hbs
+++ b/netforce_clinic/templates/report_payment_matching.hbs
@@ -4,20 +4,26 @@
{{#if lines}}
+ HN |
Patient |
- Fee(1,500) |
+ Invoice No |
+ Fee |
Medicine |
Service |
- Status |
+ Match |
+ |
{{#each lines}}
- {{name}} |
- {{fee}} |
- {{medicine}} |
- {{service}} |
- {{state}} |
+ {{hn}} |
+ {{patient_name}} |
+ {{invno}} |
+ {{fee_amt}} |
+ {{mdc_amt}} |
+ {{srv_amt}} |
+ {{match}} |
+ Edit |
{{/each}}