Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions api/src/main/java/org/openmrs/ConceptProposal.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
*/
package org.openmrs;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.util.Date;

import org.hibernate.envers.Audited;
import org.openmrs.util.OpenmrsConstants;

Expand All @@ -19,39 +26,70 @@
* an observation, a user can "propose" a new concept if one isn't found already. The proposal is a
* simple text entry that will be reviewed later. When a proposal is (edited and) accepted, the
* encounter that prompted this proposal is updated with a new observation pointing at the new (or
* edited) concept.
*/

@Entity
@Table(name = "concept_proposal")
@Audited
public class ConceptProposal extends BaseOpenmrsObject {

public static final long serialVersionUID = 57344L;

// Fields

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "concept_proposal_id")
private Integer conceptProposalId;

@ManyToOne
@JoinColumn(name = "encounter_id")
private Encounter encounter;

@ManyToOne
@JoinColumn(name = "obs_concept_id")
private Concept obsConcept;

@ManyToOne
@JoinColumn(name = "obs_id")
private Obs obs;

@ManyToOne
@JoinColumn(name = "mapped_concept_id")
private Concept mappedConcept;


/**
* @deprecated Only kept for legacy dataset and Hibernate mapping compatibility. Avoid using this field directly.
*/
@Deprecated
@ManyToOne
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this required for migrating to JPA annotations?

@JoinColumn(name = "concept_id")
private Concept concept;

@Column(name = "original_text")
private String originalText;

@Column(name = "final_text")
private String finalText;

@Column(name = "state")
private String state;

@Column(name = "comments")
private String comments;

@ManyToOne
@JoinColumn(name = "creator")
private User creator;

@Column(name = "date_created")
private Date dateCreated;

@ManyToOne
@JoinColumn(name = "changed_by")
private User changedBy;

@Column(name = "date_changed")
private Date dateChanged;

// Constructors
Expand Down
23 changes: 11 additions & 12 deletions api/src/main/java/org/openmrs/api/impl/ConceptServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -814,44 +814,43 @@ public void purgeConceptProposal(ConceptProposal cp) throws APIException {
*/
@Override
public Concept mapConceptProposalToConcept(ConceptProposal cp, Concept mappedConcept, Locale locale) throws APIException {

if (cp.getState().equals(OpenmrsConstants.CONCEPT_PROPOSAL_REJECT)) {
cp.rejectConceptProposal();
cp.setState(OpenmrsConstants.CONCEPT_PROPOSAL_REJECT);
cp.setFinalText("");
Context.getConceptService().saveConceptProposal(cp);
return null;
}

if (mappedConcept == null) {
throw new APIException("Concept.mapped.illegal", (Object[]) null);
}

ConceptName conceptName = null;
if (cp.getState().equals(OpenmrsConstants.CONCEPT_PROPOSAL_CONCEPT) || StringUtils.isBlank(cp.getFinalText())) {
cp.setState(OpenmrsConstants.CONCEPT_PROPOSAL_CONCEPT);
cp.setFinalText("");
} else if (cp.getState().equals(OpenmrsConstants.CONCEPT_PROPOSAL_SYNONYM)) {

checkIfLocked();

String finalText = cp.getFinalText();
conceptName = new ConceptName(finalText, null);
conceptName.setConcept(mappedConcept);
conceptName.setLocale(locale == null ? Context.getLocale() : locale);
conceptName.setDateCreated(new Date());
conceptName.setCreator(Context.getAuthenticatedUser());
//If this is pre 1.9
// If this is pre 1.9
if (conceptName.getUuid() == null) {
conceptName.setUuid(UUID.randomUUID().toString());
}
mappedConcept.addName(conceptName);
mappedConcept.setChangedBy(Context.getAuthenticatedUser());
mappedConcept.setDateChanged(new Date());
ValidateUtil.validate(mappedConcept);
Context.getConceptService().saveConcept(mappedConcept);
Context.getConceptService().saveConcept(mappedConcept);
}

cp.setMappedConcept(mappedConcept);

if (cp.getObsConcept() != null) {
Obs ob = new Obs();
ob.setEncounter(cp.getEncounter());
Expand All @@ -868,10 +867,10 @@ public Concept mapConceptProposalToConcept(ConceptProposal cp, Concept mappedCon
if (ob.getUuid() == null) {
ob.setUuid(UUID.randomUUID().toString());
}
Context.getObsService().saveObs(ob, null);
Context.getObsService().saveObs(ob, null);
cp.setObs(ob);
}

return mappedConcept;
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<mapping resource="org/openmrs/api/db/hibernate/ConceptNameTag.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/ConceptClass.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/ConceptDatatype.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/ConceptProposal.hbm.xml" />
<mapping class="org.openmrs.ConceptProposal"/>
<mapping resource="org/openmrs/api/db/hibernate/ConceptStateConversion.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/ConceptSet.hbm.xml" />
<mapping resource="org/openmrs/api/db/hibernate/ConceptMap.hbm.xml" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,23 @@
<comment>Empty change set for integration tests.</comment>

</changeSet>


<!-- Add mapped_concept_id column and foreign key to concept_proposal -->
<changeSet id="add-mapped-concept-id-to-concept-proposal" author="snowvirus">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you get any errors if you do not include this changeset?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snowvirus did you see the above comment?

<addColumn tableName="concept_proposal">
<column name="mapped_concept_id" type="int"/>
</addColumn>

<addForeignKeyConstraint
baseTableName="concept_proposal"
baseColumnNames="mapped_concept_id"
constraintName="concept_proposal_mapped_concept_fk"
referencedTableName="concept"
referencedColumnNames="concept_id"
deferrable="false"
initiallyDeferred="false"
onDelete="SET NULL"/>
</changeSet>


</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class DatabaseUpdaterDatabaseIT extends DatabaseIT {
* This constant needs to be updated when adding new Liquibase update files to openmrs-core.
*/

private static final int CHANGE_SET_COUNT_FOR_GREATER_THAN_2_1_X = 900;
private static final int CHANGE_SET_COUNT_FOR_GREATER_THAN_2_1_X = 901;

private static final int CHANGE_SET_COUNT_FOR_2_1_X = 870;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
<concept_name concept_id="2" name="Some numeric concept name" locale="en" creator="1" date_created="2005-01-01 00:00:00.0" concept_name_id="2" concept_name_type="FULLY_SPECIFIED" locale_preferred="0" voided="false" uuid="d8402dab-1e32-4f17-9654-a889a4eb9a89"/>
<concept_name concept_id="2" name="Numeric name with en_GB locale" locale="en_GB" creator="1" date_created="2005-01-01 00:00:00.0" concept_name_id="3" locale_preferred="0" voided="false" uuid="bbbb2dab-1e32-4f17-a654-0000a4eb9a8e"/>
<concept_numeric concept_id="2" hi_absolute="123.0" allow_decimal="false"/>
<concept_proposal concept_proposal_id="1" original_text="mapped concept proposal" final_text="mapped concept proposal" obs_concept_id="1" mapped_concept_id="2" state="SOME_STATE" creator="1" date_created="2024-01-01 00:00:00.0" uuid="abcde12345-6789-0000-1111-222233334444"/>

</dataset>
Loading