Saturday, 20 April 2013

EDI 270–5010 Documentation - ISA – Interchange Control Header

 

            

ISA – Interchange Control Header  

The ISA is a fixed record length segment and all positions within each of the data elements must be filled. The first element separator defines the  element separator to be used through the entire interchange. The segment terminator used after the ISA defines the segment terminator to be used throughout the entire interchange.This results in the segment terminator always being in position 106.


PMS Product Reference

image


  Seg ID Segment Name Format Length Ref# Req Value
Header ISA Interchange Control Header 3 R ISA
Element Separator AN 1 *
ISA01 Authorization information qualifier ID 2/2 101 R 00 or 03 See below for more information
Element Separator AN 1 *
  ISA02 Authorization information AN 10/10 102 R Will contain User ID if ISA01 is 03.
Will Contain 10 Empty spaces if ISA01 is 00
    Element Separator AN 1     *
  ISA03 Security information qualifier ID 2/2 103 R Will Contain 01 if ISA01 is 03.
Will Contain 00 if ISA01 Is 00.
    Element Separator AN 1     *
  ISA04 Security information AN 10/10 104 R Will contain Password if ISA01 is 03.
Will Contain 10 Empty spaces if ISA01 is 00
    Element Separator AN 1     *
  ISA05 Interchange ID Qualifier ID 2/2 105 R ZZ
    Element Separator AN 1     *
  ISA06 Interchange Sender ID AN 2/15 106 R See below for more information
    Element Separator AN 1     *
  ISA07 Interchange ID Qualifier ID 2/2 105 R 01
    Element Separator AN 1     *
  ISA08 Interchange Receiver ID AN 15/15 107 R See below for more information
    Element Separator AN 1     *
  ISA10 Interchange Time TM 4/4 109 R Current Time in HHMM Format
    Element Separator AN 1     *
  ISA11 Repetition Separator ID 1/1 110 R ^
    Element Separator AN 1     *
  ISA12 Interchange Control Version Number ID 5/5 111 R 00501
    Element Separator AN 1     *
  ISA13 Interchange Control Number NO 9/9 112 R 000000001 (See below for more info)
    Element Separator AN 1     *
  ISA14 Acknowledgement required          
    Element Separator AN 1     *
  ISA15 Usage indicator ID 1/1 114 R P or T (See below for more details)
    Element Separator AN 1     *
  ISA16 Component Element Separator   1/1 115 R : (semi colon). this value must be different than the data element separator and the segment terminator
    Element Separator AN 1     *
               

Sample:  

ISA*00*          *00*          *ZZ*8431           *ZZ*ZIRMED         *130215*1234*^*00501*000000001*1*P*:~


Important Note on the above sample:
ISA02
Since ISA is fixed length segment, even though if no values are present, we need to fill up empty spaces. Here ISA02 is filled with 10 empty spaces.

ISA04
Since ISA is fixed length segment, even though if no values are present, we need to fill up empty spaces. Here ISA04 is filled with 10 empty spaces.

ISA06
Since ISA is fixed length segment, if the value is not 15 characters length, then we need to append empty space to make 15 characters string.

ISA08
Since ISA is fixed length segment, if the value is not 15 characters length, then we need to append empty space to make 15 characters string.


Segment Structure  

image



Sample 2
ISA*03*id27032743*01*XYXY2233  *ZZ*XX09211223     *01*030240928      *130829*1102*^*00501*290811021*0*T*:~

User Name and Password
In some clearing house, they might ask to send the user name and password along with each EDI file. That's what Authorization information Information refer ISA01, ISA02,ISA03 and ISA04.  After you sign up with the clearing house, ask your user name and password to send along the EDI File if they need.  In such case, ISA01 will have the value"03" , ISA02 will have the user id, ISA03 will have the value "01" and ISA04 will have the actual password. Very important, since ISA is fixed length segment, and ISA02 is 10 character, so if your user id is less than 10 characters, then you need to append empty spaces to make it as 10 character word.
 
Sample with the User id and Password.

 

Segment Structure  
image



ISA01 - Authorization Information Qualifier
Code to identify the type of information in the Authorization Information
Code Definition
00 No Authorization information Present(No Meaningful information in 102). Advised unless security requirements Mandate use of Additional identification information.
03 Additional Data Identification.

 


ISA03 - Security Information Qualifier
Code to identify the type of information in the Security information qualifier

Code Definition
00 No Security information Present(No Meaningful information in 104). Advised unless security requirements Mandate use of password data.
01 Password

 

ISA05, ISA07- Interchange ID Qualifier
Code to identify the type of information in the Security information qualifier

Code Definition
01 Duns(Dun & BradStreet)
14 Duns Plus Suffix
20 Health Industry Number (HIN)
27 Carrier Identification Number
28 Fiscal Intermediary Identification Number.
29 Medicare Provider and Supplier Identification Number
30 U.S Federal Tax Identification Number
33 National Association Of Insurance Commissioners Company Code (NAIC)
ZZ Mutually Defined



ISA06 – Interchange Sender ID
During the sign up process with clearing house, they will assign a unique ID to the software vendor. So in the practice information setup, software should have a option to enter this value. This is mandatory for all the EDI Files, without this ID, clearing house will not be able to process the file.

ISA08 – Interchange Receiver ID
During the sign up process with clearing house, they will provide this value. Usually, this will be clearing house name. So in the practice information setup, software should have a option to enter this value. This is mandatory for all the EDI Files, without this ID, clearing house will not be able to process the file.

ISA13 – Interchange Control Number
Control Number assigned by the Sender for tracking purpose. This number must be identical to the Interchange Trailer IEA02. Ever time
when creating the EDI File, software can generate a unique number to identify the batch for later case to track. 

ISA14 - Acknowledgment Requested.


Code Definition
0 No Acknowledgment Requested
1 Interchange Acknowledgement Requested

Default to 0. In some cases, if the software vendor integrated to clearing house via web services. then we can ask the clearing house to send the acknowledgment for each EDI File batches.

ISA15 – Usage Indicator.

Code Definition
P Production Data
T Test Data

After the  sign up process with clearing house, they will ask the software vendor to send sample files with different use cases. In such cases, all the files should be send as Test Data. So in the practice information setup, software should have this option to select. Once test files are approved, then software admin can change this value to Production.

 

            



Questions or feedback are always welcome.


Friday, 19 April 2013

EDI 270 - 5010 Health Care Eligibility/Benefit Inquiry


If you are new to Medical Billing, then please read this article first.

If you are new to EDI, then  read the following articles

1.
What is an EDI ?
2. EDI Transactions 

3. Understanding EDI Structure
4. EDI Instruction

Introduction

For the health care industry to achieve the potential administrative cost savings with Electronic Data Interchange (EDI), standards have been developed and need to be implemented consistently by all organizations. To facilitate a smooth transition into the EDI environment, uniform implementation is critical.
Providers of medical services must currently submit health care eligibility and benefit inquiries in a variety of methods, either on paper, via phone, or electronically. The information requirements vary depending upon:

  • type of insurance plan
  • type of service performed
  • where the service is performed
  • where the inquiry is initiated
  • where the inquiry is sent

  • The Health Care Coverage, Eligibility, and Benefit transactions are designed so that inquiry submitters (information receivers) can determine (a) whether an information source organization (e.g., payer, employer, HMO) has a particular subscriber or dependent on file, and (b) the health care eligibility and/or benefit information about that subscriber and/or dependent(s). The data available through these transaction sets is used to verify an individual’s eligibility and benefits, but cannot provide a history of benefit use.
    The purpose of this implementation guide is to explain the developers’ intent when the Health Care Eligibility, Coverage, or Benefit Inquiry (270) and Health Care Eligibility, Coverage, or Benefit Information (271) transaction sets were designed and to give guidance on how they should be implemented in the health care industry. Specifically, this guide defines where data is put and when it is included for the ANSI ASC X12.281 and X12.282 transaction sets for the purpose of conveying health care eligibility and benefit information.

    This paired transaction set is comprised of two transactions: the 270, which is used to request (inquire) information, and the 271, which is used to respond with coverage, eligibility, and benefit information. The official names for these transactions are:

    ANSI ASC X12.281 - Eligibility, Coverage, or Benefit Inquiry (270)
    ANSI ASC X12.282 - Eligibility, Coverage, or Benefit Information (271)


    The 270 document typically includes the following:

  • Details of the sender of the inquiry (name and contact information of the information receiver)
  • Name of the recipient of the inquiry (the information source)
  • Details of the plan subscriber about to the inquiry is referring
  • Description of eligibility or benefit information requested

  • The ASC X12N Specification  - 5010 Version

     1. EDI 270–5010 Documentation - ISA – Interchange Control Header
     2. EDI 270–5010 Documentation – GS – Functional Group Header
     3. EDI 270–5010 Documentation – ST – Transaction Set Header
     4. EDI 270–5010 Documentation – BHT – Beginning Of Hierarchical Transaction
     5 EDI 270–5010 Documentation – HL – Hierarchical Level
     6. EDI 270–5010 Documentation–2100A Information Source Name
     7. EDI 270–5010 Documentation–2000B Information Receiver Level
     8. EDI 270–5010 Documentation–2000B Information Receiver Name
     9. EDI 270 – 5010 Documentation-2000C Hierarchical Level
    10. EDI 270 – 5010 Documentation – Subscriber Trace Number
    11. EDI 270 – 5010 Documentation –  2100C SUBSCRIBER Name

    EDI   Examples

    Please note ; all these examples are tested against WPC First Pass software.

    You can download trial version here.

    Also, you can download the following trial version software to view/validate EDI File.

    1. EDI Notepad
    2. HIPPA Document Viewer 2
    3. On Line Validator American Coders
    4. On Line Validator EDIVance

    The following open source converts X12 EDI File to XML and 1500.
    OopFactory X12 Parser

    The following URL discuss about other open source in EDI Software.
    Comparing Open Source EDI Software

    Sample EDI 270 5010. For clear understanding, line separator are used between loops

    ISA*03*id27032743*01*XYXY2233  *ZZ*XX09211223     *01*030240928      *130829*1102*^*00501*290811021*0*T*:~
    GS*HS*XX09211223*030240928*20130829*1102*1*X*005010X279A1~
    ST*270*0001*005010X279A1~
    BHT*0022*13*0001*20130829*1102~
    HL*1**20*1~
    NM1*PR*2*FLORIDA BLUE*****PI*BCBSF~
    HL*2*1*21*1~
    NM1*1P*2*Bella Vista Health Center*****XX*1306849724~
    HL*3*2*22*0~
    TRN*1*290811021*3030240928~
    NM1*IL*1*MULLIN*DANIEL****MI*XJBH12345678~
    DMG*D8*19571112~
    DTP*291*D8*20130829~
    EQ*30~
    SE*13*0001~
    GE*1*1~
    IEA*1*290811021~


    Questions or feedback are always welcome. You can email me at
    vbsenthilinnet@gmail.com.  







    ZK MVVM Form Binding CRUD with Spring and Hibernate

    In this series of articles, we will see examples for various concept of ZK Framework.

    About the application
    This is a small application to store the users information such as first name, last name, email, login id , password, etc. We will have the listing screen which will display all the users in the database. And from this listing screen, we will be able to add new users and edit the existing users in the database.

    MySQL table structure.

    CREATE TABLE `userprofile` (
    `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
    `firstname` VARCHAR(50) NOT NULL,
    `lastname` VARCHAR(50) NOT NULL,
    `middlename` VARCHAR(2) DEFAULT NULL,
    `userAccountNumber` VARCHAR(50) NOT NULL,
    `DOB` DATE DEFAULT NULL,
    `SSN` VARCHAR(50) DEFAULT NULL,
    `address1` VARCHAR(200) NOT NULL,
    `address2` VARCHAR(200) DEFAULT NULL,
    `city` VARCHAR(100) NOT NULL,
    `state` VARCHAR(2) NOT NULL,
    `zipcode` VARCHAR(12) NOT NULL,
    `email` VARCHAR(100) NOT NULL,
    `userloginid` VARCHAR(20) NOT NULL,
    `password` VARCHAR(50) NOT NULL,
    `system` INT(11) DEFAULT '0',
    `theme` VARCHAR(300) DEFAULT NULL,
    `userPhoto` LONGBLOB,
    PRIMARY KEY (`id`)
    ) ENGINE=INNODB AUTO_INCREMENT=10 DEFAULT CHARSET=latin1


    Insert some records in the database for the above table

    Technologies Used
        1. ZK 6.5.2 CE Version
        3. Hibernate Core Version 4.1.10 Final
        4. Spring ORM Version 3.2.0
        5. MySQL version 5
        6. Maven 3

    First let us setup the development environment. Download this document and follow the step by step instruction to install the necessary software’s.

    Part 1: This post explain how to create ZK Maven project in eclipse IDE as step by step.
    Part 2: This post talks about creating Domain, DAO and Service Layer.
    Part 3: Spring Integration with Hibernate
    Part 4: Presentation Layer
    Part 5: Change the look and feel.
    Part 6: Spring security 3 integration with hibernate 4
    Part 7: More features such as Data filter, etc..
    Part 8: ZK Theme customization for each user
    Part 9: Bug Fixing Cycle :)
    Part 10: jQuery integration with ZK Framework
    Part 11: Store image in the database.
    Part 12 : Validation using Hibernate Validator
    Part 13 : More Validation using Hibernate Validator


    You can download the source here.  and You can download the war file here 
    If you are not able to download the source, please drop a email to vbsenthilinnet@gmail.com





    Well, You have learned the basics of ZK Framework and now you are ready to go to develop a Complete commercial Application or Sample Application. But how to start ? You might be end with lot of questions such as “Is there any template available ?”, “any support available for the project template”?, etc.

    Here it is. I have developed a small Project start up kit with the following features


    1. Menus are Dynamic for N Level support. What does it mean ? Well, in the modern Web application, you might want to visible/invisible Menu by each users type (aka Dynamic Menu). This template has that option . All the Menu caption and levels are Stored in MySQL Database and after login , it will retrieve the menus assigned only for the user.

    2. Apart from Menu, You might be interested in giving permission to add/delete/edit for CRUD Based screens. Using this template, you can also control by each user.

    3. For all the CRUD Based screens, Export to Excel option template is provided.

    4. Sample CRUD Screen are Provided to ready to start.

    5. Integrated with Spring Security

    6. Integrated with Spring Hibernate Security.

    7. Base DAO and DAO implementation classes are provided.

    8. Utilising ZK's MVVM databinding.

    9. Project comes with 5 different themes . So you can set theme by each user and after login, the selected theme will be applied.

    Apart from the above, the Most important option is “ Support!!!!!!!”. Users who buying this kit, unlimited support will be provided to help them to understand the structure. If you are interested in buying this start up kit, please email to me at vbsenthilinnet@gmail.com




    Video Demo






    Screen shots

    image





    image




    image

    Sunday, 14 April 2013

    ZK MVVM Form Binding CRUD with Spring and Hibernate - Part 11

    Storing Image in the Database

            


    Left hugMy Sincere thanks to Joshi who helped me in this article

    In the last article, we have successfully integrated jQuery plugin with ZK. Now we will see how to upload a image file and store in the database and display back to the UI.

    Step 1:
    First we will add one more column in the mysql table userprofile. The column name will be “userPhoto” and type will be longblob. Here is the structure.
    image
    Step 2:
    Next we need to modify our bean UserProfile. Here is the modified file UserProfile.java in which we have added the new column.

    package zkexample.domain;

    import java.io.Serializable;
    import java.util.Date;

    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.Lob;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;

    import org.hibernate.annotations.NamedQuery;

    @Entity
    @Table(name = "userprofile")
    @NamedQuery(name = "UserProfile.findUserByUserID", query = "SELECT usr FROM UserProfile as usr WHERE usr.userLoginID = ?")
    public class UserProfile implements Serializable {

    /**
    *
    */
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    private String firstName;
    private String lastName;
    private String middleName;
    private String userAccountNumber;
    private String SSN;
    private String address1;
    private String address2;
    private String city;
    private String State;
    private String zipCode;
    private String email;
    private String userLoginID;
    private String password;
    private Integer system;
    private String theme;

    @Column(name = "userPhoto")
    @Lob
    private byte[] userPhoto;

    @Temporal(TemporalType.DATE)
    private Date DOB;

    public long getId() {
    return id;
    }

    public void setId(long id) {
    this.id = id;
    }

    public String getFirstName() {
    return firstName;
    }

    public void setFirstName(String firstName) {
    this.firstName = firstName;
    }

    public String getLastName() {
    return lastName;
    }

    public void setLastName(String lastName) {
    this.lastName = lastName;
    }

    public String getMiddleName() {
    return middleName;
    }

    public void setMiddleName(String middleName) {
    this.middleName = middleName;
    }

    public String getUserAccountNumber() {
    return userAccountNumber;
    }

    public void setUserAccountNumber(String userAccountNumber) {
    this.userAccountNumber = userAccountNumber;
    }

    public Date getDOB() {
    return DOB;
    }

    public void setDOB(Date dOB) {
    DOB = dOB;
    }

    public String getSSN() {
    return SSN;
    }

    public void setSSN(String sSN) {
    SSN = sSN;
    }

    public String getAddress1() {
    return address1;
    }

    public void setAddress1(String address1) {
    this.address1 = address1;
    }

    public String getAddress2() {
    return address2;
    }

    public void setAddress2(String address2) {
    this.address2 = address2;
    }

    public String getCity() {
    return city;
    }

    public void setCity(String city) {
    this.city = city;
    }

    public String getState() {
    return State;
    }

    public void setState(String state) {
    State = state;
    }

    public String getZipCode() {
    return zipCode;
    }

    public void setZipCode(String zipCode) {
    this.zipCode = zipCode;
    }

    public String getEmail() {
    return email;
    }

    public void setEmail(String email) {
    this.email = email;
    }

    public String getUserLoginID() {
    return userLoginID;
    }

    public void setUserLoginID(String userLoginID) {
    this.userLoginID = userLoginID;
    }

    public String getPassword() {
    return password;
    }

    public void setPassword(String password) {
    this.password = password;
    }

    public Integer getSystem() {
    return system;
    }

    public void setSystem(Integer system) {
    this.system = system;
    }

    public String getTheme() {
    return theme;
    }

    public void setTheme(String theme) {
    this.theme = theme;
    }

    public byte[] getUserPhoto() {
    return userPhoto;
    }

    public void setUserPhoto(byte[] userPhoto) {
    this.userPhoto = userPhoto;
    }

    }



    Step 3:
    Next we will modify our zul file such as it will have one image file and two buttons(one button is to add image and other button is to remove the image if need). In the UserCRUD.zul file, next heading “Personel Information” , add the following lines.
    You can also get the complete source at the bottom link provided.


    	<div>
    <image content="@bind(vm.myImage)" width="150px"
    style="overflow:auto;z-index:999;position:absolute;right:30px;top:56px;width:150px;height:140px;background-color:#ff99cc;" />
    <button Label="Add" sclass="mybutton button theme small"
    width="40px" upload="true,maxsize=300"
    visible="@load(not vm.makeAsReadOnly)"
    style="position:absolute;right:115px;top:200px;"
    onUpload="@command('upload', upEvent=event)" mold="trendy" />
    <button Label="Del" sclass="mybutton button theme small"
    visible="@load(not vm.makeAsReadOnly)" width="40px"
    style="position:absolute;right:30px;top:200px;"
    onClick="@command('removeImage')" mold="trendy" />
    </div>



    Step 3:
    Next in the images folder, add image male.png. You can download the source at the bottom and use that image.

    image
    Step 4:
    Next we need to modify the VM. Open the UserCRUDVM.java and do the changes
    Change : 1



    Add the following two new methods.


    @Command
    @NotifyChange("myImage")
    public void removeImage() {

    myImage = null;
    }

    @Command
    @NotifyChange("myImage")
    public void upload(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) {

    UploadEvent upEvent = null;
    Object objUploadEvent = ctx.getTriggerEvent();
    if (objUploadEvent != null && (objUploadEvent instanceof UploadEvent)) {
    upEvent = (UploadEvent) objUploadEvent;
    }
    if (upEvent != null) {
    Media media = upEvent.getMedia();
    int lengthofImage = media.getByteData().length;
    if (media instanceof Image) {
    if (lengthofImage > 500 * 1024) {
    Messagebox
    .show("Please Select a Image of size less than 500Kb.");
    return;
    } else {
    myImage = (AImage) media;// Initialize the bind object to
    // show image in zul page and
    // Notify it also
    }
    } else {
    Messagebox.show("The selected File is not an image.");
    }
    }
    }


    Change 2:
    Change the Method initSetup as follows


    @AfterCompose
    @NotifyChange("myImage")
    public void initSetup(@ContextParam(ContextType.VIEW) Component view,
    @ExecutionArgParam("selectedRecord") UserProfile userProfile,
    @ExecutionArgParam("recordMode") String recordMode,
    @ExecutionArgParam("centerArea") Center centerArea)
    throws IOException {

    Selectors.wireComponents(view, this, false);
    setRecordMode(recordMode);
    CRUDService = (CRUDService) SpringUtil.getBean("CRUDService");
    this.centerArea = centerArea;

    Themes.register("bluetheme", ThemeOrigin.FOLDER);
    Themes.register("greentheme", ThemeOrigin.FOLDER);
    Themes.register("browntheme", ThemeOrigin.FOLDER);
    Themes.register("purpletheme", ThemeOrigin.FOLDER);
    Themes.register("redtheme", ThemeOrigin.FOLDER);



    String[] themes = Themes.getThemes();
    themes = Arrays.copyOf(themes, themes.length + 1);

    // Attempting to switch to a theme that is not registered
    // will switch to the default theme (i.e. breeze)
    themes[themes.length - 1] = "unknown";
    _themes = new ListModelList<String>(themes);

    currentTheme = Themes.getCurrentTheme();
    myImage = new AImage(Executions.getCurrent().getDesktop().getWebApp().getRealPath("/images") +"/male.png" );
    if (recordMode.equals("NEW")) {
    this.selectedRecord = new UserProfile();
    this.selectedRecord.setSystem(0);
    }

    if (recordMode.equals("EDIT")) {
    this.selectedRecord = userProfile;
    if (this.selectedRecord.getUserPhoto() != null)
    myImage = new AImage("userPhoto",
    this.selectedRecord.getUserPhoto());
    }

    if (recordMode == "READ") {
    setMakeAsReadOnly(true);
    this.selectedRecord = userProfile;
    if (this.selectedRecord.getUserPhoto() != null)
    myImage = new AImage("userPhoto",
    this.selectedRecord.getUserPhoto());
    }
    }


    Change 3:
    Change the Savethis Method as follows


    	@Command
    public void saveThis(@BindingParam("action") Integer action) {
    if (myImage != null) {
    byte[] bFile = myImage.getByteData();
    this.selectedRecord.setUserPhoto(bFile);
    } else
    this.selectedRecord.setUserPhoto(null);
    CRUDService.Save(this.selectedRecord);
    if (action == 0) {
    final HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("centerArea", centerArea);
    centerArea.getChildren().clear();
    Executions.createComponents("userList.zul", centerArea, map);
    }
    if (action == 1) {
    this.selectedRecord = new UserProfile();
    BindUtils.postNotifyChange(null, null, UserCRUDVM.this,
    "selectedRecord");

    }
    }

    Step 5:
    Now you can run the application, login and Click Add new and you can see the following output.
    image

    Step 6:
    Finally, we will one more option such after each DB operation such as New/Edit/Delete, we will show the confirmation message. In the MyLib.java file, add the below function



    	public static void showSuccessmessage() {
    Clients.showNotification("Operation Completed Successfully",
    Clients.NOTIFICATION_TYPE_INFO, null, "top_center", 4100);
    }

    Now call this Function in the UserListVM.Java after delete as follows":


    @Override
    public void onConfirmClick(String code, int button) {
    if (code.equals("deleteFirstConfirm") && button == Messagebox.YES) {
    MyLib.confirm(
    "deleteSecondConfirm",
    "The Selected user \""
    + selectedItem.getUserLoginID()
    + "\" will be permanently deleted and the action cannot be undone..?",
    "Confirmation", this);
    }
    if (code.equals("deleteSecondConfirm") && button == Messagebox.YES) {

    CRUDService.delete(selectedItem);

    allReordsInDB.remove(allReordsInDB.indexOf(selectedItem));
    BindUtils.postNotifyChange(null, null, UserListVM.this, "dataSet");
    MyLib.showSuccessmessage();

    }
    }

    Similarly, call this in SaveThis in UserCRUDVM.Java as follows


    @Command
    public void saveThis(@BindingParam("action") Integer action) {
    if (myImage != null) {
    byte[] bFile = myImage.getByteData();
    this.selectedRecord.setUserPhoto(bFile);
    } else
    this.selectedRecord.setUserPhoto(null);
    CRUDService.Save(this.selectedRecord);
    MyLib.showSuccessmessage();
    if (action == 0) {
    final HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("centerArea", centerArea);
    centerArea.getChildren().clear();
    Executions.createComponents("userList.zul", centerArea, map);
    }
    if (action == 1) {
    this.selectedRecord = new UserProfile();
    BindUtils.postNotifyChange(null, null, UserCRUDVM.this,
    "selectedRecord");

    }
    }


    You can control the look and feel of the notification message. Add the below lines in Style.css


    /* ----------------------------------------------------------------------------------------------------------------------- */
    /* Start: Auto Close Notification message box
    /* ----------------------------------------------------------------------------------------------------------------------- */
    .z-notification .z-notification-cl,.z-notification .z-notification-cnt {
    height: 30px;
    width: 250px;
    }

    .z-notification-info .z-notification-cl {
    background-color: #ADD8E6;
    }

    .z-notification .z-notification-cl {
    color: white;
    }

    .z-notification .z-notification-cnt {
    background: none repeat scroll 0 center transparent;
    font-size: 14px;
    font-weight: normal;
    margin: 0 !important;
    overflow: hidden;
    }

    In Next Part 12, we will see how to validate user inputs using hibernate validator


    You can download the source from here.

    You can see the demo here :  user id wing and password is wing



            

    Thursday, 11 April 2013

    ZK MVVM Form Binding CRUD with Spring and Hibernate - Part 10

    jQuery Masked Input Plugin

            


    In the Previous part 9, we have fixed some bugs in changing the theme after user login. In this article, we will focus on the field validation. For the fields SSN, DOB and zipcode, we will apply masking stuff, so then, end user cannot add junk values into these fields.

    As s standard, the watermark and masking features (also called input prompt) guide users in filling out an input with the specified format.
    ZK's strong integration of jQuery allows developers to leverage the vast jQuery libraries to achieve the desired effects.

    In this article, the masked input and watermark input plugins are used. I have already published a step by step article how to create Masked Input component using jquery Plugin. Please refer here before continue the rest of the article.

    Project Structure.
    image

    image

    image

    Step 1:
    As per this article, let us add the jquery plugins in our project. Create a folder called “js” under the webapp and add the jquery files as shown.
    image
    We need to inform ZK that, we are going use this jquery plugin. That can be done by adding reference in the using Language add-on file.
    We have already having our own ZKAddon.xml file. So in that , let us add the reference of this jquery plugins. Here is the modified full code for ZKAddon.xml file.

    <?xml version="1.0" encoding="UTF-8"?>
    <language-addon>
    <addon-name>myaddon</addon-name>
    <language-name>xul/html</language-name>
    <stylesheet href="/css/login.css" type="text/css" />
    <stylesheet href="/css/style.css" type="text/css" />
    <javascript src="/js/jquery.maskedinput-1.3.js" />
    <javascript src="/js/watermarkinput.js" />
    </language-addon>


    Step 2:
    Next we will create our own component called as “MaskedBox”. First let us create the java class to support our new component. In the utilities package, create a class “MaskedBox” as shown.
    image


    package zkexample.utilities;

    import org.zkoss.zk.ui.event.Event;
    import org.zkoss.zk.ui.event.EventListener;
    import org.zkoss.zk.ui.event.Events;
    import org.zkoss.zul.Textbox;

    public class MaskedBox extends Textbox {

    /**
    *
    */
    private static final long serialVersionUID = 1L;
    private String format;
    private String waterMark = "";

    public String getFormat() {
    return format;
    }

    public void setFormat(String format) {
    this.format = format;
    }

    public String getWaterMark() {
    return waterMark;
    }

    public void setWaterMark(String waterMark) {
    this.waterMark = waterMark;
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public MaskedBox() {
    setMold("rounded");
    this.addEventListener(Events.ON_CREATE, new EventListener() {
    @Override
    public void onEvent(Event event) throws Exception {
    String mask;
    if (waterMark.equals(""))
    mask = "jq(this.getInputNode()).mask('" + format + "');";
    else
    mask = "jq(this.getInputNode()).mask('" + format
    + "');jq(this.getInputNode()).Watermark('"
    + waterMark + "'," + "'" + "gray" + "'" + ");";
    setWidgetListener("onBind", mask);
    }
    });

    }

    }

    Next we need to update our ZKAddon.xml file about this new component. Here is the updated ZKAddon.xml file



    <?xml version="1.0" encoding="UTF-8"?>
    <language-addon>
    <addon-name>myaddon</addon-name>
    <language-name>xul/html</language-name>
    <stylesheet href="/css/login.css" type="text/css" />
    <stylesheet href="/css/style.css" type="text/css" />
    <javascript src="/js/jquery.maskedinput-1.3.js" />
    <javascript src="/js/watermarkinput.js" />

    <component>
    <component-name>MaskedBox</component-name>
    <component-class>zkexample.utilities.MaskedBox
    </component-class>
    <extends>textbox</extends>
    </component>

    </language-addon>

    Step 3:
    Next we need to write converter to overcome the problem of masking characters stored when there is no input. For more details about this problem, Please refer here.
    Let us create class called “MaskConverter” in the utilities package which implements org.zkoss.bind.Converter. Basically, this converter removes the masking character before saving to domain object.
    image


    package zkexample.utilities;

    import org.zkoss.bind.BindContext;
    import org.zkoss.bind.Converter;
    import org.zkoss.zk.ui.Component;

    public class MaskConverter implements Converter {

    /**
    * The method coerceToUi() is invoked when loading ViewModel's property to
    * component and its return type should correspond to bound component
    * attribute's value[1]. The coerceToBean() is invoked when saving. If you
    * only need to one way conversion, you can leave unused method empty.
    */

    public Object coerceToUi(Object val, Component comp, BindContext ctx) {
    // do nothing
    return val;
    }

    public Object coerceToBean(Object val, Component comp, BindContext ctx) {
    /*
    * Here we will check only masking characters are present, if so, then
    * return null
    */
    final String propValue = (String) val;
    if (IsEmptyByMask(propValue))
    return null;
    else
    return val;

    }

    public boolean IsEmptyByMask(String s1) {
    if (isEmpty(s1) == false) {
    s1 = s1.replaceAll("_", "").replace("(", "").replace(")", "").replace("x", "")
    .replace("-", "").replace(" ", "").replace("/", "").trim();
    if (isEmpty(s1))
    return true;
    else
    return false;
    }
    return true;
    }

    public static boolean isEmpty(String s) {
    return s == null || s.trim().length() == 0;
    }
    }


    The above converter will take care of all string data types. Similarly, we need to write converter to take care of Date type fields. So let us create another converter called MyDateFormatConverter in the package utilities
    image


    package zkexample.utilities;

    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;

    import org.zkoss.bind.BindContext;
    import org.zkoss.bind.Converter;
    import org.zkoss.zk.ui.Component;

    public class MyDateFormatConverter implements Converter {
    /**
    * Convert Date to String.
    *
    * @param val
    * date to be converted
    * @param comp
    * associated component
    * @param ctx
    * bind context for associate Binding and extra parameter (e.g.
    * format)
    * @return the converted String
    */

    /**
    * The method coerceToUi() is invoked when loading ViewModel's property to
    * component and its return type should correspond to bound component
    * attribute's value[1]. The coerceToBean() is invoked when saving. If you
    * only need to one way conversion, you can leave unused method empty.
    */

    private static SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");

    public Object coerceToUi(Object val, Component comp, BindContext ctx) {
    final Date date = (Date) val;
    return date == null ? null : sdf.format(date);
    }

    /**
    * Convert String to Date.
    *
    * @param val
    * date in string form
    * @param comp
    * associated component
    * @param ctx
    * bind context for associate Binding and extra parameter (e.g.
    * format)
    * @return the converted Date
    */
    public Object coerceToBean(Object val, Component comp, BindContext ctx) {
    final String date = (String) val;
    sdf.setLenient(false);
    try {
    return date == null ? null : sdf.parse(date);
    } catch (ParseException e) {
    comp.invalidate();
    return null;

    }
    }

    }


    Step 4:
    Now we are ready to use our new component. In the UserCRUD.zul, we will remove the textbox component for SSN, DOB and Zipcode and add our new component MaskedBox as shown here.


    <?page title="" contentType="text/html;charset=UTF-8"?>
    <zk>

    <window id="userCRUD" border="none"
    apply="org.zkoss.bind.BindComposer"
    viewModel="@id('vm') @init('zkexample.zkoss.UserCRUDVM')">
    <div
    form="@id('fx') @load(vm.selectedRecord) @save(vm.selectedRecord, before='saveThis')">

    <div width="96%">
    <span width="100%">
    <div sclass="sectionTitle">
    <separator />
    <label id="lcaption" sclass="sectionTitleLabel"
    value="Add/Edit Users" />
    <label id="readonly" sclass="sectionTitleLabel"
    value="(ReadOnly)" visible="@load(vm.makeAsReadOnly)" />
    <image
    src="@load(fxStatus.dirty?'images/unsaved32x32.png':'')" />

    </div>
    </span>
    <div id="buttonsDiv"
    style="float:right;margin-top:6px;">
    <button label="Save and Close" mold="trendy"
    visible="@load(not vm.makeAsReadOnly)"
    onClick="@command('saveThis', action=0)"
    sclass="mybutton button theme small">
    </button>
    <button label="Save and Add" mold="trendy"
    visible="@load(not vm.makeAsReadOnly)"
    onClick="@command('saveThis', action=1)"
    sclass="mybutton button theme small">
    </button>
    <button
    label="@load(vm.makeAsReadOnly ?'Close':'Cancel')" mold="trendy"
    onClick="@command('cancel')"
    sclass="mybutton button theme small">
    </button>
    </div>
    <div style="clear: both;"></div>
    <div sclass="sectionSeperator"></div>
    </div>

    <span width="100%">
    <div sclass="sectionTitle">
    <separator />
    <label value="Personel Information"
    sclass="sectionTitleLabel" />
    <separator />
    </div>
    </span>

    <panel width="95%" sclass="sectionPanel">
    <panelchildren>
    <separator />
    <grid sclass="vgrid">
    <columns>
    <column hflex="10%"></column>
    <column hflex="10%"></column>
    <column hflex="10%"></column>
    <column hflex="10%"></column>
    </columns>
    <rows>
    <row>
    <vlayout>
    <label value="User Account No"
    sclass="flabel" />
    <textbox id="accountNo"
    readonly="@load(vm.makeAsReadOnly)" mold="rounded" hflex="1"
    value="@bind(fx.userAccountNumber)" />
    </vlayout>
    <vlayout>
    <label value="Last Name"
    sclass="flabel" />
    <textbox id="lastname"
    readonly="@load(vm.makeAsReadOnly)" mold="rounded" hflex="1"
    value="@bind(fx.lastName)" />
    </vlayout>
    <vlayout>
    <label value="First Name"
    sclass="flabel" />
    <textbox id="firstname"
    readonly="@load(vm.makeAsReadOnly)" mold="rounded" hflex="1"
    value="@bind(fx.firstName)" />
    </vlayout>
    <vlayout>
    <label value="Middle Name"
    sclass="flabel" />
    <textbox id="middleName"
    readonly="@load(vm.makeAsReadOnly)" mold="rounded"
    value="@bind(fx.middleName)" />
    </vlayout>

    </row>
    <row>

    <vlayout>
    <label value="Email"
    sclass="flabel" />
    <textbox id="email" hflex="1"
    readonly="@load(vm.makeAsReadOnly)" mold="rounded"
    value="@bind(fx.email)" />
    </vlayout>
    <cell colspan="2">
    <hbox>
    <vlayout>
    <label value="SSN"
    sclass="flabel" />
    <MaskedBox
    format="999-99-9999" width="115%"
    readonly="@load(vm.makeAsReadOnly)"
    value="@bind(fx.SSN) @converter('zkexample.utilities.MaskConverter')">
    </MaskedBox>
    </vlayout>
    <vlayout>
    <label value="DOB"
    sclass="flabel" />
    <MaskedBox
    waterMark="mm/dd/yyyy" format="99/99/9999"
    readonly="@load(vm.makeAsReadOnly)" width="100%"
    value="@bind(fx.DOB) @converter('zkexample.utilities.MyDateFormatConverter')">
    </MaskedBox>
    </vlayout>
    </hbox>
    </cell>
    </row>
    </rows>
    </grid>
    </panelchildren>
    </panel>
    <separator />

    <separator />
    <span width="100%">
    <div sclass="sectionTitle">
    <separator />
    <label value="Address Information"
    sclass="sectionTitleLabel" />
    <separator />
    </div>
    </span>
    <panel width="95%" sclass="sectionPanel">
    <panelchildren>
    <grid sclass="vgrid">
    <columns>
    <column hflex="1"></column>
    <column hflex="1"></column>
    <column hflex="1"></column>
    </columns>
    <rows>
    <row>
    <cell colspan="2">
    <vlayout>
    <label value="Address"
    sclass="flabel" />
    <textbox id="address1" hflex="2"
    readonly="@load(vm.makeAsReadOnly)" mold="rounded"
    value="@bind(fx.address1)" />
    </vlayout>
    </cell>
    </row>
    <row>
    <cell colspan="2">
    <vlayout>
    <textbox id="address2" hflex="2"
    readonly="@load(vm.makeAsReadOnly)" mold="rounded"
    value="@bind(fx.address2)" />
    </vlayout>
    </cell>
    </row>
    <row>
    <vlayout>
    <label value="City" sclass="flabel" />
    <textbox id="City" hflex="1"
    readonly="@load(vm.makeAsReadOnly)" mold="rounded"
    value="@bind(fx.city)" />
    </vlayout>
    <vlayout>
    <grid>
    <columns>
    <column width="60%"></column>
    <column></column>
    </columns>
    <rows>
    <row>
    <vlayout>
    <label value="State"
    sclass="flabel" />
    <textbox id="State"
    readonly="@load(vm.makeAsReadOnly)" hflex="1"
    mold="rounded" value="@bind(fx.state)" />
    </vlayout>
    <vlayout>
    <label
    value="ZipCode" sclass="flabel" />

    <MaskedBox
    format="99999-9999" hflex="1"
    readonly="@load(vm.makeAsReadOnly)"
    value="@bind(fx.zipCode) @converter('zkexample.utilities.MaskConverter')">
    </MaskedBox>

    </vlayout>
    </row>
    </rows>
    </grid>
    </vlayout>
    </row>
    </rows>
    </grid>
    </panelchildren>
    </panel>
    <separator />
    <span width="100%">
    <div sclass="sectionTitle">
    <separator />
    <label value="Login information"
    sclass="sectionTitleLabel" />
    </div>
    </span>
    <panel width="95%" sclass="sectionPanel">
    <panelchildren>
    <separator />
    <grid sclass="vgrid">
    <columns>
    <column width="20%"></column>
    <column width="26%"></column>
    </columns>
    <rows>
    <row>
    <vlayout>
    <label value="Login ID"
    sclass="flabel" />
    <textbox id="loginid" hflex="1"
    readonly="@load(vm.makeAsReadOnly)" mold="rounded"
    value="@bind(fx.userLoginID)" />
    </vlayout>
    <vlayout>
    <label value="Password"
    sclass="flabel" />
    <textbox id="password" width="80%"
    readonly="@load(vm.makeAsReadOnly)" mold="rounded"
    value="@bind(fx.password)" />
    </vlayout>
    <vlayout>
    <label value="Theme"
    sclass="flabel" />
    <combobox model="@load(vm.themes)"
    width="30%" mold="rounded" readonly="@load(vm.makeAsReadOnly)"
    selectedItem="@bind(fx.theme)" value="@bind(fx.theme)" />
    </vlayout>
    </row>
    </rows>
    </grid>
    </panelchildren>
    </panel>
    </div>
    </window>
    </zk>

    Now you can run the project and add new user and check how our new component works.
    Next Part 11, we will see how to upload a image file and store in the database.

    You can download the source here.

    Don’t forget to check online demo here. Use username as wing and password as wing