Link to home
Start Free TrialLog in
Avatar of BulldogMike
BulldogMikeFlag for United States of America

asked on

Compare 2 parts of same String to determine a condition using @if @Contains

Hi

Is it possible to compare two portions of the same string to determine if a condition exists?

For example, component PXD_DGH_NM is created from other components (I don't know how) and the resulting data is in an inconsistent format. However, it is usually in one of the following:

      DRUG ODT STR TAB
      DRUG TAB STR ODT      

It's confusing to work with since WORD 1 could be DRUG or DRUG + ODT or DRUG TAB depending how the item was setup in the master file.      

HERE is what I want to ACHIEVE:

If the format is DRUG TAB STR ODT then I want the outcome to be DRUG ODT. Therefore, if PXD_DGH_NM is "RESPERIDONE TAB O.5MG ODT" then I want "RISPERIDONE ODT" to display.

The other format DRUG ODT STR TAB is working OK [if PXD_DGH_NM = ZOFRAN ODT 4MG TAB then "ZOFRAN ODT" displays as desired].

Here is WHAT I have TRIED
:
@If (@Contains(PXD_DGH_NM; "RISPERIDONE") & @If(@Contains(PXD_DGH_NM; "ODT"); "RISPERIDONE ODT";

In this CODE "MODULE"

@If (@Contains(PXD_DGH_NM; "ZYPREXA ZYDI");"ZYPREXA ODT";
@If (@Contains(PXD_DGH_NM; "REMERON SLTB");"REMERON ODT";
@If (@Contains(PXD_DGH_NM; "RISPERDAL M"); "RISPERDAL  ODT";
@If (@Contains(PXD_DGH_NM; "RISPERDAL M"); "RISPERDAL  ODT";
@If (@Contains(PXD_DGH_NM; "RISPERDAL ODT"); "RISPERDAL  ODT";
@If (@Contains(PXD_DGH_NM; "RISPERIDONE") & @If(@Contains(PXD_DGH_NM; "ODT"); "RISPERIDONE ODT";
@If (@Contains(PXD_DGH_NM; "OLANZAPINE ODT"); "OLANZAPINE ODT";
@If (@Contains(PXD_DGH_NM; "OLANZAPINE" + "ODT"); "OLANZAPINE ODT";
@If (@Contains(PXD_DGH_NM; "ZOFRAN ODT"); "ZOFRAN ODT";
@Word(PXD_DGH_NM;" ";1) + " " + @Word(PXD_DGH_NM;" ";2)))))))))))

Thanks for your help with this

Mike
ASKER CERTIFIED SOLUTION
Avatar of Sjef Bosman
Sjef Bosman
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BulldogMike

ASKER

Sejf -  Is it possible to approach like this?  

If WORD 2 3 4 or 5 are ="ODT" then use WORD 1 plus ODT. Otherwise, use WORD 1 + WORD 2.   The data for PXD_DGH_NM IS Consistent now IN notes  
      
DRUG ODT STR TAB
DRUG TAB STR ODT
      
How to code it?

@Word(PXD_DGH_NM;" ";1) + " " + If @Word 2 3 4 or 5 is equal to "ODT"; then add "ODT"; otherwise @Word (PXD_DGH_NM;" ";1) + " " + @Word(PXD_DGH_NM;" ";2)

Thanks

Mike
It might be possible, the way you describe it, but I'm afraid your approach is not very logical. Your analysis of the case could have been better.

Did you try my code? Probably not, but I don't blame you. Formula language is much more powerful than the way you're using it. My analysis tells me that the positions of ODT and TAB are not relevant, and all you need to know is whether these words are there or not, and then they can be removed from the string. Maybe I shouldn't have used the word "word", it might have added to the confusion, for now you propose to use @Word and that's not one of my favourites.

Here's the (tested) code:

PXD_DGH_NM:= "RESPERIDONE TAB O.5MG ODT";

     words:= @Explode(PXD_DGH_NM; " ");
     odt:= @If(@Contains(words; "ODT"); "ODT"; "");
     tab:=@If( @Contains(words; "TAB"); "TAB"; "");
     words:= @Trim(@Replace(words;"ODT":"TAB";""));
     drug:= @Subset(words; 1);
     dosage:= @Subset(words; -1);
     result:= @Implode(drug:odt; " ");

@Prompt([OK];"Result"; result)

Open in new window


What happens with my code:

At step 0
String:       RESPERIDONE TAB O.5MG ODT

After step 1:
words: "RESPERIDONE" : "TAB" : "O.5MG" : "ODT"  (this is a list of 4 strings, the colon is the list concatenation operator)

After step 2:
odt: "ODT"
tab: "TAB" (both words occur in the string)
words: "RESPERIDONE" : "O.5MG" (both strings ODT and TAB are removed from the list of strings, which is thus reduced to only 2 strings)

After step 3:
drug: "RESPERIDONE" (it's the first string...)
dosage: "O.5MG" (and dosage is the last string from the list)

After step 4:
result: "RESPERIDONE ODT"

Try to understand it. If you have questions, don't hesitate to ask them!
Hi Sjef

You are a big help - thanks  

When I copied the following code into the field PXD_DGH_NM1, I received a variable already declared error on line 4 so maybe I don't understand something

     words:= @Explode(PXD_DGH_NM; " ");
     odt:= @If(@Contains(words; "ODT"); "ODT"; "");
     tab:=@If( @Contains(words; "TAB"); "TAB"; "");
     words:= @Trim(@Replace(words;"ODT":"TAB";""));  ERROR HERE
     drug:= @Subset(words; 1);
     dosage:= @Subset(words; -1);
     result:= @Implode(drug:odt; " ");
@Prompt([OK];"Result"; result)

Sorry to be illogical - maybe I should have explained better. As you can tell, I am not a professional trained programmer - I had to teach myself under as best I could under the circumstances.

Some drug names contain ODT in their description while others do not. My thought is the LOGICAL outcome should be:

      WORD1+"ODT" (if ODT or SLTB or SOLTAB is in the description) OTHERWISE
      WORD1 + WORD2
      
Here are 3 listings for Remeron and their desired outcomes to demonstrate. The acronym "ODT" means"Orally Disintegrating Tab" which is why we use "ODT"

REMERON 15MG ODT SOLTAB (SOLTAB or SLTB - manufacturer's designation for ODT)
REMERON SLTB TAB 15MG  
REMERON TAB 15MG  (NOT ODT or SLTD - just a regular tablet)  

The CODING could be like this:

      WORD1 + if PXD_DGH_NM contains "ODT" or "SOLTAB" or "SLTB" in WORDS2,3,4
      OR 5 (if available);
                THEN ADD "ODT" after WORD1;
                OTHERWISE add WORD2 after WORD1

OUTCOME Examples:

REMERON 15MG ODT SOLTAB = REMERON ODT
REMERON SLTB TAB 15MG   = REMERON ODT
REMERON TAB 15MG        = REMERON TAB
              
This is the complete list of drugs with ODT in their description for this application

ABILIFY DISC ODT 1OMG
LAMICTAL TAB ODT 25MG
LAMICTAL TAB ODT KIT
MIRTAZAPINE ODT 15MG
MIRTAZAPINE TAB 15MG ODT
OLANZAPINE ODT 15MG
OLANZAPINE TAB 15MG ODT
REMERON 15MG ODT SOLTAB
REMERON SLTB TAB 15MG
RISPERIDAL M TAB 1MG ODT
RISPERIDAL ODT M-TAB 1
RISPERIDONE TAB 1MG ODT
ZYPREX ZYDI ODT 1OMG
ZYPREX ZYDI TAB 1OMG

Thanks again for your help

Mike
The error in my code only occurs if you're on an "older" version of Notes...
PXD_DGH_NM:= "RESPERIDONE TAB O.5MG ODT";

     words:= @Explode(PXD_DGH_NM; " ");
     odt:= @If(@Contains(words; "ODT"); "ODT"; "");
     tab:=@If( @Contains(words; "TAB"); "TAB"; "");
     rwords:= @Trim(@Replace(words;"ODT":"TAB";""));
     drug:= @Subset(rwords; 1);
     dosage:= @Subset(rwords; -1);
     result:= @Implode(drug:odt; " ");

@Prompt([OK];"Result"; result)

Open in new window


Put this code in an agent or so, so you can test it with the list you have. My code should work irrespective of the place of ODT and TAB. The only conditions are that there are a maximum of 4 words, of which 2 can be ODT and TAB, and of the remaining words the first is the name of the drug and the last is the dosage.
OK I will try it - We use Notes version 5
I'm impressed...
Tried?
Thanks for your help

This is the code I am using for PXD_DGH_NM1 component and it is working.  

@If(@Contains(PXD_DGH_NM;"ODT");@Word(PXD_DGH_NM;" ";1) + " "+ "ODT";
@If(@Contains(PXD_DGH_NM;"SLTB");@Word(PXD_DGH_NM;" ";1) + " "+ "ODT";
@If(@Contains(PXD_DGH_NM;"M-TAB");@Word(PXD_DGH_NM;" ";1) + " "+ "ODT";
@If(@Contains(PXD_DGH_NM;"ZYDI");@Word(PXD_DGH_NM;" ";1) + " " + "ODT ";
@Word(PXD_DGH_NM;" ";1)  + " " + @Word(PXD_DGH_NM;" ";2)))))

It looks for "ODT" or "SLTB" and so on in PXD_DGH_NM.  If it finds a match it adds a space and "ODT" after WORD1.  If not, it uses WORD1 plus WORD2 as the default solution (which will used most of the time for the drug items ordered).

So, REMERON SLTB TAB 15MG  becomes “REMERON ODT”   and  PROZAC CAP 10MG becomes  “PROZAC CAP”  

Thanks for your help and ideas

Mike
I've requested that this question be closed as follows:

Accepted answer: 0 points for BulldogMike's comment #a39452302

for the following reason:

Sjef as always is knowledgeable and helpful.  

I haven't declared variables (like he does in his elegant solution) in my coding before but I am begining to see the possiblities available to me by doing so.

This probably sounds dumb to most professsional programmers who use them all the time. But, I am not a professionally trained programmer or even an IT person.  I am a healthcare professional.  So, I need all the help I can get especially with syntax and logical problem solving.  The books available assume the reader has attained a level of knowledge and experience that I don't have yet.  So EE is very helpful to me.

Thank You

Mike
sorry I intended to accept Sejf's solution - give him 500 points
Sjef as always is knowledgeable and helpful.  

I haven't declared variables (like he does in his elegant solution) in my coding before but I am begining to see the possiblities available to me by doing so.

This probably sounds dumb to most professsional programmers who use them all the time. But, I am not a professional trained programmer or even an IT person.  I am a healthcare professional.  So, I need all the help I can get especially with syntax and logical problem solving.  The books available assume the reader has attained a level of knowledge and experience that I don't have yet.  So EE is very helpful to me.

Thank You

Mike
Solved! Good!

But if I may suggest something: if you can find some time, please, try the code I sent you (for I get the idea you didn't try it because it looked scary or so). You can learn a lot more by making mistakes than by following a trodden path.

You can add @Prompt statements to make the intermediate results visible, and you can use the Help database to find more commands. If you want a short presentation (via Skype), just send me a mail.

The code, now with some @Prompt statements added:
PXD_DGH_NM:= "RESPERIDONE TAB O.5MG ODT";

     words:= @Explode(PXD_DGH_NM; " ");
@Prompt([OK];"words"; @Implode(words; ";"));
     odt:= @If(@Contains(words; "ODT"); "ODT"; "");
     tab:=@If( @Contains(words; "TAB"); "TAB"; "");
     rwords:= @Trim(@Replace(words;"ODT":"TAB";""));
@Prompt([OK];"rwords, odt, tab"; @Implode(rwords:odt:tab; ", "));
     drug:= @Subset(rwords; 1);
     dosage:= @Subset(rwords; -1);
     result:= @Implode(drug:odt; " ");

@Prompt([OK];"Result"; result)

Open in new window

Put it in a Formula agent, set Target to None, and execute the agent. The results you'll see on the screen.

Ah, but you changed the specifications a little, am I correct? There are also SLTB and M-TAB and ZYDI in your formulas. What any professional (programmer or not) should know is that one shouldn't develop something special that is to be used generally. What if someone adds a new drug to the list some day, say "DIPODTONE 15MG". Your code will fail, because it's too specific, so you'll have to adapt the code, over and over again.

But I understand that you don't have the time, and since it's not (supposed to be) your job, you attack the problem the pragmatic way. I'm happy to help in any case, but you'd learn a lot more if you could spend some time analysing the execution of the code.
Thanks you are always informative and helpful. I will look it over and consider using it if possible.

I not sure if "THEY" would allow me to create an agent because agent and script library programming is not within my purview.  We have IT guys who do that. Also, displaying the outcome on the monitor is not needed and would slow operations down a lot.  

Let me explain.  We use Notes to create faxes and letters for doctors, patients and clients.  Users request them in the order entry system which generates a datafile that is transfered to NOTES by an NOTES agent.  When the agent runs it merges the data files into the appropriate template and the it's queues them to either an outgoing fax machine or stored in a letter file to be printed later when requested. Currently, we have thousands of faxes in the queues at four operation sites in various processing states along with many many letters also.  So, the real IT guys ain't gonna let me touch that part of the system if creating an agent is what I think it is.

You have taught me a lot and I really appreciate it. I look forward to getting to know you better as more "problems" or opportunities cross my desk.

Thank You

Mike