Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set "N/A" if data is null in angular

Lets say i have a table and sometimes few data’s can be null but null data are showing undefined at the table instead of showing undefine i want to show "N/A" how can i achieve that ill share an image and a code below.
table

at the above image under reference data some of the data showing undefine because it is null i want it to show "N/A". I’ll share the code below. Below code there is "a.normalRange" variable that variable holds the reference data.

 var col = ["Test Name", "Result", "Unit" , "Reference"];
    this.hubxDataItemSpList.forEach((a) => {
      medicineInfo = this.hubxDataItemSpList.find(x => x.id == a.id);
      rows.push(['' + a.categoryName +' '+ a.itemTitle + '', '' + a.itemValue + '', '' + a.itemUnit ,'' + a.normalRange]);
    });

this is my Model

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

export class HubxDataItemSpModel {
    id: number;
    categoryId: number;
    categoryName:string;
    itemTitle: string;
    itemUnit: string;
    isActive: boolean=true;
    itemValue: string;
    patientId: number;
    clinicianHubXSign : string;
    isAprrovedStatus : boolean;
    isTestApproved : boolean;
    phySignDate : Date;
    notes : string;
    normalRange : string;
    //base64:any;
    isDeleted: boolean;
    createdDate : Date
}

And this is how i define my model at my component class

hubxDataItemSpList : Array<HubxDataItemSpModel>=[];

And this is how i print the table

 doc.autoTable({
            columnStyles: {
              0: { cellWidth: 45 },
              1: { cellWidth: 45 },
              2: { cellWidth: 45 },
              3: { cellWidth: 45 }
            },
            head: [col],
            body: rows,
            startY: 100,
            theme: 'plain',
            tableLineColor: [242, 238, 238],
            tableLineWidth: 0.5,
            styles: {
              font: 'courier',
              lineColor: [242, 238, 238],
              lineWidth: 0.5
            },
          });

Data from APi

{
  "expires_in": 0,
  "data": [
    {
      "id": 1727,
      "categoryId": 2,
      "categoryName": "Lipid Profile",
      "itemTitle": "Total Cholesterol",
      "itemUnit": "mg/dl",
      "patientId": 3224,
      "itemValue": "3.2",
      "isTestDone": true,
      "clinicianHubXSign": "0",
      "isAprrovedStatus": false,
      "isTestApproved": false,
      "normalRange": "3.6-6.5",
      "isActive": true,
      "createdDate": "2022-07-20T13:17:42.9735718",
      "isDeleted": false,
      "createdBy": 1,
      "phySignDate": "0001-01-01T00:00:00"
    },
    {
      "id": 1728,
      "categoryId": 2,
      "categoryName": "Lipid Profile",...

>Solution :

If any other value need to be checked call isValueEmpty method with that value.

const col = ["Test Name", "Result", "Unit" , "Reference"];
this.hubxDataItemSpList.forEach((a) => {
    medicineInfo = this.hubxDataItemSpList.find(x => x.id == a.id);
    const normalRange = changeIfValueEmpty(a.normalRange);
    rows.push(['' + a.categoryName +' '+ a.itemTitle + '', '' + a.itemValue + '', '' + a.itemUnit ,'' + normalRange]);
});

function changeIfValueEmpty(value) {
    value = value ?? ''; // reassigned if value is null or undefined
    return (value value.trim() === '') ? 'N/A' : value; // to check value only contains whitespace
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading