-
Notifications
You must be signed in to change notification settings - Fork 521
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RESTWS-939: DiagnosisResource should support formFieldPath property
- Loading branch information
1 parent
6bd939a
commit 193af52
Showing
7 changed files
with
435 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>webservices.rest</artifactId> | ||
<groupId>org.openmrs.module</groupId> | ||
<version>2.44.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>webservices.rest-omod-2.5</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Rest Web Services 2.5 OMOD</name> | ||
<description>OpenMRS module project for Rest Web Services</description> | ||
|
||
<properties> | ||
<openmrs.version.2.5.0>2.5.0</openmrs.version.2.5.0> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-common</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-common</artifactId> | ||
<version>${project.parent.version}</version> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-1.8</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-1.8</artifactId> | ||
<version>${project.parent.version}</version> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-1.9</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-1.9</artifactId> | ||
<version>${project.parent.version}</version> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-1.10</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-1.10</artifactId> | ||
<version>${project.parent.version}</version> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-1.11</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-1.11</artifactId> | ||
<version>${project.parent.version}</version> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-2.0</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-2.0</artifactId> | ||
<version>${project.parent.version}</version> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-2.2</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-2.2</artifactId> | ||
<version>${project.parent.version}</version> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-2.3</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-2.3</artifactId> | ||
<version>${project.parent.version}</version> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-2.4</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>${project.parent.groupId}</groupId> | ||
<artifactId>${project.parent.artifactId}-omod-2.4</artifactId> | ||
<version>${project.parent.version}</version> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.openmrs.api</groupId> | ||
<artifactId>openmrs-api</artifactId> | ||
<version>${openmrs.version.2.5.0}</version><!--$NO-MVN-MAN-VER$--> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.openmrs.api</groupId> | ||
<artifactId>openmrs-api</artifactId> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
<version>${openmrs.version.2.5.0}</version><!--$NO-MVN-MAN-VER$--> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.openmrs.web</groupId> | ||
<artifactId>openmrs-web</artifactId> | ||
<version>${openmrs.version.2.5.0}</version> <!-- $NO-MVN-MAN-VER$ --> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.openmrs.web</groupId> | ||
<artifactId>openmrs-web</artifactId> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
<version>${openmrs.version.2.5.0}</version> <!-- $NO-MVN-MAN-VER$--> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.openmrs.test</groupId> | ||
<artifactId>openmrs-test</artifactId> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
<version>${openmrs.version.2.5.0}</version> <!-- $NO-MVN-MAN-VER$ --> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>${javaxVersion}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.tomcat</groupId> | ||
<artifactId>jasper</artifactId> | ||
<version>${apacheTomcatVersion}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jacoco</groupId> | ||
<artifactId>jacoco-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.mycila</groupId> | ||
<artifactId>license-maven-plugin</artifactId> | ||
<configuration> | ||
<header>${project.parent.basedir}/license-header.txt</header> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
88 changes: 88 additions & 0 deletions
88
...rg/openmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_5; | ||
|
||
import io.swagger.models.Model; | ||
import io.swagger.models.ModelImpl; | ||
import io.swagger.models.properties.BooleanProperty; | ||
import org.openmrs.Diagnosis; | ||
import org.openmrs.module.webservices.rest.web.RestConstants; | ||
import org.openmrs.module.webservices.rest.web.annotation.Resource; | ||
import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation; | ||
import org.openmrs.module.webservices.rest.web.representation.FullRepresentation; | ||
import org.openmrs.module.webservices.rest.web.representation.Representation; | ||
import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource; | ||
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource; | ||
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; | ||
import org.openmrs.module.webservices.rest.web.response.ResourceDoesNotSupportOperationException; | ||
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_2.DiagnosisResource2_2; | ||
|
||
/** | ||
* {@link Resource} for Diagnosis, supporting standard CRUD operations | ||
*/ | ||
@Resource(name = RestConstants.VERSION_1 + "/patientdiagnoses", order = 1, supportedClass = Diagnosis.class, supportedOpenmrsVersions = { | ||
"2.5.* - 9.*" }) | ||
public class DiagnosisResource2_5 extends DiagnosisResource2_2 { | ||
|
||
/** | ||
* @see DelegatingCrudResource#getRepresentationDescription(Representation) | ||
*/ | ||
@Override | ||
public DelegatingResourceDescription getRepresentationDescription(Representation rep) { | ||
DelegatingResourceDescription description = super.getRepresentationDescription(rep); | ||
if (description != null) { | ||
description.addProperty("formNamespaceAndPath"); | ||
} | ||
return description; | ||
} | ||
|
||
/** | ||
* @see BaseDelegatingResource#getCreatableProperties() | ||
*/ | ||
@Override | ||
public DelegatingResourceDescription getCreatableProperties() { | ||
DelegatingResourceDescription description = super.getCreatableProperties(); | ||
description.addProperty("formNamespaceAndPath"); | ||
return description; | ||
} | ||
|
||
/** | ||
* @see BaseDelegatingResource#getUpdatableProperties() | ||
*/ | ||
@Override | ||
public DelegatingResourceDescription getUpdatableProperties() throws ResourceDoesNotSupportOperationException { | ||
DelegatingResourceDescription description = super.getUpdatableProperties(); | ||
description.addProperty("formNamespaceAndPath"); | ||
return description; | ||
} | ||
|
||
@Override | ||
public Model getGETModel(Representation rep) { | ||
return addNewProperties(super.getGETModel(rep), rep); | ||
} | ||
|
||
@Override | ||
public Model getCREATEModel(Representation rep) { | ||
return addNewProperties(super.getCREATEModel(rep), rep); | ||
} | ||
|
||
@Override | ||
public Model getUPDATEModel(Representation rep) { | ||
return addNewProperties(super.getUPDATEModel(rep), rep); | ||
} | ||
|
||
private Model addNewProperties(Model model, Representation rep) { | ||
if (rep instanceof DefaultRepresentation || rep instanceof FullRepresentation) { | ||
((ModelImpl) model).property("formNamespaceAndPath", new BooleanProperty()._default(false)); | ||
} | ||
return model; | ||
} | ||
|
||
} |
93 changes: 93 additions & 0 deletions
93
...penmrs/module/webservices/rest/web/v1_0/resource/openmrs2_5/DiagnosisResource2_5Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs2_5; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openmrs.Diagnosis; | ||
import org.openmrs.api.DiagnosisService; | ||
import org.openmrs.api.EncounterService; | ||
import org.openmrs.api.PatientService; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResourceTest; | ||
import org.openmrs.module.webservices.rest.web.v1_0.RestTestConstants2_2; | ||
|
||
/** | ||
* Tests functionality of {@link DiagnosisResource2_5}. | ||
*/ | ||
public class DiagnosisResource2_5Test extends BaseDelegatingResourceTest<DiagnosisResource2_5, Diagnosis> { | ||
|
||
|
||
private DiagnosisService diagnosisService; | ||
|
||
private EncounterService encounterService; | ||
|
||
private PatientService patientService; | ||
|
||
|
||
@Before | ||
public void before() { | ||
this.diagnosisService = Context.getDiagnosisService(); | ||
this.encounterService = Context.getEncounterService(); | ||
this.patientService = Context.getPatientService(); | ||
executeDataSet("DiagnosisResourceTestDataset.xml"); | ||
} | ||
|
||
@Override | ||
public Diagnosis newObject() { | ||
return diagnosisService.getDiagnosisByUuid(getUuidProperty()); | ||
} | ||
|
||
@Override | ||
public String getUuidProperty() { | ||
return RestTestConstants2_2.DIAGNOSIS_UUID; | ||
} | ||
|
||
@Override | ||
public void validateDefaultRepresentation() throws Exception { | ||
super.validateDefaultRepresentation(); | ||
assertPropEquals("formNamespaceAndPath", getObject().getFormNamespaceAndPath()); | ||
} | ||
|
||
@Override | ||
public void validateFullRepresentation() throws Exception { | ||
super.validateFullRepresentation(); | ||
assertPropEquals("formNamespaceAndPath", getObject().getFormNamespaceAndPath()); | ||
} | ||
|
||
@Override | ||
public String getDisplayProperty() { | ||
return ""; | ||
} | ||
|
||
@Test | ||
public void testFormFieldNamespace() { | ||
String uuid = "a303bbfb-w5w4-25d1-9f11-4f33f99d456r"; | ||
Diagnosis diagnosis = new Diagnosis(); | ||
diagnosis.setUuid(uuid); | ||
diagnosis.setEncounter(encounterService.getEncounter(1)); | ||
diagnosis.setPatient(patientService.getPatient(1)); | ||
diagnosis.setRank(2); | ||
|
||
final String NAMESPACE = "namespace"; | ||
final String FORMFIELD_PATH = "formFieldPath"; | ||
diagnosis.setFormField(NAMESPACE, FORMFIELD_PATH); | ||
diagnosisService.save(diagnosis); | ||
|
||
Diagnosis savedDiagnosis = diagnosisService.getDiagnosisByUuid(uuid); | ||
String formFieldNameSpace = savedDiagnosis.getFormFieldNamespace(); | ||
String formFieldPath = savedDiagnosis.getFormFieldPath(); | ||
|
||
Assert.assertEquals("namespace", formFieldNameSpace); | ||
Assert.assertEquals("formFieldPath", formFieldPath); | ||
Assert.assertNotNull(savedDiagnosis.getFormNamespaceAndPath()); | ||
} | ||
} |
Oops, something went wrong.