Accessing Person Attributes object in attributesCondition.js

I was creating Person Attributes as a codded answer with coded concept. How can I access this object to be the conditional requirement for hiding another section of Patient Information as stated in registration\app.json ? The wiki just exampled about age as conditional variable. When I tried to dump person object in console, there’s nothing stated about my newly added person attributes.

Object { address: {}, age: {…}, birthdate: null, calculateAge: calculateAge(), image: "../images/blank-user.gif", fullNameLocal: fullNameLocal(), getImageData: getImageData(), relationships: [], newlyAddedRelationships: (1) […], deletedRelationships: [], … }

Best regards,

Eddy

Please read this wiki. you can show/hide any section by implementing your logic like the wiki. If any problem arises to make appropriate logic you can share the business logic we can help you.

Hello rakib.hasan,

Yes I read that page on wiki. Those in the example code implement age as conditional logic, while I want something from Person Attributes concept to be the conditional logic. The attributes was coded concept.

In our one implementation, We have done this.

Here initially Person attributes referred by default is self & the referred info section is hided. when select any other option rather than self a section is appeared.

var showOrHideReferredBySection = function (patient) {
    var returnValues = {
        show: [],
        hide: []
    };
    if (patient["referredBy"].value == "Hospital") {
        returnValues.show.push("hospitalSection");
        returnValues.hide.push("doctorSection");
        returnValues.hide.push("pharmacySection");
        returnValues.hide.push("promotionalActivitySection");
    } else if (patient["referredBy"].value == "Pharmacy") {
        returnValues.show.push("pharmacySection");
        returnValues.hide.push("doctorSection");
        returnValues.hide.push("hospitalSection");
        returnValues.hide.push("promotionalActivitySection");
    } else if (patient["referredBy"].value == "Promotional Activity") {
        returnValues.show.push("promotionalActivitySection");
        returnValues.hide.push("doctorSection");
        returnValues.hide.push("hospitalSection");
        returnValues.hide.push("pharmacySection");
    } else if (patient["referredBy"].value == "Doctor") {
        returnValues.show.push("doctorSection");
        returnValues.hide.push("hospitalSection");
        returnValues.hide.push("pharmacySection");
        returnValues.hide.push("promotionalActivitySection");
    } else {
        returnValues.hide.push("hospitalSection", "doctorSection", "pharmacySection", "promotionalActivitySection");
    }
    return returnValues
};

Bahmni.Registration.AttributesConditions.rules = {
    'referredBy': function (patient) {
        return showOrHideReferredBySection(patient);
    }
};

You can see this. Here Refered by is the coded concept.

1 Like

Thank you rakib, you made my morning with smile :smiley:

I have to improve my js skill then.

Did you get an error about undefined variable? I’ve got an error about this, because initially the js object of the person attribute was undefined, So I wrapped the logic with another logic checking wether or not the object undefined. Here is the final script :

var showOrHidebpjsSection = function (patient) {
    var returnValues = {
        show: [],
        hide: []
    };
    if(typeof(patient["Jaminan"]) != 'undefined'){
      if (patient["Jaminan"].value == "BPJS") returnValues.show.push("bpjs");
      else returnValues.hide.push("bpjs");
    }
    else returnValues.hide.push("bpjs");
    return returnValues
};

And it work like charm.