ผลต่างระหว่างรุ่นของ "Openerp/histest"

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
(แทนทีข้อความทั้งหมดด้วย '== ปรับแก้โมเดล Patient ให้รองรับการถ่ายภาพผู้ป่ว...')
 
(ไม่แสดง 5 รุ่นระหว่างกลางโดยผู้ใช้คนเดียวกัน)
แถว 1: แถว 1:
−
== การสร้าง OTP เพื่อผนวกเข้ากับ workflow ของโมเดล HISAppointment ==
+
== ปรับแก้โมเดล Patient ให้รองรับการถ่ายภาพผู้ป่วย ==
  
−
=== ไฟล์ histest.py ===
+
ดาวน์โหลดมอดูล Web Camera [[File:web_camera.zip]]
−
ที่ตอนต้นของไฟล์ โหลดฟังก์ชัน send_sms จากมอดูล sms.py ที่สร้างขึ้นก่อนหน้านี้ และฟังก์ชัน randint จากมอดูล random เพื่อใช้สร้าง OTP (One-Time Password) แบบสุ่ม
 
−
<syntaxhighlight lang="python">
 
−
# encoding=utf-8
 
−
from random import randint
 
−
from osv import osv, fields
 
−
from sms import send_sms
 
−
</syntaxhighlight>
 
−
 
 
−
เพิ่มฟิลด์ phone_number ลงในโมเดล HISPatient เพื่อใช้รับ OTP ผ่าน SMS
 
−
<syntaxhighlight lang="python">
 
−
class HISPatient(osv.Model):
 
−
    :
 
−
    _columns={
 
−
        :
 
−
        'phone_number': fields.char(size=20, string=u'โทรศัพท์'),
 
−
        :
 
−
    }
 
−
</syntaxhighlight>
 
−
 
 
−
ในโมเดล HISAppointment เพิ่มฟิลด์ generated_otp และ entered_otp เพื่อใช้เก็บ OTP ที่ถูกสุ่มขึ้นและ OTP ที่ถูกป้อนโดยผู้ใช้ตามลำดับ รวมถึงเมท็อดที่ถูกเรียกใช้เมื่อ workflow ของการนัดหมายเข้าสู่สเตท arrived และเมท็อดสำหรับสร้าง OTP เพื่อส่งไปยังผู้ป่วยผ่าน SMS
 
−
 
 
−
<syntaxhighlight lang="python">
 
−
class HISAppointment(osv.Model):
 
−
    :
 
−
    _columns = {
 
−
            :
 
−
            'generated_otp': fields.char(size=10, string=u'Generated OTP'),
 
−
            'entered_otp': fields.char(size=10, string=u'Enter OTP'),
 
−
            :
 
−
            }
 
−
 
 
−
    def action_arrived(self, cr, uid, ids, context=None):
 
−
        appointments = self.browse(cr, uid, ids)
 
−
        appointment = appointments[0]
 
−
        if appointment.generated_otp == appointment.entered_otp:
 
−
            self.write(cr, uid, ids, {'state':'arrived'})
 
−
        else:
 
−
            raise osv.except_osv('Error', 'Incorrect OTP')
 
−
 
 
−
    def generate_otp(self, cr, uid, ids, context=None):
 
−
        for id in ids:
 
−
            appointments = self.browse(cr, uid, [id])
 
−
            appointment = appointments[0]
 
−
            patient_phone_number = appointment.patient_id.phone_number
 
−
            new_otp = str(randint(10000, 99999))
 
−
            self.write(cr, uid, [id], {'generated_otp': new_otp})
 
−
            send_sms('jittat', '0943fa', '0000', patient_phone_number,
 
−
                'Your OTP is: ' + new_otp)
 
−
</syntaxhighlight>
 
−
 
 
−
=== ไฟล์ histest_view.xml ===
 
−
เพิ่มฟิลด์ phone_number ในฟอร์มวิวของโมเดล HISPatient
 
−
<syntaxhighlight lang="xml">
 
−
    <record model="ir.ui.view" id="view_histest_patient_form">
 
−
            :
 
−
            <group colspan="1">
 
−
              <field name="phone_number"/>
 
−
              <field name="sex"/>
 
−
              <field name="id_number" widget="person_id" />
 
−
              <field name="appointment_ids" />
 
−
            </group>
 
−
            :
 
−
    </record>
 
−
</syntaxhighlight>
 
−
 
 
−
เพิ่มฟิลด์ generated_otp และ entered_otp ใฟ้ฟอร์มวิวของโมเดล HISAppointment รวมถึงสร้างปุ่ม Generate OTP และทำให้ปุ่มทั้งหมดแสดงผลเฉพาะใน edit mode
 
−
<syntaxhighlight lang="xml">
 
−
    <record model="ir.ui.view" id="view_histest_appointment_form">
 
−
          :
 
−
          <group>
 
−
            <field name="patient_id"/>
 
−
            <field name="department_id"/>
 
−
            <field name="date"/>
 
−
            <field name="state"/>
 
−
            <field name="generated_otp"/>
 
−
            <field name="entered_otp"/>
 
−
            <button name="generate_otp" string="Generate OTP" type="object"
 
−
                class="oe_edit_only" />
 
−
            <button name="arrive" string="Patient Arrived" states="new"
 
−
                class="oe_edit_only" />
 
−
            <button name="done" string="Done" states="arrived"
 
−
                class="oe_edit_only" />
 
−
          </group>
 
−
          :
 
−
    </record>
 
−
</syntaxhighlight>
 
−
 
 
−
เพิ่ม action window เพื่อแสดงผลเฉพาะการนัดหมายของวันที่ปัจจุบัน พร้อม menu item เพื่อเปิดหน้าวิว
 
−
<syntaxhighlight lang="xml">
 
−
    <record model="ir.actions.act_window" id="action_histest_today_appointments">
 
−
      <field name="name">Today Appointments</field>
 
−
      <field name="res_model">histest.appointment</field>
 
−
      <field name="view_type">form</field>
 
−
      <field name="view_mode">tree,form</field>
 
−
      <field name="domain">
 
−
          [('date','=',context_today().strftime('%Y-%m-%d'))]
 
−
      </field>
 
−
    </record>
 
−
 
 
−
    <menuitem name="การนัดหมายวันนี้" id="menu_histest_today_appointments"
 
−
              parent="menu_histest_main" sequence="6"
 
−
              action="histest.action_histest_today_appointments"/>
 
−
 
 
−
</syntaxhighlight>
 
−
 
 
−
== การสร้าง Scheduled Action ==
 

รุ่นแก้ไขปัจจุบันเมื่อ 07:02, 15 พฤษภาคม 2557

ปรับแก้โมเดล Patient ให้รองรับการถ่ายภาพผู้ป่วย

ดาวน์โหลดมอดูล Web Camera ไฟล์:Web camera.zip