New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TRUNK-3621 #330
TRUNK-3621 #330
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* The contents of this file are subject to the OpenMRS Public License | ||
* Version 1.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://license.openmrs.org | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" | ||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing rights and limitations | ||
* under the License. | ||
* | ||
* Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
*/ | ||
package org.openmrs.customdatatype.datatype; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
import org.openmrs.Concept; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.customdatatype.SerializingCustomDatatype; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* Datatype for Concept, represented by org.openmrs.Concept. | ||
* | ||
* @since 1.10 | ||
*/ | ||
@Component | ||
public class ConceptDatatype extends SerializingCustomDatatype<Concept> { | ||
|
||
/** | ||
* @see org.openmrs.customdatatype.SerializingCustomDatatype#serialize(java.lang.Object) | ||
*/ | ||
@Override | ||
public String serialize(Concept typedValue) { | ||
if (typedValue == null) | ||
return null; | ||
return typedValue.getUuid(); | ||
} | ||
|
||
/** | ||
* @see org.openmrs.customdatatype.SerializingCustomDatatype#deserialize(java.lang.String) | ||
*/ | ||
@Override | ||
public Concept deserialize(String serializedValue) { | ||
if (StringUtils.isEmpty(serializedValue)) | ||
return null; | ||
return Context.getConceptService().getConceptByUuid(serializedValue); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* The contents of this file are subject to the OpenMRS Public License | ||
* Version 1.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://license.openmrs.org | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" | ||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing rights and limitations | ||
* under the License. | ||
* | ||
* Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
*/ | ||
package org.openmrs.web.attribute.handler; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
import org.openmrs.Concept; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.customdatatype.CustomDatatype; | ||
import org.openmrs.customdatatype.InvalidCustomValueException; | ||
import org.openmrs.customdatatype.datatype.ConceptDatatype; | ||
import org.openmrs.messagesource.MessageSourceService; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* Handler for the concept custom datatype | ||
*/ | ||
@Component | ||
public class ConceptFieldGenDatatypeHandler implements FieldGenDatatypeHandler<ConceptDatatype, Concept> { | ||
|
||
/** | ||
* @see org.openmrs.customdatatype.CustomDatatypeHandler#setHandlerConfiguration(java.lang.String) | ||
*/ | ||
@Override | ||
public void setHandlerConfiguration(String arg0) { | ||
// not used | ||
} | ||
|
||
/** | ||
* @see org.openmrs.web.attribute.handler.FieldGenDatatypeHandler#getWidgetName() | ||
*/ | ||
@Override | ||
public String getWidgetName() { | ||
return "concept"; | ||
} | ||
|
||
/** | ||
* @see org.openmrs.web.attribute.handler.FieldGenDatatypeHandler#getValue(org.openmrs.customdatatype.CustomDatatype, | ||
* javax.servlet.http.HttpServletRequest, java.lang.String) | ||
*/ | ||
@Override | ||
public Concept getValue(org.openmrs.customdatatype.datatype.ConceptDatatype datatype, HttpServletRequest request, | ||
String formFieldName) throws InvalidCustomValueException { | ||
String result = request.getParameter(formFieldName); | ||
if (StringUtils.isBlank(result)) | ||
return null; | ||
try { | ||
return Context.getConceptService().getConceptByUuid(result); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do other datatype handlers use UUIDs rather than internal primary keys? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They actually do not use UUIDs, at this point!!! |
||
} | ||
catch (Exception e) { | ||
throw new InvalidCustomValueException("Invalid concept: " + result); | ||
} | ||
} | ||
|
||
/** | ||
* @see org.openmrs.web.attribute.handler.HtmlDisplayableDatatypeHandler#toHtmlSummary(org.openmrs.customdatatype.CustomDatatype, | ||
* java.lang.String) | ||
*/ | ||
@Override | ||
public CustomDatatype.Summary toHtmlSummary(CustomDatatype<Concept> datatype, String valueReference) { | ||
return new CustomDatatype.Summary(valueReference, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should get the actual concept value, and display its name here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @djazayeri , thanks a lot for reviewing this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method, toHtmlSummary, is supposed to return a value to be displayed to the user when the system has to render this datatype in a summary view. So, the value you return is going to be displayed to the user. |
||
} | ||
|
||
/** | ||
* @see org.openmrs.web.attribute.handler.HtmlDisplayableDatatypeHandler#toHtml(org.openmrs.customdatatype.CustomDatatype, | ||
* java.lang.String) | ||
*/ | ||
@Override | ||
public String toHtml(CustomDatatype<Concept> datatype, String valueReference) { | ||
return valueReference; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This definitely needs to return the concept's preferred name in the current locale. (Not just the uuid, like you're returning now.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I intend to do this by adding these two code lines at to cater for this comment; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as for the above comment: you need to get the concept from the database based on the datatype's value (which is a concept uuid). |
||
} | ||
|
||
@Override | ||
public Map<String, Object> getWidgetConfiguration() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method look right -- are these really the settings that you need to pass to the concept fieldgen? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have modified that whole method to some thing like; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not correct. This widget configuration consists of the parameters that will be passed to the "concept.jsp" fieldgen widget. You have just copied the values for the "boolean" fieldgen widget, and they aren't correct here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Darius, is correct, replace trueLabel and falseLabel with just one property named label, and this will be the label to display alongside the input element in the ui. |
||
MessageSourceService mss = Context.getMessageSourceService(); | ||
Map<String, Object> ret = new HashMap<String, Object>(); | ||
ret.put("isNullable", "false"); | ||
ret.put("trueLabel", mss.getMessage("general.true")); | ||
ret.put("falseLabel", mss.getMessage("general.false")); | ||
return ret; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need a test for this class. See org.openmrs.customdatatype.datatype.DateDatatypeTest for an example.