Macros Questions

Hi,

Following on from Greta's questions about macros for emails I am having a few issues with macros and was wondering if someone could help me.

1) Sometimes when I am trying to create a macro in the "Edit Macro" screen the macro will auto-expand in that screen.

So, I put @ClinicianName (macro = openvpms:get($clinician, "description")) and it executes and enters my name. Great, except that then others can't use it.

I am not sure why this happens in some instances but not others.

2) I created a macro called @hisorher with the expression expr:if(openvpms:get(.,'sex')='MALE','his', 'her') . This is in 1.7b1 I might add. I insterted into a macro we use in letter generations and it didn't work.

Suggestions would be greatly appreciated.

Thanking you,

Adrian

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Macros Questions

Adrian - herewith my input:

1) clinician name - here is my macro

Now - I am logged on a 'Admin' - if I go to the Medical records screen and set the clinician [by entering the clinican for something] then using @cname generates what is expected. If I use your syntax, ie openvpms:get($clinician, "description") then I get the same result.

Conclusion: sorry cannot replicate your problem.

2. Initially I started playing just with the raw macro.  Your expression expr:if(openvpms:get(.,'sex')='MALE','his', 'her') does not work as expected (or rather it returns null) because the . does not specify who/what's sex we want.  I change this to expr:if(openvpms:get($patient,'sex')='MALE','his', 'her') - and it works as expected.

 

Now in the above, I am playing with 'on screen expansion'. From your text, you are more concerned with expansion within letters/forms. In this case we need the macro set up a little differently as follows:

expr:if(openvpms:get(.,'patient.entity.sex')='MALE','his', 'her')

The field/merge expression we need in the odt or doc file is [macro:eval('@hisher')]

Attached is my SamplePatientDocument.odt whcih illustrates this. [Hopefully this will be part of the 1.7 package - I am still working on the Word equivalent.]

Adrian - thanks for raising this topic - I had not thought of using the expr:if capability in forms and letters.  One can use condition testing in Open Office documents, but not in Word documents.  However, these use of macro:eval and expr:if in the macro allows one to do the his/hers switching in Word.

Regards, Tim G

AttachmentSize
SamplePatientDocument1.odt 27.05 KB

Re: Macros Questions

Hi Tim,

Thanks for that. Much of this comes from my incomplete understanding of macros, archetypes, nodes, etc.

1. I think I didn't explain myself well.

I have a macro to bring up the clinician name:

I then want to insert my clinician name into another macro for example this template for one of our clinicians:

However as soon as I type some more or press "Apply" it inserts my name (presumably because I am logged in and a clinician).

So now no one else can really use this template the way it is intended because it has auto-inserted my name instead of theirs...

Weird thing is that I know in some of my other templates this does not occur?

2. Again, I think I didn't necessarily explain my problem very well, however you solved it anyway.

Basically our discharge letters are created by going NEW->LETTER at which point a input box appears. We then insert a macro DischargeVomiting for example that has all the text we require. I was trying to get the conditional formating to work here. We basically want to play with the on screen expansion as much as possible.

We do this to avoid having to go into Open Office every time we want to write/tailor a discharge letter (which is often). It also means what we write is saved in the document (previously if we made many changes to our templates we would save this back into OVPMS for medical record keeping.

Either way all I needed was to get conditional formatting working in the Letter Input Field which your modification does. Now I need to think of new and interesting ways we can use the conditional formatting using other fields...

Thanking you & happy holidays,

Adrian

Re: Macros Questions

Adrian - the first problem (immediate expansion) is due to the following (quoted from the CSH page for the Macro edit screen- http://www.openvpms.org/documentation/csh/1.7/admin/lookup/macro :

Macros in Macros: We can make use of the above two facilities by defining a macro, say @oid with the expression:

  concat($dispensingVerb, ' ', $number, ' ', $dispensingUnits, '(s) Once Daily')

Here we are invoking two other macros, dispensingVerb and dispensingUnits, and also making use of the $number.  Thus 4@oid will expand to something like "Give 4 Tablet(s) Once Daily"

Note that invoked macro (eg 'dispensingVerb') MUST have a name that starts with a letter, otherwise the expansion will not work.

[I have bolded up the bit that is giving you grief]

 

His/her steering - if you are using odt templates, then the OO conditional syntax will work - see the bottom part of the sample document I sent you.  I have this running happily in a number of our templates (notably the post operative care ones) - for example:

Note that the trick is to have an invisible field called sex (set from patient.entity.sex) which can be tested by the conditional.  The sample document shows this as per the snippet below.

Regards, Tim G

Re: Macros Questions

The macro Expression field expands macros. If it didn't, you would end up with raw macro codes in the expanded text, and you'd have to press enter again to get them to expand.

It won't always be able to expand. This occurs if the current context doesn't have the right objects to perform the expansion (e.g. the macro requires a patient, but no patient has been selected).

You can call macros in the Expression field.  To do this you need to hide the macro code from expansion using concat, and evaluate it with the macro:eval() function. E.g. to call the @lea macro:

 macro:eval(concat('@', 'lea'))

To call two macros, @lea and @rea, separated by a new line:

 concat(macro:eval(concat('@', 'lea')), '

', macro:eval(concat('@', 'rea')))

-Tim A

 

Re: Macros Questions

Hi Tim,

I guess I am a very confused.

I have a macro that is basically a text expansion but also contains other macros...

This works well for us. We create a new note, type "ConsultSOAP". The text appears and when we start typing and hit "Enter" the clinician, date, time, ref vet practice, etc all expand. Happy days.

I create another macro for a different purpose (but want similar fields):

But this one auto-expands before I can finish editing the macro...

Frustrating as I don't see the difference between ConsultSOAP & UpdateAM.

I have to dash now but will try to come back with some other issues I am having with the concat function suggested above.

Thanks,

Adrian

Re: Macros Questions

Adrian - the problem is that unless you use the (new in 1.7) macro:eval facility, you cannot invoke a macro within another macro unless its code starts with a letter. I do not understand exactly how your ConsultSoap macro got built - however I suspect it was done by loading the macro with the dataload tool - this way one could embed the @clin and other macros without them being expanded as you have found happens when you try and build the CreateAM macro.

The correct way to do things (see http://www.openvpms.org/documentation/csh/1.7/admin/lookup/macro )
 is to do as follows:

a) ensure that all the macros to be called from within your macro have codes that start with a letter (ie m_clin rather than @clin). [I note that your DateStart and TimeStart macros are set this way.]

b) write the macro expression as:

concat('VET: ',$m_clin,' ',$m_clid,'
TIME & DATE OF CONSULT: ',$DateStart,' ',$TimeStart,'
PRIMARY CARE VET: ',$m_refvetprac,'

PRESENTING COMPLAINT:

HISTORY:')

[Note that here I have assumed you have converted all your @xxxx macros to have codes m_xxxx.]

 

Hope this clarifies things.

Regards, Tim G

Re: Macros Questions

I guess that when ConsultSOAP was created, the logged in user wasn't a clinician, so the @clin and @clid didn't expand. If you were to edit it now as a clinician user, and press enter, the field should expand.

For your new macro, try:

 concat('VET: ', $clinician.name, '

DATE AND TIME: ', date:format(java.util.Date.new(), "dd/MM/yyyy h:mm a"), '

Other text

')

Note that nested macros that use variables won't be evaluated at present. I'll look into that later in the week.

-Tim

Re: Macros Questions

Hi,

I think TimA has it correct. When I set the originals up I must not have been logged in as a clinician.

I guess my new question is: What is the advantage of using the format above (that seems to require quite some more typing and know how) as compared to just creating a new user that has no clinician and creating my macro as such?).

Anyway, I will have another crack at things.

Thanks,

Adrian

Re: Macros Questions

Your approach will work. In general however, if you are trying to create macros that refer to context objects ($patient, $customer, $clinician, $whatever...), then the macros will expand if those objects are present. You may have to log out to clear the context to prevent this.

Some objects are always present in the context (e.g. $location, $user), so these will always expand, and you'll need to use the other techniques described above.

-Tim A

Syndicate content