Precision Healthcare Solutions
CLINICAL OFFICE MPAGE SUITE DEVELOPER REPORTS DESIGNER shopping_cart mail
SALES CONTACT US
TutorialsWorkflow Component1. Getting Started2. Data Retrieval3. Tabbed Menu4. Building Reusable Parts5. Information Tab6. Relationship Tab7. Provider Relationship Tab8. Final StepsFull Page MPage1. Getting Started2. User Prompts3. Custom Script - Part 14. Add a Table5. Click to View Details6. Custom Script - Part 27. Add Remaining Details8. Bonus - Deploy to DA2Third Party IntegrationExcelJS

Relationship Tab

The relationship tab will extend what we have already learned and add the Angular @for loop as well as reusable templates, sorting, and zebra striping.

Steps

  1. Open relationships.ts and update the code as shown below.
    import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
    import { NgTemplateOutlet } from '@angular/common';
    import { EncounterService, PersonService, PhoneService, AddressService, IPersonReltn, IEncntrPersonReltn } from '@clinicaloffice/mpage-developer';
    import { Common } from '../../services/common';
    import { Field } from '../field/field';
    
    @Component({
      selector: 'app-relationships',
      imports: [Field, NgTemplateOutlet],
      templateUrl: './relationships.html',
      styleUrl: './relationships.scss',
      changeDetection: ChangeDetectionStrategy.OnPush,
      standalone: true
    })
    export class Relationships {
      protected encounterService = inject(EncounterService);
      protected personService = inject(PersonService);
      protected phoneService = inject(PhoneService);
      protected addressService = inject(AddressService);
      protected common = inject(Common);
    
      // Return a relationship object in sorted order by person relation type
      protected sortedRelationships(relationship: IPersonReltn[] | IEncntrPersonReltn[] | undefined): IPersonReltn[] | IEncntrPersonReltn[] | undefined {
        return relationship ? relationship.sort((a, b) => a.personReltnType.localeCompare(b.personReltnType)) : undefined;
      }
    }

    Most of the changes above are similar to the code we added in the information tab and won't be explained again.

    We have, however, introduced NgTemplateOutlet and a new custom method called sortedRelationships. NgTemplateOutlet will be used in our HTML to create a reusable portion of HTML for the purpose of displaying both the details for the patient relationships and visit relationships with the same code. The sortedRelationships method will be used to sort our relationships by relationship type.

  2. Replace the contents of relationships.html with the following code:
    @let patient = personService.get();
    @let visit = encounterService.get();
    
    <div class="grid-2-column">
        <div class="section">
            <div class="section-title">Patient Relationships</div>
    
            @for (rel of sortedRelationships(patient?.personReltn); track rel) {
                <ng-container [ngTemplateOutlet]="relationshipTemplate" [ngTemplateOutletContext]="{rel, even: $even}" />
            }
        </div>
    
        <div class="section">
            <div class="section-title">Relationships this Visit</div>
            @for (rel of sortedRelationships(visit?.personReltn); track rel) {
                <ng-container [ngTemplateOutlet]="relationshipTemplate" [ngTemplateOutletContext]="{rel, even: $even}" />
            }
        </div>
    
    </div>
    
    <!-- Repeatable relationship template -->
    <ng-template #relationshipTemplate let-rel="rel" let-even="even">
        <div class="grid-4-column" [class]="even ? '' : 'zebra'">
            <app-field [label]="rel.personReltnType" [text]="rel.nameFullFormatted" />
            <app-field label="Relationship" [text]="rel.personReltn" />
            <app-field label="Home Phone" [text]="common.formatPhone(phoneService.get('HOME', rel.relatedPersonId ?? rel.personId))" />
            <app-field label="Address" [text]="common.addressToArray(addressService.get('HOME', rel.relatedPersonId ?? rel.personId))" />
        </div>
    </ng-template>

    Some of the code above should be familiar after working on the information tab and won't be discussed again.

    The @for statement allows for implementation of a loop in your HTML. The syntax is:

    @for (variableName of array; track variableName) { ...your code... }

    In our component, we are using the @for loop to iterate through the result of our sortedRelationships method. This method accepts an IPersonReltn array, IEncntrPersonReltn array or undefined and returns the same object back sorted by relationship type.

    Our loop uses a custom template called relationshipTemplate and passes the relationship object as well as an indicator if the row is an even numbered row in our array.

    <ng-container [ngTemplateOutlet]="relationshipTemplate" [ngTemplateOutletContext]="{rel, even: $even}" />

    At the bottom of our script, we have a template defined called relationshipTemplate. The let-rel and let-even properties of ng-template assign our rel and even variables.

    The even value is used to determine if the zebra CSS class should be applied to show the shaded background.

<< Prev: 5. Information Tab
Next: 7. Provider Relationship Tab >>
Copyright © 2026 Precision Healthcare Solutions