Groovy code to Un-void Patient Identifier

classic Classic list List threaded Threaded
17 messages Options
Erick Mugoma Erick Mugoma
Reply | Threaded
Open this post in threaded view
|

Groovy code to Un-void Patient Identifier

Hi
Can someone show me how to write a simple groovy code that can be used to un-void a specific patient Identifier. I don't want to do this using SQL since we are running the sync module and I want the changes to be propagated to all the children.

Any help will be greatly appreciated.

Thanks

Erick

[hidden email] from OpenMRS Implementers' mailing list
Mark Goodrich-2 Mark Goodrich-2
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

Erick,

 

I haven’t tested this, but if you know the id of the patient identifier, you should be able to do something like this:

 

org.openmrs.PatientIdentifier identifier = patient.getPatientIdentifier(123);

identifier.setVoided(false);

identifier.setVoidReason("");

identifier.setVoidedBy(null);

patient.savePatientIdentifier(identifier);

 

Take care,

Mark

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Monday, March 26, 2012 12:41 AM
To: [hidden email]
Subject: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi
Can someone show me how to write a simple groovy code that can be used to un-void a specific patient Identifier. I don't want to do this using SQL since we are running the sync module and I want the changes to be propagated to all the children.

Any help will be greatly appreciated.

Thanks

Erick


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list
Ben Wolfe (openmrs) Ben Wolfe (openmrs)
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

I was going to suggest that Mark, but then looked at the javadocs.  Looks like there is a PatientService.voidPatientIdentfier(PI, String) method that makes this easier

You could do:
PatientIdentifier pi = patient.getPatientIdentifierByUuid("123wf9329349234");
patient.voidPatientIdentifier(pi, "because it smells like moldy cheese");

(assuming "patient" is still aliased to Context.getPatientService())

See http://api.openmrs.org for latest javadoc.  (or http://resources.openmrs.org/doc-1.8/ for earlier)

Ben

On Mon, Mar 26, 2012 at 10:49 AM, Mark Goodrich <[hidden email]> wrote:

Erick,

 

I haven’t tested this, but if you know the id of the patient identifier, you should be able to do something like this:

 

org.openmrs.PatientIdentifier identifier = patient.getPatientIdentifier(123);

identifier.setVoided(false);

identifier.setVoidReason("");

identifier.setVoidedBy(null);

patient.savePatientIdentifier(identifier);

 

Take care,

Mark

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Monday, March 26, 2012 12:41 AM
To: [hidden email]
Subject: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi
Can someone show me how to write a simple groovy code that can be used to un-void a specific patient Identifier. I don't want to do this using SQL since we are running the sync module and I want the changes to be propagated to all the children.

Any help will be greatly appreciated.

Thanks

Erick


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list
Erick Mugoma Erick Mugoma
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

Thanks Ben and Mark.
The guideline worked fine especially when using the uuid. However I also wrote the following code to unvoid the person but it failed. Maybe am using the wrong method call?? see the code below:

org.openmrs.Person px = person.getPerson(20384);
px.setVoided(false);
px.setVoidReason("");
px.setVoidedBy(null);
person.savePerson(px);

The above code runs successfully but no changes are persisted to the database.

Thanks

Erick

On Mon, Mar 26, 2012 at 6:10 PM, Ben Wolfe <[hidden email]> wrote:
I was going to suggest that Mark, but then looked at the javadocs.  Looks like there is a PatientService.voidPatientIdentfier(PI, String) method that makes this easier

You could do:
PatientIdentifier pi = patient.getPatientIdentifierByUuid("123wf9329349234");
patient.voidPatientIdentifier(pi, "because it smells like moldy cheese");

(assuming "patient" is still aliased to Context.getPatientService())

See http://api.openmrs.org for latest javadoc.  (or http://resources.openmrs.org/doc-1.8/ for earlier)

Ben


On Mon, Mar 26, 2012 at 10:49 AM, Mark Goodrich <[hidden email]> wrote:

Erick,

 

I haven’t tested this, but if you know the id of the patient identifier, you should be able to do something like this:

 

org.openmrs.PatientIdentifier identifier = patient.getPatientIdentifier(123);

identifier.setVoided(false);

identifier.setVoidReason("");

identifier.setVoidedBy(null);

patient.savePatientIdentifier(identifier);

 

Take care,

Mark

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Monday, March 26, 2012 12:41 AM
To: [hidden email]
Subject: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi
Can someone show me how to write a simple groovy code that can be used to un-void a specific patient Identifier. I don't want to do this using SQL since we are running the sync module and I want the changes to be propagated to all the children.

Any help will be greatly appreciated.

Thanks

Erick


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list
Ben Wolfe (openmrs) Ben Wolfe (openmrs)
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

You should use person.voidPerson(px, "because they smell like moldy cheese");

You can use what you are doing, but you need to give it a real reason, not an empty string. The PersonSaveHandler prevents it.  You should see this error in your server log somewhere: "The voided bit was set to true, so a void reason is required at save time for person xyz"

Ben

On Mon, Mar 26, 2012 at 10:18 PM, Erick Mugoma <[hidden email]> wrote:
Thanks Ben and Mark.
The guideline worked fine especially when using the uuid. However I also wrote the following code to unvoid the person but it failed. Maybe am using the wrong method call?? see the code below:

org.openmrs.Person px = person.getPerson(20384);
px.setVoided(false);
px.setVoidReason("");
px.setVoidedBy(null);
person.savePerson(px);

The above code runs successfully but no changes are persisted to the database.

Thanks

Erick


On Mon, Mar 26, 2012 at 6:10 PM, Ben Wolfe <[hidden email]> wrote:
I was going to suggest that Mark, but then looked at the javadocs.  Looks like there is a PatientService.voidPatientIdentfier(PI, String) method that makes this easier

You could do:
PatientIdentifier pi = patient.getPatientIdentifierByUuid("123wf9329349234");
patient.voidPatientIdentifier(pi, "because it smells like moldy cheese");

(assuming "patient" is still aliased to Context.getPatientService())

See http://api.openmrs.org for latest javadoc.  (or http://resources.openmrs.org/doc-1.8/ for earlier)

Ben


On Mon, Mar 26, 2012 at 10:49 AM, Mark Goodrich <[hidden email]> wrote:

Erick,

 

I haven’t tested this, but if you know the id of the patient identifier, you should be able to do something like this:

 

org.openmrs.PatientIdentifier identifier = patient.getPatientIdentifier(123);

identifier.setVoided(false);

identifier.setVoidReason("");

identifier.setVoidedBy(null);

patient.savePatientIdentifier(identifier);

 

Take care,

Mark

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Monday, March 26, 2012 12:41 AM
To: [hidden email]
Subject: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi
Can someone show me how to write a simple groovy code that can be used to un-void a specific patient Identifier. I don't want to do this using SQL since we are running the sync module and I want the changes to be propagated to all the children.

Any help will be greatly appreciated.

Thanks

Erick


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list
Burke Mamlin Burke Mamlin
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

In reply to this post by Erick Mugoma
Does this work?

p = person.getPersion(20384)
person.unvoidPersion(p)

Cheers,

-Burke

On Mon, Mar 26, 2012 at 10:18 PM, Erick Mugoma <[hidden email]> wrote:
Thanks Ben and Mark.
The guideline worked fine especially when using the uuid. However I also wrote the following code to unvoid the person but it failed. Maybe am using the wrong method call?? see the code below:

org.openmrs.Person px = person.getPerson(20384);
px.setVoided(false);
px.setVoidReason("");
px.setVoidedBy(null);
person.savePerson(px);

The above code runs successfully but no changes are persisted to the database.

Thanks

Erick


On Mon, Mar 26, 2012 at 6:10 PM, Ben Wolfe <[hidden email]> wrote:
I was going to suggest that Mark, but then looked at the javadocs.  Looks like there is a PatientService.voidPatientIdentfier(PI, String) method that makes this easier

You could do:
PatientIdentifier pi = patient.getPatientIdentifierByUuid("123wf9329349234");
patient.voidPatientIdentifier(pi, "because it smells like moldy cheese");

(assuming "patient" is still aliased to Context.getPatientService())

See http://api.openmrs.org for latest javadoc.  (or http://resources.openmrs.org/doc-1.8/ for earlier)

Ben


On Mon, Mar 26, 2012 at 10:49 AM, Mark Goodrich <[hidden email]> wrote:

Erick,

 

I haven’t tested this, but if you know the id of the patient identifier, you should be able to do something like this:

 

org.openmrs.PatientIdentifier identifier = patient.getPatientIdentifier(123);

identifier.setVoided(false);

identifier.setVoidReason("");

identifier.setVoidedBy(null);

patient.savePatientIdentifier(identifier);

 

Take care,

Mark

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Monday, March 26, 2012 12:41 AM
To: [hidden email]
Subject: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi
Can someone show me how to write a simple groovy code that can be used to un-void a specific patient Identifier. I don't want to do this using SQL since we are running the sync module and I want the changes to be propagated to all the children.

Any help will be greatly appreciated.

Thanks

Erick


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list
Ben Wolfe (openmrs) Ben Wolfe (openmrs)
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

Oh, you're unvoiding, missed that.  The properties on Person are actually setPersonVoidedBy, setPersonVoidReason, etc.  There were issues with naming it the same because Person is the parent class to Patient, which also has those fields. 

But using the method Burke mentions should know that and do it for you.

Ben

On Mon, Mar 26, 2012 at 11:00 PM, Burke Mamlin <[hidden email]> wrote:
Does this work?

p = person.getPersion(20384)
person.unvoidPersion(p)

Cheers,

-Burke

On Mon, Mar 26, 2012 at 10:18 PM, Erick Mugoma <[hidden email]> wrote:
Thanks Ben and Mark.
The guideline worked fine especially when using the uuid. However I also wrote the following code to unvoid the person but it failed. Maybe am using the wrong method call?? see the code below:

org.openmrs.Person px = person.getPerson(20384);
px.setVoided(false);
px.setVoidReason("");
px.setVoidedBy(null);
person.savePerson(px);

The above code runs successfully but no changes are persisted to the database.

Thanks

Erick


On Mon, Mar 26, 2012 at 6:10 PM, Ben Wolfe <[hidden email]> wrote:
I was going to suggest that Mark, but then looked at the javadocs.  Looks like there is a PatientService.voidPatientIdentfier(PI, String) method that makes this easier

You could do:
PatientIdentifier pi = patient.getPatientIdentifierByUuid("123wf9329349234");
patient.voidPatientIdentifier(pi, "because it smells like moldy cheese");

(assuming "patient" is still aliased to Context.getPatientService())

See http://api.openmrs.org for latest javadoc.  (or http://resources.openmrs.org/doc-1.8/ for earlier)

Ben


On Mon, Mar 26, 2012 at 10:49 AM, Mark Goodrich <[hidden email]> wrote:

Erick,

 

I haven’t tested this, but if you know the id of the patient identifier, you should be able to do something like this:

 

org.openmrs.PatientIdentifier identifier = patient.getPatientIdentifier(123);

identifier.setVoided(false);

identifier.setVoidReason("");

identifier.setVoidedBy(null);

patient.savePatientIdentifier(identifier);

 

Take care,

Mark

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Monday, March 26, 2012 12:41 AM
To: [hidden email]
Subject: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi
Can someone show me how to write a simple groovy code that can be used to un-void a specific patient Identifier. I don't want to do this using SQL since we are running the sync module and I want the changes to be propagated to all the children.

Any help will be greatly appreciated.

Thanks

Erick


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list
Erick Mugoma Erick Mugoma
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

In reply to this post by Burke Mamlin
Thanks Burk and Ben,
Here is another quick question for you.
I know it is possible to write direct sql statements in groovy to insert, delete or update specific records. When you write direct sql statements are these marked for sync or they will be ignored?

Thanks

Erick

On Tue, Mar 27, 2012 at 6:00 AM, Burke Mamlin <[hidden email]> wrote:
Does this work?

p = person.getPersion(20384)
person.unvoidPersion(p)

Cheers,

-Burke

On Mon, Mar 26, 2012 at 10:18 PM, Erick Mugoma <[hidden email]> wrote:
Thanks Ben and Mark.
The guideline worked fine especially when using the uuid. However I also wrote the following code to unvoid the person but it failed. Maybe am using the wrong method call?? see the code below:

org.openmrs.Person px = person.getPerson(20384);
px.setVoided(false);
px.setVoidReason("");
px.setVoidedBy(null);
person.savePerson(px);

The above code runs successfully but no changes are persisted to the database.

Thanks

Erick


On Mon, Mar 26, 2012 at 6:10 PM, Ben Wolfe <[hidden email]> wrote:
I was going to suggest that Mark, but then looked at the javadocs.  Looks like there is a PatientService.voidPatientIdentfier(PI, String) method that makes this easier

You could do:
PatientIdentifier pi = patient.getPatientIdentifierByUuid("123wf9329349234");
patient.voidPatientIdentifier(pi, "because it smells like moldy cheese");

(assuming "patient" is still aliased to Context.getPatientService())

See http://api.openmrs.org for latest javadoc.  (or http://resources.openmrs.org/doc-1.8/ for earlier)

Ben


On Mon, Mar 26, 2012 at 10:49 AM, Mark Goodrich <[hidden email]> wrote:

Erick,

 

I haven’t tested this, but if you know the id of the patient identifier, you should be able to do something like this:

 

org.openmrs.PatientIdentifier identifier = patient.getPatientIdentifier(123);

identifier.setVoided(false);

identifier.setVoidReason("");

identifier.setVoidedBy(null);

patient.savePatientIdentifier(identifier);

 

Take care,

Mark

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Monday, March 26, 2012 12:41 AM
To: [hidden email]
Subject: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi
Can someone show me how to write a simple groovy code that can be used to un-void a specific patient Identifier. I don't want to do this using SQL since we are running the sync module and I want the changes to be propagated to all the children.

Any help will be greatly appreciated.

Thanks

Erick


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list
Ben Wolfe (openmrs) Ben Wolfe (openmrs)
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

No, you can't use sql there either.  The point of using groovy is so that the PersonService, PatientService, etc methods are called.  Sync uses hibernate to know what has changed.  So all changes need to be persisted as hibernate objects and method calls.  When you save a person with person.savePerson(px), "person" is the PersonService and "px" is a Person object that gets saved via hibernate.

Ben

On Tue, Mar 27, 2012 at 1:41 AM, Erick Mugoma <[hidden email]> wrote:
Thanks Burk and Ben,
Here is another quick question for you.
I know it is possible to write direct sql statements in groovy to insert, delete or update specific records. When you write direct sql statements are these marked for sync or they will be ignored?

Thanks

Erick


On Tue, Mar 27, 2012 at 6:00 AM, Burke Mamlin <[hidden email]> wrote:
Does this work?

p = person.getPersion(20384)
person.unvoidPersion(p)

Cheers,

-Burke

On Mon, Mar 26, 2012 at 10:18 PM, Erick Mugoma <[hidden email]> wrote:
Thanks Ben and Mark.
The guideline worked fine especially when using the uuid. However I also wrote the following code to unvoid the person but it failed. Maybe am using the wrong method call?? see the code below:

org.openmrs.Person px = person.getPerson(20384);
px.setVoided(false);
px.setVoidReason("");
px.setVoidedBy(null);
person.savePerson(px);

The above code runs successfully but no changes are persisted to the database.

Thanks

Erick


On Mon, Mar 26, 2012 at 6:10 PM, Ben Wolfe <[hidden email]> wrote:
I was going to suggest that Mark, but then looked at the javadocs.  Looks like there is a PatientService.voidPatientIdentfier(PI, String) method that makes this easier

You could do:
PatientIdentifier pi = patient.getPatientIdentifierByUuid("123wf9329349234");
patient.voidPatientIdentifier(pi, "because it smells like moldy cheese");

(assuming "patient" is still aliased to Context.getPatientService())

See http://api.openmrs.org for latest javadoc.  (or http://resources.openmrs.org/doc-1.8/ for earlier)

Ben


On Mon, Mar 26, 2012 at 10:49 AM, Mark Goodrich <[hidden email]> wrote:

Erick,

 

I haven’t tested this, but if you know the id of the patient identifier, you should be able to do something like this:

 

org.openmrs.PatientIdentifier identifier = patient.getPatientIdentifier(123);

identifier.setVoided(false);

identifier.setVoidReason("");

identifier.setVoidedBy(null);

patient.savePatientIdentifier(identifier);

 

Take care,

Mark

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Monday, March 26, 2012 12:41 AM
To: [hidden email]
Subject: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi
Can someone show me how to write a simple groovy code that can be used to un-void a specific patient Identifier. I don't want to do this using SQL since we are running the sync module and I want the changes to be propagated to all the children.

Any help will be greatly appreciated.

Thanks

Erick


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list
Erick Mugoma Erick Mugoma
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

Hi Ben,
Thanks very much. It is important that I know these facts. This is the way we want to go since we already implementing Sync and most of our database patches and updates.

Thanks

Erick.

On Tue, Mar 27, 2012 at 3:23 PM, Ben Wolfe <[hidden email]> wrote:
No, you can't use sql there either.  The point of using groovy is so that the PersonService, PatientService, etc methods are called.  Sync uses hibernate to know what has changed.  So all changes need to be persisted as hibernate objects and method calls.  When you save a person with person.savePerson(px), "person" is the PersonService and "px" is a Person object that gets saved via hibernate.

Ben


On Tue, Mar 27, 2012 at 1:41 AM, Erick Mugoma <[hidden email]> wrote:
Thanks Burk and Ben,
Here is another quick question for you.
I know it is possible to write direct sql statements in groovy to insert, delete or update specific records. When you write direct sql statements are these marked for sync or they will be ignored?

Thanks

Erick


On Tue, Mar 27, 2012 at 6:00 AM, Burke Mamlin <[hidden email]> wrote:
Does this work?

p = person.getPersion(20384)
person.unvoidPersion(p)

Cheers,

-Burke

On Mon, Mar 26, 2012 at 10:18 PM, Erick Mugoma <[hidden email]> wrote:
Thanks Ben and Mark.
The guideline worked fine especially when using the uuid. However I also wrote the following code to unvoid the person but it failed. Maybe am using the wrong method call?? see the code below:

org.openmrs.Person px = person.getPerson(20384);
px.setVoided(false);
px.setVoidReason("");
px.setVoidedBy(null);
person.savePerson(px);

The above code runs successfully but no changes are persisted to the database.

Thanks

Erick


On Mon, Mar 26, 2012 at 6:10 PM, Ben Wolfe <[hidden email]> wrote:
I was going to suggest that Mark, but then looked at the javadocs.  Looks like there is a PatientService.voidPatientIdentfier(PI, String) method that makes this easier

You could do:
PatientIdentifier pi = patient.getPatientIdentifierByUuid("123wf9329349234");
patient.voidPatientIdentifier(pi, "because it smells like moldy cheese");

(assuming "patient" is still aliased to Context.getPatientService())

See http://api.openmrs.org for latest javadoc.  (or http://resources.openmrs.org/doc-1.8/ for earlier)

Ben


On Mon, Mar 26, 2012 at 10:49 AM, Mark Goodrich <[hidden email]> wrote:

Erick,

 

I haven’t tested this, but if you know the id of the patient identifier, you should be able to do something like this:

 

org.openmrs.PatientIdentifier identifier = patient.getPatientIdentifier(123);

identifier.setVoided(false);

identifier.setVoidReason("");

identifier.setVoidedBy(null);

patient.savePatientIdentifier(identifier);

 

Take care,

Mark

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Monday, March 26, 2012 12:41 AM
To: [hidden email]
Subject: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi
Can someone show me how to write a simple groovy code that can be used to un-void a specific patient Identifier. I don't want to do this using SQL since we are running the sync module and I want the changes to be propagated to all the children.

Any help will be greatly appreciated.

Thanks

Erick


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list
Erick Mugoma Erick Mugoma
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

Hi Ben,
I've the following Groovy code to create person names to specific clients who don't have names.
Here is the code but it is not creating the patient. Any help. Thanks

 
import org.openmrs.PersonName
p=person.getPerson(1);
  // Create new person name
def pn =new PersonName();
   new_given_name="Given Dummy ";
  new_family_name="Family Dummy";
  new_middle_name="middle Dummy";

u=user.getUser(32565);
pn.setCreator(u);
pn.setDateCreated(new Date());
pn.setGivenName(new_given_name);
pn.setFamilyName(new_family_name);
 
person.savePerson(p);

Thanks

Erick


On Tue, Mar 27, 2012 at 3:49 PM, Erick Mugoma <[hidden email]> wrote:
Hi Ben,
Thanks very much. It is important that I know these facts. This is the way we want to go since we already implementing Sync and most of our database patches and updates.

Thanks

Erick.


On Tue, Mar 27, 2012 at 3:23 PM, Ben Wolfe <[hidden email]> wrote:
No, you can't use sql there either.  The point of using groovy is so that the PersonService, PatientService, etc methods are called.  Sync uses hibernate to know what has changed.  So all changes need to be persisted as hibernate objects and method calls.  When you save a person with person.savePerson(px), "person" is the PersonService and "px" is a Person object that gets saved via hibernate.

Ben


On Tue, Mar 27, 2012 at 1:41 AM, Erick Mugoma <[hidden email]> wrote:
Thanks Burk and Ben,
Here is another quick question for you.
I know it is possible to write direct sql statements in groovy to insert, delete or update specific records. When you write direct sql statements are these marked for sync or they will be ignored?

Thanks

Erick


On Tue, Mar 27, 2012 at 6:00 AM, Burke Mamlin <[hidden email]> wrote:
Does this work?

p = person.getPersion(20384)
person.unvoidPersion(p)

Cheers,

-Burke

On Mon, Mar 26, 2012 at 10:18 PM, Erick Mugoma <[hidden email]> wrote:
Thanks Ben and Mark.
The guideline worked fine especially when using the uuid. However I also wrote the following code to unvoid the person but it failed. Maybe am using the wrong method call?? see the code below:

org.openmrs.Person px = person.getPerson(20384);
px.setVoided(false);
px.setVoidReason("");
px.setVoidedBy(null);
person.savePerson(px);

The above code runs successfully but no changes are persisted to the database.

Thanks

Erick


On Mon, Mar 26, 2012 at 6:10 PM, Ben Wolfe <[hidden email]> wrote:
I was going to suggest that Mark, but then looked at the javadocs.  Looks like there is a PatientService.voidPatientIdentfier(PI, String) method that makes this easier

You could do:
PatientIdentifier pi = patient.getPatientIdentifierByUuid("123wf9329349234");
patient.voidPatientIdentifier(pi, "because it smells like moldy cheese");

(assuming "patient" is still aliased to Context.getPatientService())

See http://api.openmrs.org for latest javadoc.  (or http://resources.openmrs.org/doc-1.8/ for earlier)

Ben


On Mon, Mar 26, 2012 at 10:49 AM, Mark Goodrich <[hidden email]> wrote:

Erick,

 

I haven’t tested this, but if you know the id of the patient identifier, you should be able to do something like this:

 

org.openmrs.PatientIdentifier identifier = patient.getPatientIdentifier(123);

identifier.setVoided(false);

identifier.setVoidReason("");

identifier.setVoidedBy(null);

patient.savePatientIdentifier(identifier);

 

Take care,

Mark

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Monday, March 26, 2012 12:41 AM
To: [hidden email]
Subject: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi
Can someone show me how to write a simple groovy code that can be used to un-void a specific patient Identifier. I don't want to do this using SQL since we are running the sync module and I want the changes to be propagated to all the children.

Any help will be greatly appreciated.

Thanks

Erick


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list



[hidden email] from OpenMRS Implementers' mailing list
Mark Goodrich-2 Mark Goodrich-2
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

 

So these are people who are currently Persons in the system, but not Patients?

 

Looks like you should use the Patient getPatientOrPromotePerson(Integer patientOrPersonId) method instead of getPerson, ie:

 

p = patient.getPatientOrPromotePerson(1);

 

... same code for adding a person name …

 

patient.savePatient(p);

 

 

Though this may fail if you don’t also give the patient a patient identifier… because I believe each patient requires at least one patient identifier.

 

Mark

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Thursday, March 29, 2012 11:03 AM
To: [hidden email]
Subject: Re: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi Ben,
I've the following Groovy code to create person names to specific clients who don't have names.
Here is the code but it is not creating the patient. Any help. Thanks

  import org.openmrs.PersonName
p=person.getPerson(1);
  // Create new person name
def pn =new PersonName();
   new_given_name="Given Dummy ";
  new_family_name="Family Dummy";
  new_middle_name="middle Dummy";

u=user.getUser(32565);
pn.setCreator(u);
pn.setDateCreated(new Date());
pn.setGivenName(new_given_name);
pn.setFamilyName(new_family_name);
 
person.savePerson(p);

Thanks

Erick

On Tue, Mar 27, 2012 at 3:49 PM, Erick Mugoma <[hidden email]> wrote:

Hi Ben,
Thanks very much. It is important that I know these facts. This is the way we want to go since we already implementing Sync and most of our database patches and updates.

Thanks

Erick.

 

On Tue, Mar 27, 2012 at 3:23 PM, Ben Wolfe <[hidden email]> wrote:

No, you can't use sql there either.  The point of using groovy is so that the PersonService, PatientService, etc methods are called.  Sync uses hibernate to know what has changed.  So all changes need to be persisted as hibernate objects and method calls.  When you save a person with person.savePerson(px), "person" is the PersonService and "px" is a Person object that gets saved via hibernate.

Ben

 

On Tue, Mar 27, 2012 at 1:41 AM, Erick Mugoma <[hidden email]> wrote:

Thanks Burk and Ben,
Here is another quick question for you.
I know it is possible to write direct sql statements in groovy to insert, delete or update specific records. When you write direct sql statements are these marked for sync or they will be ignored?

Thanks

Erick

 

On Tue, Mar 27, 2012 at 6:00 AM, Burke Mamlin <[hidden email]> wrote:

Does this work?

 

p = person.getPersion(20384)

person.unvoidPersion(p)

Cheers,

 

-Burke

 

On Mon, Mar 26, 2012 at 10:18 PM, Erick Mugoma <[hidden email]> wrote:

Thanks Ben and Mark.
The guideline worked fine especially when using the uuid. However I also wrote the following code to unvoid the person but it failed. Maybe am using the wrong method call?? see the code below:

org.openmrs.Person px = person.getPerson(20384);
px.setVoided(false);
px.setVoidReason("");
px.setVoidedBy(null);
person.savePerson(px);

The above code runs successfully but no changes are persisted to the database.

Thanks

Erick

 

On Mon, Mar 26, 2012 at 6:10 PM, Ben Wolfe <[hidden email]> wrote:

I was going to suggest that Mark, but then looked at the javadocs.  Looks like there is a PatientService.voidPatientIdentfier(PI, String) method that makes this easier

You could do:
PatientIdentifier pi = patient.getPatientIdentifierByUuid("123wf9329349234");
patient.voidPatientIdentifier(pi, "because it smells like moldy cheese");

(assuming "patient" is still aliased to Context.getPatientService())

See http://api.openmrs.org for latest javadoc.  (or http://resources.openmrs.org/doc-1.8/ for earlier)

Ben

 

On Mon, Mar 26, 2012 at 10:49 AM, Mark Goodrich <[hidden email]> wrote:

Erick,

 

I haven’t tested this, but if you know the id of the patient identifier, you should be able to do something like this:

 

org.openmrs.PatientIdentifier identifier = patient.getPatientIdentifier(123);

identifier.setVoided(false);

identifier.setVoidReason("");

identifier.setVoidedBy(null);

patient.savePatientIdentifier(identifier);

 

Take care,

Mark

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Monday, March 26, 2012 12:41 AM
To: [hidden email]
Subject: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi
Can someone show me how to write a simple groovy code that can be used to un-void a specific patient Identifier. I don't want to do this using SQL since we are running the sync module and I want the changes to be propagated to all the children.

Any help will be greatly appreciated.

Thanks

Erick


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 

 


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list
Ben Wolfe (openmrs) Ben Wolfe (openmrs)
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

You need to put the name of the person onto the object you are saving.

import org.openmrs.PersonName
p=person.getPerson(1);

// Create new person name
def pn =new PersonName();
pn.setGivenName("Given Dummy ");
pn.setFamilyName("Family Dummy");
// or def pn = new PersonName("Given", "middle name", "Family");

// not needed because the savePerson call sets these on the name if they aren't there
//u=user.getUser(32565);
//pn.setCreator(u);
//pn.setDateCreated(new Date());

p.addName(pn);  // this is the important step.
person.savePerson(p);


All this can be shortened to:
import org.openmrs.PersonName
p = person.getPerson(1);
p.addName(new PersonName("Given", "middle name", "Family"));
person.savePerson(p);


Ben


On Thu, Mar 29, 2012 at 11:38 AM, Mark Goodrich <[hidden email]> wrote:

 

So these are people who are currently Persons in the system, but not Patients?

 

Looks like you should use the Patient getPatientOrPromotePerson(Integer patientOrPersonId) method instead of getPerson, ie:

 

p = patient.getPatientOrPromotePerson(1);

 

... same code for adding a person name …

 

patient.savePatient(p);

 

 

Though this may fail if you don’t also give the patient a patient identifier… because I believe each patient requires at least one patient identifier.

 

Mark

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Thursday, March 29, 2012 11:03 AM
To: [hidden email]
Subject: Re: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi Ben,
I've the following Groovy code to create person names to specific clients who don't have names.
Here is the code but it is not creating the patient. Any help. Thanks

  import org.openmrs.PersonName
p=person.getPerson(1);
  // Create new person name
def pn =new PersonName();
   new_given_name="Given Dummy ";
  new_family_name="Family Dummy";
  new_middle_name="middle Dummy";

u=user.getUser(32565);
pn.setCreator(u);
pn.setDateCreated(new Date());
pn.setGivenName(new_given_name);
pn.setFamilyName(new_family_name);
 
person.savePerson(p);

Thanks

Erick

On Tue, Mar 27, 2012 at 3:49 PM, Erick Mugoma <[hidden email]> wrote:

Hi Ben,
Thanks very much. It is important that I know these facts. This is the way we want to go since we already implementing Sync and most of our database patches and updates.

Thanks

Erick.

 

On Tue, Mar 27, 2012 at 3:23 PM, Ben Wolfe <[hidden email]> wrote:

No, you can't use sql there either.  The point of using groovy is so that the PersonService, PatientService, etc methods are called.  Sync uses hibernate to know what has changed.  So all changes need to be persisted as hibernate objects and method calls.  When you save a person with person.savePerson(px), "person" is the PersonService and "px" is a Person object that gets saved via hibernate.

Ben

 

On Tue, Mar 27, 2012 at 1:41 AM, Erick Mugoma <[hidden email]> wrote:

Thanks Burk and Ben,
Here is another quick question for you.
I know it is possible to write direct sql statements in groovy to insert, delete or update specific records. When you write direct sql statements are these marked for sync or they will be ignored?

Thanks

Erick

 

On Tue, Mar 27, 2012 at 6:00 AM, Burke Mamlin <[hidden email]> wrote:

Does this work?

 

p = person.getPersion(20384)

person.unvoidPersion(p)

Cheers,

 

-Burke

 

On Mon, Mar 26, 2012 at 10:18 PM, Erick Mugoma <[hidden email]> wrote:

Thanks Ben and Mark.
The guideline worked fine especially when using the uuid. However I also wrote the following code to unvoid the person but it failed. Maybe am using the wrong method call?? see the code below:

org.openmrs.Person px = person.getPerson(20384);
px.setVoided(false);
px.setVoidReason("");
px.setVoidedBy(null);
person.savePerson(px);

The above code runs successfully but no changes are persisted to the database.

Thanks

Erick

 

On Mon, Mar 26, 2012 at 6:10 PM, Ben Wolfe <[hidden email]> wrote:

I was going to suggest that Mark, but then looked at the javadocs.  Looks like there is a PatientService.voidPatientIdentfier(PI, String) method that makes this easier

You could do:
PatientIdentifier pi = patient.getPatientIdentifierByUuid("123wf9329349234");
patient.voidPatientIdentifier(pi, "because it smells like moldy cheese");

(assuming "patient" is still aliased to Context.getPatientService())

See http://api.openmrs.org for latest javadoc.  (or http://resources.openmrs.org/doc-1.8/ for earlier)

Ben

 

On Mon, Mar 26, 2012 at 10:49 AM, Mark Goodrich <[hidden email]> wrote:

Erick,

 

I haven’t tested this, but if you know the id of the patient identifier, you should be able to do something like this:

 

org.openmrs.PatientIdentifier identifier = patient.getPatientIdentifier(123);

identifier.setVoided(false);

identifier.setVoidReason("");

identifier.setVoidedBy(null);

patient.savePatientIdentifier(identifier);

 

Take care,

Mark

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Monday, March 26, 2012 12:41 AM
To: [hidden email]
Subject: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi
Can someone show me how to write a simple groovy code that can be used to un-void a specific patient Identifier. I don't want to do this using SQL since we are running the sync module and I want the changes to be propagated to all the children.

Any help will be greatly appreciated.

Thanks

Erick


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 

 


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list
Erick Mugoma Erick Mugoma
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

Thanks Ben and Mark,
I finally managed to get this working using the shortened code.

Erick

On Thu, Mar 29, 2012 at 8:09 PM, Ben Wolfe <[hidden email]> wrote:
You need to put the name of the person onto the object you are saving.


import org.openmrs.PersonName
p=person.getPerson(1);

// Create new person name
def pn =new PersonName();
pn.setGivenName("Given Dummy ");
pn.setFamilyName("Family Dummy");
// or def pn = new PersonName("Given", "middle name", "Family");

// not needed because the savePerson call sets these on the name if they aren't there
//u=user.getUser(32565);
//pn.setCreator(u);
//pn.setDateCreated(new Date());

p.addName(pn);  // this is the important step.
person.savePerson(p);


All this can be shortened to:
import org.openmrs.PersonName
p = person.getPerson(1);
p.addName(new PersonName("Given", "middle name", "Family"));
person.savePerson(p);


Ben



On Thu, Mar 29, 2012 at 11:38 AM, Mark Goodrich <[hidden email]> wrote:

 

So these are people who are currently Persons in the system, but not Patients?

 

Looks like you should use the Patient getPatientOrPromotePerson(Integer patientOrPersonId) method instead of getPerson, ie:

 

p = patient.getPatientOrPromotePerson(1);

 

... same code for adding a person name …

 

patient.savePatient(p);

 

 

Though this may fail if you don’t also give the patient a patient identifier… because I believe each patient requires at least one patient identifier.

 

Mark

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Thursday, March 29, 2012 11:03 AM
To: [hidden email]
Subject: Re: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi Ben,
I've the following Groovy code to create person names to specific clients who don't have names.
Here is the code but it is not creating the patient. Any help. Thanks

  import org.openmrs.PersonName
p=person.getPerson(1);
  // Create new person name
def pn =new PersonName();
   new_given_name="Given Dummy ";
  new_family_name="Family Dummy";
  new_middle_name="middle Dummy";

u=user.getUser(32565);
pn.setCreator(u);
pn.setDateCreated(new Date());
pn.setGivenName(new_given_name);
pn.setFamilyName(new_family_name);
 
person.savePerson(p);

Thanks

Erick

On Tue, Mar 27, 2012 at 3:49 PM, Erick Mugoma <[hidden email]> wrote:

Hi Ben,
Thanks very much. It is important that I know these facts. This is the way we want to go since we already implementing Sync and most of our database patches and updates.

Thanks

Erick.

 

On Tue, Mar 27, 2012 at 3:23 PM, Ben Wolfe <[hidden email]> wrote:

No, you can't use sql there either.  The point of using groovy is so that the PersonService, PatientService, etc methods are called.  Sync uses hibernate to know what has changed.  So all changes need to be persisted as hibernate objects and method calls.  When you save a person with person.savePerson(px), "person" is the PersonService and "px" is a Person object that gets saved via hibernate.

Ben

 

On Tue, Mar 27, 2012 at 1:41 AM, Erick Mugoma <[hidden email]> wrote:

Thanks Burk and Ben,
Here is another quick question for you.
I know it is possible to write direct sql statements in groovy to insert, delete or update specific records. When you write direct sql statements are these marked for sync or they will be ignored?

Thanks

Erick

 

On Tue, Mar 27, 2012 at 6:00 AM, Burke Mamlin <[hidden email]> wrote:

Does this work?

 

p = person.getPersion(20384)

person.unvoidPersion(p)

Cheers,

 

-Burke

 

On Mon, Mar 26, 2012 at 10:18 PM, Erick Mugoma <[hidden email]> wrote:

Thanks Ben and Mark.
The guideline worked fine especially when using the uuid. However I also wrote the following code to unvoid the person but it failed. Maybe am using the wrong method call?? see the code below:

org.openmrs.Person px = person.getPerson(20384);
px.setVoided(false);
px.setVoidReason("");
px.setVoidedBy(null);
person.savePerson(px);

The above code runs successfully but no changes are persisted to the database.

Thanks

Erick

 

On Mon, Mar 26, 2012 at 6:10 PM, Ben Wolfe <[hidden email]> wrote:

I was going to suggest that Mark, but then looked at the javadocs.  Looks like there is a PatientService.voidPatientIdentfier(PI, String) method that makes this easier

You could do:
PatientIdentifier pi = patient.getPatientIdentifierByUuid("123wf9329349234");
patient.voidPatientIdentifier(pi, "because it smells like moldy cheese");

(assuming "patient" is still aliased to Context.getPatientService())

See http://api.openmrs.org for latest javadoc.  (or http://resources.openmrs.org/doc-1.8/ for earlier)

Ben

 

On Mon, Mar 26, 2012 at 10:49 AM, Mark Goodrich <[hidden email]> wrote:

Erick,

 

I haven’t tested this, but if you know the id of the patient identifier, you should be able to do something like this:

 

org.openmrs.PatientIdentifier identifier = patient.getPatientIdentifier(123);

identifier.setVoided(false);

identifier.setVoidReason("");

identifier.setVoidedBy(null);

patient.savePatientIdentifier(identifier);

 

Take care,

Mark

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Monday, March 26, 2012 12:41 AM
To: [hidden email]
Subject: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi
Can someone show me how to write a simple groovy code that can be used to un-void a specific patient Identifier. I don't want to do this using SQL since we are running the sync module and I want the changes to be propagated to all the children.

Any help will be greatly appreciated.

Thanks

Erick


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 

 


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list
Ellen Ball Ellen Ball
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

In reply to this post by Erick Mugoma
Many of the groovy scripts that I've written are shown on this wiki page:

https://wiki.openmrs.org/display/docs/Groovy+Module

Hope others will add your own time-saving scripts.

Ellen Ball
Partners In Health

_________________________________________

To unsubscribe from OpenMRS Implementers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-implement-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-implement-l]
Yeung, Ada K. Yeung, Ada K.
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

That's awesome, Ellen, for sharing your groovy scripts on wiki.  I am sure lots of implementers would find them very helpful.  :)

-ada

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Ellen Ball
Sent: Friday, March 30, 2012 9:26 AM
To: [hidden email]
Subject: Re: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

Many of the groovy scripts that I've written are shown on this wiki page:

https://wiki.openmrs.org/display/docs/Groovy+Module

Hope others will add your own time-saving scripts.

Ellen Ball
Partners In Health

_________________________________________

To unsubscribe from OpenMRS Implementers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-implement-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-implement-l]

_________________________________________

To unsubscribe from OpenMRS Implementers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-implement-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-implement-l]
Mark Goodrich-2 Mark Goodrich-2
Reply | Threaded
Open this post in threaded view
|

Re: Groovy code to Un-void Patient Identifier

In reply to this post by Erick Mugoma

No problem… I misunderstood what your problem was, so my solution wouldn’t have worked…

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Friday, March 30, 2012 2:25 AM
To: [hidden email]
Subject: Re: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Thanks Ben and Mark,
I finally managed to get this working using the shortened code.

Erick

On Thu, Mar 29, 2012 at 8:09 PM, Ben Wolfe <[hidden email]> wrote:

You need to put the name of the person onto the object you are saving.



import org.openmrs.PersonName
p=person.getPerson(1);

// Create new person name
def pn =new PersonName();

pn.setGivenName("Given Dummy ");
pn.setFamilyName("Family Dummy");
// or def pn = new PersonName("Given", "middle name", "Family");

// not needed because the savePerson call sets these on the name if they aren't there
//u=user.getUser(32565);
//pn.setCreator(u);
//pn.setDateCreated(new Date());

p.addName(pn);  // this is the important step.
person.savePerson(p);


All this can be shortened to:
import org.openmrs.PersonName
p = person.getPerson(1);
p.addName(new PersonName("Given", "middle name", "Family"));
person.savePerson(p);


Ben



On Thu, Mar 29, 2012 at 11:38 AM, Mark Goodrich <[hidden email]> wrote:

 

So these are people who are currently Persons in the system, but not Patients?

 

Looks like you should use the Patient getPatientOrPromotePerson(Integer patientOrPersonId) method instead of getPerson, ie:

 

p = patient.getPatientOrPromotePerson(1);

 

... same code for adding a person name …

 

patient.savePatient(p);

 

 

Though this may fail if you don’t also give the patient a patient identifier… because I believe each patient requires at least one patient identifier.

 

Mark

 

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Thursday, March 29, 2012 11:03 AM
To: [hidden email]
Subject: Re: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi Ben,
I've the following Groovy code to create person names to specific clients who don't have names.
Here is the code but it is not creating the patient. Any help. Thanks

  import org.openmrs.PersonName
p=person.getPerson(1);
  // Create new person name
def pn =new PersonName();
   new_given_name="Given Dummy ";
  new_family_name="Family Dummy";
  new_middle_name="middle Dummy";

u=user.getUser(32565);
pn.setCreator(u);
pn.setDateCreated(new Date());
pn.setGivenName(new_given_name);
pn.setFamilyName(new_family_name);
 
person.savePerson(p);

Thanks

Erick

On Tue, Mar 27, 2012 at 3:49 PM, Erick Mugoma <[hidden email]> wrote:

Hi Ben,
Thanks very much. It is important that I know these facts. This is the way we want to go since we already implementing Sync and most of our database patches and updates.

Thanks

Erick.

 

On Tue, Mar 27, 2012 at 3:23 PM, Ben Wolfe <[hidden email]> wrote:

No, you can't use sql there either.  The point of using groovy is so that the PersonService, PatientService, etc methods are called.  Sync uses hibernate to know what has changed.  So all changes need to be persisted as hibernate objects and method calls.  When you save a person with person.savePerson(px), "person" is the PersonService and "px" is a Person object that gets saved via hibernate.

Ben

 

On Tue, Mar 27, 2012 at 1:41 AM, Erick Mugoma <[hidden email]> wrote:

Thanks Burk and Ben,
Here is another quick question for you.
I know it is possible to write direct sql statements in groovy to insert, delete or update specific records. When you write direct sql statements are these marked for sync or they will be ignored?

Thanks

Erick

 

On Tue, Mar 27, 2012 at 6:00 AM, Burke Mamlin <[hidden email]> wrote:

Does this work?

 

p = person.getPersion(20384)

person.unvoidPersion(p)

Cheers,

 

-Burke

 

On Mon, Mar 26, 2012 at 10:18 PM, Erick Mugoma <[hidden email]> wrote:

Thanks Ben and Mark.
The guideline worked fine especially when using the uuid. However I also wrote the following code to unvoid the person but it failed. Maybe am using the wrong method call?? see the code below:

org.openmrs.Person px = person.getPerson(20384);
px.setVoided(false);
px.setVoidReason("");
px.setVoidedBy(null);
person.savePerson(px);

The above code runs successfully but no changes are persisted to the database.

Thanks

Erick

 

On Mon, Mar 26, 2012 at 6:10 PM, Ben Wolfe <[hidden email]> wrote:

I was going to suggest that Mark, but then looked at the javadocs.  Looks like there is a PatientService.voidPatientIdentfier(PI, String) method that makes this easier

You could do:
PatientIdentifier pi = patient.getPatientIdentifierByUuid("123wf9329349234");
patient.voidPatientIdentifier(pi, "because it smells like moldy cheese");

(assuming "patient" is still aliased to Context.getPatientService())

See http://api.openmrs.org for latest javadoc.  (or http://resources.openmrs.org/doc-1.8/ for earlier)

Ben

 

On Mon, Mar 26, 2012 at 10:49 AM, Mark Goodrich <[hidden email]> wrote:

Erick,

 

I haven’t tested this, but if you know the id of the patient identifier, you should be able to do something like this:

 

org.openmrs.PatientIdentifier identifier = patient.getPatientIdentifier(123);

identifier.setVoided(false);

identifier.setVoidReason("");

identifier.setVoidedBy(null);

patient.savePatientIdentifier(identifier);

 

Take care,

Mark

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Erick Mugoma
Sent: Monday, March 26, 2012 12:41 AM
To: [hidden email]
Subject: [OPENMRS-IMPLEMENTERS] Groovy code to Un-void Patient Identifier

 

Hi
Can someone show me how to write a simple groovy code that can be used to un-void a specific patient Identifier. I don't want to do this using SQL since we are running the sync module and I want the changes to be propagated to all the children.

Any help will be greatly appreciated.

Thanks

Erick


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 

 


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list

 


[hidden email] from OpenMRS Implementers' mailing list


[hidden email] from OpenMRS Implementers' mailing list