# How to use lookup tag on getting the lastEncounter with Date | Html Form Entry

**URL:** <https://talk.openmrs.org/t/how-to-use-lookup-tag-on-getting-the-lastencounter-with-date-html-form-entry/39718>\
**Category:** Development\
**Created:** [May 25, 2023, 2:59pm UTC](https://talk.openmrs.org/t/how-to-use-lookup-tag-on-getting-the-lastencounter-with-date-html-form-entry/39718 "2023-05-25T14:59:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathan](https://talk.openmrs.org/user_avatar/talk.openmrs.org/jonathan/32/14972_2.png) [@jonathan](https://talk.openmrs.org/u/jonathan)\
**Post date:** [May 25, 2023, 2:59pm UTC](https://talk.openmrs.org/t/how-to-use-lookup-tag-on-getting-the-lastencounter-with-date-html-form-entry/39718/1 "2023-05-25T14:59:49Z")

</div>

Hello folks ,

Am trying to check if a patient has ever encountered a form fill-out and found this 👇🏿

[https://wiki.openmrs.org/display/docs/HTML+Form+Entry+Module+Reference#:~:text=fn.latestEncounter(EncounterType%20type%2C%20String,4eaf-85e3-87cfad31bfa6'%2C%20%24encounterDate)"/\>](https://wiki.openmrs.org/display/docs/HTML+Form+Entry+Module+Reference#:~:text=fn.latestEncounter(EncounterType%20type%2C%20String,4eaf%2D85e3%2D87cfad31bfa6%27%2C%20%24encounterDate)%22/%3E)

```auto

`First MDR-TB Encounter: <lookup expression=` `"fn.latestEncounter('ee95dbbf-5aec-4eaf-85e3-87cfad31bfa6', '2021-06-30')"` `/>`

`The method also accepts a velocity variable may be a date or a string`

`First MDR-TB Encounter: <lookup expression=` `"fn.latestEncounter('ee95dbbf-5aec-4eaf-85e3-87cfad31bfa6', $encounterDate)"` `/>`

```

However wanted to know if the encounter type talked about here

> `ee95dbbf-5aec-4eaf-85e3-87cfad31bfa6`

is the `formEncounterType` or any `conceptId`

also `$encounterDate` is it just a variable or its defined within the Html form Entry

cc @dkayiwa @sharif @mozzy

---

<div class="post-metadata">

**Author:** ![sharif](https://talk.openmrs.org/user_avatar/talk.openmrs.org/sharif/32/11982_2.png) [@sharif](https://talk.openmrs.org/u/sharif)\
**Post date:** [May 25, 2023, 3:21pm UTC](https://talk.openmrs.org/t/how-to-use-lookup-tag-on-getting-the-lastencounter-with-date-html-form-entry/39718/2 "2023-05-25T15:21:59Z")

</div>

> [@jonathan](#):
>
> also `$encounterDate` is it just a variable or its defined within the Html form Entry

Cross check in here [wiki?](https://wiki.openmrs.org/display/docs/HTML+Form+Entry+Module+Reference#HTMLFormEntryModuleReference-%3CencounterDate%3E). It have details about encounterDate widget and how it can be used in HTMLFORM

> [@jonathan](#):
>
> is the `formEncounterType` or any `conceptId`

Yes that is FormEncounterType uuid.

---

<div class="post-metadata">

**Author:** ![jonathan](https://talk.openmrs.org/user_avatar/talk.openmrs.org/jonathan/32/14972_2.png) [@jonathan](https://talk.openmrs.org/u/jonathan)\
**Post date:** [May 25, 2023, 6:41pm UTC](https://talk.openmrs.org/t/how-to-use-lookup-tag-on-getting-the-lastencounter-with-date-html-form-entry/39718/3 "2023-05-25T18:41:31Z")

</div>

> [@sharif](#):
>
> Cross check in here [wiki?](https://wiki.openmrs.org/display/docs/HTML+Form+Entry+Module+Reference#HTMLFormEntryModuleReference-%3CencounterDate%3E). It have details about encounterDate widget and how it can be used in HTMLFORM

Hey @sharif wat i meant here is

> `First MDR-TB Encounter: <lookup expression=` `"fn.latestEncounter('ee95dbbf-5aec-4eaf-85e3-87cfad31bfa6', $encounterDate)"` `/>`

this `$encounterDate` used up there is it a variable or its defined within the Html form Entry

---

<div class="post-metadata">

**Author:** ![sharif](https://talk.openmrs.org/user_avatar/talk.openmrs.org/sharif/32/11982_2.png) [@sharif](https://talk.openmrs.org/u/sharif)\
**Post date:** [May 26, 2023, 5:34am UTC](https://talk.openmrs.org/t/how-to-use-lookup-tag-on-getting-the-lastencounter-with-date-html-form-entry/39718/4 "2023-05-26T05:34:11Z")

</div>

> [@jonathan](#):
>
> this `$encounterDate` used up there is it a variable or its defined within the Html form Entry

It is defined with in htmlform.

---

<div class="post-metadata">

**Author:** ![jonathan](https://talk.openmrs.org/user_avatar/talk.openmrs.org/jonathan/32/14972_2.png) [@jonathan](https://talk.openmrs.org/u/jonathan)\
**Post date:** [May 26, 2023, 5:43am UTC](https://talk.openmrs.org/t/how-to-use-lookup-tag-on-getting-the-lastencounter-with-date-html-form-entry/39718/5 "2023-05-26T05:43:25Z")

</div>

So does this turn out to be the most recent encounter Date

---

<div class="post-metadata">

**Author:** ![sharif](https://talk.openmrs.org/user_avatar/talk.openmrs.org/sharif/32/11982_2.png) [@sharif](https://talk.openmrs.org/u/sharif)\
**Post date:** [May 26, 2023, 7:35am UTC](https://talk.openmrs.org/t/how-to-use-lookup-tag-on-getting-the-lastencounter-with-date-html-form-entry/39718/6 "2023-05-26T07:35:46Z")

</div>

Yes, you can use to get current date of an encounter.

---

<div class="post-metadata">

**Author:** ![jonathan](https://talk.openmrs.org/user_avatar/talk.openmrs.org/jonathan/32/14972_2.png) [@jonathan](https://talk.openmrs.org/u/jonathan)\
**Post date:** [May 26, 2023, 11:13am UTC](https://talk.openmrs.org/t/how-to-use-lookup-tag-on-getting-the-lastencounter-with-date-html-form-entry/39718/7 "2023-05-26T11:13:40Z")

</div>

thanks @sharif have tried to use `$encounterDate` and `$encounter.encounterDatetime` but these were returning ’ ’ for my latestEncounter

So Ended up using `$visit.startDatetime` and this seems fine thank u brother 🙂

```auto
lookup expression="fn.latestEncounter('ee95dbbf-5aec-4eaf-85e3-87cfad31bfa6', $visit.startDatetime)"/>

```
