-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changes for CWC Visit form change and changed ws-api dependency to 1.2
- Loading branch information
1 parent
ea53c46
commit 021cc51
Showing
13 changed files
with
436 additions
and
106 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
motech-server-core/src/main/java/org/motechproject/server/builder/ObsBuilder.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,74 @@ | ||
package org.motechproject.server.builder; | ||
|
||
import org.motechproject.server.model.ObsValueType; | ||
import org.openmrs.*; | ||
|
||
import java.util.Date; | ||
|
||
public class ObsBuilder { | ||
|
||
private Object value; | ||
private Concept concept; | ||
private Person person; | ||
private Encounter encounter; | ||
private Location location; | ||
private User recordedBy; | ||
private Date observationDate; | ||
private ObsValueType type; | ||
|
||
|
||
public ObsBuilder withValue(Object value) { | ||
this.value = value; | ||
return this; | ||
} | ||
|
||
public ObsBuilder withConcept(Concept concept) { | ||
this.concept = concept; | ||
return this; | ||
} | ||
|
||
public ObsBuilder withValueType(ObsValueType valueType) { | ||
this.type = valueType; | ||
return this; | ||
} | ||
|
||
public ObsBuilder forPerson(Person person) { | ||
this.person = person; | ||
return this; | ||
} | ||
|
||
public ObsBuilder against(Encounter encounter) { | ||
this.encounter = encounter; | ||
return this; | ||
} | ||
|
||
public ObsBuilder recordedOn(Date date) { | ||
this.observationDate = date; | ||
return this; | ||
} | ||
|
||
public ObsBuilder recordedAt(Location location) { | ||
this.location = location; | ||
return this; | ||
} | ||
|
||
public ObsBuilder recordedBy(User user) { | ||
this.recordedBy = user; | ||
return this; | ||
} | ||
|
||
public Obs done() { | ||
Obs obs = new Obs(); | ||
obs.setConcept(concept); | ||
obs.setObsDatetime(observationDate); | ||
obs.setPerson(person); | ||
obs.setLocation(location); | ||
if (encounter != null) { | ||
obs.setEncounter(encounter); | ||
} | ||
if (recordedBy != null) { | ||
obs.setCreator(recordedBy); | ||
} | ||
return type.setValue(obs,value); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
motech-server-core/src/main/java/org/motechproject/server/model/Immunizations.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,65 @@ | ||
package org.motechproject.server.model; | ||
|
||
import org.motechproject.server.builder.ObsBuilder; | ||
import org.motechproject.server.service.ConceptEnum; | ||
import org.openmrs.*; | ||
import org.openmrs.api.ConceptService; | ||
|
||
import java.util.Date; | ||
|
||
public enum Immunizations { | ||
|
||
BCG("bcg", ConceptEnum.CONCEPT_BCG_VACCINATION), | ||
YELLOW_FEVER("yellowfever", ConceptEnum.CONCEPT_YELLOW_FEVER_VACCINATION), | ||
MEASLES("measles", ConceptEnum.CONCEPT_MEASLES_VACCINATION), | ||
CSM("csm", ConceptEnum.CONCEPT_CEREBRO_SPINAL_MENINGITIS_VACCINATION), | ||
VITAMIN_A("vitamina", ConceptEnum.CONCEPT_VITAMIN_A), | ||
DEWORMER("dewormer", ObsValueType.BOOLEAN, ConceptEnum.CONCEPT_DEWORMER, null) { | ||
@Override | ||
public Object getValue(ConceptService conceptService) { | ||
return Boolean.TRUE; | ||
}}; | ||
|
||
|
||
private String key; | ||
private ObsValueType valueType; | ||
private ConceptEnum concept; | ||
private ConceptEnum valueConcept; | ||
|
||
private Immunizations(String key, ConceptEnum valueConcept) { | ||
this(key, ObsValueType.CODED, ConceptEnum.CONCEPT_IMMUNIZATIONS_ORDERED, valueConcept); | ||
} | ||
|
||
private Immunizations(String key, ObsValueType type, ConceptEnum concept, ConceptEnum valueConcept) { | ||
this.key = key; | ||
this.valueType = type; | ||
this.concept = concept; | ||
this.valueConcept = valueConcept; | ||
} | ||
|
||
public Obs obsWith(Date date, Patient patient, Location location, Encounter encounter, | ||
User user, ConceptService conceptService) { | ||
Obs obs = new ObsBuilder() | ||
.withValue(getValue(conceptService)) | ||
.withConcept(concept.getConcept(conceptService)) | ||
.withValueType(valueType) | ||
.forPerson(patient).against(encounter) | ||
.recordedOn(date).recordedBy(user).recordedAt(location) | ||
.done(); | ||
return obs; | ||
} | ||
|
||
public Object getValue(ConceptService conceptService) { | ||
return this.valueConcept.getConcept(conceptService); | ||
} | ||
|
||
|
||
public static Immunizations enumFor(String key) { | ||
for (Immunizations immunization : values()) { | ||
if (immunization.key.equals(key)) { | ||
return immunization; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
motech-server-core/src/main/java/org/motechproject/server/model/ObsValueType.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,42 @@ | ||
package org.motechproject.server.model; | ||
|
||
import org.openmrs.Concept; | ||
import org.openmrs.Obs; | ||
|
||
import java.util.Date; | ||
|
||
public enum ObsValueType { | ||
NUMERIC { | ||
@Override | ||
public Obs setValue(Obs obs, Object value) { | ||
obs.setValueNumeric((Double) value); | ||
return obs; | ||
}}, | ||
DATE { | ||
@Override | ||
public Obs setValue(Obs obs, Object value) { | ||
obs.setValueDatetime((Date) value); | ||
return obs; | ||
}}, | ||
CODED { | ||
@Override | ||
public Obs setValue(Obs obs, Object value) { | ||
obs.setValueCoded((Concept) value); | ||
return obs; | ||
}}, | ||
BOOLEAN { | ||
@Override | ||
public Obs setValue(Obs obs, Object value) { | ||
Boolean boolValue = (Boolean) value; | ||
Double numeric = Boolean.TRUE.equals(boolValue) ? new Double(1) : new Double(0); | ||
return NUMERIC.setValue(obs, numeric); | ||
}}, | ||
TEXT { | ||
@Override | ||
public Obs setValue(Obs obs, Object value) { | ||
obs.setValueText((String) value); | ||
return obs; | ||
}}; | ||
|
||
public abstract Obs setValue(Obs obs, Object value); | ||
} |
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
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
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
20 changes: 20 additions & 0 deletions
20
motech-server-core/src/test/java/org/motechproject/server/model/ImmunizationsTest.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,20 @@ | ||
package org.motechproject.server.model; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
|
||
public class ImmunizationsTest { | ||
|
||
@Test | ||
public void shouldGetEnumForKey() { | ||
assertEquals(Immunizations.BCG,Immunizations.enumFor("bcg")); | ||
assertEquals(Immunizations.YELLOW_FEVER,Immunizations.enumFor("yellowfever")); | ||
assertEquals(Immunizations.CSM,Immunizations.enumFor("csm")); | ||
assertEquals(Immunizations.MEASLES,Immunizations.enumFor("measles")); | ||
assertEquals(Immunizations.DEWORMER,Immunizations.enumFor("dewormer")); | ||
assertEquals(Immunizations.VITAMIN_A,Immunizations.enumFor("vitamina")); | ||
assertNull(Immunizations.enumFor("some random key")); | ||
} | ||
} |
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
Oops, something went wrong.