|
16 | 16 | import static org.hamcrest.Matchers.hasProperty;
|
17 | 17 | import static org.hamcrest.Matchers.not;
|
18 | 18 | import static org.hamcrest.Matchers.notNullValue;
|
| 19 | +import static org.mockito.Mockito.mock; |
| 20 | +import static org.mockito.Mockito.when; |
| 21 | + |
| 22 | +import java.util.Arrays; |
| 23 | +import java.util.Collections; |
19 | 24 |
|
20 | 25 | import org.hl7.fhir.r4.model.Extension;
|
21 | 26 | import org.hl7.fhir.r4.model.HumanName;
|
22 | 27 | import org.hl7.fhir.r4.model.StringType;
|
23 | 28 | import org.junit.Before;
|
24 | 29 | import org.junit.Test;
|
25 | 30 | import org.openmrs.PersonName;
|
| 31 | +import org.openmrs.api.AdministrationService; |
| 32 | +import org.openmrs.api.context.ServiceContext; |
| 33 | +import org.openmrs.layout.name.NameSupport; |
| 34 | +import org.openmrs.layout.name.NameTemplate; |
26 | 35 | import org.openmrs.module.fhir2.FhirConstants;
|
| 36 | +import org.openmrs.serialization.SerializationException; |
| 37 | +import org.openmrs.serialization.SimpleXStreamSerializer; |
27 | 38 |
|
28 | 39 | public class PersonNameTranslatorImplTest {
|
29 | 40 |
|
@@ -152,6 +163,44 @@ public void shouldOnlyCreateOneExtensionForExtensibleAttributes() {
|
152 | 163 | assertThat(extension.getExtension().size(), greaterThan(1));
|
153 | 164 | }
|
154 | 165 |
|
| 166 | + @Test |
| 167 | + public void shouldUseDefaultNameTemplateToSetNameText() throws SerializationException { |
| 168 | + AdministrationService administrationService = mock(AdministrationService.class); |
| 169 | + ServiceContext.getInstance().setAdministrationService(administrationService); |
| 170 | + when(administrationService.getGlobalProperty("layout.name.format")).thenReturn("test"); |
| 171 | + |
| 172 | + NameSupport nameSupportInstance = new NameSupport(); |
| 173 | + NameTemplate customNameTemplate = new SimpleXStreamSerializer() |
| 174 | + .deserialize("<org.openmrs.layout.name.NameTemplate>\n" + " <codeName>test</codeName>\n" |
| 175 | + + " <displayName>Test Name Format</displayName>\n" + " <nameMappings class=\"properties\">\n" |
| 176 | + + " <property name=\"givenName\" value=\"PersonName.givenName\"/>\n" |
| 177 | + + " <property name=\"middleName\" value=\"PersonName.middleName\"/>\n" |
| 178 | + + " <property name=\"familyName\" value=\"PersonName.familyName\"/>\n" + " </nameMappings>\n" |
| 179 | + + " <sizeMappings class=\"properties\">\n" + " <property name=\"givenName\" value=\"25\"/>\n" |
| 180 | + + " <property name=\"middleName\" value=\"25\"/>\n" |
| 181 | + + " <property name=\"familyName\" value=\"25\"/>\n" + " </sizeMappings>\n" |
| 182 | + + " <lineByLineFormat>\n" + " <string>givenName</string>\n" + " <string>familyName</string>\n" |
| 183 | + + " <string>middleName</string>\n" + " </lineByLineFormat>\n" + " <requiredElements>\n" |
| 184 | + + " <string>givenName</string>\n" + " <string>familyName</string>\n" |
| 185 | + + " </requiredElements>\n" + "</org.openmrs.layout.name.NameTemplate>", |
| 186 | + NameTemplate.class); |
| 187 | + nameSupportInstance.setLayoutTemplates(Collections.singletonList(customNameTemplate)); |
| 188 | + nameSupportInstance.setSpecialTokens(Arrays.asList("prefix", "givenName", "middleName", "familyNamePrefix", |
| 189 | + "familyNameSuffix", "familyName2", "familyName", "degree")); |
| 190 | + |
| 191 | + PersonName name = new PersonName(); |
| 192 | + name.setGivenName(PERSON_GIVEN_NAME); |
| 193 | + name.setMiddleName(PERSON_MIDDLE_NAME); |
| 194 | + name.setFamilyName(PERSON_FAMILY_NAME); |
| 195 | + |
| 196 | + HumanName fhirName = personNameTranslator.toFhirResource(name); |
| 197 | + |
| 198 | + assertThat(fhirName, notNullValue()); |
| 199 | + assertThat(fhirName.getTextElement(), notNullValue()); |
| 200 | + assertThat(fhirName.getTextElement().getValue(), |
| 201 | + equalTo(PERSON_GIVEN_NAME + " " + PERSON_FAMILY_NAME + " " + PERSON_MIDDLE_NAME)); |
| 202 | + } |
| 203 | + |
155 | 204 | @Test
|
156 | 205 | public void shouldConvertHumanNameToPersonName() {
|
157 | 206 | HumanName name = new HumanName();
|
|
0 commit comments