Contact Updates
Submitted by Ben_Charlton on Tue, 12/05/2015 - 16:40
I am working through the issues with activating Country in our contacts
the basic archetype change is
diff --git a/openvpms-archetypes/src/archetypes/org/openvpms/archetype/contact/contact.location.adl b/openvpms-archetypes/src/archetypes/org/openvpms/archetype/contact/contact.location.adl
index 2959e1e..f66c82c 100644
--- a/openvpms-archetypes/src/archetypes/org/openvpms/archetype/contact/contact.location.adl
+++ b/openvpms-archetypes/src/archetypes/org/openvpms/archetype/contact/contact.location.adl
@@ -43,12 +43,14 @@
<node name="state" path="/details/state"
type="java.lang.String" minCardinality="0">
<assertion name="lookup">
- <property name="type" value="lookup"/>
- <property name="source" value="lookup.state"/>
+ <property name="type" value="targetLookup"/>
+ <property name="relationship"
+ value="lookupRelationship.countryState"/>
+ <property name="value" value="/details/country"/>
<errorMessage>An error message</errorMessage>
</assertion>
</node>
- <!-- node name="country" path="/details/country"
+ <node name="country" path="/details/country"
type="java.lang.String" defaultValue="'AU'"
minCardinality="0">
<assertion name="lookup">
@@ -56,7 +58,7 @@
<property name="source" value="lookup.country" />
<errorMessage>An error message</errorMessage>
</assertion>
- </node-->
+ </node>
<node name="preferred" path="/details/preferred"
type="java.lang.Boolean" defaultValue="true()"/>
<node name="startDate" path="/activeStartTime"
@@ -76,4 +78,4 @@
</assertion>
</node>
</archetype>
-</archetypes>
\ No newline at end of file
+</archetypes>
A number of code adjustments to the tests are required to ensure that tests all pass.
eg.
@@ -254,8 +252,8 @@ public class TestHelper {
* @param postCode the post code
* @return a new location contact
*/
- public static Contact createLocationContact(String address, String suburbCode, String stateCode, String postCode) {
- return createLocationContact(address, suburbCode, null, stateCode, null, postCode);
+ public static Contact createLocationContact(String address, String suburbCode, String stateCode, String countryCode, String postCode) {
+ return createLocationContact(address, suburbCode, null, stateCode, null, countryCode, null, postCode);
}
/**
diff --git a/openvpms-esci-adapter/src/test/java/org/openvpms/esci/adapter/map/order/OrderMapperTestCase.java b/openvpms-esci-adapter/src/test/java/org/openvpms/esci/adapter/map/order/OrderMapperTestCase.java
index 1e24f25..abdf8d4 100644
--- a/openvpms-esci-adapter/src/test/java/org/openvpms/esci/adapter/map/order/OrderMapperTestCase.java
+++ b/openvpms-esci-adapter/src/test/java/org/openvpms/esci/adapter/map/order/OrderMapperTestCase.java
@@ -294,7 +294,7 @@ public class OrderMapperTestCase extends AbstractESCITest {
functions = new ArchetypeServiceFunctions(getArchetypeService(), getLookupService());
Party practice = getPractice();
practice.getContacts().clear();
- practiceContact = TestHelper.createLocationContact("1 Broadwater Avenue", "CAPE_WOOLAMAI", "VIC", "3925");
+ practiceContact = TestHelper.createLocationContact("1 Broadwater Avenue", "CAPE_WOOLAMAI", "VIC","AU", "3925");
practice.addContact(practiceContact);
phoneContact = createContact(ContactArchetypes.PHONE, "telephoneNumber", "59527054");
@@ -308,7 +308,7 @@ public class OrderMapperTestCase extends AbstractESCITest {
save(practice);
- supplierContact = TestHelper.createLocationContact("2 Peko Rd", "TENNANT_CREEK", "NT", "0862");
+ supplierContact = TestHelper.createLocationContact("2 Peko Rd", "TENNANT_CREEK", "NT","AU", "0862");
Party supplier = getSupplier();
supplier.addContact(supplierContact);
Note these changes basically ensure that locations that are created during testing meet the criteria for the contact archetype.
I assume to make this work I need to update the database contact.locations to add the node retrospectively.
Has anyone got any ideas how to create a mysql script that can detect a machine location? Best I can think of is maybe we need to look at msi packaging?
Re: Contact Updates
I think the easiest thing to do would be to create a lookupRelationship.countryState relationship for each lookup.state, linked to the default lookup.country.
If there the default country is incorrect, then you can replace it with the correct one post migration.
If there is no lookup.country, then bad things happen if you edit a customer - the suburb might be silently removed. There would therefore need to be a manual migration step to set up a default lookup.country, prior to migration taking place. e.g. "before migrating from OpenVPMS 1.8 to OpenVPMS 1.9, go to Administration - Lookups and ensure there is a default Country".
That said, I'm not sure the country-state relationship works too well.
For the most part, practices are dealing with customers and suppliers in the one country. For location contacts in another country, you need to have set up the country, state and a suburb lookups beforehand.
It may be better to either:
use:
This would constrain the state value to the default value of the country node, if there is no specified value.